30 Communicator::Communicator()
32 : communicator(MPI_COMM_SELF)
48 int Communicator::Get_rank()
const{
51 if(initialized()) MPI_Comm_rank(communicator,&r);
65 int Communicator::Get_size()
const{
68 if(initialized()) MPI_Comm_size(communicator,&s);
76 if(communicator!=MPI_COMM_SELF && communicator!=MPI_COMM_WORLD) MPI_Comm_free(&communicator);
77 if(c!=MPI_COMM_SELF) MPI_Comm_dup(c,&communicator);
84 Communicator::~Communicator(){
86 if(initialized() && communicator!=MPI_COMM_SELF && communicator!=MPI_COMM_WORLD) MPI_Comm_free(&communicator);
90 void Communicator::Set_comm(
void*val){
92 plumed_massert(initialized(),
"you are trying to use an MPI function, but MPI is not initialized");
96 plumed_merror(
"you are trying to use an MPI function, but PLUMED has been compiled without MPI support");
100 void Communicator::Set_fcomm(
void*val){
102 plumed_massert(initialized(),
"you are trying to use an MPI function, but MPI is not initialized");
104 MPI_Comm comm=MPI_Comm_f2c(*(MPI_Fint*)val);
109 plumed_merror(
"you are trying to use an MPI function, but PLUMED has been compiled without MPI support");
113 void Communicator::Abort(
int errorcode){
116 MPI_Abort(communicator,errorcode);
118 std::exit(errorcode);
120 std::exit(errorcode);
124 void Communicator::Barrier()
const{
126 if(initialized()) MPI_Barrier(communicator);
134 bool Communicator::initialized(){
136 #if defined(__PLUMED_MPI)
137 MPI_Initialized(&flag);
139 if(flag)
return true;
143 void Communicator::Request::wait(){
145 plumed_massert(initialized(),
"you are trying to use an MPI function, but MPI is not initialized");
146 MPI_Wait(&r,MPI_STATUS_IGNORE);
148 plumed_merror(
"you are trying to use an MPI function, but PLUMED has been compiled without MPI support");
152 void Communicator::Request::wait(
Status&s){
154 plumed_massert(initialized(),
"you are trying to use an MPI function, but MPI is not initialized");
158 plumed_merror(
"you are trying to use an MPI function, but PLUMED has been compiled without MPI support");
163 template<> MPI_Datatype Communicator::getMPIType<float>(){
return MPI_FLOAT;}
164 template<> MPI_Datatype Communicator::getMPIType<double>(){
return MPI_DOUBLE;}
165 template<> MPI_Datatype Communicator::getMPIType<int>() {
return MPI_INT;}
166 template<> MPI_Datatype Communicator::getMPIType<char>() {
return MPI_CHAR;}
167 template<> MPI_Datatype Communicator::getMPIType<unsigned>() {
return MPI_UNSIGNED;}
168 template<> MPI_Datatype Communicator::getMPIType<long unsigned>() {
return MPI_UNSIGNED_LONG;}
174 MPI_Comm_split(communicator,color,key,&pc.
communicator);
176 plumed_merror(
"you are trying to use an MPI function, but PLUMED has been compiled without MPI support");
Class containing wrappers to MPI.
Surrogate of MPI types when MPI library is not available.
MPI_Comm communicator
Communicator.