3 |
|
#include <string.h> |
4 |
|
#include <iostream> |
5 |
|
#include <fstream> |
6 |
+ |
#include <algorithm> |
7 |
+ |
#include <utility> |
8 |
|
|
9 |
|
#ifdef IS_MPI |
10 |
|
#include <mpi.h> |
28 |
|
if(worldRank == 0 ){ |
29 |
|
#endif // is_mpi |
30 |
|
|
29 |
– |
strcpy( outName, entry_plug->sampleName ); |
31 |
|
|
32 |
< |
outFile.open(outName, ios::out | ios::trunc ); |
32 |
> |
dumpFile.open(entry_plug->sampleName, ios::out | ios::trunc ); |
33 |
|
|
34 |
< |
if( !outFile ){ |
34 |
> |
if( !dumpFile ){ |
35 |
|
|
36 |
|
sprintf( painCave.errMsg, |
37 |
|
"Could not open \"%s\" for dump output.\n", |
38 |
< |
outName); |
38 |
> |
entry_plug->sampleName); |
39 |
|
painCave.isFatal = 1; |
40 |
|
simError(); |
41 |
|
} |
45 |
|
#ifdef IS_MPI |
46 |
|
} |
47 |
|
|
48 |
+ |
//sort the local atoms by global index |
49 |
+ |
sortByGlobalIndex(); |
50 |
+ |
|
51 |
|
sprintf( checkPointMsg, |
52 |
|
"Sucessfully opened output file for dumping.\n"); |
53 |
|
MPIcheckPoint(); |
60 |
|
if(worldRank == 0 ){ |
61 |
|
#endif // is_mpi |
62 |
|
|
63 |
< |
outFile.close(); |
63 |
> |
dumpFile.close(); |
64 |
|
|
65 |
|
#ifdef IS_MPI |
66 |
|
} |
67 |
|
#endif // is_mpi |
68 |
|
} |
69 |
|
|
70 |
< |
void DumpWriter::writeDump( double currentTime ){ |
70 |
> |
#ifdef IS_MPI |
71 |
|
|
72 |
+ |
/** |
73 |
+ |
* A hook function to load balancing |
74 |
+ |
*/ |
75 |
+ |
|
76 |
+ |
void DumpWriter::update(){ |
77 |
+ |
sortByGlobalIndex(); |
78 |
+ |
} |
79 |
+ |
|
80 |
+ |
/** |
81 |
+ |
* Auxiliary sorting function |
82 |
+ |
*/ |
83 |
+ |
|
84 |
+ |
bool indexSortingCriterion(const pair<int, int>& p1, const pair<int, int>& p2){ |
85 |
+ |
return p1.second < p2.second; |
86 |
+ |
} |
87 |
+ |
|
88 |
+ |
/** |
89 |
+ |
* Sorting the local index by global index |
90 |
+ |
*/ |
91 |
+ |
|
92 |
+ |
void DumpWriter::sortByGlobalIndex(){ |
93 |
+ |
Atom** atoms = entry_plug->atoms; |
94 |
+ |
|
95 |
+ |
indexArray.clear(); |
96 |
+ |
|
97 |
+ |
for(int i = 0; i < mpiSim->getMyNlocal();i++) |
98 |
+ |
indexArray.push_back(make_pair(i, atoms[i]->getGlobalIndex())); |
99 |
+ |
|
100 |
+ |
sort(indexArray.begin(), indexArray.end(), indexSortingCriterion); |
101 |
+ |
} |
102 |
+ |
#endif |
103 |
+ |
|
104 |
+ |
void DumpWriter::writeDump(double currentTime){ |
105 |
+ |
|
106 |
+ |
// write to eor file |
107 |
+ |
writeFinal(currentTime); |
108 |
+ |
|
109 |
+ |
//write to dump file |
110 |
+ |
writeFrame(dumpFile, currentTime); |
111 |
+ |
|
112 |
+ |
} |
113 |
+ |
|
114 |
+ |
void DumpWriter::writeFinal(double currentTime){ |
115 |
+ |
|
116 |
+ |
ofstream finalOut; |
117 |
+ |
|
118 |
+ |
//Open eor file |
119 |
+ |
#ifdef IS_MPI |
120 |
+ |
if(worldRank == 0 ){ |
121 |
+ |
#endif // is_mpi |
122 |
+ |
|
123 |
+ |
finalOut.open( entry_plug->finalName, ios::out | ios::trunc ); |
124 |
+ |
if( !finalOut ){ |
125 |
+ |
sprintf( painCave.errMsg, |
126 |
+ |
"Could not open \"%s\" for final dump output.\n", |
127 |
+ |
entry_plug->finalName ); |
128 |
+ |
painCave.isFatal = 1; |
129 |
+ |
simError(); |
130 |
+ |
} |
131 |
+ |
|
132 |
+ |
#ifdef IS_MPI |
133 |
+ |
} |
134 |
+ |
#endif |
135 |
+ |
|
136 |
+ |
//write to eor file |
137 |
+ |
writeFrame(finalOut, currentTime); |
138 |
+ |
|
139 |
+ |
//close eor file |
140 |
+ |
#ifdef IS_MPI |
141 |
+ |
if(worldRank == 0 ){ |
142 |
+ |
finalOut.close(); |
143 |
+ |
} |
144 |
+ |
#endif // is_mpi |
145 |
+ |
|
146 |
+ |
} |
147 |
+ |
|
148 |
+ |
void DumpWriter::writeFrame( ofstream& outFile, double currentTime ){ |
149 |
+ |
|
150 |
|
const int BUFFERSIZE = 2000; |
151 |
< |
const int MINIBUFFERSIZE = 10; |
151 |
> |
const int MINIBUFFERSIZE = 100; |
152 |
|
|
153 |
|
char tempBuffer[BUFFERSIZE]; |
154 |
|
char writeLine[BUFFERSIZE]; |
155 |
|
|
156 |
|
int i; |
157 |
+ |
|
158 |
|
#ifdef IS_MPI |
159 |
< |
int j, which_node, done, which_atom, local_index; |
160 |
< |
double atomTransData[6]; |
161 |
< |
double atomOrientData[7]; |
159 |
> |
|
160 |
> |
int *potatoes; |
161 |
> |
int myPotato; |
162 |
> |
|
163 |
> |
int nProc; |
164 |
> |
int j, which_node, done, which_atom, local_index, currentIndex; |
165 |
> |
double atomData6[6]; |
166 |
> |
double atomData13[13]; |
167 |
|
int isDirectional; |
168 |
|
char* atomTypeString; |
169 |
< |
int me; |
170 |
< |
int atomTypeTag; |
83 |
< |
int atomIsDirectionalTag; |
84 |
< |
int atomTransDataTag; |
85 |
< |
int atomOrientDataTag; |
169 |
> |
char MPIatomTypeString[MINIBUFFERSIZE]; |
170 |
> |
|
171 |
|
#else //is_mpi |
172 |
|
int nAtoms = entry_plug->n_atoms; |
173 |
|
#endif //is_mpi |
177 |
|
Atom** atoms = entry_plug->atoms; |
178 |
|
double pos[3], vel[3]; |
179 |
|
|
95 |
– |
// write current frame to the eor file |
96 |
– |
|
97 |
– |
this->writeFinal( currentTime ); |
98 |
– |
|
180 |
|
#ifndef IS_MPI |
181 |
|
|
182 |
|
outFile << nAtoms << "\n"; |
234 |
|
|
235 |
|
outFile << writeLine; |
236 |
|
} |
156 |
– |
outFile.flush(); |
237 |
|
|
238 |
|
#else // is_mpi |
239 |
|
|
240 |
< |
// first thing first, suspend fatalities. |
241 |
< |
painCave.isEventLoop = 1; |
240 |
> |
/* code to find maximum tag value */ |
241 |
> |
|
242 |
> |
int *tagub, flag, MAXTAG; |
243 |
> |
MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
244 |
> |
if (flag) { |
245 |
> |
MAXTAG = *tagub; |
246 |
> |
} else { |
247 |
> |
MAXTAG = 32767; |
248 |
> |
} |
249 |
|
|
163 |
– |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
250 |
|
int haveError; |
251 |
|
|
252 |
|
MPI_Status istatus; |
255 |
|
// write out header and node 0's coordinates |
256 |
|
|
257 |
|
if( worldRank == 0 ){ |
258 |
+ |
|
259 |
+ |
// Node 0 needs a list of the magic potatoes for each processor; |
260 |
+ |
|
261 |
+ |
nProc = mpiSim->getNumberProcessors(); |
262 |
+ |
potatoes = new int[nProc]; |
263 |
+ |
|
264 |
+ |
for (i = 0; i < nProc; i++) |
265 |
+ |
potatoes[i] = 0; |
266 |
+ |
|
267 |
|
outFile << mpiSim->getTotAtoms() << "\n"; |
268 |
|
|
269 |
|
outFile << currentTime << ";\t" |
282 |
|
outFile << entry_plug->the_integrator->getAdditionalParameters(); |
283 |
|
outFile << endl; |
284 |
|
outFile.flush(); |
285 |
+ |
|
286 |
+ |
currentIndex = 0; |
287 |
|
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
288 |
+ |
|
289 |
|
// Get the Node number which has this atom; |
290 |
< |
|
290 |
> |
|
291 |
|
which_node = AtomToProcMap[i]; |
292 |
< |
|
292 |
> |
|
293 |
|
if (which_node != 0) { |
196 |
– |
|
197 |
– |
atomTypeTag = 4*i; |
198 |
– |
atomIsDirectionalTag = 4*i + 1; |
199 |
– |
atomTransDataTag = 4*i + 2; |
200 |
– |
atomOrientDataTag = 4*i + 3; |
294 |
|
|
295 |
< |
MPI_Recv(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
296 |
< |
atomTypeTag, MPI_COMM_WORLD, &istatus); |
295 |
> |
if (potatoes[which_node] + 3 >= MAXTAG) { |
296 |
> |
// The potato was going to exceed the maximum value, |
297 |
> |
// so wrap this processor potato back to 0: |
298 |
> |
|
299 |
> |
potatoes[which_node] = 0; |
300 |
> |
MPI_Send(0, 1, MPI_INT, which_node, 0, MPI_COMM_WORLD); |
301 |
> |
|
302 |
> |
} |
303 |
> |
|
304 |
> |
myPotato = potatoes[which_node]; |
305 |
|
|
306 |
< |
MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
307 |
< |
atomIsDirectionalTag, MPI_COMM_WORLD, &istatus); |
306 |
> |
MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
307 |
> |
myPotato, MPI_COMM_WORLD, &istatus); |
308 |
|
|
309 |
< |
MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node, |
310 |
< |
atomTransDataTag, MPI_COMM_WORLD, &istatus); |
309 |
> |
atomTypeString = MPIatomTypeString; |
310 |
> |
|
311 |
> |
myPotato++; |
312 |
|
|
313 |
< |
if (isDirectional) { |
313 |
> |
MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
314 |
> |
myPotato, MPI_COMM_WORLD, &istatus); |
315 |
> |
|
316 |
> |
myPotato++; |
317 |
|
|
318 |
< |
MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node, |
319 |
< |
atomOrientDataTag, MPI_COMM_WORLD, &istatus); |
320 |
< |
|
318 |
> |
if (isDirectional) { |
319 |
> |
MPI_Recv(atomData13, 13, MPI_DOUBLE, which_node, |
320 |
> |
myPotato, MPI_COMM_WORLD, &istatus); |
321 |
> |
} else { |
322 |
> |
MPI_Recv(atomData6, 6, MPI_DOUBLE, which_node, |
323 |
> |
myPotato, MPI_COMM_WORLD, &istatus); |
324 |
|
} |
325 |
+ |
|
326 |
+ |
myPotato++; |
327 |
+ |
potatoes[which_node] = myPotato; |
328 |
|
|
329 |
|
} else { |
330 |
|
|
331 |
|
haveError = 0; |
332 |
|
which_atom = i; |
333 |
< |
local_index=-1; |
334 |
< |
|
335 |
< |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
336 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
337 |
< |
} |
227 |
< |
|
228 |
< |
if (local_index != -1) { |
229 |
< |
|
333 |
> |
|
334 |
> |
local_index = indexArray[currentIndex].first; |
335 |
> |
|
336 |
> |
if (which_atom == indexArray[currentIndex].second) { |
337 |
> |
|
338 |
|
atomTypeString = atoms[local_index]->getType(); |
339 |
|
|
340 |
|
atoms[local_index]->getPos(pos); |
341 |
< |
atoms[local_index]->getVel(vel); |
341 |
> |
atoms[local_index]->getVel(vel); |
342 |
|
|
343 |
< |
atomTransData[0] = pos[0]; |
344 |
< |
atomTransData[1] = pos[1]; |
345 |
< |
atomTransData[2] = pos[2]; |
343 |
> |
atomData6[0] = pos[0]; |
344 |
> |
atomData6[1] = pos[1]; |
345 |
> |
atomData6[2] = pos[2]; |
346 |
|
|
347 |
< |
atomTransData[3] = vel[0]; |
348 |
< |
atomTransData[4] = vel[1]; |
349 |
< |
atomTransData[5] = vel[2]; |
347 |
> |
atomData6[3] = vel[0]; |
348 |
> |
atomData6[4] = vel[1]; |
349 |
> |
atomData6[5] = vel[2]; |
350 |
|
|
351 |
|
isDirectional = 0; |
352 |
|
|
356 |
|
|
357 |
|
dAtom = (DirectionalAtom *)atoms[local_index]; |
358 |
|
dAtom->getQ( q ); |
251 |
– |
|
252 |
– |
atomOrientData[0] = q[0]; |
253 |
– |
atomOrientData[1] = q[1]; |
254 |
– |
atomOrientData[2] = q[2]; |
255 |
– |
atomOrientData[3] = q[3]; |
359 |
|
|
360 |
< |
atomOrientData[4] = dAtom->getJx(); |
361 |
< |
atomOrientData[5] = dAtom->getJy(); |
362 |
< |
atomOrientData[6] = dAtom->getJz(); |
360 |
> |
for (int j = 0; j < 6 ; j++) |
361 |
> |
atomData13[j] = atomData6[j]; |
362 |
> |
|
363 |
> |
atomData13[6] = q[0]; |
364 |
> |
atomData13[7] = q[1]; |
365 |
> |
atomData13[8] = q[2]; |
366 |
> |
atomData13[9] = q[3]; |
367 |
> |
|
368 |
> |
atomData13[10] = dAtom->getJx(); |
369 |
> |
atomData13[11] = dAtom->getJy(); |
370 |
> |
atomData13[12] = dAtom->getJz(); |
371 |
|
} |
372 |
< |
|
372 |
> |
|
373 |
|
} else { |
374 |
|
sprintf(painCave.errMsg, |
375 |
|
"Atom %d not found on processor %d\n", |
377 |
|
haveError= 1; |
378 |
|
simError(); |
379 |
|
} |
380 |
< |
|
380 |
> |
|
381 |
|
if(haveError) DieDieDie(); |
271 |
– |
|
272 |
– |
// If we've survived to here, format the line: |
382 |
|
|
383 |
< |
sprintf( tempBuffer, |
384 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
385 |
< |
atomTypeString, |
386 |
< |
atomTransData[0], |
387 |
< |
atomTransData[1], |
388 |
< |
atomTransData[2], |
389 |
< |
atomTransData[3], |
390 |
< |
atomTransData[4], |
391 |
< |
atomTransData[5]); |
383 |
> |
currentIndex ++; |
384 |
> |
} |
385 |
> |
// If we've survived to here, format the line: |
386 |
> |
|
387 |
> |
if (!isDirectional) { |
388 |
> |
|
389 |
> |
sprintf( writeLine, |
390 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
391 |
> |
atomTypeString, |
392 |
> |
atomData6[0], |
393 |
> |
atomData6[1], |
394 |
> |
atomData6[2], |
395 |
> |
atomData6[3], |
396 |
> |
atomData6[4], |
397 |
> |
atomData6[5]); |
398 |
|
|
399 |
< |
strcpy( writeLine, tempBuffer ); |
400 |
< |
|
401 |
< |
if (isDirectional) { |
402 |
< |
|
403 |
< |
sprintf( tempBuffer, |
404 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
405 |
< |
atomOrientData[0], |
406 |
< |
atomOrientData[1], |
407 |
< |
atomOrientData[2], |
408 |
< |
atomOrientData[3], |
409 |
< |
atomOrientData[4], |
410 |
< |
atomOrientData[5], |
411 |
< |
atomOrientData[6]); |
412 |
< |
strcat( writeLine, tempBuffer ); |
413 |
< |
|
414 |
< |
} else { |
415 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
416 |
< |
} |
417 |
< |
|
418 |
< |
outFile << writeLine; |
419 |
< |
outFile.flush(); |
399 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
400 |
> |
|
401 |
> |
} else { |
402 |
> |
|
403 |
> |
sprintf( writeLine, |
404 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
405 |
> |
atomTypeString, |
406 |
> |
atomData13[0], |
407 |
> |
atomData13[1], |
408 |
> |
atomData13[2], |
409 |
> |
atomData13[3], |
410 |
> |
atomData13[4], |
411 |
> |
atomData13[5], |
412 |
> |
atomData13[6], |
413 |
> |
atomData13[7], |
414 |
> |
atomData13[8], |
415 |
> |
atomData13[9], |
416 |
> |
atomData13[10], |
417 |
> |
atomData13[11], |
418 |
> |
atomData13[12]); |
419 |
> |
|
420 |
|
} |
421 |
+ |
|
422 |
+ |
outFile << writeLine; |
423 |
|
} |
424 |
+ |
|
425 |
|
|
426 |
|
outFile.flush(); |
427 |
|
sprintf( checkPointMsg, |
428 |
|
"Sucessfully took a dump.\n"); |
429 |
|
MPIcheckPoint(); |
430 |
< |
|
430 |
> |
delete[] potatoes; |
431 |
|
} else { |
432 |
|
|
433 |
|
// worldRank != 0, so I'm a remote node. |
434 |
+ |
|
435 |
+ |
// Set my magic potato to 0: |
436 |
+ |
|
437 |
+ |
myPotato = 0; |
438 |
+ |
currentIndex = 0; |
439 |
|
|
440 |
|
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
441 |
|
|
443 |
|
|
444 |
|
if (AtomToProcMap[i] == worldRank) { |
445 |
|
|
446 |
< |
local_index=-1; |
447 |
< |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
448 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
446 |
> |
if (myPotato + 3 >= MAXTAG) { |
447 |
> |
|
448 |
> |
// The potato was going to exceed the maximum value, |
449 |
> |
// so wrap this processor potato back to 0 (and block until |
450 |
> |
// node 0 says we can go: |
451 |
> |
|
452 |
> |
MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus); |
453 |
> |
|
454 |
|
} |
455 |
< |
if (local_index != -1) { |
455 |
> |
which_atom = i; |
456 |
> |
local_index = indexArray[currentIndex].first; |
457 |
> |
|
458 |
> |
if (which_atom == indexArray[currentIndex].second) { |
459 |
|
|
460 |
|
atomTypeString = atoms[local_index]->getType(); |
461 |
|
|
462 |
|
atoms[local_index]->getPos(pos); |
463 |
|
atoms[local_index]->getVel(vel); |
464 |
|
|
465 |
< |
atomTransData[0] = pos[0]; |
466 |
< |
atomTransData[1] = pos[1]; |
467 |
< |
atomTransData[2] = pos[2]; |
465 |
> |
atomData6[0] = pos[0]; |
466 |
> |
atomData6[1] = pos[1]; |
467 |
> |
atomData6[2] = pos[2]; |
468 |
|
|
469 |
< |
atomTransData[3] = vel[0]; |
470 |
< |
atomTransData[4] = vel[1]; |
471 |
< |
atomTransData[5] = vel[2]; |
469 |
> |
atomData6[3] = vel[0]; |
470 |
> |
atomData6[4] = vel[1]; |
471 |
> |
atomData6[5] = vel[2]; |
472 |
|
|
473 |
|
isDirectional = 0; |
474 |
|
|
479 |
|
dAtom = (DirectionalAtom *)atoms[local_index]; |
480 |
|
dAtom->getQ( q ); |
481 |
|
|
482 |
< |
atomOrientData[0] = q[0]; |
483 |
< |
atomOrientData[1] = q[1]; |
484 |
< |
atomOrientData[2] = q[2]; |
485 |
< |
atomOrientData[3] = q[3]; |
482 |
> |
for (int j = 0; j < 6 ; j++) |
483 |
> |
atomData13[j] = atomData6[j]; |
484 |
> |
|
485 |
> |
atomData13[6] = q[0]; |
486 |
> |
atomData13[7] = q[1]; |
487 |
> |
atomData13[8] = q[2]; |
488 |
> |
atomData13[9] = q[3]; |
489 |
|
|
490 |
< |
atomOrientData[4] = dAtom->getJx(); |
491 |
< |
atomOrientData[5] = dAtom->getJy(); |
492 |
< |
atomOrientData[6] = dAtom->getJz(); |
490 |
> |
atomData13[10] = dAtom->getJx(); |
491 |
> |
atomData13[11] = dAtom->getJy(); |
492 |
> |
atomData13[12] = dAtom->getJz(); |
493 |
|
} |
494 |
|
|
495 |
|
} else { |
500 |
|
simError(); |
501 |
|
} |
502 |
|
|
503 |
< |
// I've survived this far, so send off the data! |
503 |
> |
strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
504 |
|
|
505 |
< |
atomTypeTag = 4*i; |
506 |
< |
atomIsDirectionalTag = 4*i + 1; |
373 |
< |
atomTransDataTag = 4*i + 2; |
374 |
< |
atomOrientDataTag = 4*i + 3; |
505 |
> |
// null terminate the string before sending (just in case): |
506 |
> |
MPIatomTypeString[MINIBUFFERSIZE-1] = '\0'; |
507 |
|
|
508 |
< |
MPI_Send(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
509 |
< |
atomTypeTag, MPI_COMM_WORLD); |
508 |
> |
MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
509 |
> |
myPotato, MPI_COMM_WORLD); |
510 |
|
|
511 |
+ |
myPotato++; |
512 |
+ |
|
513 |
|
MPI_Send(&isDirectional, 1, MPI_INT, 0, |
514 |
< |
atomIsDirectionalTag, MPI_COMM_WORLD); |
514 |
> |
myPotato, MPI_COMM_WORLD); |
515 |
|
|
516 |
< |
MPI_Send(atomTransData, 6, MPI_DOUBLE, 0, |
517 |
< |
atomTransDataTag, MPI_COMM_WORLD); |
384 |
< |
|
516 |
> |
myPotato++; |
517 |
> |
|
518 |
|
if (isDirectional) { |
519 |
|
|
520 |
< |
MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0, |
521 |
< |
atomOrientDataTag, MPI_COMM_WORLD); |
520 |
> |
MPI_Send(atomData13, 13, MPI_DOUBLE, 0, |
521 |
> |
myPotato, MPI_COMM_WORLD); |
522 |
|
|
390 |
– |
} |
391 |
– |
|
392 |
– |
} |
393 |
– |
} |
394 |
– |
|
395 |
– |
sprintf( checkPointMsg, |
396 |
– |
"Sucessfully took a dump.\n"); |
397 |
– |
MPIcheckPoint(); |
398 |
– |
|
399 |
– |
} |
400 |
– |
|
401 |
– |
painCave.isEventLoop = 0; |
402 |
– |
|
403 |
– |
#endif // is_mpi |
404 |
– |
} |
405 |
– |
|
406 |
– |
void DumpWriter::writeFinal(double finalTime){ |
407 |
– |
|
408 |
– |
char finalName[500]; |
409 |
– |
ofstream finalOut; |
410 |
– |
|
411 |
– |
const int BUFFERSIZE = 2000; |
412 |
– |
const int MINIBUFFERSIZE = 10; |
413 |
– |
char tempBuffer[BUFFERSIZE]; |
414 |
– |
char writeLine[BUFFERSIZE]; |
415 |
– |
|
416 |
– |
double q[4]; |
417 |
– |
DirectionalAtom* dAtom; |
418 |
– |
Atom** atoms = entry_plug->atoms; |
419 |
– |
int i; |
420 |
– |
#ifdef IS_MPI |
421 |
– |
int j, which_node, done, which_atom, local_index; |
422 |
– |
double atomTransData[6]; |
423 |
– |
double atomOrientData[7]; |
424 |
– |
int isDirectional; |
425 |
– |
char* atomTypeString; |
426 |
– |
int atomTypeTag; |
427 |
– |
int atomIsDirectionalTag; |
428 |
– |
int atomTransDataTag; |
429 |
– |
int atomOrientDataTag; |
430 |
– |
#else //is_mpi |
431 |
– |
int nAtoms = entry_plug->n_atoms; |
432 |
– |
#endif //is_mpi |
433 |
– |
|
434 |
– |
double pos[3], vel[3]; |
435 |
– |
|
436 |
– |
#ifdef IS_MPI |
437 |
– |
if(worldRank == 0 ){ |
438 |
– |
#endif // is_mpi |
439 |
– |
|
440 |
– |
strcpy( finalName, entry_plug->finalName ); |
441 |
– |
|
442 |
– |
finalOut.open( finalName, ios::out | ios::trunc ); |
443 |
– |
if( !finalOut ){ |
444 |
– |
sprintf( painCave.errMsg, |
445 |
– |
"Could not open \"%s\" for final dump output.\n", |
446 |
– |
finalName ); |
447 |
– |
painCave.isFatal = 1; |
448 |
– |
simError(); |
449 |
– |
} |
450 |
– |
|
451 |
– |
// finalOut.setf( ios::scientific ); |
452 |
– |
|
453 |
– |
#ifdef IS_MPI |
454 |
– |
} |
455 |
– |
|
456 |
– |
sprintf(checkPointMsg,"Opened file for final configuration\n"); |
457 |
– |
MPIcheckPoint(); |
458 |
– |
|
459 |
– |
#endif //is_mpi |
460 |
– |
|
461 |
– |
|
462 |
– |
#ifndef IS_MPI |
463 |
– |
|
464 |
– |
finalOut << nAtoms << "\n"; |
465 |
– |
|
466 |
– |
finalOut << finalTime << ";\t" |
467 |
– |
<< entry_plug->Hmat[0][0] << "\t" |
468 |
– |
<< entry_plug->Hmat[1][0] << "\t" |
469 |
– |
<< entry_plug->Hmat[2][0] << ";\t" |
470 |
– |
|
471 |
– |
<< entry_plug->Hmat[0][1] << "\t" |
472 |
– |
<< entry_plug->Hmat[1][1] << "\t" |
473 |
– |
<< entry_plug->Hmat[2][1] << ";\t" |
474 |
– |
|
475 |
– |
<< entry_plug->Hmat[0][2] << "\t" |
476 |
– |
<< entry_plug->Hmat[1][2] << "\t" |
477 |
– |
<< entry_plug->Hmat[2][2] << ";"; |
478 |
– |
|
479 |
– |
//write out additional parameters, such as chi and eta |
480 |
– |
finalOut << entry_plug->the_integrator->getAdditionalParameters(); |
481 |
– |
finalOut << endl; |
482 |
– |
|
483 |
– |
for( i=0; i<nAtoms; i++ ){ |
484 |
– |
|
485 |
– |
atoms[i]->getPos(pos); |
486 |
– |
atoms[i]->getVel(vel); |
487 |
– |
|
488 |
– |
sprintf( tempBuffer, |
489 |
– |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
490 |
– |
atoms[i]->getType(), |
491 |
– |
pos[0], |
492 |
– |
pos[1], |
493 |
– |
pos[2], |
494 |
– |
vel[0], |
495 |
– |
vel[1], |
496 |
– |
vel[2]); |
497 |
– |
strcpy( writeLine, tempBuffer ); |
498 |
– |
|
499 |
– |
if( atoms[i]->isDirectional() ){ |
500 |
– |
|
501 |
– |
dAtom = (DirectionalAtom *)atoms[i]; |
502 |
– |
dAtom->getQ( q ); |
503 |
– |
|
504 |
– |
sprintf( tempBuffer, |
505 |
– |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
506 |
– |
q[0], |
507 |
– |
q[1], |
508 |
– |
q[2], |
509 |
– |
q[3], |
510 |
– |
dAtom->getJx(), |
511 |
– |
dAtom->getJy(), |
512 |
– |
dAtom->getJz()); |
513 |
– |
strcat( writeLine, tempBuffer ); |
514 |
– |
} |
515 |
– |
else |
516 |
– |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
517 |
– |
|
518 |
– |
finalOut << writeLine; |
519 |
– |
} |
520 |
– |
finalOut.flush(); |
521 |
– |
finalOut.close(); |
522 |
– |
|
523 |
– |
#else // is_mpi |
524 |
– |
|
525 |
– |
// first thing first, suspend fatalities. |
526 |
– |
painCave.isEventLoop = 1; |
527 |
– |
|
528 |
– |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
529 |
– |
int haveError; |
530 |
– |
|
531 |
– |
MPI_Status istatus; |
532 |
– |
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
533 |
– |
|
534 |
– |
// write out header and node 0's coordinates |
535 |
– |
|
536 |
– |
if( worldRank == 0 ){ |
537 |
– |
finalOut << mpiSim->getTotAtoms() << "\n"; |
538 |
– |
|
539 |
– |
finalOut << finalTime << ";\t" |
540 |
– |
<< entry_plug->Hmat[0][0] << "\t" |
541 |
– |
<< entry_plug->Hmat[1][0] << "\t" |
542 |
– |
<< entry_plug->Hmat[2][0] << ";\t" |
543 |
– |
|
544 |
– |
<< entry_plug->Hmat[0][1] << "\t" |
545 |
– |
<< entry_plug->Hmat[1][1] << "\t" |
546 |
– |
<< entry_plug->Hmat[2][1] << ";\t" |
547 |
– |
|
548 |
– |
<< entry_plug->Hmat[0][2] << "\t" |
549 |
– |
<< entry_plug->Hmat[1][2] << "\t" |
550 |
– |
<< entry_plug->Hmat[2][2] << ";"; |
551 |
– |
|
552 |
– |
finalOut << entry_plug->the_integrator->getAdditionalParameters(); |
553 |
– |
finalOut << endl; |
554 |
– |
finalOut.flush(); |
555 |
– |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
556 |
– |
// Get the Node number which has this atom; |
557 |
– |
|
558 |
– |
which_node = AtomToProcMap[i]; |
559 |
– |
|
560 |
– |
if (which_node != 0) { |
561 |
– |
|
562 |
– |
atomTypeTag = 4*i; |
563 |
– |
atomIsDirectionalTag = 4*i + 1; |
564 |
– |
atomTransDataTag = 4*i + 2; |
565 |
– |
atomOrientDataTag = 4*i + 3; |
566 |
– |
|
567 |
– |
MPI_Recv(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
568 |
– |
atomTypeTag, MPI_COMM_WORLD, &istatus); |
569 |
– |
|
570 |
– |
MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
571 |
– |
atomIsDirectionalTag, MPI_COMM_WORLD, &istatus); |
572 |
– |
|
573 |
– |
MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node, |
574 |
– |
atomTransDataTag, MPI_COMM_WORLD, &istatus); |
575 |
– |
|
576 |
– |
if (isDirectional) { |
577 |
– |
|
578 |
– |
MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node, |
579 |
– |
atomOrientDataTag, MPI_COMM_WORLD, &istatus); |
580 |
– |
|
581 |
– |
} |
582 |
– |
|
583 |
– |
} else { |
584 |
– |
|
585 |
– |
haveError = 0; |
586 |
– |
which_atom = i; |
587 |
– |
local_index=-1; |
588 |
– |
|
589 |
– |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
590 |
– |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
591 |
– |
} |
592 |
– |
|
593 |
– |
if (local_index != -1) { |
594 |
– |
|
595 |
– |
atomTypeString = atoms[local_index]->getType(); |
596 |
– |
|
597 |
– |
atoms[local_index]->getPos(pos); |
598 |
– |
atoms[local_index]->getVel(vel); |
599 |
– |
|
600 |
– |
atomTransData[0] = pos[0]; |
601 |
– |
atomTransData[1] = pos[1]; |
602 |
– |
atomTransData[2] = pos[2]; |
603 |
– |
|
604 |
– |
atomTransData[3] = vel[0]; |
605 |
– |
atomTransData[4] = vel[1]; |
606 |
– |
atomTransData[5] = vel[2]; |
607 |
– |
|
608 |
– |
isDirectional = 0; |
609 |
– |
|
610 |
– |
if( atoms[local_index]->isDirectional() ){ |
611 |
– |
|
612 |
– |
isDirectional = 1; |
613 |
– |
|
614 |
– |
dAtom = (DirectionalAtom *)atoms[local_index]; |
615 |
– |
dAtom->getQ( q ); |
616 |
– |
|
617 |
– |
atomOrientData[0] = q[0]; |
618 |
– |
atomOrientData[1] = q[1]; |
619 |
– |
atomOrientData[2] = q[2]; |
620 |
– |
atomOrientData[3] = q[3]; |
621 |
– |
|
622 |
– |
atomOrientData[4] = dAtom->getJx(); |
623 |
– |
atomOrientData[5] = dAtom->getJy(); |
624 |
– |
atomOrientData[6] = dAtom->getJz(); |
625 |
– |
} |
626 |
– |
|
523 |
|
} else { |
628 |
– |
sprintf(painCave.errMsg, |
629 |
– |
"Atom %d not found on processor %d\n", |
630 |
– |
i, worldRank ); |
631 |
– |
haveError= 1; |
632 |
– |
simError(); |
633 |
– |
} |
524 |
|
|
525 |
< |
if(haveError) DieDieDie(); |
526 |
< |
|
637 |
< |
// If we've survived to here, format the line: |
638 |
< |
|
639 |
< |
sprintf( tempBuffer, |
640 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
641 |
< |
atomTypeString, |
642 |
< |
atomTransData[0], |
643 |
< |
atomTransData[1], |
644 |
< |
atomTransData[2], |
645 |
< |
atomTransData[3], |
646 |
< |
atomTransData[4], |
647 |
< |
atomTransData[5]); |
648 |
< |
|
649 |
< |
strcpy( writeLine, tempBuffer ); |
650 |
< |
|
651 |
< |
if (isDirectional) { |
652 |
< |
|
653 |
< |
sprintf( tempBuffer, |
654 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
655 |
< |
atomOrientData[0], |
656 |
< |
atomOrientData[1], |
657 |
< |
atomOrientData[2], |
658 |
< |
atomOrientData[3], |
659 |
< |
atomOrientData[4], |
660 |
< |
atomOrientData[5], |
661 |
< |
atomOrientData[6]); |
662 |
< |
strcat( writeLine, tempBuffer ); |
663 |
< |
|
664 |
< |
} else { |
665 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
525 |
> |
MPI_Send(atomData6, 6, MPI_DOUBLE, 0, |
526 |
> |
myPotato, MPI_COMM_WORLD); |
527 |
|
} |
528 |
|
|
529 |
< |
finalOut << writeLine; |
530 |
< |
finalOut.flush(); |
529 |
> |
myPotato++; |
530 |
> |
currentIndex++; |
531 |
|
} |
532 |
|
} |
533 |
|
|
673 |
– |
finalOut.flush(); |
534 |
|
sprintf( checkPointMsg, |
535 |
|
"Sucessfully took a dump.\n"); |
536 |
|
MPIcheckPoint(); |
537 |
|
|
538 |
< |
} else { |
679 |
< |
|
680 |
< |
// worldRank != 0, so I'm a remote node. |
681 |
< |
|
682 |
< |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
683 |
< |
|
684 |
< |
// Am I the node which has this atom? |
685 |
< |
|
686 |
< |
if (AtomToProcMap[i] == worldRank) { |
687 |
< |
|
688 |
< |
local_index=-1; |
689 |
< |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
690 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
691 |
< |
} |
692 |
< |
if (local_index != -1) { |
693 |
< |
|
694 |
< |
atomTypeString = atoms[local_index]->getType(); |
695 |
< |
|
696 |
< |
atoms[local_index]->getPos(pos); |
697 |
< |
atoms[local_index]->getVel(vel); |
698 |
< |
|
699 |
< |
atomTransData[0] = pos[0]; |
700 |
< |
atomTransData[1] = pos[1]; |
701 |
< |
atomTransData[2] = pos[2]; |
702 |
< |
|
703 |
< |
atomTransData[3] = vel[0]; |
704 |
< |
atomTransData[4] = vel[1]; |
705 |
< |
atomTransData[5] = vel[2]; |
706 |
< |
|
707 |
< |
isDirectional = 0; |
708 |
< |
|
709 |
< |
if( atoms[local_index]->isDirectional() ){ |
710 |
< |
|
711 |
< |
isDirectional = 1; |
712 |
< |
|
713 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
714 |
< |
dAtom->getQ( q ); |
715 |
< |
|
716 |
< |
atomOrientData[0] = q[0]; |
717 |
< |
atomOrientData[1] = q[1]; |
718 |
< |
atomOrientData[2] = q[2]; |
719 |
< |
atomOrientData[3] = q[3]; |
720 |
< |
|
721 |
< |
atomOrientData[4] = dAtom->getJx(); |
722 |
< |
atomOrientData[5] = dAtom->getJy(); |
723 |
< |
atomOrientData[6] = dAtom->getJz(); |
724 |
< |
} |
725 |
< |
|
726 |
< |
} else { |
727 |
< |
sprintf(painCave.errMsg, |
728 |
< |
"Atom %d not found on processor %d\n", |
729 |
< |
i, worldRank ); |
730 |
< |
haveError= 1; |
731 |
< |
simError(); |
732 |
< |
} |
733 |
< |
|
734 |
< |
// I've survived this far, so send off the data! |
735 |
< |
|
736 |
< |
atomTypeTag = 4*i; |
737 |
< |
atomIsDirectionalTag = 4*i + 1; |
738 |
< |
atomTransDataTag = 4*i + 2; |
739 |
< |
atomOrientDataTag = 4*i + 3; |
740 |
< |
|
741 |
< |
MPI_Send(atomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
742 |
< |
atomTypeTag, MPI_COMM_WORLD); |
743 |
< |
|
744 |
< |
MPI_Send(&isDirectional, 1, MPI_INT, 0, |
745 |
< |
atomIsDirectionalTag, MPI_COMM_WORLD); |
746 |
< |
|
747 |
< |
MPI_Send(atomTransData, 6, MPI_DOUBLE, 0, |
748 |
< |
atomTransDataTag, MPI_COMM_WORLD); |
749 |
< |
|
750 |
< |
if (isDirectional) { |
751 |
< |
|
752 |
< |
MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0, |
753 |
< |
atomOrientDataTag, MPI_COMM_WORLD); |
754 |
< |
|
755 |
< |
} |
756 |
< |
|
757 |
< |
} |
758 |
< |
} |
759 |
< |
|
760 |
< |
sprintf( checkPointMsg, |
761 |
< |
"Sucessfully wrote final file.\n"); |
762 |
< |
MPIcheckPoint(); |
763 |
< |
|
764 |
< |
} |
538 |
> |
} |
539 |
|
|
766 |
– |
painCave.isEventLoop = 0; |
767 |
– |
|
768 |
– |
if( worldRank == 0 ) finalOut.close(); |
540 |
|
#endif // is_mpi |
541 |
|
} |
542 |
|
|
772 |
– |
|
773 |
– |
|
543 |
|
#ifdef IS_MPI |
544 |
|
|
545 |
|
// a couple of functions to let us escape the write loop |