17 #include <ios/MinimalLogger.hpp> 18 #include <metaprogramming/TypeTraits.hpp> 19 #include <system/Timer.hpp> 20 #include <serialize/Binarize.hpp> 21 #include <utility/SingleInstance.hpp> 22 #include <Threads.hpp> 27 #define ALLOWS_ALL_RANKS_TO_PRINT_FOR_THIS_SCOPE(LOGGER) 33 inline MPI_Datatype mpiType()
40 #define PROVIDE_MPI_DATATYPE(MPI_TYPE,TYPE) 42 inline MPI_Datatype mpiType<TYPE>() 49 PROVIDE_MPI_DATATYPE(MPI_CHAR,
char);
51 PROVIDE_MPI_DATATYPE(MPI_INT,
int);
53 PROVIDE_MPI_DATATYPE(MPI_DOUBLE,
double);
61 #define MPI_CRASH_ON_ERROR(...) 62 Mpi::crashOnError(__LINE__,__FILE__,__PRETTY_FUNCTION__,__VA_ARGS__) 68 template <
typename...Args>
78 if(rc!=MPI_SUCCESS
and rank()==0)
84 char err[MPI_MAX_ERROR_STRING];
85 MPI_Error_string(rc,err,&len);
87 minimalCrash(file,line,
__PRETTY_FUNCTION__,
"(args ignored!), raised error %d, err: %s",rc,err);
115 MPI_CRASH_ON_ERROR(durationOf(initDur,MPI_Init,nullptr,nullptr),
"Error initializing MPI");
117 minimalLogger(runLog,
"MPI initialized in %lg s",durationInSec(initDur));
130 MPI_CRASH_ON_ERROR(MPI_Initialized(&res),
"Checking MPI initialization");
149 MPI_CRASH_ON_ERROR(MPI_Finalize(),
"Finalizing MPI");
163 MPI_CRASH_ON_ERROR(MPI_Comm_rank(MPI_COMM_WORLD,&res),
"Getting current rank");
198 MPI_CRASH_ON_ERROR(MPI_Comm_size(MPI_COMM_WORLD,&res),
"Getting total number of ranks");
217 (rank()==MASTER_RANK);
236 template <
typename T>
248 MPI_CRASH_ON_ERROR(MPI_Allreduce(&in,&out,1,mpiType<T>(),MPI_SUM,MPI_COMM_WORLD),
"Reducing among all processes");
265 template <
typename T,
281 template <
typename T,
293 template <
typename T,
int rank() const
Cached value of current rank.
T allReduce(const T &in) const
Reduces among all MPI process.
int getRank() const
Get current rank calling explicitly MPI.
bool isInitialized() const
Check initialization flag.
int crashOnError(const int line, const char *file, const char *function, const int rc, Args &&...args) const
Logger runLog("/dev/stdout")
Global logger.
int nRanks() const
Cached value of total number of ranks.
#define SWALLOW_SEMICOLON_AT_GLOBAL_SCOPE
#define SFINAE_ON_TEMPLATE_ARG(...)
int getNRanks() const
Get the total number of ranks, calling explicitly MPI.
bool isMasterRank() const
Check if this is the master rank.
#define SET_FOR_CURRENT_SCOPE(NAME, VAR,...)
Set for current scope.
void broadcast(T &&val, int root=MASTER_RANK) const