From f514b70b4e3be2240d031fceb44ce11052422a1c Mon Sep 17 00:00:00 2001 From: Alejandro Gallo Date: Tue, 19 Oct 2021 13:47:35 +0200 Subject: [PATCH] Simplify naive distribution --- atrip.org | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/atrip.org b/atrip.org index f643c97..227dfaf 100644 --- a/atrip.org +++ b/atrip.org @@ -721,6 +721,7 @@ This section presents some utilities #include #include +#include namespace atrip { #+end_src @@ -1510,10 +1511,16 @@ getABCRange(size_t np, size_t rank, ABCTuples const& tuplesList) { auto const& it = n_tuples_per_rank.begin(); - return - { std::accumulate(it, it + rank , 0) - , std::accumulate(it, it + rank + 1, 0) - }; + std::pair const + range = { std::accumulate(it, it + rank , 0) + , std::accumulate(it, it + rank + 1, 0) - 1 + }; + + WITH_RANK << "range = " + << range.first << " -> " << range.second + << std::endl; + + return range; } #+end_src @@ -1527,12 +1534,23 @@ struct NaiveDistribution : public TuplesDistribution { MPI_Comm_rank(universe, &rank); MPI_Comm_size(universe, &np); auto const all = getTuplesList(Nv); - auto const range = getABCRange((size_t)np, (size_t)rank, all); + const size_t + tuplesPerRank + = all.size() / np + + size_t(all.size() % np != 0) + ; + //auto const range = getABCRange((size_t)np, (size_t)rank, all); + + std::pair const + range = { tuplesPerRank * rank + , tuplesPerRank * (rank + 1) - 1 + }; + std::vector result(range.second - range.first, FAKE_TUPLE); std::copy(all.begin() + range.first, range.second >= all.size() - ? all.end() - : all.begin() + range.first + range.second, + ? all.end() + : all.begin() + range.first + range.second, result.begin()); return result; } @@ -1688,7 +1706,6 @@ specialDistribution(Info info, std::vector const& allTuples) { size_t nNodes(info.nNodes); size_t np(info.np); size_t N(allTuples.size()); - size_t tuplePerNode( ceil( ((double)N) / nNodes) ); // nodeid tuple list std::map > container1d;