1 #ifndef CAFFE2_MPI_MPI_COMMON_H_ 2 #define CAFFE2_MPI_MPI_COMMON_H_ 7 #include "caffe2/core/common.h" 8 #include "caffe2/core/logging.h" 12 inline void CheckInitializedMPI() {
14 MPI_Initialized(&flag);
15 CAFFE_ENFORCE(flag,
"MPI does not seem to have been initialized.");
20 #define MPI_DATATYPE_WRAPPER(c_type, mpi_type) \ 21 template<> class MPIDataTypeWrapper<c_type> { \ 23 inline static MPI_Datatype type() { return mpi_type; } \ 26 MPI_DATATYPE_WRAPPER(
char, MPI_CHAR)
27 MPI_DATATYPE_WRAPPER(
float, MPI_FLOAT)
28 MPI_DATATYPE_WRAPPER(
double, MPI_DOUBLE)
30 #undef MPI_DATATYPE_WRAPPER 33 CAFFE2_API std::mutex& MPIMutex();
35 #define MPI_CHECK(condition) \ 37 std::lock_guard<std::mutex> guard(::caffe2::MPIMutex()); \ 38 int error = (condition); \ 40 error == MPI_SUCCESS, \ 41 "Caffe2 MPI Error at: ", \ 87 MPI_Comm src_comm = MPI_COMM_NULL,
90 if (src_comm == MPI_COMM_NULL) {
94 MPI_CHECK(MPI_Comm_rank(src_comm, &
rank));
96 MPI_CHECK(MPI_Comm_split(src_comm, color,
rank, &comm_));
97 MPI_CHECK(MPI_Comm_size(comm_, &size_));
98 MPI_CHECK(MPI_Comm_rank(comm_, &rank_));
103 MPI_CHECK(MPI_Finalized(&ret));
105 MPI_Comm_free(&comm_);
152 const string& job_path);
155 #endif // CAFFE2_MPI_MPI_COMMON_H_
void SetGlobalMPIComm(MPI_Comm new_comm)
Sets the global MPI communicator.
MPI_Comm comm() const
Returns the common world held by the wrapper.
int rank() const
Returns the rank of this process in the world.
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
int size() const
Returns the size of the world.
MPI_Comm GlobalMPIComm()
Gets the global MPI communicator used by Caffe2.
MPICommonWorldWrapper(MPI_Comm src_comm=MPI_COMM_NULL, int color=0, int rank=-1)
Creates a common world wrapper.
A simple wrapper over an MPI common world.
void MPISetupPeers(const int replicas, const string &role, const string &job_path)
A function used to perform peer setup so one does not need to use mpirun / mpiexec to run the binary...
int MPICommSize(MPI_Comm comm)
A helper function to return the size of the given communicator.
int MPICommRank(MPI_Comm comm)
A helper function to return the rank of the given communicator.