1 #ifndef CAFFE2_MPI_MPI_COMMON_H_ 2 #define CAFFE2_MPI_MPI_COMMON_H_ 7 #include "caffe2/core/logging.h" 11 inline void CheckInitializedMPI() {
13 MPI_Initialized(&flag);
14 CAFFE_ENFORCE(flag,
"MPI does not seem to have been initialized.");
19 #define MPI_DATATYPE_WRAPPER(c_type, mpi_type) \ 20 template<> class MPIDataTypeWrapper<c_type> { \ 22 inline static MPI_Datatype type() { return mpi_type; } \ 25 MPI_DATATYPE_WRAPPER(
char, MPI_CHAR)
26 MPI_DATATYPE_WRAPPER(
float, MPI_FLOAT)
27 MPI_DATATYPE_WRAPPER(
double, MPI_DOUBLE)
29 #undef MPI_DATATYPE_WRAPPER 32 std::mutex& MPIMutex();
34 #define MPI_CHECK(condition) \ 36 std::lock_guard<std::mutex> guard(::caffe2::MPIMutex()); \ 37 int error = (condition); \ 39 error == MPI_SUCCESS, \ 40 "Caffe2 MPI Error at: ", \ 86 MPI_Comm src_comm = MPI_COMM_NULL,
89 if (src_comm == MPI_COMM_NULL) {
93 MPI_CHECK(MPI_Comm_rank(src_comm, &
rank));
95 MPI_CHECK(MPI_Comm_split(src_comm, color,
rank, &comm_));
96 MPI_CHECK(MPI_Comm_size(comm_, &size_));
97 MPI_CHECK(MPI_Comm_rank(comm_, &rank_));
102 MPI_CHECK(MPI_Finalized(&ret));
104 MPI_Comm_free(&comm_);
151 const string& job_path);
154 #endif // CAFFE2_MPI_MPI_COMMON_H_ int size() const
Returns the size of the world.
MPICommonWorldWrapper(MPI_Comm src_comm=MPI_COMM_NULL, int color=0, int rank=-1)
Creates a common world wrapper.
MPI_Comm GlobalMPIComm()
Gets the global MPI communicator used by Caffe2.
void SetGlobalMPIComm(MPI_Comm new_comm)
Sets the global MPI communicator.
A simple wrapper over an MPI common world.
int MPICommRank(MPI_Comm comm)
A helper function to return the rank of the given communicator.
Simple registry implementation in Caffe2 that uses static variables to register object creators durin...
int MPICommSize(MPI_Comm comm)
A helper function to return the size of the given communicator.
int rank() const
Returns the rank of this process in the 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...
MPI_Comm comm() const
Returns the common world held by the wrapper.