# | Line 3 | Line 3 | |
---|---|---|
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> | |
11 | #include "mpiSimulation.hpp" | |
10 | – | #define TAKE_THIS_TAG_CHAR 1 |
11 | – | #define TAKE_THIS_TAG_INT 2 |
12 | ||
13 | namespace dWrite{ | |
14 | < | void nodeZeroError( void ); |
15 | < | void anonymousNodeDie( void ); |
14 | > | void DieDieDie( void ); |
15 | } | |
16 | ||
17 | using namespace dWrite; | |
# | Line 29 | Line 28 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ | |
28 | if(worldRank == 0 ){ | |
29 | #endif // is_mpi | |
30 | ||
32 | – | 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 | } | |
# | Line 47 | Line 45 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ | |
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(); | |
# | Line 59 | Line 60 | DumpWriter::~DumpWriter( ){ | |
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 | + | |
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; |
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 | > | |
171 | #else //is_mpi | |
172 | int nAtoms = entry_plug->n_atoms; | |
173 | #endif //is_mpi | |
# | Line 84 | Line 177 | void DumpWriter::writeDump( double currentTime ){ | |
177 | Atom** atoms = entry_plug->atoms; | |
178 | double pos[3], vel[3]; | |
179 | ||
87 | – | |
88 | – | // write current frame to the eor file |
89 | – | |
90 | – | this->writeFinal( currentTime ); |
91 | – | |
180 | #ifndef IS_MPI | |
181 | ||
182 | outFile << nAtoms << "\n"; | |
# | Line 146 | Line 234 | void DumpWriter::writeDump( double currentTime ){ | |
234 | ||
235 | outFile << writeLine; | |
236 | } | |
149 | – | 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 | ||
156 | – | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
250 | int haveError; | |
251 | ||
252 | MPI_Status istatus; | |
# | Line 162 | Line 255 | void DumpWriter::writeDump( double currentTime ){ | |
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" | |
# | Line 180 | Line 282 | void DumpWriter::writeDump( double currentTime ){ | |
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 | + | |
293 | + | if (which_node != 0) { |
294 | ||
295 | < | if (which_node == 0 ) { |
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 | + | myPotato, MPI_COMM_WORLD, &istatus); |
308 | + | |
309 | + | atomTypeString = MPIatomTypeString; |
310 | + | |
311 | + | myPotato++; |
312 | + | |
313 | + | MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
314 | + | myPotato, MPI_COMM_WORLD, &istatus); |
315 | + | |
316 | + | myPotato++; |
317 | + | |
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 | < | for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
335 | < | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
336 | < | } |
337 | < | if (local_index != -1) { |
338 | < | //format the line |
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 | < | sprintf( tempBuffer, |
344 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
345 | < | atoms[local_index]->getType(), |
205 | < | pos[0], |
206 | < | pos[1], |
207 | < | pos[2], |
208 | < | vel[0], |
209 | < | vel[1], |
210 | < | vel[2]); // check here. |
211 | < | strcpy( writeLine, tempBuffer ); |
343 | > | atomData6[0] = pos[0]; |
344 | > | atomData6[1] = pos[1]; |
345 | > | atomData6[2] = pos[2]; |
346 | ||
347 | + | atomData6[3] = vel[0]; |
348 | + | atomData6[4] = vel[1]; |
349 | + | atomData6[5] = vel[2]; |
350 | + | |
351 | + | isDirectional = 0; |
352 | + | |
353 | if( atoms[local_index]->isDirectional() ){ | |
354 | ||
355 | + | isDirectional = 1; |
356 | + | |
357 | dAtom = (DirectionalAtom *)atoms[local_index]; | |
358 | dAtom->getQ( q ); | |
359 | ||
360 | < | sprintf( tempBuffer, |
361 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
362 | < | q[0], |
363 | < | q[1], |
364 | < | q[2], |
365 | < | q[3], |
366 | < | dAtom->getJx(), |
367 | < | dAtom->getJy(), |
368 | < | dAtom->getJz()); |
369 | < | strcat( writeLine, tempBuffer ); |
370 | < | |
371 | < | } |
372 | < | else |
373 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
232 | < | } |
233 | < | else { |
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 | > | |
373 | > | } else { |
374 | sprintf(painCave.errMsg, | |
375 | "Atom %d not found on processor %d\n", | |
376 | i, worldRank ); | |
377 | haveError= 1; | |
378 | simError(); | |
379 | } | |
380 | < | |
381 | < | if(haveError) nodeZeroError(); |
382 | < | |
380 | > | |
381 | > | if(haveError) DieDieDie(); |
382 | > | |
383 | > | currentIndex ++; |
384 | } | |
385 | < | else { |
386 | < | myStatus = 1; |
387 | < | MPI_Send(&myStatus, 1, MPI_INT, which_node, |
388 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
389 | < | MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
390 | < | MPI_COMM_WORLD); |
391 | < | MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
392 | < | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
393 | < | MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
394 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
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 | < | if(!myStatus) nodeZeroError(); |
400 | < | |
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 | < | |
421 | > | |
422 | outFile << writeLine; | |
260 | – | outFile.flush(); |
423 | } | |
424 | + | |
425 | ||
426 | < | // kill everyone off: |
427 | < | myStatus = -1; |
428 | < | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
429 | < | MPI_Send(&myStatus, 1, MPI_INT, j, |
430 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
268 | < | } |
269 | < | |
426 | > | outFile.flush(); |
427 | > | sprintf( checkPointMsg, |
428 | > | "Sucessfully took a dump.\n"); |
429 | > | MPIcheckPoint(); |
430 | > | delete[] potatoes; |
431 | } else { | |
432 | ||
433 | < | done = 0; |
273 | < | while (!done) { |
433 | > | // worldRank != 0, so I'm a remote node. |
434 | ||
435 | < | MPI_Recv(&myStatus, 1, MPI_INT, 0, |
276 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
435 | > | // Set my magic potato to 0: |
436 | ||
437 | < | if(!myStatus) anonymousNodeDie(); |
437 | > | myPotato = 0; |
438 | > | currentIndex = 0; |
439 | > | |
440 | > | for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
441 | > | |
442 | > | // Am I the node which has this atom? |
443 | > | |
444 | > | if (AtomToProcMap[i] == worldRank) { |
445 | ||
446 | < | if(myStatus < 0) break; |
446 | > | if (myPotato + 3 >= MAXTAG) { |
447 | ||
448 | < | MPI_Recv(&which_atom, 1, MPI_INT, 0, |
449 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
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 | < | myStatus = 1; |
453 | < | local_index=-1; |
454 | < | for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
455 | < | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
456 | < | } |
457 | < | if (local_index != -1) { |
458 | < | //format the line |
452 | > | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus); |
453 | > | |
454 | > | } |
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); |
462 | > | atoms[local_index]->getPos(pos); |
463 | > | atoms[local_index]->getVel(vel); |
464 | ||
465 | < | sprintf( tempBuffer, |
466 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
467 | < | atoms[local_index]->getType(), |
299 | < | pos[0], |
300 | < | pos[1], |
301 | < | pos[2], |
302 | < | vel[0], |
303 | < | vel[1], |
304 | < | vel[2]); // check here. |
305 | < | strcpy( writeLine, tempBuffer ); |
465 | > | atomData6[0] = pos[0]; |
466 | > | atomData6[1] = pos[1]; |
467 | > | atomData6[2] = pos[2]; |
468 | ||
469 | < | if( atoms[local_index]->isDirectional() ){ |
469 | > | atomData6[3] = vel[0]; |
470 | > | atomData6[4] = vel[1]; |
471 | > | atomData6[5] = vel[2]; |
472 | > | |
473 | > | isDirectional = 0; |
474 | ||
475 | < | dAtom = (DirectionalAtom *)atoms[local_index]; |
310 | < | dAtom->getQ( q ); |
475 | > | if( atoms[local_index]->isDirectional() ){ |
476 | ||
477 | < | sprintf( tempBuffer, |
478 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
479 | < | q[0], |
480 | < | q[1], |
481 | < | q[2], |
482 | < | q[3], |
483 | < | dAtom->getJx(), |
484 | < | dAtom->getJy(), |
485 | < | dAtom->getJz()); |
486 | < | strcat( writeLine, tempBuffer ); |
487 | < | } |
488 | < | else{ |
324 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
325 | < | } |
326 | < | } |
327 | < | else { |
328 | < | sprintf(painCave.errMsg, |
329 | < | "Atom %d not found on processor %d\n", |
330 | < | which_atom, worldRank ); |
331 | < | myStatus = 0; |
332 | < | simError(); |
477 | > | isDirectional = 1; |
478 | > | |
479 | > | dAtom = (DirectionalAtom *)atoms[local_index]; |
480 | > | dAtom->getQ( q ); |
481 | > | |
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 | < | strcpy( writeLine, "Hello, I'm an error.\n"); |
491 | < | } |
490 | > | atomData13[10] = dAtom->getJx(); |
491 | > | atomData13[11] = dAtom->getJy(); |
492 | > | atomData13[12] = dAtom->getJz(); |
493 | > | } |
494 | ||
495 | < | MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
338 | < | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
339 | < | MPI_Send( &myStatus, 1, MPI_INT, 0, |
340 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
341 | < | } |
342 | < | } |
343 | < | outFile.flush(); |
344 | < | sprintf( checkPointMsg, |
345 | < | "Sucessfully took a dump.\n"); |
346 | < | MPIcheckPoint(); |
347 | < | |
348 | < | // last thing last, enable fatalities. |
349 | < | painCave.isEventLoop = 0; |
350 | < | |
351 | < | #endif // is_mpi |
352 | < | } |
353 | < | |
354 | < | void DumpWriter::writeFinal(double finalTime){ |
355 | < | |
356 | < | char finalName[500]; |
357 | < | ofstream finalOut; |
358 | < | |
359 | < | const int BUFFERSIZE = 2000; |
360 | < | char tempBuffer[BUFFERSIZE]; |
361 | < | char writeLine[BUFFERSIZE]; |
362 | < | |
363 | < | double q[4]; |
364 | < | DirectionalAtom* dAtom; |
365 | < | Atom** atoms = entry_plug->atoms; |
366 | < | int i; |
367 | < | #ifdef IS_MPI |
368 | < | int j, which_node, done, which_atom, local_index; |
369 | < | #else //is_mpi |
370 | < | int nAtoms = entry_plug->n_atoms; |
371 | < | #endif //is_mpi |
372 | < | |
373 | < | double pos[3], vel[3]; |
374 | < | |
375 | < | #ifdef IS_MPI |
376 | < | if(worldRank == 0 ){ |
377 | < | #endif // is_mpi |
378 | < | |
379 | < | strcpy( finalName, entry_plug->finalName ); |
380 | < | |
381 | < | finalOut.open( finalName, ios::out | ios::trunc ); |
382 | < | if( !finalOut ){ |
383 | < | sprintf( painCave.errMsg, |
384 | < | "Could not open \"%s\" for final dump output.\n", |
385 | < | finalName ); |
386 | < | painCave.isFatal = 1; |
387 | < | simError(); |
388 | < | } |
389 | < | |
390 | < | // finalOut.setf( ios::scientific ); |
391 | < | |
392 | < | #ifdef IS_MPI |
393 | < | } |
394 | < | |
395 | < | sprintf(checkPointMsg,"Opened file for final configuration\n"); |
396 | < | MPIcheckPoint(); |
397 | < | |
398 | < | #endif //is_mpi |
399 | < | |
400 | < | |
401 | < | #ifndef IS_MPI |
402 | < | |
403 | < | finalOut << nAtoms << "\n"; |
404 | < | |
405 | < | finalOut << finalTime << ";\t" |
406 | < | << entry_plug->Hmat[0][0] << "\t" |
407 | < | << entry_plug->Hmat[1][0] << "\t" |
408 | < | << entry_plug->Hmat[2][0] << ";\t" |
409 | < | |
410 | < | << entry_plug->Hmat[0][1] << "\t" |
411 | < | << entry_plug->Hmat[1][1] << "\t" |
412 | < | << entry_plug->Hmat[2][1] << ";\t" |
413 | < | |
414 | < | << entry_plug->Hmat[0][2] << "\t" |
415 | < | << entry_plug->Hmat[1][2] << "\t" |
416 | < | << entry_plug->Hmat[2][2] << ";"; |
417 | < | |
418 | < | //write out additional parameters, such as chi and eta |
419 | < | finalOut << entry_plug->the_integrator->getAdditionalParameters(); |
420 | < | finalOut << endl; |
421 | < | |
422 | < | for( i=0; i<nAtoms; i++ ){ |
423 | < | |
424 | < | atoms[i]->getPos(pos); |
425 | < | atoms[i]->getVel(vel); |
426 | < | |
427 | < | sprintf( tempBuffer, |
428 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
429 | < | atoms[i]->getType(), |
430 | < | pos[0], |
431 | < | pos[1], |
432 | < | pos[2], |
433 | < | vel[0], |
434 | < | vel[1], |
435 | < | vel[2]); |
436 | < | strcpy( writeLine, tempBuffer ); |
437 | < | |
438 | < | if( atoms[i]->isDirectional() ){ |
439 | < | |
440 | < | dAtom = (DirectionalAtom *)atoms[i]; |
441 | < | dAtom->getQ( q ); |
442 | < | |
443 | < | sprintf( tempBuffer, |
444 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
445 | < | q[0], |
446 | < | q[1], |
447 | < | q[2], |
448 | < | q[3], |
449 | < | dAtom->getJx(), |
450 | < | dAtom->getJy(), |
451 | < | dAtom->getJz()); |
452 | < | strcat( writeLine, tempBuffer ); |
453 | < | } |
454 | < | else |
455 | < | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
456 | < | |
457 | < | finalOut << writeLine; |
458 | < | } |
459 | < | finalOut.flush(); |
460 | < | finalOut.close(); |
461 | < | |
462 | < | #else // is_mpi |
463 | < | |
464 | < | // first thing first, suspend fatalities. |
465 | < | painCave.isEventLoop = 1; |
466 | < | |
467 | < | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
468 | < | int haveError; |
469 | < | |
470 | < | MPI_Status istatus; |
471 | < | int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
472 | < | |
473 | < | // write out header and node 0's coordinates |
474 | < | |
475 | < | haveError = 0; |
476 | < | if( worldRank == 0 ){ |
477 | < | finalOut << mpiSim->getTotAtoms() << "\n"; |
478 | < | |
479 | < | finalOut << finalTime << ";\t" |
480 | < | << entry_plug->Hmat[0][0] << "\t" |
481 | < | << entry_plug->Hmat[1][0] << "\t" |
482 | < | << entry_plug->Hmat[2][0] << ";\t" |
483 | < | |
484 | < | << entry_plug->Hmat[0][1] << "\t" |
485 | < | << entry_plug->Hmat[1][1] << "\t" |
486 | < | << entry_plug->Hmat[2][1] << ";\t" |
487 | < | |
488 | < | << entry_plug->Hmat[0][2] << "\t" |
489 | < | << entry_plug->Hmat[1][2] << "\t" |
490 | < | << entry_plug->Hmat[2][2] << ";"; |
491 | < | |
492 | < | //write out additional parameters, such as chi and eta |
493 | < | finalOut << entry_plug->the_integrator->getAdditionalParameters(); |
494 | < | finalOut << endl; |
495 | < | |
496 | < | for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
497 | < | // Get the Node number which has this molecule: |
498 | < | |
499 | < | which_node = AtomToProcMap[i]; |
500 | < | |
501 | < | if (which_node == mpiSim->getMyNode()) { |
502 | < | |
503 | < | which_atom = i; |
504 | < | local_index=-1; |
505 | < | for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
506 | < | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
507 | < | } |
508 | < | if (local_index != -1) { |
509 | < | |
510 | < | atoms[local_index]->getPos(pos); |
511 | < | atoms[local_index]->getVel(vel); |
512 | < | |
513 | < | sprintf( tempBuffer, |
514 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
515 | < | atoms[local_index]->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[local_index]->isDirectional() ){ |
525 | < | |
526 | < | dAtom = (DirectionalAtom *)atoms[local_index]; |
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 | < | else { |
495 | > | } else { |
496 | sprintf(painCave.errMsg, | |
497 | "Atom %d not found on processor %d\n", | |
498 | i, worldRank ); | |
# | Line 548 | Line 500 | void DumpWriter::writeFinal(double finalTime){ | |
500 | simError(); | |
501 | } | |
502 | ||
503 | < | if(haveError) nodeZeroError(); |
503 | > | strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
504 | ||
505 | < | } |
506 | < | else { |
505 | > | // null terminate the string before sending (just in case): |
506 | > | MPIatomTypeString[MINIBUFFERSIZE-1] = '\0'; |
507 | ||
508 | < | myStatus = 1; |
509 | < | MPI_Send(&myStatus, 1, MPI_INT, which_node, |
510 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
511 | < | MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
560 | < | MPI_COMM_WORLD); |
561 | < | MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
562 | < | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
563 | < | MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
564 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
508 | > | MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
509 | > | myPotato, MPI_COMM_WORLD); |
510 | > | |
511 | > | myPotato++; |
512 | ||
513 | < | if(!myStatus) nodeZeroError(); |
514 | < | } |
513 | > | MPI_Send(&isDirectional, 1, MPI_INT, 0, |
514 | > | myPotato, MPI_COMM_WORLD); |
515 | > | |
516 | > | myPotato++; |
517 | > | |
518 | > | if (isDirectional) { |
519 | ||
520 | < | finalOut << writeLine; |
521 | < | } |
520 | > | MPI_Send(atomData13, 13, MPI_DOUBLE, 0, |
521 | > | myPotato, MPI_COMM_WORLD); |
522 | > | |
523 | > | } else { |
524 | ||
525 | < | // kill everyone off: |
526 | < | myStatus = -1; |
527 | < | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
575 | < | MPI_Send(&myStatus, 1, MPI_INT, j, |
576 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
577 | < | } |
525 | > | MPI_Send(atomData6, 6, MPI_DOUBLE, 0, |
526 | > | myPotato, MPI_COMM_WORLD); |
527 | > | } |
528 | ||
529 | < | } else { |
530 | < | |
581 | < | done = 0; |
582 | < | while (!done) { |
583 | < | |
584 | < | MPI_Recv(&myStatus, 1, MPI_INT, 0, |
585 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
586 | < | |
587 | < | if(!myStatus) anonymousNodeDie(); |
588 | < | |
589 | < | if(myStatus < 0) break; |
590 | < | |
591 | < | MPI_Recv(&which_atom, 1, MPI_INT, 0, |
592 | < | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
593 | < | |
594 | < | myStatus = 1; |
595 | < | local_index=-1; |
596 | < | for (j=0; j < mpiSim->getMyNlocal(); j++) { |
597 | < | if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
529 | > | myPotato++; |
530 | > | currentIndex++; |
531 | } | |
599 | – | if (local_index != -1) { |
600 | – | |
601 | – | atoms[local_index]->getPos(pos); |
602 | – | atoms[local_index]->getVel(vel); |
603 | – | |
604 | – | //format the line |
605 | – | sprintf( tempBuffer, |
606 | – | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
607 | – | atoms[local_index]->getType(), |
608 | – | pos[0], |
609 | – | pos[1], |
610 | – | pos[2], |
611 | – | vel[0], |
612 | – | vel[1], |
613 | – | vel[2]); // check here. |
614 | – | strcpy( writeLine, tempBuffer ); |
615 | – | |
616 | – | if( atoms[local_index]->isDirectional() ){ |
617 | – | |
618 | – | dAtom = (DirectionalAtom *)atoms[local_index]; |
619 | – | dAtom->getQ( q ); |
620 | – | |
621 | – | sprintf( tempBuffer, |
622 | – | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
623 | – | q[0], |
624 | – | q[1], |
625 | – | q[2], |
626 | – | q[3], |
627 | – | dAtom->getJx(), |
628 | – | dAtom->getJy(), |
629 | – | dAtom->getJz()); |
630 | – | strcat( writeLine, tempBuffer ); |
631 | – | } |
632 | – | else{ |
633 | – | strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
634 | – | } |
635 | – | } |
636 | – | else { |
637 | – | sprintf(painCave.errMsg, |
638 | – | "Atom %d not found on processor %d\n", |
639 | – | which_atom, worldRank ); |
640 | – | myStatus = 0; |
641 | – | simError(); |
642 | – | |
643 | – | strcpy( writeLine, "Hello, I'm an error.\n"); |
644 | – | } |
645 | – | |
646 | – | MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
647 | – | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
648 | – | MPI_Send( &myStatus, 1, MPI_INT, 0, |
649 | – | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
532 | } | |
651 | – | } |
652 | – | finalOut.flush(); |
653 | – | sprintf( checkPointMsg, |
654 | – | "Sucessfully took a dump.\n"); |
655 | – | MPIcheckPoint(); |
533 | ||
534 | < | if( worldRank == 0 ) finalOut.close(); |
534 | > | sprintf( checkPointMsg, |
535 | > | "Sucessfully took a dump.\n"); |
536 | > | MPIcheckPoint(); |
537 | > | |
538 | > | } |
539 | > | |
540 | #endif // is_mpi | |
541 | } | |
542 | ||
661 | – | |
662 | – | |
543 | #ifdef IS_MPI | |
544 | ||
545 | // a couple of functions to let us escape the write loop | |
546 | ||
547 | < | void dWrite::nodeZeroError( void ){ |
668 | < | int j, myStatus; |
547 | > | void dWrite::DieDieDie( void ){ |
548 | ||
670 | – | myStatus = 0; |
671 | – | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
672 | – | MPI_Send( &myStatus, 1, MPI_INT, j, |
673 | – | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
674 | – | } |
675 | – | |
676 | – | |
549 | MPI_Finalize(); | |
550 | exit (0); | |
679 | – | |
551 | } | |
552 | ||
682 | – | void dWrite::anonymousNodeDie( void ){ |
683 | – | |
684 | – | MPI_Finalize(); |
685 | – | exit (0); |
686 | – | } |
687 | – | |
553 | #endif //is_mpi |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |