include/pops/mesh/layout/distribution_mapping.hpp Source FileΒΆ

adc_cpp: include/pops/mesh/layout/distribution_mapping.hpp Source File
adc_cpp 0.3.0
Model-free C++23 core for coupled hyperbolic-elliptic systems on adaptive (AMR) meshes, with MPI and GPU (Kokkos) backends
distribution_mapping.hpp
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <utility>
13#include <vector>
14
15namespace pops {
16
20 public:
22
24 DistributionMapping(int nboxes, int nranks) {
25 rank_.resize(nboxes);
26 for (int i = 0; i < nboxes; ++i)
27 rank_[i] = (nranks > 0) ? i % nranks : 0;
28 }
29
32 explicit DistributionMapping(std::vector<int> rank) : rank_(std::move(rank)) {}
33
35 int operator[](int i) const { return rank_[i]; }
37 int size() const { return static_cast<int>(rank_.size()); }
39 const std::vector<int>& ranks() const { return rank_; }
40
41 private:
42 std::vector<int> rank_{};
43};
44
45} // namespace pops
Owning MPI rank of each box, indexed by GLOBAL box index (parallel to a BoxArray).
Definition distribution_mapping.hpp:19
int operator[](int i) const
Owning rank of the box with global index i.
Definition distribution_mapping.hpp:35
const std::vector< int > & ranks() const
View on the rank vector (element-by-element equality = same assignment).
Definition distribution_mapping.hpp:39
int size() const
Number of boxes covered (= size of the associated BoxArray).
Definition distribution_mapping.hpp:37
DistributionMapping(std::vector< int > rank)
EXPLICIT assignment: rank[i] = owning rank of box i (move).
Definition distribution_mapping.hpp:32
DistributionMapping(int nboxes, int nranks)
Round-robin: box i -> rank i % nranks (rank 0 if nranks <= 0). Default distribution.
Definition distribution_mapping.hpp:24
Definition amr_hierarchy.hpp:29