-
Notifications
You must be signed in to change notification settings - Fork 33
/
distribute.C
54 lines (44 loc) · 1.45 KB
/
distribute.C
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
/*
Developed by Sandeep Sharma and Garnet K.-L. Chan, 2012
Copyright (c) 2012, Garnet K.-L. Chan
This program is integrated in Molpro with the permission of
Sandeep Sharma and Garnet K.-L. Chan
*/
#include "distribute.h"
namespace SpinAdapted{
#ifdef SERIAL
int receivefrom(int offsetproc)
{
return 0;
}
#else
#include <boost/mpi/communicator.hpp>
int receivefrom(int offsetproc)
{
boost::mpi::communicator world;
int rank = world.rank();
int size = world.size();
rank -= offsetproc;
if (rank < 0) rank += size; // modulo size arithmetic
return ((rank - 1) / Broadcastsettings::npyramid + offsetproc) % size;
}
#endif
#ifdef SERIAL
void makesendlist(vector<int>& tolist, int offsetproc) {;}
#else
void makesendlist(vector<int>& tolist, int offsetproc)
{
boost::mpi::communicator world;
int rank = world.rank();
int size = world.size();
rank -= offsetproc; // if offsetproc == rank, then treat current proc as the root node
if (rank < 0) rank += size;
for (int i = 1; i <= Broadcastsettings::npyramid; ++i)
{
int tosend = rank * Broadcastsettings::npyramid +i;
if (tosend < size)
tolist.push_back((tosend + offsetproc) % size); // if offsetproc is not zero, add it back on, and then wraparound
}
}
#endif
}