Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
Only test if ADIOS2 version at least 2.9
  • Loading branch information
franzpoeschel committed Apr 25, 2023
1 parent bfdb74b commit 64b9a73
Show file tree
Hide file tree
Showing 2 changed files with 334 additions and 34 deletions.
156 changes: 156 additions & 0 deletions test/ParallelIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1766,4 +1766,160 @@ TEST_CASE("unavailable_backend", "[core][parallel]")
}
#endif
}

void joined_dim(std::string const &ext)
{
using type = float;
using patchType = uint64_t;
constexpr size_t patches_per_rank = 5;
constexpr size_t length_of_patch = 10;

int size{-1};
int rank{-1};
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

{
Series s(
"../samples/joinedDimParallel." + ext,
Access::CREATE,
MPI_COMM_WORLD);
std::vector<UniquePtrWithLambda<type>> writeFrom(patches_per_rank);

auto it = s.writeIterations()[100];

Dataset numParticlesDS(
determineDatatype<patchType>(), {Dataset::JOINED_DIMENSION});
auto numParticles =
it.particles["e"]
.particlePatches["numParticles"][RecordComponent::SCALAR];
auto numParticlesOffset =
it.particles["e"]
.particlePatches["numParticlesOffset"][RecordComponent::SCALAR];
numParticles.resetDataset(numParticlesDS);
numParticlesOffset.resetDataset(numParticlesDS);

auto patchOffset = it.particles["e"].particlePatches["offset"]["x"];
auto patchExtent = it.particles["e"].particlePatches["extent"]["x"];
Dataset particlePatchesDS(
determineDatatype<float>(), {Dataset::JOINED_DIMENSION});
patchOffset.resetDataset(particlePatchesDS);
patchExtent.resetDataset(particlePatchesDS);

float start_value = rank * patches_per_rank * length_of_patch;
for (size_t i = 0; i < 5; ++i)
{
writeFrom[i] = UniquePtrWithLambda<type>(
new type[length_of_patch],
[](auto const *ptr) { delete[] ptr; });
std::iota(
writeFrom[i].get(),
writeFrom[i].get() + 10,
start_value + length_of_patch * i);
patchOffset.store<type>(start_value + length_of_patch * i);
}

auto epx = it.particles["e"]["position"]["x"];
Dataset ds(determineDatatype<type>(), {Dataset::JOINED_DIMENSION});
epx.resetDataset(ds);

size_t counter = 0;
for (auto &chunk : writeFrom)
{
epx.storeChunk(std::move(chunk), {}, {length_of_patch});
numParticles.store<patchType>(length_of_patch);
/*
* For the sake of the test case, we know that the
* numParticlesOffset has this value. In general, the purpose of the
* joined array is that we don't need to know these values, so the
* specification of particle patches is somewhat difficult.
*/
numParticlesOffset.store<patchType>(
start_value + counter++ * length_of_patch);
patchExtent.store<type>(10);
}
writeFrom.clear();
it.close();
s.close();
}

{
Series s(
"../samples/joinedDimParallel." + ext,
Access::READ_ONLY,
MPI_COMM_WORLD);
auto it = s.iterations[100];
auto e = it.particles["e"];

auto particleData = e["position"]["x"].loadChunk<type>();
auto numParticles =
e.particlePatches["numParticles"][RecordComponent::SCALAR]
.load<patchType>();
auto numParticlesOffset =
e.particlePatches["numParticlesOffset"][RecordComponent::SCALAR]
.load<patchType>();
auto patchOffset = e.particlePatches["offset"]["x"].load<type>();
auto patchExtent = e.particlePatches["extent"]["x"].load<type>();

it.close();

// check validity of particle patches
auto numPatches =
e.particlePatches["numParticlesOffset"][RecordComponent::SCALAR]
.getExtent()[0];
REQUIRE(
e.particlePatches["numParticles"][RecordComponent::SCALAR]
.getExtent()[0] == numPatches);
for (size_t i = 0; i < numPatches; ++i)
{
for (size_t j = 0; j < numParticles.get()[i]; ++j)
{
REQUIRE(
patchOffset.get()[i] <=
particleData.get()[numParticlesOffset.get()[i] + j]);
REQUIRE(
particleData.get()[numParticlesOffset.get()[i] + j] <
patchOffset.get()[i] + patchExtent.get()[i]);
}
}

/*
* Check that joined array joins early writes before later writes from
* the same rank
*/
for (size_t i = 0; i < size * length_of_patch * patches_per_rank; ++i)
{
REQUIRE(float(i) == particleData.get()[i]);
}
for (size_t i = 0; i < size * patches_per_rank; ++i)
{
REQUIRE(length_of_patch * i == numParticlesOffset.get()[i]);
REQUIRE(type(length_of_patch * i) == patchOffset.get()[i]);
}
}
}

TEST_CASE("joined_dim", "[parallel]")
{
#if 100000000 * ADIOS2_VERSION_MAJOR + 1000000 * ADIOS2_VERSION_MINOR + \
10000 * ADIOS2_VERSION_PATCH + 100 * ADIOS2_VERSION_TWEAK >= \
209000000
constexpr char const *supportsJoinedDims[] = {"bp", "bp4", "bp5"};
#else
// no zero-size arrays
std::vector<char const *> supportsJoinedDims;
#endif
for (auto const &t : testedFileExtensions())
{
for (auto const supported : supportsJoinedDims)
{
if (t == supported)
{
joined_dim(t);
break;
}
}
}
}

#endif // openPMD_HAVE_ADIOS2 && openPMD_HAVE_MPI
Loading

0 comments on commit 64b9a73

Please sign in to comment.