30#ifndef INCLUDED_DECOMP_HPP
31#define INCLUDED_DECOMP_HPP
46 static constexpr int Dim = 3;
64 fileStream << it->first.getIndex() <<
" " << it->second <<
" ";
71 int sizeKeyRankMap(0), rank(0);
72 fileStream >> sizeKeyRankMap;
74 for (
int i = 0; i < sizeKeyRankMap; ++i) {
83 std::vector<key_type>
initialize(
int nProcs,
int _rank,
int resumeSimulation)
noexcept
85 std::vector<key_type> keys;
87 if (resumeSimulation == 0) {
90 float chunks =
static_cast<float>(nCells_t + 0.5) / nProcs;
92 std::vector<int> nCells_per_rank;
93 for (
int i = 0; i < nProcs; ++i) {
94 size_t start = (size_t)(i * chunks);
95 size_t end = std::min(
static_cast<int>((i + 1) * chunks), nCells_t);
96 const int nlocal = end - start;
99 nCells_per_rank.emplace_back(nlocal);
101 while (count < nlocal) {
107 if (i == nProcs - 1) {
108 nCells_per_rank.emplace_back(0);
114 std::advance(key_it, _rank);
116 auto nCells = nCells_per_rank[_rank];
119 for (
int i = 0; i <
nCells; ++i) {
132 auto map_key_next = std::next(map_key);
134 if (map_key->second == _rank) {
135 auto key = map_key->first;
136 while (key != map_key_next->first) {
156 return _key0 == _key1;
164 if (range.first->first == range.second->first) {
165 auto it = range.first;
166 return (--it)->second;
169 return range.first->second;
180 for (
int d = 0; d <
Dim; ++d) {
181 if (_coord[d] < 0 || _coord[d] >=
nCells_global_[d])
return false;
190 if (it->second == itPrev->second) {
200 void communicateMaps(
int _nCpu, std::vector<typename key_type::value_type>& localKeys, std::vector<int>& localRanks)
203 int localMapSize = localKeys.size();
206 std::vector<int> mapSizes(_nCpu);
207 MPI_Allgather(&localMapSize, 1, MPI_INT, &mapSizes[0], 1, MPI_INT, MPI_COMM_WORLD);
210 std::vector<int> displacements(_nCpu);
212 for (
int i = 0; i < _nCpu; ++i) {
213 displacements[i] = sumMapSizes;
214 sumMapSizes += mapSizes[i];
216 std::vector<typename key_type::value_type> globalKeys(sumMapSizes);
217 std::vector<int> globalRanks(sumMapSizes);
219 &localKeys[0], localMapSize, MPI_UNSIGNED_LONG_LONG, &globalKeys[0], &mapSizes[0], &displacements[0], MPI_UNSIGNED_LONG_LONG, MPI_COMM_WORLD);
220 MPI_Allgatherv(&localRanks[0], localMapSize, MPI_INT, &globalRanks[0], &mapSizes[0], &displacements[0], MPI_INT, MPI_COMM_WORLD);
226 for (std::size_t i = 0; i < globalKeys.size(); ++i) {
Class for a coordinate system object such as coordinates of the vertex or a vector.
Definition Coord.h:43
void printDomainDecomposition(std::ofstream &fileStream) const noexcept
Definition decomposition.hpp:59
void communicateMaps(int _nCpu, std::vector< typename key_type::value_type > &localKeys, std::vector< int > &localRanks)
Definition decomposition.hpp:200
std::array< int, Dim > nCells_global_
Definition decomposition.hpp:232
bool is_inside(const Coord &_coord)
Definition decomposition.hpp:178
void readDomainDecomposition(std::ifstream &fileStream) noexcept
Definition decomposition.hpp:69
Decomposition(const Decomposition &)=default
bool is_valid(const key_type &_key) const noexcept
Definition decomposition.hpp:173
bool areConsecutive(key_type _key0, key_type _key1)
Definition decomposition.hpp:151
std::map< key_type, int > key_rank_map_
Definition decomposition.hpp:233
static constexpr int Dim
Definition decomposition.hpp:46
Decomposition(Decomposition &&)=default
std::vector< key_type > initialize(int nProcs, int _rank, int resumeSimulation) noexcept
Definition decomposition.hpp:83
Decomposition & operator=(Decomposition &&) &=default
void updatePhysicalDomainSizes(std::array< int, Dim > _nCells) noexcept
Definition decomposition.hpp:81
int get_rank(const key_type &_key)
Definition decomposition.hpp:161
Key< Dim > key_type
Definition decomposition.hpp:47
Decomposition(std::array< int, Dim > _nCells)
Definition decomposition.hpp:57
Decomposition & operator=(const Decomposition &) &=default
void recombineStarts()
Definition decomposition.hpp:186
Definition decomposition.hpp:40
unsigned long long int value_type
Definition key.hpp:46