Skip to content

Commit e509ed6

Browse files
committed
Add BlocksOfSourceRanks strategy
1 parent adbdfaa commit e509ed6

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

include/openPMD/ChunkInfo.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,22 @@ namespace chunk_assignment
251251
[[nodiscard]] std::unique_ptr<Strategy> clone() const override;
252252
};
253253

254+
struct BlocksOfSourceRanks : Strategy
255+
{
256+
private:
257+
unsigned int mpi_size, mpi_rank;
258+
259+
public:
260+
BlocksOfSourceRanks(unsigned int mpi_rank, unsigned int mpi_size);
261+
262+
Assignment assign(
263+
PartialAssignment,
264+
RankMeta const &in,
265+
RankMeta const &out) override;
266+
267+
[[nodiscard]] std::unique_ptr<Strategy> clone() const override;
268+
};
269+
254270
/**
255271
* @brief Strategy that assigns chunks to be read by processes within
256272
* the same host that produced the chunk.

src/ChunkInfo.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,47 @@ namespace chunk_assignment
361361
return std::unique_ptr<Strategy>(new Blocks(*this));
362362
}
363363

364+
BlocksOfSourceRanks::BlocksOfSourceRanks(
365+
unsigned int mpi_rank_in, unsigned int mpi_size_in)
366+
: mpi_size(mpi_size_in), mpi_rank(mpi_rank_in)
367+
{}
368+
369+
Assignment BlocksOfSourceRanks::assign(
370+
PartialAssignment pa, RankMeta const &, RankMeta const &)
371+
{
372+
auto [notAssigned, res] = std::move(pa);
373+
std::map<unsigned int, std::deque<WrittenChunkInfo>>
374+
sortSourceChunksBySourceRank;
375+
for (auto &chunk : notAssigned)
376+
{
377+
auto sourceID = chunk.sourceID;
378+
sortSourceChunksBySourceRank[sourceID].push_back(std::move(chunk));
379+
}
380+
notAssigned.clear();
381+
auto [myChunksFrom, myChunksTo] =
382+
OneDimensionalBlockSlicer::n_th_block_inside(
383+
sortSourceChunksBySourceRank.size(), mpi_rank, mpi_size);
384+
auto it = sortSourceChunksBySourceRank.begin();
385+
for (size_t i = 0; i < myChunksFrom; ++i)
386+
{
387+
++it;
388+
}
389+
for (size_t i = 0; i < myChunksTo; ++i, ++it)
390+
{
391+
std::transform(
392+
it->second.begin(),
393+
it->second.end(),
394+
std::back_inserter(res[mpi_rank]),
395+
[](WrittenChunkInfo &chunk) { return std::move(chunk); });
396+
}
397+
return res;
398+
}
399+
400+
std::unique_ptr<Strategy> BlocksOfSourceRanks::clone() const
401+
{
402+
return std::unique_ptr<Strategy>(new BlocksOfSourceRanks(*this));
403+
}
404+
364405
ByHostname::ByHostname(std::unique_ptr<Strategy> withinNode)
365406
: m_withinNode(std::move(withinNode))
366407
{}

src/binding/python/ChunkInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ void init_Chunk(py::module &m)
305305
py::init<unsigned int, unsigned int>(),
306306
py::arg("mpi_rank"),
307307
py::arg("mpi_size"));
308+
py::class_<BlocksOfSourceRanks, Strategy>(m, "BlocksOfSourceRanks")
309+
.def(
310+
py::init<unsigned int, unsigned int>(),
311+
py::arg("mpi_rank"),
312+
py::arg("mpi_size"));
308313

309314
py::class_<ByHostname, PartialStrategy>(m, "ByHostname")
310315
.def(

test/ParallelIOTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,6 +2460,14 @@ void adios2_chunk_distribution()
24602460
auto blocksAssignment = blocksStrategy.assign(
24612461
chunkTable, rankMetaIn, readingRanksHostnames);
24622462
printAssignment("BLOCKS", blocksAssignment, readingRanksHostnames);
2463+
2464+
BlocksOfSourceRanks blocksOfSourceRanksStrategy(mpi_rank, mpi_size);
2465+
auto blocksOfSourceRanksAssignment = blocksOfSourceRanksStrategy.assign(
2466+
chunkTable, rankMetaIn, readingRanksHostnames);
2467+
printAssignment(
2468+
"BLOCKS OF SOURCE RANKS",
2469+
blocksOfSourceRanksAssignment,
2470+
readingRanksHostnames);
24632471
}
24642472
}
24652473

0 commit comments

Comments
 (0)