22#include <unordered_map>
40 inline void _internal_gather_str(
41 const std::basic_string<Tchar> &send_vec, std::basic_string<Tchar> &recv_vec) {
51 std::vector<int> counts(wsize);
52 std::vector<int> disps(wsize);
54 u32 local_count = send_vec.size();
58 for (
int i = 0; i < wsize; i++) {
59 disps[i] = (i > 0) ? (disps[i - 1] + counts[i - 1]) : 0;
62 std::string result =
"";
65 u32 global_len = disps[wsize - 1] + counts[wsize - 1];
66 result.resize(global_len);
89 inline void _internal_allgather_str(
90 const std::basic_string<Tchar> &send_vec, std::basic_string<Tchar> &recv_vec) {
99 size_t wsize_sz =
static_cast<size_t>(wsize);
102 std::vector<int> counts(wsize_sz);
103 std::vector<int> disps(wsize_sz);
106 int local_count =
static_cast<int>(send_vec.size());
109 &local_count, 1, MPI_INT, counts.data(), 1, MPI_INT, MPI_COMM_WORLD);
111 for (
size_t i = 0; i < wsize_sz; i++) {
112 disps[i] = (i > 0) ? (disps[i - 1] + counts[i - 1]) : 0;
115 int global_len = disps[wsize_sz - 1] + counts[wsize_sz - 1];
117 std::basic_string<Tchar> result;
118 result.resize(
static_cast<size_t>(global_len));
137 _internal_gather_str(send_vec, recv_vec);
141 const std::basic_string<byte> &send_vec, std::basic_string<byte> &recv_vec) {
143 _internal_gather_str(send_vec, recv_vec);
148 _internal_allgather_str(send_vec, recv_vec);
152 const std::basic_string<byte> &send_vec, std::basic_string<byte> &recv_vec) {
154 _internal_allgather_str(send_vec, recv_vec);
std::uint32_t u32
32 bit unsigned integer
std::int32_t i32
32 bit integer
MPI string gather / allgather helpers (declarations; implementations in shamalgs/src/collective/gathe...
void allgather_basic_str(const std::basic_string< byte > &send_vec, std::basic_string< byte > &recv_vec)
same as allgather_str but with std::basic_string
void allgather_str(const std::string &send_vec, std::string &recv_vec)
Allgathers a string from all nodes and concatenates it in a std::string.
void gather_basic_str(const std::basic_string< byte > &send_vec, std::basic_string< byte > &recv_vec)
same as gather_str but with std::basic_string
void gather_str(const std::string &send_vec, std::string &recv_vec)
Gathers a string from all nodes and store the result in a std::string.
i32 world_rank()
Gives the rank of the current process in the MPI communicator.
i32 world_size()
Gives the size of the MPI communicator.
This file contains the definition for the stacktrace related functionality.
Functions related to the MPI communicator.
void Gatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, const int recvcounts[], const int displs[], MPI_Datatype recvtype, int root, MPI_Comm comm)
MPI wrapper for MPI_Gatherv.
void Allgatherv(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, const int recvcounts[], const int displs[], MPI_Datatype recvtype, MPI_Comm comm)
MPI wrapper for MPI_Allgatherv.
void Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
MPI wrapper for MPI_Gather.
void Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
MPI wrapper for MPI_Allgather.