22 #ifndef __PLUMED_tools_Communicator_h
23 #define __PLUMED_tools_Communicator_h
49 static MPI_Datatype getMPIType();
107 void Allgatherv(
const T*,
int,T*,
const int*,
const int*);
115 void Recv(T*,
int,
int,
int);
117 void Bcast(T*,
int,
int);
125 #if defined(__PLUMED_MPI)
135 #if defined(__PLUMED_MPI)
147 #if defined(__PLUMED_MPI)
148 plumed_massert(
initialized(),
"you are trying to use an MPI function, but MPI is not initialized");
149 void*s=
const_cast<void*
>((
const void*)sendbuf);
150 void*r=
const_cast<void*
>((
const void*)recvbuf);
151 int*rc=
const_cast<int*
>(recvcounts);
152 int*di=
const_cast<int*
>(displs);
153 if(s==NULL)s=MPI_IN_PLACE;
154 MPI_Allgatherv(s,sendcount,getMPIType<T>(),r,rc,di,getMPIType<T>(),
communicator);
161 plumed_merror(
"you are trying to use an MPI function, but PLUMED has been compiled without MPI support");
167 #if defined(__PLUMED_MPI)
168 plumed_massert(
initialized(),
"you are trying to use an MPI function, but MPI is not initialized");
169 void*s=
const_cast<void*
>((
const void*)sendbuf);
170 void*r=
const_cast<void*
>((
const void*)recvbuf);
171 if(s==NULL)s=MPI_IN_PLACE;
172 MPI_Allgather(s,sendcount,getMPIType<T>(),r,recvcount,getMPIType<T>(),
communicator);
178 plumed_merror(
"you are trying to use an MPI function, but PLUMED has been compiled without MPI support");
186 plumed_massert(
initialized(),
"you are trying to use an MPI function, but MPI is not initialized");
187 void*s=
const_cast<void*
>((
const void*)buf);
188 MPI_Isend(s,count,getMPIType<T>(),source,tag,
communicator,&req.r);
194 plumed_merror(
"you are trying to use an MPI function, but PLUMED has been compiled without MPI support");
202 plumed_massert(
initialized(),
"you are trying to use an MPI function, but MPI is not initialized");
203 MPI_Recv(buf,count,getMPIType<T>(),source,tag,
communicator,&status.s);
210 plumed_merror(
"you are trying to use an MPI function, but PLUMED has been compiled without MPI support");
217 plumed_massert(
initialized(),
"you are trying to use an MPI function, but MPI is not initialized");
218 MPI_Recv(buf,count,getMPIType<T>(),source,tag,
communicator,MPI_STATUS_IGNORE);
224 plumed_merror(
"you are trying to use an MPI function, but PLUMED has been compiled without MPI support");
232 plumed_massert(
initialized(),
"you are trying to use an MPI function, but MPI is not initialized");
233 MPI_Get_count(const_cast<MPI_Status*>(&s),getMPIType<T>(),&i);
236 plumed_merror(
"you are trying to use an MPI function, but PLUMED has been compiled without MPI support");
void Split(int, int, Communicator &) const
Wrapper to MPI_Comm_split.
static bool initialized()
Tests if MPI library is initialized.
virtual ~Communicator()
Destructor.
void Bcast(T *, int, int)
MPI_Comm & Get_comm()
Reference to MPI communicator.
Class containing wrappers to MPI.
void Allgather(const T *, int, T *, int)
int Get_rank() const
Obtain the rank of the present process.
static Communicator & Get_world()
Returns MPI_COMM_WORLD if MPI is initialized, otherwise the default communicator. ...
void Recv(T *, int, int, int, Status &)
Communicator & operator=(const Communicator &)
Assignment operator.
void Barrier() const
Wrapper to MPI_Barrier.
void Set_comm(MPI_Comm)
Set from a real MPI communicator.
Surrogate of MPI types when MPI library is not available.
int Get_size() const
Obtain the number of processes.
void Set_fcomm(void *comm)
Set from a pointer to a real MPI communicator (FORTRAN)
void Allgatherv(const T *, int, T *, const int *, const int *)
Wrapper for MPI_Allgatherv.
void Sum(T *, int)
Wrapper for MPI_Allreduce with MPI_SUM.
Communicator()
Default constructor.
Request Isend(const T *, int, int, int)
void Abort(int)
Wrapper to MPI_Abort.
MPI_Comm communicator
Communicator.