11#define scint64_t static_cast<int64_t>
18 const uint64_t local_size,
19 const uint64_t global_size,
20 const std::vector<int64_t>& ghost_ids,
21 const MPI_Comm communicator)
22 : local_size_(local_size),
23 global_size_(global_size),
24 ghost_ids_(ghost_ids),
29 cached_parallel_data_(MakeCachedParallelData())
39 std::map<int, std::vector<int64_t>> recv_map;
46 std::map<int64_t, size_t> ghost_to_recv_map;
48 for (
const auto& [pid, gids] : recv_map)
49 for (
const int64_t gid : gids)
50 ghost_to_recv_map[gid] = count++;
52 std::vector<int> sendcounts;
53 std::vector<int> senddispls;
54 std::vector<int> recvcounts;
55 std::vector<int> recvdispls;
61 int total_recvcounts = 0;
64 for (
const auto& [pid, gids] : recv_map)
66 recvcounts[pid] =
static_cast<int>(gids.size());
67 recvdispls[pid] = total_recvcounts;
68 total_recvcounts +=
static_cast<int>(gids.size());
78 std::map<int, std::vector<int64_t>> send_map =
84 for (
const auto& [pid, gids] : send_map)
85 send_size += gids.size();
89 std::vector<int64_t> local_ids_to_send;
90 local_ids_to_send.reserve(send_size);
91 for (
const auto& [pid, gids] : send_map)
92 for (
const int64_t gid : gids)
96 std::string(__FUNCTION__) +
": " +
97 "Problem determining communication pattern. Process " +
98 std::to_string(pid) +
" determined that process " +
99 std::to_string(
location_id_) +
" needs to communicate global id " +
100 std::to_string(gid) +
" to it, but this id is not locally owned.");
107 int total_sendcounts = 0;
110 for (
const auto& [pid, gids] : send_map)
112 sendcounts[pid] =
static_cast<int>(gids.size());
113 senddispls[pid] = total_sendcounts;
114 total_sendcounts +=
static_cast<int>(gids.size());
118 std::move(senddispls),
119 std::move(recvcounts),
120 std::move(recvdispls),
121 std::move(local_ids_to_send),
122 std::move(ghost_to_recv_map)};
127 : local_size_(other.local_size_),
128 global_size_(other.local_size_),
129 ghost_ids_(other.ghost_ids_),
131 location_id_(other.location_id_),
132 process_count_(other.process_count_),
133 extents_(other.extents_),
134 cached_parallel_data_(other.cached_parallel_data_)
140 : local_size_(other.local_size_),
141 global_size_(other.local_size_),
142 ghost_ids_(other.ghost_ids_),
144 location_id_(other.location_id_),
145 process_count_(other.process_count_),
146 extents_(other.extents_),
147 cached_parallel_data_(other.cached_parallel_data_)
156 "The given ghost id does not belong to this communicator.");
168 std::vector<double>& ghosted_vector)
const
171 std::string(__FUNCTION__) +
172 ": Vector size mismatch. "
174 std::to_string(ghosted_vector.size()) +
180 std::vector<double> send_data;
181 send_data.reserve(send_size);
183 send_data.push_back(ghosted_vector[local_id]);
187 std::vector<double> recv_data(recv_size, 0.0);
190 MPI_Alltoallv(send_data.data(),
204 for (
size_t k = 0; k < recv_size; ++k)
213 return std::vector<double>(ghosted_size, 0.0);
218 const std::vector<double>& local_vector)
const
221 std::string(__FUNCTION__) +
222 ": Incompatible unghosted vector." +
223 "unghosted_vector.size() != local_size_");
226 std::vector<double> vec = local_vector;
227 for (
size_t i = 0; i <
ghost_ids_.size(); ++i)
228 vec.emplace_back(0.0);
236 std::string(__FUNCTION__) +
": Invalid global id." +
237 "Global ids must be in [0, global_size_). " +
238 std::to_string(global_id) +
" vs [0," +
#define ChiLogicalErrorIf(condition, message)
#define ChiInvalidArgumentIf(condition, message)
int64_t MapGhostToLocal(int64_t ghost_id) const
const uint64_t local_size_
const std::vector< uint64_t > extents_
std::vector< double > MakeGhostedVector() const
const std::vector< int64_t > ghost_ids_
CachedParallelData MakeCachedParallelData()
const CachedParallelData cached_parallel_data_
void CommunicateGhostEntries(std::vector< double > &ghosted_vector) const
int FindOwnerPID(int64_t global_id) const
VectorGhostCommunicator(uint64_t local_size, uint64_t global_size, const std::vector< int64_t > &ghost_ids, MPI_Comm communicator)
const uint64_t global_size_
int GetProcessCount(MPI_Comm mpi_comm)
std::vector< uint64_t > BuildLocationExtents(uint64_t local_size, MPI_Comm comm)
int GetLocationID(MPI_Comm mpi_comm)
std::map< K, std::vector< T > > MapAllToAll(const std::map< K, std::vector< T > > &pid_data_pairs, const MPI_Datatype data_mpi_type, const MPI_Comm communicator=Chi::mpi.comm)
std::map< int64_t, size_t > ghost_to_recv_map_
std::vector< int64_t > local_ids_to_send_
std::vector< int > senddispls_
std::vector< int > recvcounts_
std::vector< int > recvdispls_
std::vector< int > sendcounts_