Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a simple indexed loop #329

Merged
merged 1 commit into from
Nov 23, 2024
Merged

Use a simple indexed loop #329

merged 1 commit into from
Nov 23, 2024

Conversation

chiphogg
Copy link
Contributor

Apparently, some platforms struggle with range-based for loops on
C-style arrays. Other platforms don't seem to like the C-style array at
all, so we're trying a std::array. You'd think we'd be able to use
range-for with this... but, no, begin isn't constexpr until C++17,
so we're using an indexed loop anyways.

Tested on the Aurora-internal code that revealed the problem.

Follow-up for #217.

Apparently, some platforms struggle with range-based `for` loops on
C-style arrays.  Other platforms don't seem to like the C-style array at
all, so we're trying a `std::array`.  You'd think we'd be able to use
range-for with this... but, no, `begin` isn't `constexpr` until C++17,
so we're using an indexed loop anyways.

Follow-up for #217.
@chiphogg chiphogg added the release notes: 🐛 lib (bugfix) PR fixing a defect in the library code label Nov 23, 2024
@chiphogg chiphogg requested a review from geoffviola November 23, 2024 03:27
@chiphogg chiphogg merged commit a1a451c into main Nov 23, 2024
13 checks passed
@chiphogg chiphogg deleted the chiphogg/range-for#217 branch November 23, 2024 13:47
// First, do trial division against the first N primes.
for (const auto &p : first_primes) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Which compiler didn't support C-Style arrays? It seems OK for clang and gcc: godbolt.

std::array is generally recommended per the cppcoreguidelines. But I don't like that the length has to be specified in C++14. It doesn't in C++17 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! I slacked you the (Aurora-internal) build log. I think it was NvccCompile choking on the particular way that we were using the array. It was complaining about an incomplete type, but I didn't want to mess with it and decided to just try using std::array instead. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes: 🐛 lib (bugfix) PR fixing a defect in the library code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants