forked from N-BodyShop/changa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Orb3dLB_notopo.cpp
171 lines (134 loc) · 4.09 KB
/
Orb3dLB_notopo.cpp
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
#include <charm++.h>
#include "cklists.h"
#include "Orb3dLB_notopo.h"
#include "ParallelGravity.h"
#include "TopoManager.h"
#include "Vector3D.h"
#include "formatted_string.h"
extern CProxy_TreePiece treeProxy;
extern int doDumpLB;
extern int lbDumpIteration;
extern int doSimulateLB;
CkpvExtern(int, _lb_obj_index);
void Orb3dLB_notopo::init() {
lbname = "Orb3dLB_notopo";
if (CkpvAccess(_lb_obj_index) == -1)
CkpvAccess(_lb_obj_index) = LBRegisterObjUserData(sizeof(TaggedVector3D));
}
//#define ORB3DLB_NOTOPO_DEBUG CkPrintf
using namespace std;
#if CHARM_VERSION > 61002
static void lbinit()
{
LBRegisterBalancer<Orb3dLB_notopo>("Orb3dLB_notopo",
"3D ORB mapping of treepiece space onto processors without topology information");
}
#else
CreateLBFunc_Def(Orb3dLB_notopo, "3d ORB mapping of tree piece space onto 3d processor mesh");
#endif
Orb3dLB_notopo::Orb3dLB_notopo(const CkLBOptions &opt): CBase_Orb3dLB_notopo(opt)
{
init();
if (CkMyPe() == 0){
CkPrintf("[%d] Orb3dLB_notopo created\n",CkMyPe());
}
}
bool Orb3dLB_notopo::QueryBalanceNow(int step){
if(step == 0) return false;
return true;
}
void Orb3dLB_notopo::work(BaseLB::LDStats* stats)
{
const int numobjs = stats->objData.size();
double gstarttime = CkWallTimer();
vector<Event> tpEvents[NDIMS];
for(int i = 0; i < NDIMS; i++){
tpEvents[i].reserve(numobjs);
}
tps.resize(numobjs);
OrientedBox<float> box;
int numProcessed = 0;
if(doSimulateLB){
FILE *dumpFile = fopen("lb_dump.dat","r");
CkAssert(dumpFile != NULL);
PUP::fromTextFile pff(dumpFile);
pupDump(pff,stats,tpEvents);
CkPrintf("read dump\n");
fclose(dumpFile);
}
else{
for(int i = 0; i < numobjs; i++){
float load;
load = stats->objData[i].wallTime;
LDObjData &odata = stats->objData[i];
if (!odata.migratable) continue;
TaggedVector3D* udata = (TaggedVector3D *)odata.getUserData(CkpvAccess(_lb_obj_index));
tpEvents[XDIM].push_back(Event(udata->vec.x,load,i));
tpEvents[YDIM].push_back(Event(udata->vec.y,load,i));
tpEvents[ZDIM].push_back(Event(udata->vec.z,load,i));
tps[i] = OrbObject(i,udata->myNumParticles);
tps[i].centroid = udata->vec;
numProcessed++;
}
}
int flagDump = doDumpLB;
CkPrintf("doDump %d dumpIter %d step %d\n", flagDump, lbDumpIteration, step());
if(lbDumpIteration > 0 && (step() == lbDumpIteration)){
FILE *dumpFile = fopen("lb_dump.dat","w");
CkAssert(dumpFile != NULL);
PUP::toTextFile ptf(dumpFile);
pupDump(ptf,stats,tpEvents);
CkPrintf("done LB dump, exiting\n");
fclose(dumpFile);
CkExit();
return;
}
orbPrepare(tpEvents, box, numobjs, stats);
orbPartition(tpEvents,box,stats->nprocs(), tps, stats);
int mcount = 0;
for(int i = 0; i < numobjs; i++) {
if (stats->to_proc[i] != stats->from_proc[i]) {
mcount++;
}
}
refine(stats, numobjs);
CkPrintf("[%d] OrbLB_notopo> migrations count %d started at %f total time %f s\n",
CkMyPe(), mcount, gstarttime, CkWallTimer() - gstarttime);
if(_lb_args.debug() >= 2) {
// Write out "particle file" of load balance information
auto achFileName = make_formatted_string("lb.%d.sim", step());
FILE *fp = fopen(achFileName.c_str(), "w");
CkAssert(fp != NULL);
int num_migratables = numobjs;
for(int i = 0; i < numobjs; i++) {
if (!stats->objData[i].migratable) {
num_migratables--;
}
}
fprintf(fp, "%d %d 0\n", num_migratables, num_migratables);
for(int i = 0; i < numobjs; i++) {
if (!stats->objData[i].migratable) continue;
CkAssert(tps[i].lbindex < numobjs);
CkAssert(tps[i].lbindex >= 0);
fprintf(fp, "%g %g %g %g 0.0 0.0 0.0 %d 0.0\n",
stats->objData[tps[i].lbindex].wallTime,
tps[i].centroid.x,
tps[i].centroid.y,
tps[i].centroid.z,
stats->to_proc[tps[i].lbindex]);
}
fclose(fp);
}
if(doSimulateLB){
CkExit();
return;
}
}
void Orb3dLB_notopo::pupDump(PUP::er &p, BaseLB::LDStats *stats, vector<Event> *tpEvents){
stats->pup(p);
for(int i = XDIM; i <= ZDIM; i++){
p|tpEvents[i];
}
p|tps;
}
#include "Orb3dLB_notopo.def.h"