25#include <unordered_map>
30 std::unordered_map<std::string, f64> mpi_timers;
34namespace shamcomm::mpi {
36 mpi_timers[timername] += time;
37 mpi_timers[
"total"] += time;
46 f64 get_timer(std::string timername) {
return mpi_timers[timername]; }
48 const std::unordered_map<std::string, f64> &
get_timers() {
return mpi_timers; }
50 std::vector<std::string> possible_keys{
51 "total",
"MPI_Isend",
"MPI_Irecv",
52 "MPI_Allreduce",
"MPI_Allgather",
"MPI_Allgatherv",
53 "MPI_Exscan",
"MPI_Wait",
"MPI_Waitall",
54 "MPI_Barrier",
"MPI_Probe",
"MPI_Recv",
55 "MPI_Get_count",
"MPI_Send",
"MPI_File_set_view",
56 "MPI_Type_size",
"MPI_File_write_all",
"MPI_File_write",
57 "MPI_File_read",
"MPI_File_write_at",
"MPI_File_read_at",
58 "MPI_File_close",
"MPI_File_open",
"MPI_Test",
59 "MPI_Gather",
"MPI_Gatherv",
69 inline void wrap_profiling(std::string timername, Func &&f) {
78namespace shamcomm::mpi {
80 void check_tag_value(
i32 tag) {
90 MPI_Datatype datatype,
94 MPI_Request *request) {
99 wrap_profiling(
"MPI_Isend", [&]() {
100 MPICHECK(MPI_Isend(buf, count, datatype, dest, tag, comm, request));
107 MPI_Datatype datatype,
111 MPI_Request *request) {
114 check_tag_value(tag);
116 wrap_profiling(
"MPI_Irecv", [&]() {
117 MPICHECK(MPI_Irecv(buf, count, datatype, source, tag, comm, request));
125 MPI_Datatype datatype,
130 wrap_profiling(
"MPI_Allreduce", [&]() {
131 MPICHECK(MPI_Allreduce(sendbuf, recvbuf, count, datatype, op, comm));
138 MPI_Datatype sendtype,
141 MPI_Datatype recvtype,
145 wrap_profiling(
"MPI_Allgather", [&]() {
147 MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm));
154 MPI_Datatype sendtype,
156 const int recvcounts[],
158 MPI_Datatype recvtype,
162 wrap_profiling(
"MPI_Allgatherv", [&]() {
164 sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm));
172 MPI_Datatype datatype,
177 wrap_profiling(
"MPI_Exscan", [&]() {
178 MPICHECK(MPI_Exscan(sendbuf, recvbuf, count, datatype, op, comm));
182 void Wait(MPI_Request *request, MPI_Status *status) {
184 wrap_profiling(
"MPI_Wait", [&]() {
185 MPICHECK(MPI_Wait(request, status));
189 void Waitall(
int count, MPI_Request array_of_requests[], MPI_Status *array_of_statuses) {
191 wrap_profiling(
"MPI_Waitall", [&]() {
192 MPICHECK(MPI_Waitall(count, array_of_requests, array_of_statuses));
198 wrap_profiling(
"MPI_Barrier", [&]() {
203 void Probe(
int source,
int tag, MPI_Comm comm, MPI_Status *status) {
205 wrap_profiling(
"MPI_Probe", [&]() {
206 MPICHECK(MPI_Probe(source, tag, comm, status));
213 MPI_Datatype datatype,
217 MPI_Status *status) {
219 wrap_profiling(
"MPI_Recv", [&]() {
220 MPICHECK(MPI_Recv(buf, count, datatype, source, tag, comm, status));
224 void Get_count(
const MPI_Status *status, MPI_Datatype datatype,
int *count) {
226 wrap_profiling(
"MPI_Get_count", [&]() {
227 MPICHECK(MPI_Get_count(status, datatype, count));
231 void Send(
const void *buf,
int count, MPI_Datatype datatype,
int dest,
int tag, MPI_Comm comm) {
233 wrap_profiling(
"MPI_Send", [&]() {
234 MPICHECK(MPI_Send(buf, count, datatype, dest, tag, comm));
242 MPI_Datatype filetype,
246 wrap_profiling(
"MPI_File_set_view", [&]() {
247 MPICHECK(MPI_File_set_view(fh, disp, etype, filetype, datarep, info));
253 wrap_profiling(
"MPI_Type_size", [&]() {
254 MPICHECK(MPI_Type_size(type, size));
259 MPI_File fh,
const void *buf,
int count, MPI_Datatype datatype, MPI_Status *status) {
261 wrap_profiling(
"MPI_File_write_all", [&]() {
262 MPICHECK(MPI_File_write_all(fh, buf, count, datatype, status));
267 MPI_File fh,
const void *buf,
int count, MPI_Datatype datatype, MPI_Status *status) {
269 wrap_profiling(
"MPI_File_write", [&]() {
270 MPICHECK(MPI_File_write(fh, buf, count, datatype, status));
274 void File_read(MPI_File fh,
void *buf,
int count, MPI_Datatype datatype, MPI_Status *status) {
276 wrap_profiling(
"MPI_File_read", [&]() {
277 MPICHECK(MPI_File_read(fh, buf, count, datatype, status));
286 MPI_Datatype datatype,
287 MPI_Status *status) {
289 wrap_profiling(
"MPI_File_write_at", [&]() {
290 MPICHECK(MPI_File_write_at(fh, offset, buf, count, datatype, status));
299 MPI_Datatype datatype,
300 MPI_Status *status) {
302 wrap_profiling(
"MPI_File_read_at", [&]() {
303 MPICHECK(MPI_File_read_at(fh, offset, buf, count, datatype, status));
309 wrap_profiling(
"MPI_File_close", [&]() {
314 void File_open(MPI_Comm comm,
const char *filename,
int amode, MPI_Info info, MPI_File *fh) {
316 wrap_profiling(
"MPI_File_open", [&]() {
317 MPICHECK(MPI_File_open(comm, filename, amode, info, fh));
321 void Test(MPI_Request *request,
int *flag, MPI_Status *status) {
323 wrap_profiling(
"MPI_Test", [&]() {
324 MPICHECK(MPI_Test(request, flag, status));
331 MPI_Datatype sendtype,
334 MPI_Datatype recvtype,
338 wrap_profiling(
"MPI_Gather", [&]() {
340 MPI_Gather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm));
347 MPI_Datatype sendtype,
349 const int recvcounts[],
351 MPI_Datatype recvtype,
355 wrap_profiling(
"MPI_Gatherv", [&]() {
357 sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, root, comm));
double f64
Alias for double.
std::int32_t i32
32 bit integer
This header file contains utility functions related to exception handling in the code.
Utility functions for MPI error checking.
#define MPICHECK(mpicall)
Shortcut macro to check MPI return codes.
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
i32 mpi_max_tag_value()
Gets the maximum value of the MPI tag.
bool is_profiling_enabled()
Check if profiling is enabled.
void register_counter_val(const std::string &name, f64 time, f64 val)
Register a counter value.
This file contains the definition for the stacktrace related functionality.
shambase::details::BasicStackEntry StackEntry
Alias for shambase::details::BasicStackEntry.
f64 get_wtime()
Returns the current wall clock time in seconds.
Functions related to the MPI communicator.
void File_set_view(MPI_File fh, MPI_Offset disp, MPI_Datatype etype, MPI_Datatype filetype, const char *datarep, MPI_Info info)
MPI wrapper for MPI_File_set_view.
void Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count)
MPI wrapper for MPI_Get_count.
void Recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status)
MPI wrapper for MPI_Recv.
void Irecv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Request *request)
MPI wrapper for MPI_Irecv.
void Exscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
MPI wrapper for MPI_Exscan.
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 Probe(int source, int tag, MPI_Comm comm, MPI_Status *status)
MPI wrapper for MPI_Probe.
void Barrier(MPI_Comm comm)
MPI wrapper for MPI_Barrier.
void File_close(MPI_File *fh)
MPI wrapper for MPI_File_close.
void File_read(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
MPI wrapper for MPI_File_read.
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.
const std::vector< std::string > & get_possible_keys()
return all possible keys for the internal timers
void register_time(std::string timername, f64 time)
Register a timer value.
f64 get_timer(std::string timername)
get a timer value
void File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
MPI wrapper for MPI_File_write_at.
void File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info, MPI_File *fh)
MPI wrapper for MPI_File_open.
void Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
MPI wrapper for MPI_Allreduce.
void Waitall(int count, MPI_Request array_of_requests[], MPI_Status *array_of_statuses)
MPI wrapper for MPI_Waitall.
void Wait(MPI_Request *request, MPI_Status *status)
MPI wrapper for MPI_Wait.
void Type_size(MPI_Datatype type, int *size)
MPI wrapper for MPI_Type_size.
const std::unordered_map< std::string, f64 > & get_timers()
return all internal timers
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 File_write(MPI_File fh, const void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
MPI wrapper for MPI_File_write.
void Send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
MPI wrapper for MPI_Send.
void Test(MPI_Request *request, int *flag, MPI_Status *status)
MPI wrapper for MPI_Test.
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.
void Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
MPI wrapper for MPI_Isend.
void File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
MPI wrapper for MPI_File_read_at.
void File_write_all(MPI_File fh, const void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
MPI wrapper for MPI_File_write_all.