12 #include "../config/config.hpp"
32 group_lproc(gt.group_lproc)
34 gt.groupmaster_lproc.
Copy(groupmaster_lproc);
35 gt.lproc_proc.
Copy(lproc_proc);
36 gt.group_mgroup.
Copy(group_mgroup);
39 void GroupTopology::ProcToLProc()
42 MPI_Comm_size(MyComm, &NRanks);
44 map<int, int> proc_lproc;
46 int lproc_counter = 0;
49 const pair<const int, int> p(group_lproc.
GetJ()[i], lproc_counter);
50 if (proc_lproc.insert(p).second)
57 lproc_proc.
SetSize(lproc_counter);
58 for (map<int, int>::iterator it = proc_lproc.begin();
59 it != proc_lproc.end(); ++it)
61 lproc_proc[it->second] = it->first;
66 group_lproc.
GetJ()[i] = proc_lproc[group_lproc.
GetJ()[i]];
69 for (
int i = 0; i <
NGroups(); i++)
71 groupmaster_lproc[i] = proc_lproc[groupmaster_lproc[i]];
79 Table group_mgroupandproc;
82 for (
int i = 0; i <
NGroups(); i++)
84 int j = group_mgroupandproc.
GetI()[i];
85 group_mgroupandproc.
GetI()[i+1] = j + group_lproc.
RowSize(i) + 1;
86 group_mgroupandproc.
GetJ()[j] = i;
88 for (
int k = group_lproc.
GetI()[i];
89 j < group_mgroupandproc.
GetI()[i+1]; j++, k++)
91 group_mgroupandproc.
GetJ()[j] = group_lproc.
GetJ()[k];
99 for (
int i = 0; i <
NGroups(); i++)
114 int send_counter = 0;
115 int recv_counter = 0;
116 for (
int i = 1; i <
NGroups(); i++)
117 if (groupmaster_lproc[i] != 0)
123 send_counter += group_lproc.
RowSize(i)-1;
126 MPI_Request *requests =
new MPI_Request[send_counter];
127 MPI_Status *statuses =
new MPI_Status[send_counter];
129 int max_recv_size = 0;
131 for (
int i = 1; i <
NGroups(); i++)
133 if (groupmaster_lproc[i] == 0)
137 for (
int j = group_lproc.
GetI()[i];
138 j < group_lproc.
GetI()[i+1]; j++)
140 if (group_lproc.
GetJ()[j] != 0)
142 MPI_Isend(group_mgroupandproc.
GetRow(i),
143 group_mgroupandproc.
RowSize(i),
145 lproc_proc[group_lproc.
GetJ()[j]],
148 &requests[send_counter]);
154 if (max_recv_size < group_lproc.
RowSize(i))
156 max_recv_size = group_lproc.
RowSize(i);
162 if (recv_counter > 0)
166 int *recv_buf =
new int[max_recv_size];
167 for ( ; recv_counter > 0; recv_counter--)
169 MPI_Recv(recv_buf, max_recv_size, MPI_INT,
170 MPI_ANY_SOURCE, mpitag, MyComm, &status);
172 MPI_Get_count(&status, MPI_INT, &count);
174 group.
Recreate(count-1, recv_buf+1);
175 int g = groups.
Lookup(group);
176 group_mgroup[g] = recv_buf[0];
178 if (lproc_proc[groupmaster_lproc[g]] != status.MPI_SOURCE)
180 cerr <<
"\n\n\nGroupTopology::GroupTopology: "
181 <<
MyRank() <<
": ERROR\n\n\n" << endl;
188 MPI_Waitall(send_counter, requests, statuses);
206 for (
int i = 0; i < ldof_group.
Size(); i++)
208 int group = ldof_group[i];
216 for (
int i = 0; i < ldof_group.
Size(); i++)
218 int group = ldof_group[i];
231 int request_counter = 0;
233 for (
int gr = 1; gr < group_ldof.
Size(); gr++)
234 if (group_ldof.
RowSize(gr) != 0)
246 request_counter += gr_requests;
247 group_buf_size += gr_requests * group_ldof.
RowSize(gr);
250 requests =
new MPI_Request[request_counter];
251 statuses =
new MPI_Status[request_counter];
257 if (group_buf_size == 0)
262 group_buf.
SetSize(group_buf_size*
sizeof(T));
263 T *buf = (T *)group_buf.
GetData();
265 int i, gr, request_counter = 0;
267 for (gr = 1; gr < group_ldof.
Size(); gr++)
269 const int nldofs = group_ldof.
RowSize(gr);
281 Get_MPI_Datatype<T>(),
285 &requests[request_counter]);
291 const int *ldofs = group_ldof.
GetRow(gr);
292 for (i = 0; i < nldofs; i++)
294 buf[i] = ldata[ldofs[i]];
298 const int *nbs = gtopo.
GetGroup(gr);
299 for (i = 0; i < gs; i++)
305 Get_MPI_Datatype<T>(),
309 &requests[request_counter]);
317 MPI_Waitall(request_counter, requests, statuses);
320 buf = (T *)group_buf.
GetData();
321 for (gr = 1; gr < group_ldof.
Size(); gr++)
323 const int nldofs = group_ldof.
RowSize(gr);
333 const int *ldofs = group_ldof.
GetRow(gr);
334 for (i = 0; i < nldofs; i++)
336 ldata[ldofs[i]] = buf[i];
346 if (group_buf_size == 0)
351 int i, gr, request_counter = 0;
354 group_buf.
SetSize(group_buf_size*
sizeof(T));
357 for (gr = 1; gr < group_ldof.
Size(); gr++)
371 for (i = 0; i < opd.
nldofs; i++)
378 Get_MPI_Datatype<T>(),
382 &requests[request_counter]);
389 const int *nbs = gtopo.
GetGroup(gr);
390 for (i = 0; i < gs; i++)
396 Get_MPI_Datatype<T>(),
400 &requests[request_counter]);
408 MPI_Waitall(request_counter, requests, statuses);
412 for (gr = 1; gr < group_ldof.
Size(); gr++)
439 for (
int i = 0; i < opd.
nldofs; i++)
442 for (
int j = 0; j < opd.
nb; j++)
453 for (
int i = 0; i < opd.
nldofs; i++)
456 for (
int j = 0; j < opd.
nb; j++)
471 for (
int i = 0; i < opd.
nldofs; i++)
474 for (
int j = 0; j < opd.
nb; j++)
489 for (
int i = 0; i < opd.
nldofs; i++)
492 for (
int j = 0; j < opd.
nb; j++)
507 template <>
inline MPI_Datatype GroupCommunicator::Get_MPI_Datatype<int>()
512 template <>
inline MPI_Datatype GroupCommunicator::Get_MPI_Datatype<double>()
520 template void GroupCommunicator::Bcast<int>(
int *);
521 template void GroupCommunicator::Reduce<int>(
int *, void (*)(OpData<int>));
523 template void GroupCommunicator::Bcast<double>(
double *);
524 template void GroupCommunicator::Reduce<double>(
525 double *, void (*)(OpData<double>));
530 template void GroupCommunicator::Sum<int>(OpData<int>);
531 template void GroupCommunicator::Min<int>(OpData<int>);
532 template void GroupCommunicator::Max<int>(OpData<int>);
533 template void GroupCommunicator::BitOR<int>(OpData<int>);
535 template void GroupCommunicator::Sum<double>(OpData<double>);
536 template void GroupCommunicator::Min<double>(OpData<double>);
537 template void GroupCommunicator::Max<double>(OpData<double>);
int Lookup(IntegerSet &s)
int GetGroupMasterRank(int g) const
void Create(ListOfIntegerSets &groups, int mpitag)
int Size() const
Logical size of the array.
void Recreate(const int n, const int *p)
int GetGroupMasterGroup(int g) const
GroupCommunicator(GroupTopology >)
void MakeI(int nrows)
Next 7 methods are used together with the default constructor.
int GetGroupSize(int g) const
void SetDims(int rows, int nnz)
const int * GetGroup(int g) const
void Copy(Array ©) const
Create a copy of the current array.
T * GetData()
Returns the data.
void GetRow(int i, Array< int > &row) const
Return row i in array row (the Table must be finalized)
int Size_of_connections() const
int PickElementInSet(int i)
bool IAmMaster(int g) const
static void Sum(OpData< T >)
Reduce operation Sum, instantiated for int and double.
void Finalize()
Allocate internal buffers after the GroupLDofTable is defined.
void AddConnection(int r, int c)
static void Min(OpData< T >)
Reduce operation Min, instantiated for int and double.
int Size() const
Returns the number of TYPE I elements.
int GetNeighborRank(int i) const
static void Max(OpData< T >)
Reduce operation Max, instantiated for int and double.
void AddAColumnInRow(int r)
void mfem_error(const char *msg)
void SetSize(int nsize)
Change logical size of the array, keep existing entries.
void Reduce(T *ldata, void(*Op)(OpData< T >))
void Create(Array< int > &ldof_group)
static void BitOR(OpData< T >)
Reduce operation bitwise OR, instantiated for int only.