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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines