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

Joined arrays in ADIOS2 #1382

Merged
merged 13 commits into from
Feb 28, 2024
Merged

Joined arrays in ADIOS2 #1382

merged 13 commits into from
Feb 28, 2024

Conversation

franzpoeschel
Copy link
Contributor

@franzpoeschel franzpoeschel commented Feb 27, 2023

This implements ornladios/ADIOS2#3452 in openPMD and (partially) fixes #1374.

We will need a fallback implementation for backends other than ADIOS2. Quoting the discussion in #1374:

Since this feature is relevant for basically all parallel code that writes particles, we should (as a second step) implement this also in openPMD, so that those codes still stay compatible with HDF5.
Using MPI collectives to determine local block offsets inside the particle list is a really common pattern for using openPMD in such code, and this is a great chance to eliminate this pattern, while still staying compatible with all openPMD backends.

TODO

test/SerialIOTest.cpp Fixed Show fixed Hide fixed
@franzpoeschel franzpoeschel marked this pull request as ready for review February 28, 2023 16:48
@franzpoeschel franzpoeschel force-pushed the joined-arrays branch 2 times, most recently from d0d1e7a to 4d68621 Compare March 1, 2023 12:04
s.close();
}

TEST_CASE("joined_dim", "[serial]")

Check notice

Code scanning / CodeQL

Unused static function Note test

Static function C_A_T_C_H_T_E_S_T_88 is unreachable (
autoRegistrar89
must be removed at the same time)
@franzpoeschel franzpoeschel changed the title [WIP] Joined arrays in ADIOS2 Joined arrays in ADIOS2 Mar 3, 2023
@franzpoeschel
Copy link
Contributor Author

Except for the documentation, this is now somewhat ready.
I see one problem: With this, it's practically impossible to write the particlePatchesOffset as that is determined by ADIOS2 and we don't know it before it's written.

*/
for (size_t i = 0; i < length_of_patch * patches_per_rank; ++i)
{
REQUIRE(float(i) == particleData.get()[i]);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
for (size_t i = 0; i < patches_per_rank; ++i)
{
REQUIRE(length_of_patch * i == numParticlesOffset.get()[i]);
REQUIRE(type(length_of_patch * i) == patchOffset.get()[i]);

Check notice

Code scanning / CodeQL

Equality test on floating-point values Note test

Equality checks on floating point values can yield unexpected results.
@ax3l ax3l requested review from ax3l and guj March 7, 2023 18:41
}
}

TEST_CASE("joined_dim", "[serial]")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you mean "parallel"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, good catch

auto patchOffset = it.particles["e"].particlePatches["offset"]["x"];
auto patchExtent = it.particles["e"].particlePatches["extent"]["x"];
Dataset particlePatchesDS(determineDatatype<float>(), {0});
particlePatchesDS.joinedDimension = 0;
Copy link
Contributor

@guj guj Mar 9, 2023

Choose a reason for hiding this comment

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

Is a sanity check needed here? do we want to throw error if someone set an invalid value of joinedDimension?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will probably switch to the same API as ADIOS2, i.e. have some magic number JOINED_DIMENSION=std::numeric_limits<>::max and then use something like Dataset ds(<type>, {JOINED_DIMENSION, 128 , 128}). We should add a sanity check there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The constructor of Dataset now verifies this.

Copy link
Contributor Author

@franzpoeschel franzpoeschel left a comment

Choose a reason for hiding this comment

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

see inline comments

template <typename T>
void verifyChunk(Offset const &, Extent const &) const;

void verifyChunk(Datatype, Offset const &, Extent const &) const;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Earlier versions of this PR added additional calls to RecordComponent::storeChunk, so instead of duplicating the verification logic, I extracted it.
Now no longer necessary, but it's still a useful refactoring.

@ax3l ax3l added this to the 0.16.0 milestone May 9, 2023
@ax3l ax3l self-assigned this Jul 25, 2023
@@ -397,7 +376,7 @@
} // namespace detail

template <typename Visitor, typename... Args>
constexpr auto RecordComponent::visit(Args &&...args)
auto RecordComponent::visit(Args &&...args)

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable args is not used.

void markActive(Writable *);

// bool isActive(std::string const & path);

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
@franzpoeschel franzpoeschel force-pushed the joined-arrays branch 4 times, most recently from 23ff8e6 to c13c20e Compare January 23, 2024 16:58
@ax3l
Copy link
Member

ax3l commented Jan 30, 2024

This looks great! Potentially can you add a Python test, to make sure the new enum exposed to the bindings works well?

@franzpoeschel franzpoeschel force-pushed the joined-arrays branch 2 times, most recently from 793576d to ce51f2a Compare February 6, 2024 14:33
extent.at(curAxis) =
undo_mocked_extent && slicelength == PYTHON_JOINED_DIMENSION
? Dataset::JOINED_DIMENSION
: slicelength; // stop - start;

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

Looks great!!


(Currently) only supported in ADIOS2 no older than v2.9.0 under the conditions listed in the `ADIOS2 documentation on joined arrays <https://adios2.readthedocs.io/en/latest/components/components.html#shapes>`_.

In some cases, the concrete chunk within a dataset does not matter and the computation of indexes is a needless computational and mental overhead.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
In some cases, the concrete chunk within a dataset does not matter and the computation of indexes is a needless computational and mental overhead.
In some cases, the concrete chunk within a dataset does not matter and the computation of indexes is a needless computational, (MPI) communication and mental overhead.

Comment on lines +80 to +85
if USE_JOINED_DIMENSION:
# explicit API
# mymesh.store_chunk(local_data, [], [10, 300])
mymesh[:, :] = local_data
# or short:
# mymesh[()] = local_data
Copy link
Member

Choose a reason for hiding this comment

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

Fancy!
Good examples even in the commented code.

@ax3l ax3l merged commit 5fec415 into openPMD:dev Feb 28, 2024
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: new additions to the API backend: ADIOS2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Particles: Support Auto-Shape Counting
3 participants