43 operator const MPI_Comm&()
const noexcept {
return *comm_m; }
45 int size()
const noexcept {
return size_m; }
47 int rank()
const noexcept {
return rank_m; }
49 void barrier() { MPI_Barrier(*comm_m); }
51 void abort(
int errorcode = -1) { MPI_Abort(*comm_m, errorcode); }
59 void send(
const T& buffer,
int count,
int dest,
int tag);
62 void send(
const T* buffer,
int count,
int dest,
int tag);
65 void recv(T& output,
int count,
int source,
int tag,
Status& status);
68 void recv(T* output,
int count,
int source,
int tag,
Status& status);
70 void probe(
int source,
int tag,
Status& status);
78 void isend(
const T& buffer,
int count,
int dest,
int tag,
Request& request);
81 void isend(
const T* buffer,
int count,
int dest,
int tag,
Request& request);
84 void irecv(T& buffer,
int count,
int source,
int tag,
Request& request);
87 void irecv(T* buffer,
int count,
int source,
int tag,
Request& request);
89 bool iprobe(
int source,
int tag,
Status& status);
99 void gather(
const T* input, T* output,
int count,
int root = 0);
104 template <
typename T>
105 void scatter(
const T* input, T* output,
int count,
int root = 0);
111 template <
typename T,
class Op>
112 void reduce(
const T* input, T* output,
int count, Op op,
int root = 0);
114 template <
typename T,
class Op>
115 void reduce(
const T& input, T& output,
int count, Op op,
int root = 0);
117 template <
typename T,
class Op>
118 void allreduce(
const T* input, T* output,
int count, Op op);
120 template <
typename T,
class Op>
121 void allreduce(
const T& input, T& output,
int count, Op op);
123 template <
typename T,
class Op>
124 void allreduce(T* inout,
int count, Op op);
126 template <
typename T,
class Op>
127 void allreduce(T& inout,
int count, Op op);
130 template <
typename MemorySpace = Kokkos::DefaultExecutionSpace::memory_space>
133 template <
typename MemorySpace = Kokkos::DefaultExecutionSpace::memory_space>
134 using buffer_type = std::shared_ptr<archive_type<MemorySpace>>;
137 template <
typename MemorySpace>
138 using buffer_container_type = DefaultBufferHandler<MemorySpace>;
140 using buffer_handler_type =
141 typename detail::ContainerForAllSpaces<buffer_container_type>::type;
144 using size_type = detail::size_type;
145 double getDefaultOverallocation()
const {
return defaultOveralloc_m; }
146 void setDefaultOverallocation(
double factor);
148 template <
typename MemorySpace = Kokkos::DefaultExecutionSpace::memory_space,
150 buffer_type<MemorySpace> getBuffer(size_type size,
double overallocation = 1.0);
152 void deleteAllBuffers();
153 void freeAllBuffers();
155 template <
typename MemorySpace = Kokkos::DefaultExecutionSpace::memory_space>
156 void freeBuffer(buffer_type<MemorySpace> buffer);
158 const MPI_Comm& getCommunicator()
const noexcept {
return *comm_m; }
160 template <
class Buffer,
typename Archive>
161 void recv(
int src,
int tag, Buffer& buffer, Archive& ar, size_type msize,
166 if (msize > INT_MAX) {
167 std::cerr <<
"Message size exceeds range of int" << std::endl;
171 MPI_Recv(ar.getBuffer(), msize, MPI_BYTE, src, tag, *comm_m, &status);
173 buffer.deserialize(ar, nrecvs);
176 template <
class Buffer,
typename Archive>
177 void isend(
int dest,
int tag, Buffer& buffer, Archive& ar, MPI_Request& request,
179 if (ar.getSize() > INT_MAX) {
180 std::cerr <<
"Message size exceeds range of int" << std::endl;
183 buffer.serialize(ar, nsends);
184 MPI_Isend(ar.getBuffer(), ar.getSize(), MPI_BYTE, dest, tag, *comm_m, &request);
187 template <
typename Archive>
188 void irecv(
int src,
int tag, Archive& ar, MPI_Request& request, size_type msize) {
189 if (msize > INT_MAX) {
190 std::cerr <<
"Message size exceeds range of int" << std::endl;
193 MPI_Irecv(ar.getBuffer(), msize, MPI_BYTE, src, tag, *comm_m, &request);
196 void printLogs(
const std::string& filename);
199 std::vector<LogEntry> gatherLocalLogs();
200 void sendLogsToRank0(
const std::vector<LogEntry>& localLogs);
201 std::vector<LogEntry> gatherLogsFromAllRanks(
const std::vector<LogEntry>& localLogs);
202 void writeLogsToFile(
const std::vector<LogEntry>& allLogs,
const std::string& filename);
204 std::shared_ptr<buffer_handler_type> buffer_handlers_m;
205 double defaultOveralloc_m = 1.0;
210 std::shared_ptr<MPI_Comm> comm_m;
215 std::shared_ptr<buffer_handler_type> get_buffer_handler_instance();