12 #ifndef MFEM_COMMUNICATION
13 #define MFEM_COMMUNICATION
15 #include "../config/config.hpp"
52 int MyRank() {
int r; MPI_Comm_rank(MyComm, &r);
return r; }
53 int NRanks() {
int s; MPI_Comm_size(MyComm, &s);
return s; }
62 bool IAmMaster(
int g)
const {
return (groupmaster_lproc[g] == 0); }
68 {
return lproc_proc[groupmaster_lproc[g]]; }
85 MPI_Request *requests;
90 template <
class T>
static inline MPI_Datatype Get_MPI_Datatype();
108 template <
class T>
void Bcast(T *ldata);
125 { Reduce<T>((T *)ldata, Op); }
128 template <
class T>
static void Sum(OpData<T>);
130 template <
class T>
static void Min(OpData<T>);
132 template <
class T>
static void Max(OpData<T>);
134 template <
class T>
static void BitOR(OpData<T>);
151 MPI_Isend((
void*)
data.data(),
data.length(), MPI_BYTE, rank, Tag, comm,
156 template<
typename MapT>
157 static void IsendAll(MapT& rank_msg, MPI_Comm comm)
159 typename MapT::iterator it;
160 for (it = rank_msg.begin(); it != rank_msg.end(); ++it)
162 it->second.Isend(it->first, comm);
167 template<
typename MapT>
170 typename MapT::iterator it;
171 for (it = rank_msg.begin(); it != rank_msg.end(); ++it)
173 MPI_Wait(&it->second.send_request, MPI_STATUS_IGNORE);
180 static void Probe(
int &rank,
int &size, MPI_Comm comm)
183 MPI_Probe(MPI_ANY_SOURCE, Tag, comm, &status);
184 rank = status.MPI_SOURCE;
185 MPI_Get_count(&status, MPI_BYTE, &size);
191 static bool IProbe(
int &rank,
int &size, MPI_Comm comm)
195 MPI_Iprobe(MPI_ANY_SOURCE, Tag, comm, &flag, &status);
196 if (!flag) {
return false; }
198 rank = status.MPI_SOURCE;
199 MPI_Get_count(&status, MPI_BYTE, &size);
204 void Recv(
int rank,
int size, MPI_Comm comm)
206 MFEM_ASSERT(size >= 0,
"");
209 MPI_Recv((
void*)
data.data(), size, MPI_BYTE, rank, Tag, comm, &status);
212 MPI_Get_count(&status, MPI_BYTE, &count);
213 MFEM_VERIFY(count == size,
"");
219 template<
typename MapT>
220 static void RecvAll(MapT& rank_msg, MPI_Comm comm)
222 int recv_left = rank_msg.size();
223 while (recv_left > 0)
226 Probe(rank, size, comm);
227 MFEM_ASSERT(rank_msg.find(rank) != rank_msg.end(),
"");
229 rank_msg[rank].Recv(rank, size, comm);
240 "WaitAllSent was not called after Isend");
247 "Cannot copy message with a pending send.");
int GetGroupMasterRank(int g) const
void Create(ListOfIntegerSets &groups, int mpitag)
int Size() const
Logical size of the array.
void Bcast(Array< T > &ldata)
int GetGroupMasterGroup(int g) const
GroupCommunicator(GroupTopology >)
GroupTopology(MPI_Comm comm)
int GetGroupSize(int g) const
const int * GetGroup(int g) const
void GetRow(int i, Array< int > &row) const
Return row i in array row (the Table must be finalized)
void Reduce(Array< T > &ldata, void(*Op)(OpData< T >))
void Recv(int rank, int size, MPI_Comm comm)
Post-probe receive from processor 'rank' of message size 'size'.
bool IAmMaster(int g) const
VarMessage(const VarMessage &other)
static void Sum(OpData< T >)
Reduce operation Sum, instantiated for int and double.
int GetNumNeighbors() const
void Finalize()
Allocate internal buffers after the GroupLDofTable is defined.
static void Min(OpData< T >)
Reduce operation Min, instantiated for int and double.
static void IsendAll(MapT &rank_msg, MPI_Comm comm)
Helper to send all messages in a rank-to-message map container.
int Size() const
Returns the number of TYPE I elements.
GroupTopology & GetGroupTopology()
Get a reference to the group topology object.
int GetGroupMaster(int g) const
int GetNeighborRank(int i) const
static void Max(OpData< T >)
Reduce operation Max, instantiated for int and double.
static void RecvAll(MapT &rank_msg, MPI_Comm comm)
Helper to receive all messages in a rank-to-message map container.
void Reduce(T *ldata, void(*Op)(OpData< T >))
void Isend(int rank, MPI_Comm comm)
Non-blocking send to processor 'rank'.
void Create(Array< int > &ldof_group)
static void WaitAllSent(MapT &rank_msg)
Helper to wait for all messages in a map container to be sent.
static bool IProbe(int &rank, int &size, MPI_Comm comm)
Variable-length MPI message containing unspecific binary data.
static void Probe(int &rank, int &size, MPI_Comm comm)
static void BitOR(OpData< T >)
Reduce operation bitwise OR, instantiated for int only.