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 = 100; |
152 |
|
|
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 |
|
char MPIatomTypeString[MINIBUFFERSIZE]; |
170 |
< |
int me; |
83 |
< |
int atomTypeTag; |
84 |
< |
int atomIsDirectionalTag; |
85 |
< |
int atomTransDataTag; |
86 |
< |
int atomOrientDataTag; |
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 |
|
|
96 |
– |
// write current frame to the eor file |
97 |
– |
|
98 |
– |
this->writeFinal( currentTime ); |
99 |
– |
|
180 |
|
#ifndef IS_MPI |
181 |
|
|
182 |
|
outFile << nAtoms << "\n"; |
234 |
|
|
235 |
|
outFile << writeLine; |
236 |
|
} |
157 |
– |
outFile.flush(); |
237 |
|
|
238 |
|
#else // is_mpi |
239 |
|
|
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 |
< |
} |
248 |
> |
} |
249 |
|
|
250 |
|
int haveError; |
251 |
|
|
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 |
< |
tag = 0; |
198 |
< |
|
285 |
> |
|
286 |
> |
currentIndex = 0; |
287 |
|
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
200 |
– |
|
201 |
– |
if (tag + 2 >= MAXTAG) { |
202 |
– |
// The tag was going to exceed the maximum value, so wrap around to 0: |
203 |
– |
tag = 0; |
204 |
– |
// Send the newly zeroed tag on to the other nodes: |
205 |
– |
MPI_Bcast(&tag, 1, MPI_INT, 0, MPI_COMM_WORLD); |
206 |
– |
} |
288 |
|
|
289 |
|
// Get the Node number which has this atom; |
290 |
|
|
291 |
|
which_node = AtomToProcMap[i]; |
292 |
|
|
293 |
|
if (which_node != 0) { |
294 |
+ |
|
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(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
307 |
< |
atomTypeTag, MPI_COMM_WORLD, &istatus); |
307 |
> |
myPotato, MPI_COMM_WORLD, &istatus); |
308 |
|
|
309 |
< |
strncpy(atomTypeString, MPIatomTypeString, MINIBUFFERSIZE); |
310 |
< |
|
311 |
< |
// Null terminate the atomTypeString just in case: |
309 |
> |
atomTypeString = MPIatomTypeString; |
310 |
> |
|
311 |
> |
myPotato++; |
312 |
|
|
221 |
– |
atomTypeString[strlen(atomTypeString) - 1] = '\0'; |
222 |
– |
|
313 |
|
MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
314 |
< |
atomIsDirectionalTag, MPI_COMM_WORLD, &istatus); |
315 |
< |
|
316 |
< |
MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node, |
227 |
< |
atomTransDataTag, MPI_COMM_WORLD, &istatus); |
314 |
> |
myPotato, MPI_COMM_WORLD, &istatus); |
315 |
> |
|
316 |
> |
myPotato++; |
317 |
|
|
318 |
< |
if (isDirectional) { |
319 |
< |
|
320 |
< |
MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node, |
321 |
< |
atomOrientDataTag, MPI_COMM_WORLD, &istatus); |
322 |
< |
|
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 |
< |
} |
245 |
< |
|
246 |
< |
if (local_index != -1) { |
247 |
< |
|
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 ); |
269 |
– |
|
270 |
– |
atomOrientData[0] = q[0]; |
271 |
– |
atomOrientData[1] = q[1]; |
272 |
– |
atomOrientData[2] = q[2]; |
273 |
– |
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(); |
289 |
– |
|
290 |
– |
// 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 |
|
|
387 |
– |
// I've survived this far, so send off the data! |
388 |
– |
|
389 |
– |
atomTypeTag = 4*i; |
390 |
– |
atomIsDirectionalTag = 4*i + 1; |
391 |
– |
atomTransDataTag = 4*i + 2; |
392 |
– |
atomOrientDataTag = 4*i + 3; |
393 |
– |
|
394 |
– |
|
503 |
|
strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
504 |
|
|
505 |
|
// null terminate the string before sending (just in case): |
506 |
|
MPIatomTypeString[MINIBUFFERSIZE-1] = '\0'; |
507 |
|
|
508 |
|
MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
509 |
< |
atomTypeTag, MPI_COMM_WORLD); |
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); |
408 |
< |
|
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 |
|
|
523 |
< |
} |
415 |
< |
|
416 |
< |
} |
417 |
< |
} |
523 |
> |
} else { |
524 |
|
|
525 |
< |
sprintf( checkPointMsg, |
526 |
< |
"Sucessfully took a dump.\n"); |
421 |
< |
MPIcheckPoint(); |
422 |
< |
|
423 |
< |
} |
424 |
< |
|
425 |
< |
painCave.isEventLoop = 0; |
426 |
< |
|
427 |
< |
#endif // is_mpi |
428 |
< |
} |
429 |
< |
|
430 |
< |
void DumpWriter::writeFinal(double finalTime){ |
431 |
< |
|
432 |
< |
char finalName[500]; |
433 |
< |
ofstream finalOut; |
434 |
< |
|
435 |
< |
const int BUFFERSIZE = 2000; |
436 |
< |
const int MINIBUFFERSIZE = 100; |
437 |
< |
char tempBuffer[BUFFERSIZE]; |
438 |
< |
char writeLine[BUFFERSIZE]; |
439 |
< |
|
440 |
< |
double q[4]; |
441 |
< |
DirectionalAtom* dAtom; |
442 |
< |
Atom** atoms = entry_plug->atoms; |
443 |
< |
int i; |
444 |
< |
#ifdef IS_MPI |
445 |
< |
int j, which_node, done, which_atom, local_index; |
446 |
< |
double atomTransData[6]; |
447 |
< |
double atomOrientData[7]; |
448 |
< |
int isDirectional; |
449 |
< |
char* atomTypeString; |
450 |
< |
char MPIatomTypeString[MINIBUFFERSIZE]; |
451 |
< |
int atomTypeTag; |
452 |
< |
int atomIsDirectionalTag; |
453 |
< |
int atomTransDataTag; |
454 |
< |
int atomOrientDataTag; |
455 |
< |
#else //is_mpi |
456 |
< |
int nAtoms = entry_plug->n_atoms; |
457 |
< |
#endif //is_mpi |
458 |
< |
|
459 |
< |
double pos[3], vel[3]; |
460 |
< |
|
461 |
< |
#ifdef IS_MPI |
462 |
< |
if(worldRank == 0 ){ |
463 |
< |
#endif // is_mpi |
464 |
< |
|
465 |
< |
strcpy( finalName, entry_plug->finalName ); |
466 |
< |
|
467 |
< |
finalOut.open( finalName, ios::out | ios::trunc ); |
468 |
< |
if( !finalOut ){ |
469 |
< |
sprintf( painCave.errMsg, |
470 |
< |
"Could not open \"%s\" for final dump output.\n", |
471 |
< |
finalName ); |
472 |
< |
painCave.isFatal = 1; |
473 |
< |
simError(); |
474 |
< |
} |
475 |
< |
|
476 |
< |
// finalOut.setf( ios::scientific ); |
477 |
< |
|
478 |
< |
#ifdef IS_MPI |
479 |
< |
} |
480 |
< |
|
481 |
< |
sprintf(checkPointMsg,"Opened file for final configuration\n"); |
482 |
< |
MPIcheckPoint(); |
483 |
< |
|
484 |
< |
#endif //is_mpi |
485 |
< |
|
486 |
< |
|
487 |
< |
#ifndef IS_MPI |
488 |
< |
|
489 |
< |
finalOut << nAtoms << "\n"; |
490 |
< |
|
491 |
< |
finalOut << finalTime << ";\t" |
492 |
< |
<< entry_plug->Hmat[0][0] << "\t" |
493 |
< |
<< entry_plug->Hmat[1][0] << "\t" |
494 |
< |
<< entry_plug->Hmat[2][0] << ";\t" |
495 |
< |
|
496 |
< |
<< entry_plug->Hmat[0][1] << "\t" |
497 |
< |
<< entry_plug->Hmat[1][1] << "\t" |
498 |
< |
<< entry_plug->Hmat[2][1] << ";\t" |
499 |
< |
|
500 |
< |
<< entry_plug->Hmat[0][2] << "\t" |
501 |
< |
<< entry_plug->Hmat[1][2] << "\t" |
502 |
< |
<< entry_plug->Hmat[2][2] << ";"; |
503 |
< |
|
504 |
< |
//write out additional parameters, such as chi and eta |
505 |
< |
finalOut << entry_plug->the_integrator->getAdditionalParameters(); |
506 |
< |
finalOut << endl; |
507 |
< |
|
508 |
< |
for( i=0; i<nAtoms; i++ ){ |
509 |
< |
|
510 |
< |
atoms[i]->getPos(pos); |
511 |
< |
atoms[i]->getVel(vel); |
512 |
< |
|
513 |
< |
sprintf( tempBuffer, |
514 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
515 |
< |
atoms[i]->getType(), |
516 |
< |
pos[0], |
517 |
< |
pos[1], |
518 |
< |
pos[2], |
519 |
< |
vel[0], |
520 |
< |
vel[1], |
521 |
< |
vel[2]); |
522 |
< |
strcpy( writeLine, tempBuffer ); |
523 |
< |
|
524 |
< |
if( atoms[i]->isDirectional() ){ |
525 |
< |
|
526 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
527 |
< |
dAtom->getQ( q ); |
528 |
< |
|
529 |
< |
sprintf( tempBuffer, |
530 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
531 |
< |
q[0], |
532 |
< |
q[1], |
533 |
< |
q[2], |
534 |
< |
q[3], |
535 |
< |
dAtom->getJx(), |
536 |
< |
dAtom->getJy(), |
537 |
< |
dAtom->getJz()); |
538 |
< |
strcat( writeLine, tempBuffer ); |
539 |
< |
} |
540 |
< |
else |
541 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
542 |
< |
|
543 |
< |
finalOut << writeLine; |
544 |
< |
} |
545 |
< |
finalOut.flush(); |
546 |
< |
finalOut.close(); |
547 |
< |
|
548 |
< |
#else // is_mpi |
549 |
< |
|
550 |
< |
// first thing first, suspend fatalities. |
551 |
< |
painCave.isEventLoop = 1; |
552 |
< |
|
553 |
< |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
554 |
< |
int haveError; |
555 |
< |
|
556 |
< |
MPI_Status istatus; |
557 |
< |
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
558 |
< |
|
559 |
< |
// write out header and node 0's coordinates |
560 |
< |
|
561 |
< |
if( worldRank == 0 ){ |
562 |
< |
finalOut << mpiSim->getTotAtoms() << "\n"; |
563 |
< |
|
564 |
< |
finalOut << finalTime << ";\t" |
565 |
< |
<< entry_plug->Hmat[0][0] << "\t" |
566 |
< |
<< entry_plug->Hmat[1][0] << "\t" |
567 |
< |
<< entry_plug->Hmat[2][0] << ";\t" |
568 |
< |
|
569 |
< |
<< entry_plug->Hmat[0][1] << "\t" |
570 |
< |
<< entry_plug->Hmat[1][1] << "\t" |
571 |
< |
<< entry_plug->Hmat[2][1] << ";\t" |
572 |
< |
|
573 |
< |
<< entry_plug->Hmat[0][2] << "\t" |
574 |
< |
<< entry_plug->Hmat[1][2] << "\t" |
575 |
< |
<< entry_plug->Hmat[2][2] << ";"; |
576 |
< |
|
577 |
< |
finalOut << entry_plug->the_integrator->getAdditionalParameters(); |
578 |
< |
finalOut << endl; |
579 |
< |
finalOut.flush(); |
580 |
< |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
581 |
< |
// Get the Node number which has this atom; |
582 |
< |
|
583 |
< |
which_node = AtomToProcMap[i]; |
584 |
< |
|
585 |
< |
if (which_node != 0) { |
586 |
< |
|
587 |
< |
atomTypeTag = 4*i; |
588 |
< |
atomIsDirectionalTag = 4*i + 1; |
589 |
< |
atomTransDataTag = 4*i + 2; |
590 |
< |
atomOrientDataTag = 4*i + 3; |
591 |
< |
|
592 |
< |
MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
593 |
< |
atomTypeTag, MPI_COMM_WORLD, &istatus); |
594 |
< |
|
595 |
< |
strncpy(atomTypeString, MPIatomTypeString, MINIBUFFERSIZE); |
596 |
< |
|
597 |
< |
MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
598 |
< |
atomIsDirectionalTag, MPI_COMM_WORLD, &istatus); |
599 |
< |
|
600 |
< |
MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node, |
601 |
< |
atomTransDataTag, MPI_COMM_WORLD, &istatus); |
602 |
< |
|
603 |
< |
if (isDirectional) { |
604 |
< |
|
605 |
< |
MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node, |
606 |
< |
atomOrientDataTag, MPI_COMM_WORLD, &istatus); |
607 |
< |
|
525 |
> |
MPI_Send(atomData6, 6, MPI_DOUBLE, 0, |
526 |
> |
myPotato, MPI_COMM_WORLD); |
527 |
|
} |
528 |
|
|
529 |
< |
} else { |
530 |
< |
|
612 |
< |
haveError = 0; |
613 |
< |
which_atom = i; |
614 |
< |
local_index=-1; |
615 |
< |
|
616 |
< |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
617 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
618 |
< |
} |
619 |
< |
|
620 |
< |
if (local_index != -1) { |
621 |
< |
|
622 |
< |
atomTypeString = atoms[local_index]->getType(); |
623 |
< |
|
624 |
< |
atoms[local_index]->getPos(pos); |
625 |
< |
atoms[local_index]->getVel(vel); |
626 |
< |
|
627 |
< |
atomTransData[0] = pos[0]; |
628 |
< |
atomTransData[1] = pos[1]; |
629 |
< |
atomTransData[2] = pos[2]; |
630 |
< |
|
631 |
< |
atomTransData[3] = vel[0]; |
632 |
< |
atomTransData[4] = vel[1]; |
633 |
< |
atomTransData[5] = vel[2]; |
634 |
< |
|
635 |
< |
isDirectional = 0; |
636 |
< |
|
637 |
< |
if( atoms[local_index]->isDirectional() ){ |
638 |
< |
|
639 |
< |
isDirectional = 1; |
640 |
< |
|
641 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
642 |
< |
dAtom->getQ( q ); |
643 |
< |
|
644 |
< |
atomOrientData[0] = q[0]; |
645 |
< |
atomOrientData[1] = q[1]; |
646 |
< |
atomOrientData[2] = q[2]; |
647 |
< |
atomOrientData[3] = q[3]; |
648 |
< |
|
649 |
< |
atomOrientData[4] = dAtom->getJx(); |
650 |
< |
atomOrientData[5] = dAtom->getJy(); |
651 |
< |
atomOrientData[6] = dAtom->getJz(); |
652 |
< |
} |
653 |
< |
|
654 |
< |
} else { |
655 |
< |
sprintf(painCave.errMsg, |
656 |
< |
"Atom %d not found on processor %d\n", |
657 |
< |
i, worldRank ); |
658 |
< |
haveError= 1; |
659 |
< |
simError(); |
660 |
< |
} |
661 |
< |
|
662 |
< |
if(haveError) DieDieDie(); |
663 |
< |
|
664 |
< |
// If we've survived to here, format the line: |
665 |
< |
|
666 |
< |
sprintf( tempBuffer, |
667 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
668 |
< |
atomTypeString, |
669 |
< |
atomTransData[0], |
670 |
< |
atomTransData[1], |
671 |
< |
atomTransData[2], |
672 |
< |
atomTransData[3], |
673 |
< |
atomTransData[4], |
674 |
< |
atomTransData[5]); |
675 |
< |
|
676 |
< |
strcpy( writeLine, tempBuffer ); |
677 |
< |
|
678 |
< |
if (isDirectional) { |
679 |
< |
|
680 |
< |
sprintf( tempBuffer, |
681 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
682 |
< |
atomOrientData[0], |
683 |
< |
atomOrientData[1], |
684 |
< |
atomOrientData[2], |
685 |
< |
atomOrientData[3], |
686 |
< |
atomOrientData[4], |
687 |
< |
atomOrientData[5], |
688 |
< |
atomOrientData[6]); |
689 |
< |
strcat( writeLine, tempBuffer ); |
690 |
< |
|
691 |
< |
} else { |
692 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
693 |
< |
} |
694 |
< |
|
695 |
< |
finalOut << writeLine; |
696 |
< |
finalOut.flush(); |
529 |
> |
myPotato++; |
530 |
> |
currentIndex++; |
531 |
|
} |
532 |
|
} |
533 |
|
|
700 |
– |
finalOut.flush(); |
534 |
|
sprintf( checkPointMsg, |
535 |
|
"Sucessfully took a dump.\n"); |
536 |
|
MPIcheckPoint(); |
537 |
|
|
538 |
< |
} else { |
706 |
< |
|
707 |
< |
// worldRank != 0, so I'm a remote node. |
708 |
< |
|
709 |
< |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
710 |
< |
|
711 |
< |
// Am I the node which has this atom? |
712 |
< |
|
713 |
< |
if (AtomToProcMap[i] == worldRank) { |
714 |
< |
|
715 |
< |
local_index=-1; |
716 |
< |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
717 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
718 |
< |
} |
719 |
< |
if (local_index != -1) { |
720 |
< |
|
721 |
< |
atomTypeString = atoms[local_index]->getType(); |
722 |
< |
|
723 |
< |
atoms[local_index]->getPos(pos); |
724 |
< |
atoms[local_index]->getVel(vel); |
725 |
< |
|
726 |
< |
atomTransData[0] = pos[0]; |
727 |
< |
atomTransData[1] = pos[1]; |
728 |
< |
atomTransData[2] = pos[2]; |
729 |
< |
|
730 |
< |
atomTransData[3] = vel[0]; |
731 |
< |
atomTransData[4] = vel[1]; |
732 |
< |
atomTransData[5] = vel[2]; |
733 |
< |
|
734 |
< |
isDirectional = 0; |
735 |
< |
|
736 |
< |
if( atoms[local_index]->isDirectional() ){ |
737 |
< |
|
738 |
< |
isDirectional = 1; |
739 |
< |
|
740 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
741 |
< |
dAtom->getQ( q ); |
742 |
< |
|
743 |
< |
atomOrientData[0] = q[0]; |
744 |
< |
atomOrientData[1] = q[1]; |
745 |
< |
atomOrientData[2] = q[2]; |
746 |
< |
atomOrientData[3] = q[3]; |
747 |
< |
|
748 |
< |
atomOrientData[4] = dAtom->getJx(); |
749 |
< |
atomOrientData[5] = dAtom->getJy(); |
750 |
< |
atomOrientData[6] = dAtom->getJz(); |
751 |
< |
} |
752 |
< |
|
753 |
< |
} else { |
754 |
< |
sprintf(painCave.errMsg, |
755 |
< |
"Atom %d not found on processor %d\n", |
756 |
< |
i, worldRank ); |
757 |
< |
haveError= 1; |
758 |
< |
simError(); |
759 |
< |
} |
760 |
< |
|
761 |
< |
// I've survived this far, so send off the data! |
762 |
< |
|
763 |
< |
atomTypeTag = 4*i; |
764 |
< |
atomIsDirectionalTag = 4*i + 1; |
765 |
< |
atomTransDataTag = 4*i + 2; |
766 |
< |
atomOrientDataTag = 4*i + 3; |
767 |
< |
|
768 |
< |
strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
769 |
< |
|
770 |
< |
MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
771 |
< |
atomTypeTag, MPI_COMM_WORLD); |
772 |
< |
|
773 |
< |
MPI_Send(&isDirectional, 1, MPI_INT, 0, |
774 |
< |
atomIsDirectionalTag, MPI_COMM_WORLD); |
775 |
< |
|
776 |
< |
MPI_Send(atomTransData, 6, MPI_DOUBLE, 0, |
777 |
< |
atomTransDataTag, MPI_COMM_WORLD); |
778 |
< |
|
779 |
< |
if (isDirectional) { |
780 |
< |
|
781 |
< |
MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0, |
782 |
< |
atomOrientDataTag, MPI_COMM_WORLD); |
783 |
< |
|
784 |
< |
} |
785 |
< |
|
786 |
< |
} |
787 |
< |
} |
788 |
< |
|
789 |
< |
sprintf( checkPointMsg, |
790 |
< |
"Sucessfully wrote final file.\n"); |
791 |
< |
MPIcheckPoint(); |
792 |
< |
|
793 |
< |
} |
538 |
> |
} |
539 |
|
|
795 |
– |
painCave.isEventLoop = 0; |
796 |
– |
|
797 |
– |
if( worldRank == 0 ) finalOut.close(); |
540 |
|
#endif // is_mpi |
541 |
|
} |
542 |
|
|
801 |
– |
|
802 |
– |
|
543 |
|
#ifdef IS_MPI |
544 |
|
|
545 |
|
// a couple of functions to let us escape the write loop |