-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprepare_neighbours.cc
72 lines (66 loc) · 1.81 KB
/
prepare_neighbours.cc
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
/*
@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_NS
{
void Graph::Prepare_Neighbours(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_t> > uniq_req(nprocs());
/* build a list of ID requests to be sent to processors */
for (iterator obj1=begin(); obj1!=end(); obj1++)
for (Ptrlist::iterator obj2=(*obj1)->begin(); obj2!=(*obj1)->end(); obj2++)
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] << objects[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>>objects[requests[b.proc][i]];
}
#endif /* MPI_SUPPORT */
}
}