-
Notifications
You must be signed in to change notification settings - Fork 1
/
AlgSeven.C
272 lines (230 loc) · 8.25 KB
/
AlgSeven.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/**
*** Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by
*** The Board of Trustees of the University of Illinois.
*** All rights reserved.
**/
/*****************************************************************************
* $Source: /home/cvs/namd/cvsroot/namd2/src/AlgSeven.C,v $
* $Author: jim $
* $Date: 2013/06/07 22:34:36 $
* $Revision: 1.60 $
*****************************************************************************/
#include "common.h"
#include "InfoStream.h"
#include "Node.h"
#include "Alg7.h"
#define TINYLOAD 0.0005
Alg7::Alg7(computeInfo *computeArray, patchInfo *patchArray,
processorInfo *processorArray, int nComps,
int nPatches, int nPes) :
Rebalancer(computeArray, patchArray,
processorArray, nComps,
nPatches, nPes)
{
strategyName = "Alg7";
strategy();
}
extern int isPmeProcessor(int);
void Alg7::togrid(processorInfo* goodP[3][3][2], processorInfo* poorP[3][3][2],
processorInfo *p, computeInfo *c) {
if(p->available == false) return;
int nPatches, nProxies, badForComm;
numAvailable(c,p,&nPatches,&nProxies,&badForComm);
if (c->load + p->load < overLoad*averageLoad) {
processorInfo* &altp = goodP[nPatches][nProxies][badForComm];
#if USE_TOPOMAP
if(!altp)
altp = p;
else {
//Find processors that are patch neighbors on the BGL torus
int neighbor = 0, neighbor_alt = 0;
/*
if((tmgr->isNeighbor(altp->Id, patches[c->patch1].processor) ||
tmgr->isNeighbor(altp->Id, patches[c->patch2].processor)))
neighbor_alt = 1;
if(tmgr->isNeighbor(p->Id, patches[c->patch1].processor) ||
tmgr->isNeighbor(p->Id, patches[c->patch2].processor))
neighbor = 1;
*/
if(tmgr.areNeighbors(altp->Id, patches[c->patch1].processor,
patches[c->patch2].processor, 4))
neighbor_alt = 1;
if(tmgr.areNeighbors(p->Id, patches[c->patch1].processor,
patches[c->patch2].processor, 4))
neighbor = 1;
if(neighbor_alt == 1 && neighbor == 1) {
//Both are neighbors, only replace if lighter
if (p->load < altp->load ) {
altp = p;
}
}
else if(neighbor_alt == 0 && neighbor == 1)
//Previous was not a neighbor, kick him out
altp = p;
else if(neighbor_alt == 1 && neighbor == 0)
; //Give preference to good neighbors
else {
//Both not neighbors, choose nearby node to minimize hop bytes
/*
if (!altp || p->load < altp->load ) {
altp = p;
}
*/
int alt_dist = 0, dist = 0;
int ax,ay,az, x,y,z, p1x,p1y,p1z, p2x,p2y,p2z;
tmgr.rankToCoordinates(altp->Id, ax,ay,az);
tmgr.rankToCoordinates(p->Id, x,y,z);
tmgr.rankToCoordinates(patches[c->patch1].processor, p1x, p1y, p1z);
tmgr.rankToCoordinates(patches[c->patch2].processor, p2x, p2y, p2z);
alt_dist = abs(p1x - ax) + abs(p2x - ax) +
abs(p1y - ay) + abs(p1z - az) +
abs(p2y - ay) + abs(p2z - az);
dist = abs(p1x - x) + abs(p2x - x) +
abs(p1y - y) + abs(p1z - z) +
abs(p2y - y) + abs(p2z - z);
if(alt_dist > dist)
altp = p;
}
}
#else
if (!altp || p->load < altp->load ) {
altp = p;
}
#endif
}
{
processorInfo* &altp = poorP[nPatches][nProxies][badForComm];
if (!altp || p->load < altp->load ) {
altp = p;
}
}
}
void Alg7::strategy()
{
// double bestSize0, bestSize1, bestSize2;
computeInfo *c;
int numAssigned;
processorInfo* goodP[3][3][2]; // goodP[# of real patches][# of proxies]
processorInfo* poorP[3][3][2]; // fallback option
double startTime = CmiWallTimer();
// iout << iINFO << "calling makeHeaps. \n";
adjustBackgroundLoadAndComputeAverage();
makeHeaps();
// iout << iINFO << "Before assignment\n" << endi;
// printLoads();
/*
int numOverloaded = 0;
for (int ip=0; ip<P; ip++) {
if ( processors[ip].backgroundLoad > averageLoad ) ++numOverloaded;
}
if ( numOverloaded ) {
iout << iWARN << numOverloaded
<< " processors are overloaded due to background load.\n" << endi;
}
*/
numAssigned = 0;
// for (int i=0; i<numPatches; i++)
// { std::cout << "(" << patches[i].Id << "," << patches[i].processor ;}
overLoad = 1.2;
for (int ic=0; ic<numComputes; ic++) {
// place computes w/ patches on heavily background loaded nodes first
// place pair before self, because self is more flexible
c = (computeInfo *) computeBgPairHeap->deleteMax();
if ( ! c ) c = (computeInfo *) computeBgSelfHeap->deleteMax();
if ( ! c ) c = (computeInfo *) computePairHeap->deleteMax();
if ( ! c ) c = (computeInfo *) computeSelfHeap->deleteMax();
if (c->processor != -1) continue; // skip to the next compute;
if ( ! c ) NAMD_bug("Alg7: computesHeap empty!");
int i,j,k;
for(i=0;i<3;i++)
for(j=0;j<3;j++) {
for(k=0;k<2;k++) {
goodP[i][j][k]=0;
poorP[i][j][k]=0;
}
}
// first try for at least one proxy
{
Iterator nextProc;
processorInfo *p;
p = &processors[patches[c->patch1].processor];
togrid(goodP, poorP, p, c);
p = &processors[patches[c->patch2].processor];
togrid(goodP, poorP, p, c);
p = (processorInfo *)patches[c->patch1].
proxiesOn.iterator((Iterator *)&nextProc);
while (p) {
togrid(goodP, poorP, p, c);
p = (processorInfo *)patches[c->patch1].
proxiesOn.next((Iterator*)&nextProc);
}
p = (processorInfo *)patches[c->patch2].
proxiesOn.iterator((Iterator *)&nextProc);
while (p) {
togrid(goodP, poorP, p, c);
p = (processorInfo *)patches[c->patch2].
proxiesOn.next((Iterator*)&nextProc);
}
p = 0;
// prefer to place compute with existing proxies over home patches
if ((p = goodP[0][2][0]) // No home, two proxies
|| (p = goodP[1][1][0]) // One home, one proxy
|| (p = goodP[2][0][0]) // Two home, no proxies
|| (p = goodP[0][1][0]) // No home, one proxy
|| (p = goodP[1][0][0]) // One home, no proxies
|| (p = goodP[0][0][0]) // No home, no proxies
|| (p = goodP[0][1][1]) // No home, one proxy
|| (p = goodP[1][0][1]) // One home, no proxies
|| (p = goodP[0][0][1]) // No home, no proxies
) {
assign(c,p); numAssigned++;
continue;
}
}
// no luck, do it the long way
heapIterator nextProcessor;
processorInfo *p = (processorInfo *)
pes->iterator((heapIterator *) &nextProcessor);
while (p) {
togrid(goodP, poorP, p, c);
p = (processorInfo *) pes->next(&nextProcessor);
}
// if (numAssigned >= 0) { Else is commented out below
p = 0;
// prefer to place compute with existing proxies over home patches
if ((p = goodP[0][2][0]) // No home, two proxies
|| (p = goodP[1][1][0]) // One home, one proxy
|| (p = goodP[2][0][0]) // Two home, no proxies
|| (p = goodP[0][1][0]) // No home, one proxy
|| (p = goodP[1][0][0]) // One home, no proxies
|| (p = goodP[0][0][0]) // No home, no proxies
|| (p = goodP[0][1][1]) // No home, one proxy
|| (p = goodP[1][0][1]) // One home, no proxies
|| (p = goodP[0][0][1]) // No home, no proxies
) {
assign(c,p); numAssigned++;
} else if ( // overloaded processors
(p = poorP[0][2][0]) // No home, two proxies
|| (p = poorP[1][1][0]) // One home, one proxy
|| (p = poorP[2][0][0]) // Two home, no proxies
|| (p = poorP[0][1][0]) // No home, one proxy
|| (p = poorP[1][0][0]) // One home, no proxies
|| (p = poorP[0][0][0]) // No home, no proxies
|| (p = poorP[0][1][1]) // No home, one proxy
|| (p = poorP[1][0][1]) // One home, no proxies
|| (p = poorP[0][0][1]) // No home, no proxies
) {
//iout << iWARN << "overload assign to " << p->Id << "\n" << endi;
assign(c,p); numAssigned++;
} else {
NAMD_bug("*** Alg 7 No receiver found 1 ***");
break;
}
}
printLoads();
if ( computeMax() <= origMaxLoad ) {
// binary-search refinement procedure
multirefine(1.05);
printLoads();
}
}