Skip to content

Use for sizes#1331

Open
pgrete wants to merge 1 commit intodevelopfrom
pgrete/size_t-for-size
Open

Use for sizes#1331
pgrete wants to merge 1 commit intodevelopfrom
pgrete/size_t-for-size

Conversation

@pgrete
Copy link
Collaborator

@pgrete pgrete commented Oct 22, 2025

PR Summary

I ran into an issues when trying to write a conserved variable vector for a 16384^3 mesh (turns out it was more related to the local mesh size rather than the total).
This motivated going a little more through the code base and fix some type mismatches.
There are still plenty left (which should be addressed in the context of #175) .

PR Checklist

  • Code passes cpplint
  • New features are documented.
  • Adds a test for any bugs fixed. Adds tests for new features.
  • Code is formatted
  • Changes are summarized in CHANGELOG.md
  • Change is breaking (API, behavior, ...)
    • Change is additionally added to CHANGELOG.md in the breaking section
    • PR is marked as breaking
    • Short summary API changes at the top of the PR (plus optionally with an automated update/fix script)
  • CI has been triggered on Darwin for performance regression tests.
  • Docs build
  • (@lanl.gov employees) Update copyright on changed files

Comment on lines -78 to +82
int Size() const;
size_t Size() const;
// Includes topological element shape
int TensorSize() const;
size_t TensorSize() const;
// Size of region that needs to be filled with 0s if not allocated
int FillSize(const IndexDomain domain) const;
size_t FillSize(const IndexDomain domain) const;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Those ints were the original issue.

Those propagated into the openpmd output for calculating the size of the output buffer vector and resulted in an overflow when multiplied by the number of local blocks.
Note, the hdf5 output is fine as the results from these calls are directly being put into a size_t variable.

Copy link
Collaborator

@Yurlungur Yurlungur left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! This is long overdue.

I think we should use std::size_t instead of size_t just for clarity/C++ consistency.

Comment on lines +864 to +870
PARTHENON_REQUIRE_THROWS(
nbtotal < std::numeric_limits<int>::max(),
"Congratulations. You're the first one to run a simulation with more blocks than "
"max `int`. Many loops in parthenon still use `int` indices over blocks or use "
"`int` for pack indices and partitions, so who knows what happens next. Please get "
"in contact with the dev team before proceeding (or proceed on your own risk and "
"remove this statement).");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hah. Good error message.

Copy link
Collaborator

@lroberts36 lroberts36 left a comment

Choose a reason for hiding this comment

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

Thanks for going through and fixing all these, I know I am guilty of using int in place of size_t in many places!

Comment on lines +137 to +143
const auto rank = shape.size();
const bool is_vector = m.IsSet(Metadata::Vector);
std::size_t total_count = count;
for (int i = 0; i < CHUNK_MAX_DIM; ++i) {
h5_offset[i] = h5_count[i] = 0;
}
for (int i = 0; i < rank; ++i) {
for (auto i = 0; i < rank; ++i) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why auto here instead of size_t?

@@ -102,7 +102,7 @@ struct var_base_t {
KOKKOS_INLINE_FUNCTION
static int ndim() { return sizeof...(NCOMP); }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
static int ndim() { return sizeof...(NCOMP); }
static size_t ndim() { return sizeof...(NCOMP); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants