7 |
|
#ifdef IS_MPI |
8 |
|
#include <mpi.h> |
9 |
|
#include "mpiSimulation.hpp" |
10 |
– |
#define TAKE_THIS_TAG_CHAR 15 |
11 |
– |
#define TAKE_THIS_TAG_INT 20 |
10 |
|
|
11 |
|
namespace dWrite{ |
12 |
< |
void nodeZeroError( void ); |
15 |
< |
void anonymousNodeDie( void ); |
12 |
> |
void DieDieDie( void ); |
13 |
|
} |
14 |
|
|
15 |
|
using namespace dWrite; |
66 |
|
void DumpWriter::writeDump( double currentTime ){ |
67 |
|
|
68 |
|
const int BUFFERSIZE = 2000; |
69 |
+ |
const int MINIBUFFERSIZE = 100; |
70 |
+ |
|
71 |
|
char tempBuffer[BUFFERSIZE]; |
72 |
|
char writeLine[BUFFERSIZE]; |
73 |
|
|
74 |
|
int i; |
75 |
|
#ifdef IS_MPI |
76 |
|
int j, which_node, done, which_atom, local_index; |
77 |
+ |
double atomTransData[6]; |
78 |
+ |
double atomOrientData[7]; |
79 |
+ |
int isDirectional; |
80 |
+ |
char* atomTypeString; |
81 |
+ |
char MPIatomTypeString[MINIBUFFERSIZE]; |
82 |
+ |
int me; |
83 |
+ |
int atomTypeTag; |
84 |
+ |
int atomIsDirectionalTag; |
85 |
+ |
int atomTransDataTag; |
86 |
+ |
int atomOrientDataTag; |
87 |
|
#else //is_mpi |
88 |
|
int nAtoms = entry_plug->n_atoms; |
89 |
|
#endif //is_mpi |
93 |
|
Atom** atoms = entry_plug->atoms; |
94 |
|
double pos[3], vel[3]; |
95 |
|
|
87 |
– |
|
96 |
|
// write current frame to the eor file |
97 |
|
|
98 |
|
this->writeFinal( currentTime ); |
158 |
|
|
159 |
|
#else // is_mpi |
160 |
|
|
161 |
< |
// first thing first, suspend fatalities. |
162 |
< |
painCave.isEventLoop = 1; |
161 |
> |
/* code to find maximum tag value */ |
162 |
> |
int *tagub, flag, MAXTAG; |
163 |
> |
MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
164 |
> |
if (flag) { |
165 |
> |
MAXTAG = *tagub; |
166 |
> |
} else { |
167 |
> |
MAXTAG = 32767; |
168 |
> |
} |
169 |
|
|
156 |
– |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
170 |
|
int haveError; |
171 |
|
|
172 |
|
MPI_Status istatus; |
193 |
|
outFile << entry_plug->the_integrator->getAdditionalParameters(); |
194 |
|
outFile << endl; |
195 |
|
outFile.flush(); |
196 |
+ |
|
197 |
+ |
tag = 0; |
198 |
+ |
|
199 |
|
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
184 |
– |
// Get the Node number which has this atom; |
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 |
+ |
} |
207 |
+ |
|
208 |
+ |
// Get the Node number which has this atom; |
209 |
+ |
|
210 |
|
which_node = AtomToProcMap[i]; |
211 |
+ |
|
212 |
+ |
if (which_node != 0) { |
213 |
+ |
|
214 |
+ |
MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
215 |
+ |
atomTypeTag, MPI_COMM_WORLD, &istatus); |
216 |
+ |
|
217 |
+ |
strncpy(atomTypeString, MPIatomTypeString, MINIBUFFERSIZE); |
218 |
+ |
|
219 |
+ |
// Null terminate the atomTypeString just in case: |
220 |
|
|
221 |
< |
if (which_node == 0 ) { |
221 |
> |
atomTypeString[strlen(atomTypeString) - 1] = '\0'; |
222 |
|
|
223 |
+ |
MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
224 |
+ |
atomIsDirectionalTag, MPI_COMM_WORLD, &istatus); |
225 |
+ |
|
226 |
+ |
MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node, |
227 |
+ |
atomTransDataTag, MPI_COMM_WORLD, &istatus); |
228 |
+ |
|
229 |
+ |
if (isDirectional) { |
230 |
+ |
|
231 |
+ |
MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node, |
232 |
+ |
atomOrientDataTag, MPI_COMM_WORLD, &istatus); |
233 |
+ |
|
234 |
+ |
} |
235 |
+ |
|
236 |
+ |
} else { |
237 |
+ |
|
238 |
|
haveError = 0; |
239 |
|
which_atom = i; |
240 |
|
local_index=-1; |
241 |
+ |
|
242 |
|
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
243 |
|
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
244 |
|
} |
245 |
+ |
|
246 |
|
if (local_index != -1) { |
197 |
– |
//format the line |
247 |
|
|
248 |
+ |
atomTypeString = atoms[local_index]->getType(); |
249 |
+ |
|
250 |
|
atoms[local_index]->getPos(pos); |
251 |
|
atoms[local_index]->getVel(vel); |
252 |
|
|
253 |
< |
sprintf( tempBuffer, |
254 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
255 |
< |
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 ); |
253 |
> |
atomTransData[0] = pos[0]; |
254 |
> |
atomTransData[1] = pos[1]; |
255 |
> |
atomTransData[2] = pos[2]; |
256 |
|
|
257 |
+ |
atomTransData[3] = vel[0]; |
258 |
+ |
atomTransData[4] = vel[1]; |
259 |
+ |
atomTransData[5] = vel[2]; |
260 |
+ |
|
261 |
+ |
isDirectional = 0; |
262 |
+ |
|
263 |
|
if( atoms[local_index]->isDirectional() ){ |
264 |
|
|
265 |
+ |
isDirectional = 1; |
266 |
+ |
|
267 |
|
dAtom = (DirectionalAtom *)atoms[local_index]; |
268 |
|
dAtom->getQ( q ); |
269 |
+ |
|
270 |
+ |
atomOrientData[0] = q[0]; |
271 |
+ |
atomOrientData[1] = q[1]; |
272 |
+ |
atomOrientData[2] = q[2]; |
273 |
+ |
atomOrientData[3] = q[3]; |
274 |
|
|
275 |
< |
sprintf( tempBuffer, |
276 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
277 |
< |
q[0], |
278 |
< |
q[1], |
222 |
< |
q[2], |
223 |
< |
q[3], |
224 |
< |
dAtom->getJx(), |
225 |
< |
dAtom->getJy(), |
226 |
< |
dAtom->getJz()); |
227 |
< |
strcat( writeLine, tempBuffer ); |
275 |
> |
atomOrientData[4] = dAtom->getJx(); |
276 |
> |
atomOrientData[5] = dAtom->getJy(); |
277 |
> |
atomOrientData[6] = dAtom->getJz(); |
278 |
> |
} |
279 |
|
|
280 |
< |
} |
230 |
< |
else |
231 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
232 |
< |
} |
233 |
< |
else { |
280 |
> |
} else { |
281 |
|
sprintf(painCave.errMsg, |
282 |
|
"Atom %d not found on processor %d\n", |
283 |
|
i, worldRank ); |
285 |
|
simError(); |
286 |
|
} |
287 |
|
|
288 |
< |
if(haveError) nodeZeroError(); |
288 |
> |
if(haveError) DieDieDie(); |
289 |
> |
|
290 |
> |
// If we've survived to here, format the line: |
291 |
> |
|
292 |
> |
sprintf( tempBuffer, |
293 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
294 |
> |
atomTypeString, |
295 |
> |
atomTransData[0], |
296 |
> |
atomTransData[1], |
297 |
> |
atomTransData[2], |
298 |
> |
atomTransData[3], |
299 |
> |
atomTransData[4], |
300 |
> |
atomTransData[5]); |
301 |
|
|
302 |
< |
} |
244 |
< |
else { |
245 |
< |
myStatus = 1; |
246 |
< |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
247 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
248 |
< |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
249 |
< |
MPI_COMM_WORLD); |
250 |
< |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
251 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
252 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
253 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
302 |
> |
strcpy( writeLine, tempBuffer ); |
303 |
|
|
304 |
< |
if(!myStatus) nodeZeroError(); |
304 |
> |
if (isDirectional) { |
305 |
|
|
306 |
< |
} |
306 |
> |
sprintf( tempBuffer, |
307 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
308 |
> |
atomOrientData[0], |
309 |
> |
atomOrientData[1], |
310 |
> |
atomOrientData[2], |
311 |
> |
atomOrientData[3], |
312 |
> |
atomOrientData[4], |
313 |
> |
atomOrientData[5], |
314 |
> |
atomOrientData[6]); |
315 |
> |
strcat( writeLine, tempBuffer ); |
316 |
|
|
317 |
< |
outFile << writeLine; |
318 |
< |
outFile.flush(); |
319 |
< |
} |
317 |
> |
} else { |
318 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
319 |
> |
} |
320 |
|
|
321 |
< |
// kill everyone off: |
322 |
< |
myStatus = -1; |
323 |
< |
for (j = 1; j < mpiSim->getNumberProcessors(); j++) { |
266 |
< |
MPI_Send(&myStatus, 1, MPI_INT, j, |
267 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
321 |
> |
outFile << writeLine; |
322 |
> |
outFile.flush(); |
323 |
> |
} |
324 |
|
} |
325 |
|
|
326 |
+ |
outFile.flush(); |
327 |
+ |
sprintf( checkPointMsg, |
328 |
+ |
"Sucessfully took a dump.\n"); |
329 |
+ |
MPIcheckPoint(); |
330 |
+ |
|
331 |
|
} else { |
332 |
|
|
333 |
< |
done = 0; |
334 |
< |
while (!done) { |
335 |
< |
|
336 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
337 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
333 |
> |
// worldRank != 0, so I'm a remote node. |
334 |
> |
|
335 |
> |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
336 |
> |
|
337 |
> |
// Am I the node which has this atom? |
338 |
> |
|
339 |
> |
if (AtomToProcMap[i] == worldRank) { |
340 |
|
|
341 |
< |
if(!myStatus) anonymousNodeDie(); |
341 |
> |
local_index=-1; |
342 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
343 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
344 |
> |
} |
345 |
> |
if (local_index != -1) { |
346 |
> |
|
347 |
> |
atomTypeString = atoms[local_index]->getType(); |
348 |
|
|
349 |
< |
if(myStatus < 0) break; |
349 |
> |
atoms[local_index]->getPos(pos); |
350 |
> |
atoms[local_index]->getVel(vel); |
351 |
|
|
352 |
< |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
353 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
352 |
> |
atomTransData[0] = pos[0]; |
353 |
> |
atomTransData[1] = pos[1]; |
354 |
> |
atomTransData[2] = pos[2]; |
355 |
|
|
356 |
< |
myStatus = 1; |
357 |
< |
local_index=-1; |
358 |
< |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
359 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
360 |
< |
} |
290 |
< |
if (local_index != -1) { |
291 |
< |
//format the line |
356 |
> |
atomTransData[3] = vel[0]; |
357 |
> |
atomTransData[4] = vel[1]; |
358 |
> |
atomTransData[5] = vel[2]; |
359 |
> |
|
360 |
> |
isDirectional = 0; |
361 |
|
|
362 |
< |
atoms[local_index]->getPos(pos); |
294 |
< |
atoms[local_index]->getVel(vel); |
362 |
> |
if( atoms[local_index]->isDirectional() ){ |
363 |
|
|
364 |
< |
sprintf( tempBuffer, |
365 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
366 |
< |
atoms[local_index]->getType(), |
367 |
< |
pos[0], |
368 |
< |
pos[1], |
369 |
< |
pos[2], |
370 |
< |
vel[0], |
371 |
< |
vel[1], |
372 |
< |
vel[2]); // check here. |
305 |
< |
strcpy( writeLine, tempBuffer ); |
364 |
> |
isDirectional = 1; |
365 |
> |
|
366 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
367 |
> |
dAtom->getQ( q ); |
368 |
> |
|
369 |
> |
atomOrientData[0] = q[0]; |
370 |
> |
atomOrientData[1] = q[1]; |
371 |
> |
atomOrientData[2] = q[2]; |
372 |
> |
atomOrientData[3] = q[3]; |
373 |
|
|
374 |
< |
if( atoms[local_index]->isDirectional() ){ |
374 |
> |
atomOrientData[4] = dAtom->getJx(); |
375 |
> |
atomOrientData[5] = dAtom->getJy(); |
376 |
> |
atomOrientData[6] = dAtom->getJz(); |
377 |
> |
} |
378 |
|
|
379 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
380 |
< |
dAtom->getQ( q ); |
381 |
< |
|
382 |
< |
sprintf( tempBuffer, |
383 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
384 |
< |
q[0], |
315 |
< |
q[1], |
316 |
< |
q[2], |
317 |
< |
q[3], |
318 |
< |
dAtom->getJx(), |
319 |
< |
dAtom->getJy(), |
320 |
< |
dAtom->getJz()); |
321 |
< |
strcat( writeLine, tempBuffer ); |
379 |
> |
} else { |
380 |
> |
sprintf(painCave.errMsg, |
381 |
> |
"Atom %d not found on processor %d\n", |
382 |
> |
i, worldRank ); |
383 |
> |
haveError= 1; |
384 |
> |
simError(); |
385 |
|
} |
323 |
– |
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(); |
386 |
|
|
387 |
< |
strcpy( writeLine, "Hello, I'm an error.\n"); |
335 |
< |
} |
387 |
> |
// I've survived this far, so send off the data! |
388 |
|
|
389 |
< |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
390 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
391 |
< |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
392 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
389 |
> |
atomTypeTag = 4*i; |
390 |
> |
atomIsDirectionalTag = 4*i + 1; |
391 |
> |
atomTransDataTag = 4*i + 2; |
392 |
> |
atomOrientDataTag = 4*i + 3; |
393 |
> |
|
394 |
> |
|
395 |
> |
strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
396 |
> |
|
397 |
> |
// null terminate the string before sending (just in case): |
398 |
> |
MPIatomTypeString[MINIBUFFERSIZE-1] = '\0'; |
399 |
> |
|
400 |
> |
MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
401 |
> |
atomTypeTag, MPI_COMM_WORLD); |
402 |
> |
|
403 |
> |
MPI_Send(&isDirectional, 1, MPI_INT, 0, |
404 |
> |
atomIsDirectionalTag, MPI_COMM_WORLD); |
405 |
> |
|
406 |
> |
MPI_Send(atomTransData, 6, MPI_DOUBLE, 0, |
407 |
> |
atomTransDataTag, MPI_COMM_WORLD); |
408 |
> |
|
409 |
> |
if (isDirectional) { |
410 |
> |
|
411 |
> |
MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0, |
412 |
> |
atomOrientDataTag, MPI_COMM_WORLD); |
413 |
> |
|
414 |
> |
} |
415 |
> |
|
416 |
> |
} |
417 |
|
} |
342 |
– |
} |
343 |
– |
outFile.flush(); |
344 |
– |
sprintf( checkPointMsg, |
345 |
– |
"Sucessfully took a dump.\n"); |
346 |
– |
MPIcheckPoint(); |
418 |
|
|
419 |
< |
// last thing last, enable fatalities. |
419 |
> |
sprintf( checkPointMsg, |
420 |
> |
"Sucessfully took a dump.\n"); |
421 |
> |
MPIcheckPoint(); |
422 |
> |
|
423 |
> |
} |
424 |
> |
|
425 |
|
painCave.isEventLoop = 0; |
426 |
|
|
427 |
|
#endif // is_mpi |
433 |
|
ofstream finalOut; |
434 |
|
|
435 |
|
const int BUFFERSIZE = 2000; |
436 |
+ |
const int MINIBUFFERSIZE = 100; |
437 |
|
char tempBuffer[BUFFERSIZE]; |
438 |
|
char writeLine[BUFFERSIZE]; |
439 |
|
|
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 |
558 |
|
|
559 |
|
// write out header and node 0's coordinates |
560 |
|
|
475 |
– |
haveError = 0; |
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" |
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" |
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] << ";"; |
573 |
> |
<< entry_plug->Hmat[0][2] << "\t" |
574 |
> |
<< entry_plug->Hmat[1][2] << "\t" |
575 |
> |
<< entry_plug->Hmat[2][2] << ";"; |
576 |
|
|
492 |
– |
//write out additional parameters, such as chi and eta |
577 |
|
finalOut << entry_plug->the_integrator->getAdditionalParameters(); |
578 |
|
finalOut << endl; |
579 |
< |
|
579 |
> |
finalOut.flush(); |
580 |
|
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
581 |
< |
// Get the Node number which has this molecule: |
581 |
> |
// Get the Node number which has this atom; |
582 |
|
|
583 |
|
which_node = AtomToProcMap[i]; |
584 |
|
|
585 |
< |
if (which_node == mpiSim->getMyNode()) { |
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 |
+ |
|
608 |
+ |
} |
609 |
+ |
|
610 |
+ |
} else { |
611 |
+ |
|
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 |
< |
sprintf( tempBuffer, |
628 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
629 |
< |
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 ); |
627 |
> |
atomTransData[0] = pos[0]; |
628 |
> |
atomTransData[1] = pos[1]; |
629 |
> |
atomTransData[2] = pos[2]; |
630 |
|
|
631 |
< |
if( atoms[local_index]->isDirectional() ){ |
631 |
> |
atomTransData[3] = vel[0]; |
632 |
> |
atomTransData[4] = vel[1]; |
633 |
> |
atomTransData[5] = vel[2]; |
634 |
> |
|
635 |
> |
isDirectional = 0; |
636 |
|
|
637 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
527 |
< |
dAtom->getQ( q ); |
637 |
> |
if( atoms[local_index]->isDirectional() ){ |
638 |
|
|
639 |
< |
sprintf( tempBuffer, |
640 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
641 |
< |
q[0], |
642 |
< |
q[1], |
643 |
< |
q[2], |
644 |
< |
q[3], |
645 |
< |
dAtom->getJx(), |
646 |
< |
dAtom->getJy(), |
647 |
< |
dAtom->getJz()); |
648 |
< |
strcat( writeLine, tempBuffer ); |
649 |
< |
} |
650 |
< |
else |
651 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
652 |
< |
} |
653 |
< |
else { |
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 ); |
659 |
|
simError(); |
660 |
|
} |
661 |
|
|
662 |
< |
if(haveError) nodeZeroError(); |
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 |
< |
} |
554 |
< |
else { |
676 |
> |
strcpy( writeLine, tempBuffer ); |
677 |
|
|
678 |
< |
myStatus = 1; |
557 |
< |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
558 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
559 |
< |
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); |
678 |
> |
if (isDirectional) { |
679 |
|
|
680 |
< |
if(!myStatus) nodeZeroError(); |
681 |
< |
} |
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 |
< |
finalOut << writeLine; |
692 |
< |
} |
691 |
> |
} else { |
692 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
693 |
> |
} |
694 |
|
|
695 |
< |
// kill everyone off: |
696 |
< |
myStatus = -1; |
697 |
< |
for (j = 1; j < mpiSim->getNumberProcessors(); j++) { |
575 |
< |
MPI_Send(&myStatus, 1, MPI_INT, j, |
576 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
695 |
> |
finalOut << writeLine; |
696 |
> |
finalOut.flush(); |
697 |
> |
} |
698 |
|
} |
699 |
|
|
700 |
+ |
finalOut.flush(); |
701 |
+ |
sprintf( checkPointMsg, |
702 |
+ |
"Sucessfully took a dump.\n"); |
703 |
+ |
MPIcheckPoint(); |
704 |
+ |
|
705 |
|
} else { |
706 |
|
|
707 |
< |
done = 0; |
708 |
< |
while (!done) { |
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 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
716 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
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 |
< |
if(!myStatus) anonymousNodeDie(); |
723 |
> |
atoms[local_index]->getPos(pos); |
724 |
> |
atoms[local_index]->getVel(vel); |
725 |
|
|
726 |
< |
if(myStatus < 0) break; |
726 |
> |
atomTransData[0] = pos[0]; |
727 |
> |
atomTransData[1] = pos[1]; |
728 |
> |
atomTransData[2] = pos[2]; |
729 |
|
|
730 |
< |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
731 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
730 |
> |
atomTransData[3] = vel[0]; |
731 |
> |
atomTransData[4] = vel[1]; |
732 |
> |
atomTransData[5] = vel[2]; |
733 |
> |
|
734 |
> |
isDirectional = 0; |
735 |
|
|
736 |
< |
myStatus = 1; |
595 |
< |
local_index=-1; |
596 |
< |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
597 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
598 |
< |
} |
599 |
< |
if (local_index != -1) { |
736 |
> |
if( atoms[local_index]->isDirectional() ){ |
737 |
|
|
738 |
< |
atoms[local_index]->getPos(pos); |
739 |
< |
atoms[local_index]->getVel(vel); |
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 |
< |
//format the line |
749 |
< |
sprintf( tempBuffer, |
750 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
751 |
< |
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 ); |
748 |
> |
atomOrientData[4] = dAtom->getJx(); |
749 |
> |
atomOrientData[5] = dAtom->getJy(); |
750 |
> |
atomOrientData[6] = dAtom->getJz(); |
751 |
> |
} |
752 |
|
|
753 |
< |
if( atoms[local_index]->isDirectional() ){ |
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 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
619 |
< |
dAtom->getQ( q ); |
761 |
> |
// I've survived this far, so send off the data! |
762 |
|
|
763 |
< |
sprintf( tempBuffer, |
764 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
765 |
< |
q[0], |
766 |
< |
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(); |
763 |
> |
atomTypeTag = 4*i; |
764 |
> |
atomIsDirectionalTag = 4*i + 1; |
765 |
> |
atomTransDataTag = 4*i + 2; |
766 |
> |
atomOrientDataTag = 4*i + 3; |
767 |
|
|
768 |
< |
strcpy( writeLine, "Hello, I'm an error.\n"); |
644 |
< |
} |
768 |
> |
strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
769 |
|
|
770 |
< |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
771 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
772 |
< |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
773 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
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 |
|
} |
794 |
< |
finalOut.flush(); |
795 |
< |
sprintf( checkPointMsg, |
654 |
< |
"Sucessfully took a dump.\n"); |
655 |
< |
MPIcheckPoint(); |
794 |
> |
|
795 |
> |
painCave.isEventLoop = 0; |
796 |
|
|
797 |
|
if( worldRank == 0 ) finalOut.close(); |
798 |
|
#endif // is_mpi |
804 |
|
|
805 |
|
// a couple of functions to let us escape the write loop |
806 |
|
|
807 |
< |
void dWrite::nodeZeroError( void ){ |
668 |
< |
int j, myStatus; |
807 |
> |
void dWrite::DieDieDie( void ){ |
808 |
|
|
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 |
– |
|
809 |
|
MPI_Finalize(); |
810 |
|
exit (0); |
679 |
– |
|
811 |
|
} |
812 |
|
|
682 |
– |
void dWrite::anonymousNodeDie( void ){ |
683 |
– |
|
684 |
– |
MPI_Finalize(); |
685 |
– |
exit (0); |
686 |
– |
} |
687 |
– |
|
813 |
|
#endif //is_mpi |