12#include <kernel/util/binary_stream.hpp>
13#include <kernel/util/type_traits.hpp>
20#include <unordered_map>
81#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
96 explicit Datatype(MPI_Datatype dt_, std::size_t bytes_) :
dt(dt_),
bytes(bytes_) {}
103 explicit Datatype(
int dt_, std::size_t bytes_) :
dt(dt_),
bytes(bytes_) {}
110 return this->dt == other.dt;
116 return this->dt != other.dt;
179#if defined(FEAT_HAVE_QUADMATH) || defined(DOXYGEN)
184#if defined(FEAT_HAVE_HALFMATH) || defined(DOXYGEN)
258 template<
typename T_>
261 return add_entry(displacement, Dist::autotype<T_>(), blocklength);
312 template<
typename T_>
318 return T_::typemap();
337 std::unordered_map<std::type_index, Datatype>
_types;
351 int next_mock_id = 1024;
378 template<
typename T_>
383 static_assert(std::is_standard_layout_v<T_>,
"MPI typemaps require standard-layout types!");
385 std::scoped_lock<std::recursive_mutex> lock(
_mutex);
387 const std::type_index idx(
typeid(T_));
389 const auto it =
_types.find(idx);
395 XASSERTM(desc.
count() > 0,
"TypeRegistry::get_type: empty typemap!");
398 std::vector<MPI_Datatype> mpi_types;
399 mpi_types.reserve(desc.
count());
403 std::back_inserter(mpi_types),
404 [](
const Datatype& d) { return d.dt; });
407 std::vector<MPI_Aint> displacements;
408 displacements.reserve(desc.
count());
412 std::back_inserter(displacements),
413 [](
const std::size_t d) { return static_cast<MPI_Aint>(d); });
416 MPI_Datatype tmptype;
417 MPI_Type_create_struct(
static_cast<int>(desc.
count()), desc.
_blocklengths.data(), displacements.data(), mpi_types.data(), &tmptype);
422 MPI_Datatype newtype;
423 MPI_Type_create_resized(tmptype, 0,
sizeof(T_), &newtype);
426 MPI_Type_commit(&newtype);
429 MPI_Type_free(&tmptype);
432 const auto [iter, _] =
_types.try_emplace(idx,
Datatype(newtype,
sizeof(T_)));
447 std::scoped_lock<std::recursive_mutex> lock(
_mutex);
449 for(
auto& [_, dt] :
_types)
451 MPI_Type_free(&dt.dt);
457 template<
typename T_>
460 std::scoped_lock<std::recursive_mutex> lock(
_mutex);
462 const std::type_index idx(
typeid(T_));
464 auto it =
_types.find(idx);
467 const auto [iter, _] =
_types.try_emplace(idx,
Datatype(next_mock_id++,
sizeof(T_)));
483 std::scoped_lock<std::recursive_mutex> lock(
_mutex);
489 template<
typename T_>
496 template<>
inline const Datatype& autotype<char>() {
return dt_char;}
497 template<>
inline const Datatype& autotype<wchar_t>() {
return dt_wchar;}
498 template<>
inline const Datatype& autotype<signed char>() {
return dt_signed_char;}
499 template<>
inline const Datatype& autotype<signed short>() {
return dt_signed_short;}
500 template<>
inline const Datatype& autotype<signed int>() {
return dt_signed_int;}
501 template<>
inline const Datatype& autotype<signed long>() {
return dt_signed_long;}
502 template<>
inline const Datatype& autotype<signed long long>() {
return dt_signed_long_long;}
503 template<>
inline const Datatype& autotype<unsigned char>() {
return dt_unsigned_char;}
504 template<>
inline const Datatype& autotype<unsigned short>() {
return dt_unsigned_short;}
505 template<>
inline const Datatype& autotype<unsigned int>() {
return dt_unsigned_int;}
506 template<>
inline const Datatype& autotype<unsigned long>() {
return dt_unsigned_long;}
508 template<>
inline const Datatype& autotype<float>() {
return dt_float;}
509 template<>
inline const Datatype& autotype<double>() {
return dt_double;}
510 template<>
inline const Datatype& autotype<long double>() {
return dt_long_double;}
512#if defined(FEAT_HAVE_QUADMATH) || defined(DOXYGEN)
513 template<>
inline const Datatype& autotype<__float128>() {
return dt__float128;}
516#if defined(FEAT_HAVE_HALFMATH) || defined(DOXYGEN)
517 template<>
inline const Datatype& autotype<__half>() {
return dt__half;}
538#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
560 return this->op == other.op;
566 return this->op != other.op;
596#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
605 status.MPI_SOURCE = MPI_PROC_NULL;
626 return status.MPI_SOURCE == MPI_PROC_NULL;
667 MPI_Get_count(&
status, datatype.
dt, &c);
668 return std::size_t(c);
675 MPI_Get_count(&
status, MPI_BYTE, &c);
676 return std::size_t(c);
701 static_assert(
sizeof(
Status) ==
sizeof(MPI_Status),
"invalid Status class size; class Status must be a POD");
732#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
751#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
753 explicit Request(MPI_Request req_);
906 static_assert(
sizeof(Request) ==
sizeof(MPI_Request),
"invalid Request class size; class Request must be a POD");
955#if defined(FEAT_HAVE_MPI)
958 return int(
_reqs.size());
961 MPI_Request* _reqs_array()
963 return reinterpret_cast<MPI_Request*
>(
_reqs.data());
966 MPI_Status* _stats_array()
968 return reinterpret_cast<MPI_Status*
>(
_stats.data());
1041 _reqs = std::forward<std::vector<Request>>(other._reqs);
1042 _stats = std::forward<std::vector<Status>>(other._stats);
1051 XASSERTM(
is_null(),
"You are trying to destroy an active request vector!");
1123 if(size_ <=
_reqs.size())
1125 _reqs.reserve(size_);
1145 for(std::size_t i(size_); i <
_reqs.size(); ++i)
1149 _reqs.resize(size_);
1168 std::size_t i(0), j(0), n =
_reqs.size();
1196 _reqs.emplace_back(std::forward<Request>(request));
1211 return _reqs.size();
1225 std::size_t count(0);
1226 for(
const auto& r :
_reqs)
1247 return _reqs.empty();
1264 for(
const auto& r :
_reqs)
1284 for(
auto& r :
_reqs)
1302 for(
auto& r :
_reqs)
1658#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
1670#if !defined(FEAT_HAVE_MPI) && !defined(DOXYGEN)
1682#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
1695 explicit Comm(MPI_Comm comm_);
1745#if defined(FEAT_HAVE_MPI) || defined(DOXYGEN)
1951 void send(
const void* buffer, std::size_t count,
const Datatype& datatype,
int dest,
int tag = 0)
const;
1972 template<
typename T_>
1973 void send(
const T_* buffer, std::size_t count,
int dest,
int tag = 0)
const
1975 send(buffer, count, autotype<T_>(), dest, tag);
2001 void recv(
void* buffer, std::size_t count,
const Datatype& datatype,
int source,
int tag,
Status& status)
const;
2025 void recv(
void* buffer, std::size_t count,
const Datatype& datatype,
int source,
int tag = 0)
const
2028 recv(buffer, count, datatype, source, tag, status);
2053 template<
typename T_>
2054 void recv(T_* buffer, std::size_t count,
int source,
int tag,
Status& status)
const
2056 recv(buffer, count, autotype<T_>(), source, tag, status);
2079 template<
typename T_>
2080 void recv(T_* buffer, std::size_t count,
int source,
int tag = 0)
const
2083 recv(buffer, count, autotype<T_>(), source, tag, status);
2117 Request isend(
const void* buffer, std::size_t count,
const Datatype& datatype,
int dest,
int tag = 0)
const;
2141 template<
typename T_>
2142 Request isend(
const T_* buffer, std::size_t count,
int dest,
int tag = 0)
const
2144 return isend(buffer, count, autotype<T_>(), dest, tag);
2170 Request irecv(
void* buffer, std::size_t count,
const Datatype& datatype,
int source,
int tag = 0)
const;
2194 template<
typename T_>
2195 Request irecv(T_* buffer, std::size_t count,
int source,
int tag = 0)
const
2197 return irecv(buffer, count, autotype<T_>(), source, tag);
2225 void bcast(
void* buffer, std::size_t count,
const Datatype& datatype,
int root)
const;
2243 template<
typename T_>
2244 void bcast(T_* buffer, std::size_t count,
int root)
const
2246 bcast(buffer, count, autotype<T_>(), root);
2290 template<
typename T_>
2293 return ibcast(buffer, count, autotype<T_>(), root);
2334 void gather(
const void* sendbuf, std::size_t sendcount,
const Datatype& sendtype,
void* recvbuf, std::size_t recvcount,
const Datatype& recvtype,
int root)
const;
2362 template<
typename ST_,
typename RT_>
2363 void gather(
const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount,
int root)
const
2365 gather(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>(), root);
2402 Request igather(
const void* sendbuf, std::size_t sendcount,
const Datatype& sendtype,
void* recvbuf, std::size_t recvcount,
const Datatype& recvtype,
int root)
const;
2434 template<
typename ST_,
typename RT_>
2435 Request igather(
const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount,
int root)
const
2437 return igather(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>(), root);
2470 void scatter(
const void* sendbuf, std::size_t sendcount,
const Datatype& sendtype,
void* recvbuf, std::size_t recvcount,
const Datatype& recvtype,
int root)
const;
2498 template<
typename ST_,
typename RT_>
2499 void scatter(
const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount,
int root)
const
2501 scatter(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>(), root);
2538 Request iscatter(
const void* sendbuf, std::size_t sendcount,
const Datatype& sendtype,
void* recvbuf, std::size_t recvcount,
const Datatype& recvtype,
int root)
const;
2570 template<
typename ST_,
typename RT_>
2571 Request iscatter(
const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount,
int root)
const
2573 return iscatter(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>(), root);
2603 void allgather(
const void* sendbuf, std::size_t sendcount,
const Datatype& sendtype,
void* recvbuf, std::size_t recvcount,
const Datatype& recvtype)
const;
2628 template<
typename ST_,
typename RT_>
2629 void allgather(
const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount)
const
2631 allgather(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>());
2694 template<
typename ST_,
typename RT_>
2695 Request iallgather(
const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount)
const
2697 return iallgather(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>());
2734 void allgatherv(
const void* sendbuf, std::size_t sendcount,
const Datatype& sendtype,
void* recvbuf,
const int* recvcounts,
const int* displs,
const Datatype& recvtype)
const;
2766 template<
typename ST_,
typename RT_>
2767 void allgatherv(
const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf,
const int* recvcounts,
const int* displs)
const
2769 allgatherv(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcounts, displs, autotype<RT_>());
2799 void alltoall(
const void* sendbuf, std::size_t sendcount,
const Datatype& sendtype,
void* recvbuf, std::size_t recvcount,
const Datatype& recvtype)
const;
2824 template<
typename ST_,
typename RT_>
2825 void alltoall(
const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount)
const
2827 alltoall(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>());
2861 Request ialltoall(
const void* sendbuf, std::size_t sendcount,
const Datatype& sendtype,
void* recvbuf, std::size_t recvcount,
const Datatype& recvtype)
const;
2890 template<
typename ST_,
typename RT_>
2891 Request ialltoall(
const ST_* sendbuf, std::size_t sendcount, RT_* recvbuf, std::size_t recvcount)
const
2893 return ialltoall(sendbuf, sendcount, autotype<ST_>(), recvbuf, recvcount, autotype<RT_>());
2933 void alltoallv(
const void* sendbuf,
const int* sendcounts,
const int* sdispls,
const Datatype& sendtype,
void* recvbuf,
const int* recvcounts,
const int* rdispls,
const Datatype& recvtype)
const;
2968 template<
typename ST_,
typename RT_>
2969 void alltoallv(
const ST_* sendbuf,
const int* sendcounts,
const int* sdispls, RT_* recvbuf,
const int* recvcounts,
const int* rdispls)
const
2971 alltoallv(sendbuf, sendcounts, sdispls, autotype<ST_>(), recvbuf, recvcounts, rdispls, autotype<RT_>());
3009 void reduce(
const void* sendbuf,
void* recvbuf, std::size_t count,
const Datatype& datatype,
const Operation& op,
int root)
const;
3037 template<
typename T_>
3038 void reduce(
const T_* sendbuf, T_* recvbuf, std::size_t count,
const Operation& op,
int root)
const
3040 reduce(sendbuf, recvbuf, count, autotype<T_>(), op, root);
3106 template<
typename T_>
3109 return ireduce(sendbuf, recvbuf, count, autotype<T_>(), op, root);
3161 template<
typename T_>
3164 allreduce(sendbuf, recvbuf, count, autotype<T_>(), op);
3224 template<
typename T_>
3227 return iallreduce(sendbuf, recvbuf, count, autotype<T_>(), op);
3254 void scan(
const void* sendbuf,
void* recvbuf, std::size_t count,
const Datatype& datatype,
const Operation& op)
const;
3279 template<
typename T_>
3280 void scan(
const T_* sendbuf, T_* recvbuf, std::size_t count,
const Operation& op)
const
3282 scan(sendbuf, recvbuf, count, autotype<T_>(), op);
3317 void exscan(
const void* sendbuf,
void* recvbuf, std::size_t count,
const Datatype& datatype,
const Operation& op)
const;
3342 template<
typename T_>
3345 exscan(sendbuf, recvbuf, count, autotype<T_>(), op);
3387 void pack(
const void* inbuf, std::size_t incount,
const Datatype& datatype,
void* outbuf, std::size_t outsize,
int* position)
const;
3411 template<
typename T_>
3412 void pack(
const T_* inbuf, std::size_t incount,
void* outbuf, std::size_t outsize,
int* position)
const
3414 pack(inbuf, incount, autotype<T_>(), outbuf, outsize, position);
3440 void unpack(
const void* inbuf, std::size_t insize,
int* position,
void* outbuf, std::size_t outcount,
const Datatype& datatype)
const;
3467 template<
typename T_>
3468 void unpack(
const void* inbuf, std::size_t insize,
int* position, T_* outbuf, std::size_t outcount)
const
3470 unpack(inbuf, insize, position, outbuf, outcount, autotype<T_>());
3501 template<
typename T_>
3553 void print(std::ostream& os,
const String& msg,
int root = 0)
const;
3567 print(std::cout, msg, root);
3584 void allprint(std::ostream& os,
const String& msg,
int root = 0)
const;
3611 void print_flush(std::ostream& os,
int root = 0)
const;
#define XASSERT(expr)
Assertion macro definition.
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
void scatter(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype, int root) const
Blocking scatter.
Comm & operator=(const Comm &)=delete
communicators are non-copyable
void bcast(void *buffer, std::size_t count, const Datatype &datatype, int root) const
Blocking broadcast.
void reduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op, int root) const
Blocking Reduce.
Request iallgather(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype) const
Nonblocking gather-to-all.
Comm comm_create_range_incl(int count, int first=0, int stride=1) const
Creates a new sub-communicator from a strided range of ranks.
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
void barrier() const
Blocking barrier.
Request ibcast(void *buffer, std::size_t count, const Datatype &datatype, int root) const
Nonblocking broadcast.
int size() const
Returns the size of this communicator.
void exscan(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking Exclusive Scan.
Comm comm_create_incl(int n, const int *ranks) const
Creates a new sub-communicator for a given set of ranks.
void recv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag=0) const
Blocking Receive.
Request igather(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype, int root) const
Nonblocking gather.
Request isend(const T_ *buffer, std::size_t count, int dest, int tag=0) const
Nonblocking Send.
static Comm null()
Returns a null communicator.
Request ibarrier() const
Nonblocking barrier.
void print(const String &msg, int root=0) const
Prints a message line to the standard output stream cout.
void allreduce(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op) const
Blocking All-Reduce.
Request igather(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount, int root) const
Nonblocking gather.
virtual ~Comm()
virtual destructor
void exscan(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op) const
Blocking Exclusive Scan.
void gather(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount, int root) const
Blocking gather.
Request iallreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Nonblocking All-Reduce.
Request irecv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag=0) const
Nonblocking Receive.
Comm()
Standard constructor.
void print_flush(int root=0) const
Explicitly flushes cout.
Comm comm_split(int color, int key) const
Creates a new sub-communicator by splitting this communicator.
void recv(T_ *buffer, std::size_t count, int source, int tag=0) const
Blocking Receive.
bool is_world() const
Checks whether this communicator is the world communicator.
void recv(T_ *buffer, std::size_t count, int source, int tag, Status &status) const
Blocking Receive.
void bcast_binarystream(BinaryStream &stream, int root=0) const
Blocking broadcast of a BinaryStream.
void recv(void *buffer, std::size_t count, const Datatype &datatype, int source, int tag, Status &status) const
Blocking Receive.
void bcast(T_ *buffer, std::size_t count, int root) const
Blocking broadcast.
Request isend(const void *buffer, std::size_t count, const Datatype &datatype, int dest, int tag=0) const
Nonblocking Send.
int _size
the communicator size
MPI_Comm comm
our MPI communicator handle
Request iscatter(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype, int root) const
Nonblocking scatter.
void pack(const T_ *inbuf, std::size_t incount, void *outbuf, std::size_t outsize, int *position) const
Pack message.
void unpack(const void *inbuf, std::size_t insize, int *position, void *outbuf, std::size_t outcount, const Datatype &datatype) const
Unpack message.
void scatter(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount, int root) const
Blocking scatter.
Comm(const Comm &)=delete
communicators are non-copyable
void gather(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype, int root) const
Blocking gather.
static Comm self()
Returns a copy of the self communicator.
Request iallgather(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount) const
Nonblocking gather-to-all.
bool is_self() const
Checks whether this communicator is the self communicator.
const MPI_Comm & mpi_comm() const
void allgatherv(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, const int *recvcounts, const int *displs) const
Blocking gather-to-all.
void alltoallv(const void *sendbuf, const int *sendcounts, const int *sdispls, const Datatype &sendtype, void *recvbuf, const int *recvcounts, const int *rdispls, const Datatype &recvtype) const
Blocking All-to-All Scatter/Gather.
void pack_size(std::size_t incount, const Datatype &datatype, int *size) const
Determine upper bound on increment of position by call to pack/unpack.
void allgather(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount) const
Blocking gather-to-all.
Request iscatter(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount, int root) const
Nonblocking scatter.
void alltoall(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype) const
Blocking All-to-All Scatter/Gather.
void pack_size(std::size_t incount, int *size) const
Determine upper bound on increment of position by call to pack/unpack.
void alltoallv(const ST_ *sendbuf, const int *sendcounts, const int *sdispls, RT_ *recvbuf, const int *recvcounts, const int *rdispls) const
Blocking All-to-All Scatter/Gather.
void send(const void *buffer, std::size_t count, const Datatype &datatype, int dest, int tag=0) const
Blocking Send.
void pack(const void *inbuf, std::size_t incount, const Datatype &datatype, void *outbuf, std::size_t outsize, int *position) const
Pack message.
void print_flush(std::ostream &os, int root=0) const
Explicitly flushes the output stream.
Request ibcast(T_ *buffer, std::size_t count, int root) const
Nonblocking broadcast.
void reduce(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op, int root) const
Blocking Reduce.
void send(const T_ *buffer, std::size_t count, int dest, int tag=0) const
Blocking Send.
Comm comm_dup() const
Creates a copy of this communicator.
void allprint(std::ostream &os, const String &msg, int root=0) const
Prints the ordered messages of all processes to an output stream.
Request ireduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op, int root) const
Nonblocking Reduce.
Request ireduce(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op, int root) const
Nonblocking Reduce.
void scan(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op) const
Blocking Inclusive Scan.
void allgatherv(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, const int *recvcounts, const int *displs, const Datatype &recvtype) const
Blocking gather-to-all.
void allprint(const String &msg, int root=0) const
Prints the ordered messages of all processes to the standard output stream cout.
Request ialltoall(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype) const
Nonblocking All-to-All Scatter/Gather.
int rank() const
Returns the rank of this process in this communicator.
Request iallreduce(const T_ *sendbuf, T_ *recvbuf, std::size_t count, const Operation &op) const
Nonblocking All-Reduce.
Request irecv(T_ *buffer, std::size_t count, int source, int tag=0) const
Nonblocking Receive.
void alltoall(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount) const
Blocking All-to-All Scatter/Gather.
void unpack(const void *inbuf, std::size_t insize, int *position, T_ *outbuf, std::size_t outcount) const
Unpack message.
void allgather(const void *sendbuf, std::size_t sendcount, const Datatype &sendtype, void *recvbuf, std::size_t recvcount, const Datatype &recvtype) const
Blocking gather-to-all.
bool is_null() const
Checks whether this communicator is a null communicator.
Request ialltoall(const ST_ *sendbuf, std::size_t sendcount, RT_ *recvbuf, std::size_t recvcount) const
Nonblocking All-to-All Scatter/Gather.
static Comm world()
Returns a copy of the world communicator.
void print(std::ostream &os, const String &msg, int root=0) const
Prints a message line to an output stream.
void scan(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking Inclusive Scan.
void bcast_stringstream(std::stringstream &stream, int root=0) const
Blocking broadcast of a std::stringstream.
Communication Request class.
MPI_Request request
our internal MPI request handle
bool test(Status &status)
Tests whether the request is fulfilled (or null) without blocking.
Request(const Request &)=delete
Request objects are non-copyable.
~Request()
non-virtual destructor
Request()
Standard constructor.
bool wait(Status &status)
Blocks until the request is fulfilled (or null).
bool wait()
Blocks until the request is fulfilled (or null).
bool test()
Tests whether the request is fulfilled (or null).
void free()
Frees the request.
MPI_Request * mpi_request()
void cancel()
Cancels the request.
Request & operator=(const Request &)=delete
Request objects are non-copyable.
bool is_null() const
Checks whether this request is null.
Communication Request vector class.
Status & get_status(std::size_t idx)
Returns a (const) reference to a single status in the vector.
void resize(std::size_t size_)
Resizes the request vector.
RequestVector(const RequestVector &)=delete
request vectors are non-copyable
void push_back(Request &&request)
Inserts a new request at the end of the request vector.
RequestVector()
Standard constructor.
void reserve(std::size_t size_)
Reserves sufficient space for a specified number of requests.
bool test_for(std::size_t idx)
Tests whether a specific request is fulfilled (or null).
std::size_t active_count() const
Returns the number of active requests in the vector.
void cancel()
Cancels all remaining active requests.
const Request & get_request(std::size_t idx) const
Returns a (const) reference to a single request in the vector.
Request & get_request(std::size_t idx)
Returns a (const) reference to a single request in the vector.
Request & operator[](std::size_t idx)
Returns a (const) reference to a single request in the vector.
bool wait_for(std::size_t idx, Status &status)
Blocks until a specific request is fulfilled (or null).
bool wait_for(std::size_t idx)
Blocks until a specific request is fulfilled (or null).
bool test_all()
Tests whether all active requests are fulfilled (or null).
bool wait_any(Status &status)
Blocks until one of the active requests has been fulfilled.
RequestVector & operator=(RequestVector &&other)
Move-assignment operator.
bool empty() const
Checks whether the request vector is empty.
bool test_any(std::size_t &idx, Status &status)
Tests whether one of the active requests has been fulfilled.
bool is_null() const
Checks whether all requests are null requests.
std::vector< Request > _reqs
internal vector of Request objects
RequestVector(RequestVector &&other)
Move constructor.
const Request & operator[](std::size_t idx) const
Returns a (const) reference to a single request in the vector.
bool wait_any(std::size_t &idx)
Blocks until one of the active requests has been fulfilled.
void free()
Frees all remaining active requests.
bool test_any(Status &status)
Tests whether one of the active requests has been fulfilled.
std::size_t size() const
Returns the total number of (both active and null) requests in the vector.
std::vector< Status > _stats
internal vector of Status objects
std::size_t compress()
Compresses the request vector.
void clear()
Clears the request vector.
bool wait_any(std::size_t &idx, Status &status)
Blocks until one of the active requests has been fulfilled.
const Status & get_status(std::size_t idx) const
Returns a (const) reference to a single status in the vector.
bool test_any(std::size_t &idx)
Tests whether one of the active requests has been fulfilled.
virtual ~RequestVector()
virtual destructor
RequestVector & operator=(const RequestVector &)=delete
request vectors are non-copyable
RequestVector(std::size_t size_)
Sized constructor.
void wait_all()
Blocks until all active requests are fulfilled.
bool test_for(std::size_t idx, Status &status)
Tests whether a specific request is fulfilled (or null).
Communication Status class.
std::size_t get_size() const
Status()
standard constructor
std::size_t get_count(const Datatype &datatype) const
Returns the size of the message.
Status & operator=(const Status &)=default
status objects are copyable
bool is_null() const
Checks whether the source rank is MPI_PROC_NULL.
MPI_Status status
the MPI status structure
MPI_Status * mpi_status()
Status(const Status &)=default
status objects are copyable
Singleton for managing derived Datatypes.
const Datatype & get_type()
Retrieve Datatype for type T_.
TypeRegistry()=default
Constructor.
std::unordered_map< std::type_index, Datatype > _types
Mapping of C++ types to Datatypes.
std::recursive_mutex _mutex
Mutex against concurrent access.
void free()
Frees all commited Datatypes.
static TypeRegistry & instance() noexcept
Singleton accessor.
TypeRegistry(const TypeRegistry &other)=delete
Deleted copy constructor.
TypeRegistry(TypeRegistry &&other)=delete
Deleted move constructor.
void operator=(const TypeRegistry &other)=delete
Deleted copy-assignment operator.
void operator=(TypeRegistry &&other)=delete
Deleted move-assignment operator.
std::vector< std::size_t > _displacements
Displacements for each entry.
Typemap()=default
Constructor.
Typemap & add_entry(std::size_t displacement, int blocklength=1)
Add a member to this typemap.
std::size_t count() const noexcept
Returns the number of entries in this typemap.
std::vector< int > _blocklengths
Blocklengths for each entry.
Typemap & add_entry(std::size_t displacement, const Dist::Datatype &type, int blocklength=1)
Add a member to this typemap.
std::vector< Dist::Datatype > _types
Types for each entry.
String class implementation.
bool initialize(int &argc, char **&argv)
Initializes the distributed communication system.
const Datatype dt_byte(MPI_BYTE, sizeof(char))
Datatype wrapper for MPI_BYTE.
const Datatype dt_wchar(MPI_WCHAR, sizeof(wchar_t))
Datatype wrapper for MPI_WCHAR.
const Datatype dt_signed_long(MPI_LONG, sizeof(long))
Datatype wrapper for MPI_LONG.
const Datatype dt_float(MPI_FLOAT, sizeof(float))
Datatype wrapper for MPI_FLOAT.
const Datatype dt_signed_char(MPI_SIGNED_CHAR, sizeof(signed char))
Datatype wrapper for MPI_SIGNED_CHAR.
const Datatype dt_signed_short(MPI_SHORT, sizeof(short))
Datatype wrapper for MPI_SHORT.
const Datatype dt_unsigned_long_long(MPI_UNSIGNED_LONG_LONG, sizeof(unsigned long long))
Datatype wrapper for MPI_UNSIGNED_LONG_LONG.
const Datatype dt_signed_int32(MPI_INT32_T, sizeof(std::int32_t))
Datatype wrapper for MPI_INT32_T.
const Datatype & autotype()
Automatic Datatype deduction function template.
const Datatype dt_unsigned_int32(MPI_UINT32_T, sizeof(std::uint32_t))
Datatype wrapper for MPI_UINT32_T.
void finalize()
Finalizes the distributed communication system.
const Datatype dt_signed_int8(MPI_INT8_T, sizeof(std::int8_t))
Datatype wrapper for MPI_INT8_T.
const Datatype dt_char(MPI_CHAR, sizeof(char))
Datatype wrapper for MPI_CHAR.
const Operation op_min(MPI_MIN)
Operation wrapper for MPI_MIN.
const Datatype dt_unsigned_int(MPI_UNSIGNED, sizeof(unsigned int))
Datatype wrapper for MPI_UNSIGNED.
const Datatype dt_unsigned_int16(MPI_UINT16_T, sizeof(std::uint16_t))
Datatype wrapper for MPI_UINT16_T.
const Datatype dt_unsigned_int8(MPI_UINT8_T, sizeof(std::uint8_t))
Datatype wrapper for MPI_UINT8_T.
const Datatype dt__half
custom Datatype for __half
const Datatype dt_signed_int(MPI_INT, sizeof(int))
Datatype wrapper for MPI_INT.
const Datatype dt_signed_long_long(MPI_LONG_LONG, sizeof(long long))
Datatype wrapper for MPI_LONG_LONG.
const Operation op_max(MPI_MAX)
Operation wrapper for MPI_MAX.
const Datatype dt_double(MPI_DOUBLE, sizeof(double))
Datatype wrapper for MPI_DOUBLE.
const Datatype dt_unsigned_char(MPI_UNSIGNED_CHAR, sizeof(unsigned char))
Datatype wrapper for MPI_UNSIGNED_CHAR.
const Datatype dt_packed(MPI_PACKED, sizeof(char))
Datatype wrapper for MPI_PACKED.
const Datatype dt_signed_int16(MPI_INT16_T, sizeof(std::int16_t))
Datatype wrapper for MPI_INT16_T.
const Datatype dt_unsigned_short(MPI_UNSIGNED_SHORT, sizeof(unsigned short))
Datatype wrapper for MPI_UNSIGNED_SHORT.
const Datatype dt_unsigned_int64(MPI_UINT64_T, sizeof(std::uint64_t))
Datatype wrapper for MPI_UINT64_T.
const Datatype dt_long_double(MPI_LONG_DOUBLE, sizeof(long double))
Datatype wrapper for MPI_LONG_DOUBLE.
const Operation op_sum(MPI_SUM)
Operation wrapper for MPI_SUM.
const Datatype dt__float128
custom Datatype for __float128
const Datatype dt_unsigned_long(MPI_UNSIGNED_LONG, sizeof(unsigned long))
Datatype wrapper for MPI_UNSIGNED_LONG.
const Datatype dt_signed_int64(MPI_INT64_T, sizeof(std::int64_t))
Datatype wrapper for MPI_INT64_T.
Status
Solver status return codes enumeration.
Communication Datatype class.
MPI_Datatype dt
the MPI datatype handle
Datatype(MPI_Datatype dt_, std::size_t bytes_)
MPI_Datatype handle constructor
bool operator!=(const Datatype &other) const
inequality comparison operator
bool operator==(const Datatype &other) const
equality comparison operator
std::size_t size() const
Returns the size of the datatype in bytes, as given in the constructor.
std::size_t bytes
the size of the datatype in bytes
Communication Operation class.
bool operator==(const Operation &other) const
equality comparison operator
Operation(MPI_Op op_)
MPI_Op handle constructor
bool operator!=(const Operation &other) const
inequality comparison operator
MPI_Op op
the MPI operation handle
Mapping from types to Typemaps.
static Typemap typemap()
Produce a Typemap for T_.