Skip to content

Commit 41b73c2

Browse files
committed
Do not read rankTable in file encoding
1 parent 9639713 commit 41b73c2

4 files changed

Lines changed: 54 additions & 16 deletions

File tree

include/openPMD/Series.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,18 @@ class Series : public Attributable
457457
*/
458458
Series &setMeshesPath(std::string const &meshesPath);
459459

460+
/**
461+
* @return True if there is a rankTable dataset defined for this Series.
462+
* False in write-only access modes.
463+
* Will indiscriminately return false in file encoding:
464+
* rankTable is not explicitly supported in file encoding,
465+
* finding out if one is defined would require opening all available
466+
* files. You may still call Series::rankTable() to retrieve the
467+
* rank table if you know that there is one, but note that it will
468+
* return the rank table from the file that was last opened.
469+
*/
470+
bool hasRankTableRead();
471+
460472
/**
461473
* @throw no_such_attribute_error If optional attribute is not present.
462474
* @param collective Run this read operation collectively.
@@ -1008,6 +1020,8 @@ OPENPMD_private
10081020
* steps?
10091021
*/
10101022
[[nodiscard]] bool randomAccessSteps() const;
1023+
1024+
std::vector<std::string> availableDatasets();
10111025
}; // Series
10121026

10131027
namespace debug

src/Series.cpp

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,38 @@ Series &Series::setMeshesPath(std::string const &mp)
215215
return *this;
216216
}
217217

218+
std::vector<std::string> Series::availableDatasets()
219+
{
220+
if (iterationEncoding() == IterationEncoding::variableBased &&
221+
IOHandler()->m_backendAccess == Access::READ_RANDOM_ACCESS)
222+
{
223+
Parameter<Operation::ADVANCE> advance;
224+
advance.mode =
225+
Parameter<Operation::ADVANCE>::StepSelection{std::nullopt};
226+
IOHandler()->enqueue(IOTask(this, std::move(advance)));
227+
}
228+
Parameter<Operation::LIST_DATASETS> listDatasets;
229+
IOHandler()->enqueue(IOTask(this, listDatasets));
230+
IOHandler()->flush(internal::defaultFlushParams);
231+
return std::move(*listDatasets.datasets);
232+
}
233+
234+
bool Series::hasRankTableRead()
235+
{
236+
if (access::writeOnly(IOHandler()->m_frontendAccess))
237+
{
238+
return false;
239+
}
240+
auto &series = get();
241+
if (series.m_rankTable.m_bufferedRead.has_value())
242+
{
243+
return true;
244+
}
245+
auto datasets = availableDatasets();
246+
return std::find(datasets.begin(), datasets.end(), "rankTable") !=
247+
datasets.end();
248+
}
249+
218250
#if openPMD_HAVE_MPI
219251
chunk_assignment::RankMeta Series::rankTable(bool collective)
220252
#else
@@ -245,21 +277,9 @@ chunk_assignment::RankMeta Series::rankTable([[maybe_unused]] bool collective)
245277
IOHandler()->enqueue(IOTask(this, openFile));
246278
#endif
247279
}
248-
if (iterationEncoding() == IterationEncoding::variableBased &&
249-
IOHandler()->m_backendAccess == Access::READ_RANDOM_ACCESS)
250-
{
251-
Parameter<Operation::ADVANCE> advance;
252-
advance.mode =
253-
Parameter<Operation::ADVANCE>::StepSelection{std::nullopt};
254-
IOHandler()->enqueue(IOTask(this, std::move(advance)));
255-
}
256-
Parameter<Operation::LIST_DATASETS> listDatasets;
257-
IOHandler()->enqueue(IOTask(this, listDatasets));
258-
IOHandler()->flush(internal::defaultFlushParams);
259-
if (std::none_of(
260-
listDatasets.datasets->begin(),
261-
listDatasets.datasets->end(),
262-
[](std::string const &str) { return str == "rankTable"; }))
280+
auto datasets = availableDatasets();
281+
if (std::find(datasets.begin(), datasets.end(), "rankTable") ==
282+
datasets.end())
263283
{
264284
rankTable.m_bufferedRead = chunk_assignment::RankMeta{};
265285
return {};

src/binding/python/Series.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ this method.
442442
.def_property("base_path", &Series::basePath, &Series::setBasePath)
443443
.def_property(
444444
"meshes_path", &Series::meshesPath, &Series::setMeshesPath)
445+
.def_property_readonly("has_rank_table_read", &Series::hasRankTableRead)
445446
.def("get_rank_table", &Series::rankTable, py::arg("collective"))
446447
.def("set_rank_table", &Series::setRankTable, py::arg("my_rank_info"))
447448
.def_property(

src/binding/python/openpmd_api/pipe/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,10 @@ def __copy(self, src, dest, current_path="/data/"):
401401
print("\t {0}".format(r))
402402
# With linear read mode, we can only load the source rank table
403403
# inside `read_iterations()` since it's a dataset.
404-
self.inranks = src.get_rank_table(collective=True)
404+
if src.has_rank_table_read:
405+
self.inranks = src.get_rank_table(collective=True)
406+
else:
407+
self.inranks = {}
405408
out_iteration = write_iterations[in_iteration.iteration_index]
406409
sys.stdout.flush()
407410
self.__copy(

0 commit comments

Comments
 (0)