-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprepare_neighbours.cc
More file actions
74 lines (67 loc) · 1.78 KB
/
prepare_neighbours.cc
File metadata and controls
74 lines (67 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
@copyright Russell Standish 2000-2013
@author Russell Standish
This file is part of EcoLab
Open source licensed under the MIT license. See LICENSE for details.
*/
#include "graphcode.h"
#include "classdesc_epilogue.h"
#ifdef ECOLAB_LIB
#include "ecolab_epilogue.h"
#endif
namespace graphcode
{
void GraphBase::prepareNeighbours(bool cache_requests)
{
#ifdef MPI_SUPPORT
if (nprocs()==1) return;
vector<vector<ObjRef> > return_data(nprocs());
if (!cache_requests || rec_req.size()!=nprocs())
{
rec_req.clear();
rec_req.resize(nprocs());
requests.clear();
requests.resize(nprocs());
vector<set<GraphId> > uniq_req(nprocs());
/* build a list of ID requests to be sent to processors */
for (auto& obj1:*this)
for (auto& obj2: *obj1)
if (obj2.proc()!=myid())
uniq_req[obj2.proc()].insert(obj2.id());
/* now send & receive requests */
tag++;
MPIbuf_array sendbuf(nprocs());
for (unsigned proc=0; proc<nprocs(); proc++)
{
if (proc==myid()) continue;
sendbuf[proc] << uniq_req[proc] >> requests[proc];
sendbuf[proc].isend(proc,tag);
}
for (unsigned i=0; i<nprocs()-1; i++)
{
MPIbuf b;
b.get(MPI_ANY_SOURCE,tag);
b >> rec_req[b.proc];
}
}
/* now service requests */
tag++;
MPIbuf_array sendbuf(nprocs());
for (unsigned proc=0; proc<nprocs(); proc++)
{
if (proc==myid()) continue;
unsigned i;
for (i=0; i<rec_req[proc].size(); i++)
sendbuf[proc] << objectRef(rec_req[proc][i]);
sendbuf[proc].isend(proc,tag);
}
for (unsigned p=0; p<nprocs()-1; p++)
{
MPIbuf b; b.get(MPI_ANY_SOURCE,tag);
for (unsigned i=0; i<requests[b.proc].size(); i++)
b>>objectRef(requests[b.proc][i]);
}
rebuildPtrLists();
#endif /* MPI_SUPPORT */
}
}