Skip to content

Commit 53bdf60

Browse files
committed
Properly distinguish flush modi in tests
1 parent c1a5871 commit 53bdf60

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

include/openPMD/Series.hpp

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

792+
[[nodiscard]] bool flushImmediately() const;
793+
792794
// clang-format off
793795
OPENPMD_private
794796
// clang-format on

src/Series.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3549,6 +3549,16 @@ void Series::close()
35493549
m_attri.reset();
35503550
}
35513551

3552+
bool Series::flushImmediately() const
3553+
{
3554+
auto ioHandler = IOHandler();
3555+
if (!ioHandler)
3556+
{
3557+
return false;
3558+
}
3559+
return ioHandler->m_flush_immediately;
3560+
}
3561+
35523562
auto Series::currentSnapshot() -> std::optional<std::vector<IterationIndex_t>>
35533563
{
35543564
using vec_t = std::vector<IterationIndex_t>;

test/Files_ParallelIO/bug_1655_bp5_writer_hangup.cpp

Lines changed: 5 additions & 0 deletions
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

test/ParallelIOTest.cpp

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

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

924939
chunk_assignment::RankMeta compare;

test/SerialIOTest.cpp

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

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

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

43554355
{
43564356
auto component =
@@ -4387,8 +4387,16 @@ void adios2_bp5_flush(std::string const &cfg, FlushDuringStep flushDuringStep)
43874387
if (flushDuringStep == FlushDuringStep::Default_Yes ||
43884388
flushDuringStep == FlushDuringStep::Always)
43894389
{
4390-
// should still be roughly within 1% of 4Mb
4391-
REQUIRE(std::abs(1 - double(currentSize) / (4 * size)) <= 0.01);
4390+
if (flushImmediately)
4391+
{
4392+
// should still be roughly within 1% of 8Mb
4393+
REQUIRE(std::abs(1 - double(currentSize) / (8 * size)) <= 0.01);
4394+
}
4395+
else
4396+
{
4397+
// should still be roughly within 1% of 4Mb
4398+
REQUIRE(std::abs(1 - double(currentSize) / (4 * size)) <= 0.01);
4399+
}
43924400
}
43934401
else
43944402
{
@@ -4428,8 +4436,17 @@ void adios2_bp5_flush(std::string const &cfg, FlushDuringStep flushDuringStep)
44284436
}
44294437
else if (flushDuringStep == FlushDuringStep::Default_Yes)
44304438
{
4431-
// should now be roughly within 1% of 8Mb
4432-
REQUIRE(std::abs(1 - double(currentSize) / (8 * size)) <= 0.01);
4439+
if (flushImmediately)
4440+
{
4441+
// should now be roughly within 1% of 12Mb
4442+
REQUIRE(
4443+
std::abs(1 - double(currentSize) / (12 * size)) <= 0.01);
4444+
}
4445+
else
4446+
{
4447+
// should now be roughly within 1% of 8Mb
4448+
REQUIRE(std::abs(1 - double(currentSize) / (8 * size)) <= 0.01);
4449+
}
44334450
}
44344451
else
44354452
{

0 commit comments

Comments
 (0)