ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/DumpWriter.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/DumpWriter.cpp (file contents):
Revision 905 by tim, Wed Jan 7 19:26:12 2004 UTC vs.
Revision 910 by gezelter, Thu Jan 8 18:05:37 2004 UTC

# Line 7 | Line 7
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;
# Line 69 | Line 66 | void DumpWriter::writeDump( double currentTime ){
66   void DumpWriter::writeDump( double currentTime ){
67  
68    const int BUFFERSIZE = 2000;
69 +  const int MINIBUFFERSIZE = 10;
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
# Line 84 | Line 93 | void DumpWriter::writeDump( double currentTime ){
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 );
# Line 185 | Line 193 | void DumpWriter::writeDump( double currentTime ){
193  
194        which_node = AtomToProcMap[i];
195  
196 <      if (which_node == 0 ) {
196 >      if (which_node != 0) {
197 >        
198 >        atomTypeTag          = 4*i;
199 >        atomIsDirectionalTag = 4*i + 1;
200 >        atomTransDataTag     = 4*i + 2;
201 >        atomOrientDataTag    = 4*i + 3;
202  
203 +        MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node,
204 +                 atomTypeTag, MPI_COMM_WORLD, &istatus);
205 +        
206 +        strncpy(atomTypeString, MPIatomTypeString, MINIBUFFERSIZE);
207 +
208 +        MPI_Recv(&isDirectional, 1, MPI_INT, which_node,
209 +                 atomIsDirectionalTag, MPI_COMM_WORLD, &istatus);
210 +        
211 +        MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node,
212 +                 atomTransDataTag, MPI_COMM_WORLD, &istatus);
213 +
214 +        if (isDirectional) {
215 +
216 +          MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node,
217 +                   atomOrientDataTag, MPI_COMM_WORLD, &istatus);
218 +
219 +        }
220 +
221 +      } else {
222 +        
223          haveError = 0;
224          which_atom = i;
225          local_index=-1;
226 +
227          for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
228            if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
229          }
230 +
231          if (local_index != -1) {
197          //format the line
232  
233 +          atomTypeString = atoms[local_index]->getType();
234 +
235            atoms[local_index]->getPos(pos);
236            atoms[local_index]->getVel(vel);
237  
238 <          sprintf( tempBuffer,
239 <                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
240 <                   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 );
238 >          atomTransData[0] = pos[0];
239 >          atomTransData[1] = pos[1];
240 >          atomTransData[2] = pos[2];
241  
242 +          atomTransData[3] = vel[0];
243 +          atomTransData[4] = vel[1];
244 +          atomTransData[5] = vel[2];
245 +          
246 +          isDirectional = 0;
247 +
248            if( atoms[local_index]->isDirectional() ){
249  
250 +            isDirectional = 1;
251 +            
252              dAtom = (DirectionalAtom *)atoms[local_index];
253              dAtom->getQ( q );
254 +            
255 +            atomOrientData[0] = q[0];
256 +            atomOrientData[1] = q[1];
257 +            atomOrientData[2] = q[2];
258 +            atomOrientData[3] = q[3];
259  
260 <            sprintf( tempBuffer,
261 <                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
262 <                     q[0],
263 <                     q[1],
222 <                     q[2],
223 <                     q[3],
224 <                     dAtom->getJx(),
225 <                     dAtom->getJy(),
226 <                     dAtom->getJz());
227 <            strcat( writeLine, tempBuffer );
260 >            atomOrientData[4] = dAtom->getJx();
261 >            atomOrientData[5] = dAtom->getJy();
262 >            atomOrientData[6] = dAtom->getJz();
263 >          }
264  
265 <          }
230 <          else
231 <            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
232 <        }
233 <        else {
265 >        } else {
266            sprintf(painCave.errMsg,
267                    "Atom %d not found on processor %d\n",
268                    i, worldRank );
# Line 238 | Line 270 | void DumpWriter::writeDump( double currentTime ){
270            simError();
271          }
272  
273 <        if(haveError) nodeZeroError();
273 >        if(haveError) DieDieDie();
274 >                              
275 >        // If we've survived to here, format the line:
276 >        
277 >        sprintf( tempBuffer,
278 >                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
279 >                 atomTypeString,
280 >                 atomTransData[0],
281 >                 atomTransData[1],
282 >                 atomTransData[2],
283 >                 atomTransData[3],
284 >                 atomTransData[4],
285 >                 atomTransData[5]);
286  
287 <      }
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);
287 >        strcpy( writeLine, tempBuffer );
288  
289 <        if(!myStatus) nodeZeroError();
289 >        if (isDirectional) {
290  
291 <      }
291 >          sprintf( tempBuffer,
292 >                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
293 >                   atomOrientData[0],
294 >                   atomOrientData[1],
295 >                   atomOrientData[2],
296 >                   atomOrientData[3],
297 >                   atomOrientData[4],
298 >                   atomOrientData[5],
299 >                   atomOrientData[6]);
300 >          strcat( writeLine, tempBuffer );
301  
302 <      outFile << writeLine;
303 <      outFile.flush();
304 <    }
302 >        } else {
303 >          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
304 >        }
305  
306 <    // kill everyone off:
307 <    myStatus = -1;
308 <    for (j = 1; j < mpiSim->getNumberProcessors(); j++) {
266 <      MPI_Send(&myStatus, 1, MPI_INT, j,
267 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
306 >        outFile << writeLine;
307 >        outFile.flush();
308 >      }
309      }
310  
311 +    outFile.flush();
312 +    sprintf( checkPointMsg,
313 +             "Sucessfully took a dump.\n");
314 +    MPIcheckPoint();        
315 +    
316    } else {
317  
318 <    done = 0;
319 <    while (!done) {
318 >    // worldRank != 0, so I'm a remote node.  
319 >    
320 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
321 >      
322 >      // Am I the node which has this atom?
323 >      
324 >      if (AtomToProcMap[i] == worldRank) {
325  
326 <      MPI_Recv(&myStatus, 1, MPI_INT, 0,
327 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
326 >        local_index=-1;
327 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
328 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
329 >        }
330 >        if (local_index != -1) {
331 >        
332 >          atomTypeString = atoms[local_index]->getType();
333  
334 <      if(!myStatus) anonymousNodeDie();
335 <
280 <      if(myStatus < 0) break;
334 >          atoms[local_index]->getPos(pos);
335 >          atoms[local_index]->getVel(vel);
336  
337 <      MPI_Recv(&which_atom, 1, MPI_INT, 0,
338 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
337 >          atomTransData[0] = pos[0];
338 >          atomTransData[1] = pos[1];
339 >          atomTransData[2] = pos[2];
340  
341 <      myStatus = 1;
342 <      local_index=-1;
343 <      for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
344 <        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
345 <      }
290 <      if (local_index != -1) {
291 <        //format the line
341 >          atomTransData[3] = vel[0];
342 >          atomTransData[4] = vel[1];
343 >          atomTransData[5] = vel[2];
344 >          
345 >          isDirectional = 0;
346  
347 <        atoms[local_index]->getPos(pos);
294 <        atoms[local_index]->getVel(vel);
347 >          if( atoms[local_index]->isDirectional() ){
348  
349 <        sprintf( tempBuffer,
350 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
351 <                 atoms[local_index]->getType(),
352 <                 pos[0],
353 <                 pos[1],
354 <                 pos[2],
355 <                 vel[0],
356 <                 vel[1],
357 <                 vel[2]); // check here.
305 <        strcpy( writeLine, tempBuffer );
349 >            isDirectional = 1;
350 >            
351 >            dAtom = (DirectionalAtom *)atoms[local_index];
352 >            dAtom->getQ( q );
353 >            
354 >            atomOrientData[0] = q[0];
355 >            atomOrientData[1] = q[1];
356 >            atomOrientData[2] = q[2];
357 >            atomOrientData[3] = q[3];
358  
359 <        if( atoms[local_index]->isDirectional() ){
359 >            atomOrientData[4] = dAtom->getJx();
360 >            atomOrientData[5] = dAtom->getJy();
361 >            atomOrientData[6] = dAtom->getJz();
362 >          }
363  
364 <          dAtom = (DirectionalAtom *)atoms[local_index];
365 <          dAtom->getQ( q );
366 <
367 <          sprintf( tempBuffer,
368 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
369 <                   q[0],
315 <                   q[1],
316 <                   q[2],
317 <                   q[3],
318 <                   dAtom->getJx(),
319 <                   dAtom->getJy(),
320 <                   dAtom->getJz());
321 <          strcat( writeLine, tempBuffer );
364 >        } else {
365 >          sprintf(painCave.errMsg,
366 >                  "Atom %d not found on processor %d\n",
367 >                  i, worldRank );
368 >          haveError= 1;
369 >          simError();
370          }
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();
371  
372 <        strcpy( writeLine, "Hello, I'm an error.\n");
335 <      }
372 >        // I've survived this far, so send off the data!
373  
374 <      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
375 <               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
376 <      MPI_Send( &myStatus, 1, MPI_INT, 0,
377 <                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
374 >        atomTypeTag          = 4*i;
375 >        atomIsDirectionalTag = 4*i + 1;
376 >        atomTransDataTag     = 4*i + 2;
377 >        atomOrientDataTag    = 4*i + 3;
378 >
379 >
380 >        strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
381 >
382 >        MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
383 >                 atomTypeTag, MPI_COMM_WORLD);
384 >        
385 >        MPI_Send(&isDirectional, 1, MPI_INT, 0,
386 >                 atomIsDirectionalTag, MPI_COMM_WORLD);
387 >        
388 >        MPI_Send(atomTransData, 6, MPI_DOUBLE, 0,
389 >                 atomTransDataTag, MPI_COMM_WORLD);
390 >
391 >        if (isDirectional) {
392 >
393 >          MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0,
394 >                   atomOrientDataTag, MPI_COMM_WORLD);
395 >          
396 >        }
397 >      
398 >      }
399      }
342  }
343  outFile.flush();
344  sprintf( checkPointMsg,
345           "Sucessfully took a dump.\n");
346  MPIcheckPoint();
400  
401 < // last  thing last, enable  fatalities.
401 >    sprintf( checkPointMsg,
402 >             "Sucessfully took a dump.\n");
403 >    MPIcheckPoint();        
404 >    
405 >  }
406 >  
407    painCave.isEventLoop = 0;
408  
409   #endif // is_mpi
# Line 357 | Line 415 | void DumpWriter::writeFinal(double finalTime){
415    ofstream finalOut;
416  
417    const int BUFFERSIZE = 2000;
418 +  const int MINIBUFFERSIZE = 10;
419    char tempBuffer[BUFFERSIZE];
420    char writeLine[BUFFERSIZE];
421  
# Line 366 | Line 425 | void DumpWriter::writeFinal(double finalTime){
425    int i;
426   #ifdef IS_MPI
427    int j, which_node, done, which_atom, local_index;
428 +  double atomTransData[6];
429 +  double atomOrientData[7];
430 +  int isDirectional;
431 +  char* atomTypeString;
432 +  char MPIatomTypeString[MINIBUFFERSIZE];
433 +  int atomTypeTag;
434 +  int atomIsDirectionalTag;
435 +  int atomTransDataTag;
436 +  int atomOrientDataTag;
437   #else //is_mpi
438    int nAtoms = entry_plug->n_atoms;
439   #endif //is_mpi
# Line 472 | Line 540 | void DumpWriter::writeFinal(double finalTime){
540  
541    // write out header and node 0's coordinates
542  
475  haveError = 0;
543    if( worldRank == 0 ){
544      finalOut << mpiSim->getTotAtoms() << "\n";
545  
546      finalOut << finalTime << ";\t"
547 <             << entry_plug->Hmat[0][0] << "\t"
548 <             << entry_plug->Hmat[1][0] << "\t"
549 <             << entry_plug->Hmat[2][0] << ";\t"
547 >            << entry_plug->Hmat[0][0] << "\t"
548 >            << entry_plug->Hmat[1][0] << "\t"
549 >            << entry_plug->Hmat[2][0] << ";\t"
550  
551 <             << entry_plug->Hmat[0][1] << "\t"
552 <             << entry_plug->Hmat[1][1] << "\t"
553 <             << entry_plug->Hmat[2][1] << ";\t"
551 >            << entry_plug->Hmat[0][1] << "\t"
552 >            << entry_plug->Hmat[1][1] << "\t"
553 >            << entry_plug->Hmat[2][1] << ";\t"
554  
555 <             << entry_plug->Hmat[0][2] << "\t"
556 <             << entry_plug->Hmat[1][2] << "\t"
557 <             << entry_plug->Hmat[2][2] << ";";
555 >            << entry_plug->Hmat[0][2] << "\t"
556 >            << entry_plug->Hmat[1][2] << "\t"
557 >            << entry_plug->Hmat[2][2] << ";";
558  
492    //write out additional parameters, such as chi and eta
559      finalOut << entry_plug->the_integrator->getAdditionalParameters();
560      finalOut << endl;
561 <
561 >    finalOut.flush();
562      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
563 <      // Get the Node number which has this molecule:
563 >      // Get the Node number which has this atom;
564  
565        which_node = AtomToProcMap[i];
566  
567 <      if (which_node == mpiSim->getMyNode()) {
567 >      if (which_node != 0) {
568 >        
569 >        atomTypeTag          = 4*i;
570 >        atomIsDirectionalTag = 4*i + 1;
571 >        atomTransDataTag     = 4*i + 2;
572 >        atomOrientDataTag    = 4*i + 3;
573  
574 +        MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node,
575 +                 atomTypeTag, MPI_COMM_WORLD, &istatus);
576 +        
577 +        strncpy(atomTypeString, MPIatomTypeString, MINIBUFFERSIZE);
578 +
579 +        MPI_Recv(&isDirectional, 1, MPI_INT, which_node,
580 +                 atomIsDirectionalTag, MPI_COMM_WORLD, &istatus);
581 +        
582 +        MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node,
583 +                 atomTransDataTag, MPI_COMM_WORLD, &istatus);
584 +
585 +        if (isDirectional) {
586 +
587 +          MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node,
588 +                   atomOrientDataTag, MPI_COMM_WORLD, &istatus);
589 +
590 +        }
591 +
592 +      } else {
593 +        
594 +        haveError = 0;
595          which_atom = i;
596          local_index=-1;
597 +
598          for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
599            if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
600          }
601 +
602          if (local_index != -1) {
603  
604 +          atomTypeString = atoms[local_index]->getType();
605 +
606            atoms[local_index]->getPos(pos);
607            atoms[local_index]->getVel(vel);
608  
609 <          sprintf( tempBuffer,
610 <                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
611 <                   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 );
609 >          atomTransData[0] = pos[0];
610 >          atomTransData[1] = pos[1];
611 >          atomTransData[2] = pos[2];
612  
613 <          if( atoms[local_index]->isDirectional() ){
613 >          atomTransData[3] = vel[0];
614 >          atomTransData[4] = vel[1];
615 >          atomTransData[5] = vel[2];
616 >          
617 >          isDirectional = 0;
618  
619 <            dAtom = (DirectionalAtom *)atoms[local_index];
527 <            dAtom->getQ( q );
619 >          if( atoms[local_index]->isDirectional() ){
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 <        else {
621 >            isDirectional = 1;
622 >            
623 >            dAtom = (DirectionalAtom *)atoms[local_index];
624 >            dAtom->getQ( q );
625 >            
626 >            atomOrientData[0] = q[0];
627 >            atomOrientData[1] = q[1];
628 >            atomOrientData[2] = q[2];
629 >            atomOrientData[3] = q[3];
630 >
631 >            atomOrientData[4] = dAtom->getJx();
632 >            atomOrientData[5] = dAtom->getJy();
633 >            atomOrientData[6] = dAtom->getJz();
634 >          }
635 >
636 >        } else {
637            sprintf(painCave.errMsg,
638                    "Atom %d not found on processor %d\n",
639                    i, worldRank );
# Line 548 | Line 641 | void DumpWriter::writeFinal(double finalTime){
641            simError();
642          }
643  
644 <        if(haveError) nodeZeroError();
644 >        if(haveError) DieDieDie();
645 >                              
646 >        // If we've survived to here, format the line:
647 >        
648 >        sprintf( tempBuffer,
649 >                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
650 >                 atomTypeString,
651 >                 atomTransData[0],
652 >                 atomTransData[1],
653 >                 atomTransData[2],
654 >                 atomTransData[3],
655 >                 atomTransData[4],
656 >                 atomTransData[5]);
657  
658 <      }
554 <      else {
658 >        strcpy( writeLine, tempBuffer );
659  
660 <        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);
660 >        if (isDirectional) {
661  
662 <        if(!myStatus) nodeZeroError();
663 <      }
662 >          sprintf( tempBuffer,
663 >                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
664 >                   atomOrientData[0],
665 >                   atomOrientData[1],
666 >                   atomOrientData[2],
667 >                   atomOrientData[3],
668 >                   atomOrientData[4],
669 >                   atomOrientData[5],
670 >                   atomOrientData[6]);
671 >          strcat( writeLine, tempBuffer );
672  
673 <      finalOut << writeLine;
674 <    }
673 >        } else {
674 >          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
675 >        }
676  
677 <    // kill everyone off:
678 <    myStatus = -1;
679 <    for (j = 1; j < mpiSim->getNumberProcessors(); j++) {
575 <      MPI_Send(&myStatus, 1, MPI_INT, j,
576 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
677 >        finalOut << writeLine;
678 >        finalOut.flush();
679 >      }
680      }
681  
682 +    finalOut.flush();
683 +    sprintf( checkPointMsg,
684 +             "Sucessfully took a dump.\n");
685 +    MPIcheckPoint();        
686 +    
687    } else {
688  
689 <    done = 0;
690 <    while (!done) {
689 >    // worldRank != 0, so I'm a remote node.  
690 >    
691 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
692 >      
693 >      // Am I the node which has this atom?
694 >      
695 >      if (AtomToProcMap[i] == worldRank) {
696  
697 <      MPI_Recv(&myStatus, 1, MPI_INT, 0,
698 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
697 >        local_index=-1;
698 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
699 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
700 >        }
701 >        if (local_index != -1) {
702 >        
703 >          atomTypeString = atoms[local_index]->getType();
704  
705 <      if(!myStatus) anonymousNodeDie();
705 >          atoms[local_index]->getPos(pos);
706 >          atoms[local_index]->getVel(vel);
707  
708 <      if(myStatus < 0) break;
708 >          atomTransData[0] = pos[0];
709 >          atomTransData[1] = pos[1];
710 >          atomTransData[2] = pos[2];
711  
712 <      MPI_Recv(&which_atom, 1, MPI_INT, 0,
713 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
712 >          atomTransData[3] = vel[0];
713 >          atomTransData[4] = vel[1];
714 >          atomTransData[5] = vel[2];
715 >          
716 >          isDirectional = 0;
717  
718 <      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) {
718 >          if( atoms[local_index]->isDirectional() ){
719  
720 <        atoms[local_index]->getPos(pos);
721 <        atoms[local_index]->getVel(vel);
720 >            isDirectional = 1;
721 >            
722 >            dAtom = (DirectionalAtom *)atoms[local_index];
723 >            dAtom->getQ( q );
724 >            
725 >            atomOrientData[0] = q[0];
726 >            atomOrientData[1] = q[1];
727 >            atomOrientData[2] = q[2];
728 >            atomOrientData[3] = q[3];
729  
730 <        //format the line
731 <        sprintf( tempBuffer,
732 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
733 <                 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 );
730 >            atomOrientData[4] = dAtom->getJx();
731 >            atomOrientData[5] = dAtom->getJy();
732 >            atomOrientData[6] = dAtom->getJz();
733 >          }
734  
735 <        if( atoms[local_index]->isDirectional() ){
735 >        } else {
736 >          sprintf(painCave.errMsg,
737 >                  "Atom %d not found on processor %d\n",
738 >                  i, worldRank );
739 >          haveError= 1;
740 >          simError();
741 >        }
742  
743 <          dAtom = (DirectionalAtom *)atoms[local_index];
619 <          dAtom->getQ( q );
743 >        // I've survived this far, so send off the data!
744  
745 <          sprintf( tempBuffer,
746 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
747 <                   q[0],
748 <                   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();
745 >        atomTypeTag          = 4*i;
746 >        atomIsDirectionalTag = 4*i + 1;
747 >        atomTransDataTag     = 4*i + 2;
748 >        atomOrientDataTag    = 4*i + 3;
749  
750 <        strcpy( writeLine, "Hello, I'm an error.\n");
644 <      }
750 >        strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
751  
752 <      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
753 <               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
754 <      MPI_Send( &myStatus, 1, MPI_INT, 0,
755 <                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
752 >        MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
753 >                 atomTypeTag, MPI_COMM_WORLD);
754 >        
755 >        MPI_Send(&isDirectional, 1, MPI_INT, 0,
756 >                 atomIsDirectionalTag, MPI_COMM_WORLD);
757 >        
758 >        MPI_Send(atomTransData, 6, MPI_DOUBLE, 0,
759 >                 atomTransDataTag, MPI_COMM_WORLD);
760 >
761 >        if (isDirectional) {
762 >
763 >          MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0,
764 >                   atomOrientDataTag, MPI_COMM_WORLD);
765 >          
766 >        }
767 >      
768 >      }
769      }
770 +
771 +    sprintf( checkPointMsg,
772 +             "Sucessfully wrote final file.\n");
773 +    MPIcheckPoint();        
774 +    
775    }
776 <  finalOut.flush();
777 <  sprintf( checkPointMsg,
654 <           "Sucessfully took a dump.\n");
655 <  MPIcheckPoint();
776 >  
777 >  painCave.isEventLoop = 0;
778  
779    if( worldRank == 0 ) finalOut.close();
780   #endif // is_mpi
# Line 664 | Line 786 | void dWrite::nodeZeroError( void ){
786  
787   // a couple of functions to let us escape the write loop
788  
789 < void dWrite::nodeZeroError( void ){
668 <  int j, myStatus;
789 > void dWrite::DieDieDie( void ){
790  
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
791    MPI_Finalize();
792    exit (0);
679
793   }
794  
682 void dWrite::anonymousNodeDie( void ){
683
684  MPI_Finalize();
685  exit (0);
686 }
687
795   #endif //is_mpi

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines