Skip to content

Commit

Permalink
Reset steps before reading the rankTable
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jan 14, 2025
1 parent d5ca329 commit 82eea7a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/openPMD/IO/ADIOS/ADIOS2File.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ class ADIOS2File
StreamStatus streamStatus = StreamStatus::OutsideOfStep;

size_t currentStep();
void setStepSelection(size_t);
void setStepSelection(std::optional<size_t>);
[[nodiscard]] std::optional<size_t> stepSelection() const;

private:
Expand Down
2 changes: 1 addition & 1 deletion include/openPMD/IO/IOTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ struct OPENPMDAPI_EXPORT Parameter<Operation::ADVANCE>

struct StepSelection
{
size_t step;
std::optional<size_t> step;
};

//! input parameter
Expand Down
14 changes: 11 additions & 3 deletions src/IO/ADIOS/ADIOS2File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,24 @@ size_t ADIOS2File::currentStep()
}
}

void ADIOS2File::setStepSelection(size_t step)
void ADIOS2File::setStepSelection(std::optional<size_t> step)
{
if (streamStatus != StreamStatus::ReadWithoutStream)
{
throw error::Internal(
"ADIOS2 backend: Cannot only use random-access step selections "
"when reading without streaming mode.");
}
m_currentStep = step;
useStepSelection = true;
if (!step.has_value())
{
m_currentStep = 0;
useStepSelection = false;
}
else
{
m_currentStep = *step;
useStepSelection = true;
}
}

std::optional<size_t> ADIOS2File::stepSelection() const
Expand Down
6 changes: 5 additions & 1 deletion src/IO/AbstractIOHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,11 @@ std::future<void> AbstractIOHandlerImpl::flush()
[](Parameter<Operation::ADVANCE>::StepSelection
step) {
std::stringstream s;
s << "RANDOMACCESS '" << step.step << "'";
s << "RANDOMACCESS '"
<< (step.step.has_value()
? std::to_string(*step.step)
: std::string("RESET"))
<< "'";
return s.str();
}},
parameter.mode);
Expand Down
8 changes: 8 additions & 0 deletions src/Series.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ chunk_assignment::RankMeta Series::rankTable([[maybe_unused]] bool collective)
rankTable.m_bufferedRead = chunk_assignment::RankMeta{};
return {};
}
if (iterationEncoding() == IterationEncoding::variableBased &&
IOHandler()->m_backendAccess == Access::READ_RANDOM_ACCESS)
{
Parameter<Operation::ADVANCE> advance;
advance.mode =
Parameter<Operation::ADVANCE>::StepSelection{std::nullopt};
IOHandler()->enqueue(IOTask(this, std::move(advance)));
}
Parameter<Operation::OPEN_DATASET> openDataset;
openDataset.name = "rankTable";
IOHandler()->enqueue(IOTask(&rankTable.m_attributable, openDataset));
Expand Down
9 changes: 8 additions & 1 deletion test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5246,7 +5246,8 @@ void serial_iterator(std::string const &file)
{
constexpr Extent::value_type extent = 1000;
{
Series writeSeries(file, Access::CREATE);
Series writeSeries(
file, Access::CREATE, "rank_table = \"posix_hostname\"");
auto iterations = writeSeries.writeIterations();
for (size_t i = 0; i < 10; ++i)
{
Expand Down Expand Up @@ -5277,6 +5278,12 @@ void serial_iterator(std::string const &file)
}
last_iteration_index = iteration.iterationIndex;
}
if (readSeries.iterationEncoding() == IterationEncoding::variableBased)
for (auto const &[rank, host] : readSeries.rankTable(true))
{
std::cout << "POST Rank '" << rank << "' written from host '"
<< host << "'\n";
}
REQUIRE(last_iteration_index == 9);
REQUIRE(numberOfIterations == 10);
}
Expand Down

0 comments on commit 82eea7a

Please sign in to comment.