Skip to content

Commit 94bbb7e

Browse files
committed
Properly distinguish flush modi in tests
1 parent 6de90f6 commit 94bbb7e

5 files changed

Lines changed: 59 additions & 9 deletions

File tree

include/openPMD/Series.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,8 @@ class Series : public Attributable
796796
"Cannot call this on an instance of Series.");
797797
}
798798

799+
[[nodiscard]] bool flushImmediately() const;
800+
799801
// clang-format off
800802
OPENPMD_private
801803
// clang-format on

src/Series.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3559,6 +3559,16 @@ void Series::close()
35593559
m_attri.reset();
35603560
}
35613561

3562+
bool Series::flushImmediately() const
3563+
{
3564+
auto ioHandler = IOHandler();
3565+
if (!ioHandler)
3566+
{
3567+
return false;
3568+
}
3569+
return ioHandler->m_flush_immediately;
3570+
}
3571+
35623572
auto Series::currentSnapshot() -> std::optional<std::vector<IterationIndex_t>>
35633573
{
35643574
using vec_t = std::vector<IterationIndex_t>;

test/Files_ParallelIO/bug_1655_bp5_writer_hangup.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ auto worker(std::string const &ext) -> void
3939
std::string filename = "../samples/ptl_%T." + ext;
4040

4141
Series series = Series(filename, Access::CREATE_LINEAR, MPI_COMM_WORLD);
42+
if (series.flushImmediately())
43+
{
44+
// Cannot run this test in immediate flush mode
45+
return;
46+
}
4247

4348
Datatype datatype = determineDatatype<float>();
4449

@@ -49,7 +54,7 @@ auto worker(std::string const &ext) -> void
4954

5055
series.flush();
5156

52-
if (false && mpi_rank == 0) // only rank 0 adds data
57+
if (mpi_rank == 0) // only rank 0 adds data
5358
myptl["charge"].storeChunk(local_data, {0}, {3000});
5459

5560
series.flush(); // hangs here

test/ParallelIOTest.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void write_test_zero_extent(
148148
Access::CREATE_LINEAR,
149149
MPI_COMM_WORLD);
150150

151-
if (!writeAllChunks)
151+
if (o.flushImmediately() && !writeAllChunks)
152152
{
153153
// immediate flushing makes storeChunk collective, cannot do this
154154
return;
@@ -918,8 +918,24 @@ void close_iteration_test(std::string const &file_ending)
918918
REQUIRE(data[i % 4] == chunk.get()[i]);
919919
}
920920
// Cannot write/read chunks to/from closed Iterations.
921-
// auto read_again = E_x_read.loadChunk<int>({0, 0}, {mpi_size, 4});
922-
// REQUIRE_THROWS(read.flush());
921+
if (read.flushImmediately())
922+
{
923+
#if openPMD_USE_INVASIVE_TESTS
924+
REQUIRE_THROWS_WITH(
925+
E_x_read.loadChunk<int>({0, 0}, {mpi_size, 4}),
926+
"Cannot write/read chunks to/from closed Iterations.");
927+
#else
928+
REQUIRE_THROWS_WITH(
929+
E_x_read.loadChunk<int>({0, 0}, {mpi_size, 4}),
930+
"Wrong API usage: [Series] Closed iteration (idx=1) must be "
931+
"open()ed explicitly before interacting with it again.");
932+
#endif
933+
}
934+
else
935+
{
936+
auto read_again = E_x_read.loadChunk<int>({0, 0}, {mpi_size, 4});
937+
// REQUIRE_THROWS(read.flush());
938+
}
923939
}
924940

925941
chunk_assignment::RankMeta compare;

test/SerialIOTest.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4307,7 +4307,6 @@ enum class FlushDuringStep : std::uint8_t
43074307

43084308
void adios2_bp5_flush(std::string const &cfg, FlushDuringStep flushDuringStep)
43094309
{
4310-
return;
43114310
constexpr size_t size = size_t(1024) * 1024;
43124311

43134312
auto getsize = []() {
@@ -4352,6 +4351,7 @@ void adios2_bp5_flush(std::string const &cfg, FlushDuringStep flushDuringStep)
43524351
Datatype dtype = determineDatatype<int32_t>();
43534352
{
43544353
Series write("../samples/bp5_flush.bp", Access::CREATE_LINEAR, cfg);
4354+
bool flushImmediately = write.flushImmediately();
43554355

43564356
{
43574357
auto component =
@@ -4388,8 +4388,16 @@ void adios2_bp5_flush(std::string const &cfg, FlushDuringStep flushDuringStep)
43884388
if (flushDuringStep == FlushDuringStep::Default_Yes ||
43894389
flushDuringStep == FlushDuringStep::Always)
43904390
{
4391-
// should still be roughly within 1% of 4Mb
4392-
REQUIRE(std::abs(1 - double(currentSize) / (4 * size)) <= 0.01);
4391+
if (flushImmediately)
4392+
{
4393+
// should still be roughly within 1% of 8Mb
4394+
REQUIRE(std::abs(1 - double(currentSize) / (8 * size)) <= 0.01);
4395+
}
4396+
else
4397+
{
4398+
// should still be roughly within 1% of 4Mb
4399+
REQUIRE(std::abs(1 - double(currentSize) / (4 * size)) <= 0.01);
4400+
}
43934401
}
43944402
else
43954403
{
@@ -4429,8 +4437,17 @@ void adios2_bp5_flush(std::string const &cfg, FlushDuringStep flushDuringStep)
44294437
}
44304438
else if (flushDuringStep == FlushDuringStep::Default_Yes)
44314439
{
4432-
// should now be roughly within 1% of 8Mb
4433-
REQUIRE(std::abs(1 - double(currentSize) / (8 * size)) <= 0.01);
4440+
if (flushImmediately)
4441+
{
4442+
// should now be roughly within 1% of 12Mb
4443+
REQUIRE(
4444+
std::abs(1 - double(currentSize) / (12 * size)) <= 0.01);
4445+
}
4446+
else
4447+
{
4448+
// should now be roughly within 1% of 8Mb
4449+
REQUIRE(std::abs(1 - double(currentSize) / (8 * size)) <= 0.01);
4450+
}
44344451
}
44354452
else
44364453
{

0 commit comments

Comments
 (0)