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 437 by chuckv, Fri Mar 28 22:34:02 2003 UTC vs.
Revision 469 by mmeineke, Mon Apr 7 20:06:31 2003 UTC

# Line 4 | Line 4
4  
5   #ifdef IS_MPI
6   #include <mpi.h>
7 #include <mpi++.h>
7   #include "mpiSimulation.hpp"
8   #define TAKE_THIS_TAG_CHAR 1
9   #define TAKE_THIS_TAG_INT 2
10 +
11 + namespace dWrite{
12 +  void nodeZeroError( void );
13 +  void anonymousNodeDie( void );
14 + }
15 +
16 + using namespace dWrite;
17   #endif //is_mpi
18  
19   #include "ReadWrite.hpp"
# Line 17 | Line 23 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
23  
24    entry_plug = the_entry_plug;
25  
26 +  std::cerr << "Look at me I'm a freebird!\n";
27 +
28   #ifdef IS_MPI
29    if(worldRank == 0 ){
30   #endif // is_mpi
# Line 35 | Line 43 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
43        painCave.isFatal = 1;
44        simError();
45      }
46 <  
46 >
47 >    std::cerr << "me TOO!\n";
48 >
49      //outFile.setf( ios::scientific );
50  
51   #ifdef IS_MPI
# Line 66 | Line 76 | void DumpWriter::writeDump( double currentTime ){
76    char tempBuffer[BUFFERSIZE];
77    char writeLine[BUFFERSIZE];
78  
79 <  int i, j, which_node, done, game_over, which_atom, local_index;
79 >  int i, j, which_node, done, which_atom, local_index;
80    double q[4];
81    DirectionalAtom* dAtom;
82    int nAtoms = entry_plug->n_atoms;
# Line 121 | Line 131 | void DumpWriter::writeDump( double currentTime ){
131  
132   #else // is_mpi
133  
134 <  MPI::Status istatus;
134 >  // first thing first, suspend fatalities.
135 >  painCave.isEventLoop = 1;
136 >
137 >  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
138 >  int haveError;
139 >
140 >  MPI_Status istatus;
141    int *AtomToProcMap = mpiSim->getAtomToProcMap();
142    
143    // write out header and node 0's coordinates
# Line 141 | Line 157 | void DumpWriter::writeDump( double currentTime ){
157        
158        if (which_node == 0 ) {
159          
160 +        haveError = 0;
161          which_atom = i;
162          local_index=-1;        
163          for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
# Line 180 | Line 197 | void DumpWriter::writeDump( double currentTime ){
197              strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
198          }
199          else {
200 <          strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
200 >          sprintf(painCave.errMsg,
201 >                  "Atom %d not found on processor %d\n",
202 >                  i, worldRank );
203 >          haveError= 1;
204 >          simError();
205          }
206 <      }
206 >        
207 >        if(haveError) nodeZeroError();
208 >
209 >      }
210        else {
211 <        
212 <        //std::cerr << "node 0: sending node " << which_node << " request for atom " << i << "\n";
213 <        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT);
214 <        //std::cerr << "node 0: sent!\n";
215 <        MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
216 <                             TAKE_THIS_TAG_CHAR, istatus);
217 <        //std::cerr << "node 0: got this line: " << writeLine;
211 >        myStatus = 1;
212 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
213 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
214 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
215 >                 MPI_COMM_WORLD);
216 >        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
217 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
218 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
219 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
220 >        
221 >        if(!myStatus) nodeZeroError();
222 >
223        }
224        
225        outFile << writeLine;
# Line 198 | Line 227 | void DumpWriter::writeDump( double currentTime ){
227      }
228      
229      // kill everyone off:
230 <    game_over = -1;
230 >    myStatus = -1;
231      for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
232 <      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT);
232 >      MPI_Send(&myStatus, 1, MPI_INT, j,
233 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
234      }
235  
236    } else {
237      
238      done = 0;
239      while (!done) {
240 <      //std::cerr << "node: " << mpiSim->getMyNode() << " Waiting for receive \n";
241 <      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
242 <                           TAKE_THIS_TAG_INT, istatus);
243 <      //std::cerr << "node: " << mpiSim->getMyNode() << " got request for atom " << which_atom << "\n";
244 <      if (which_atom == -1) {
245 <        done=1;
246 <        continue;
247 <      } else {
248 <        local_index=-1;        
249 <        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
250 <          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
251 <        }
252 <        if (local_index != -1) {
253 <          //format the line
254 <          sprintf( tempBuffer,
255 <                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
256 <                   atoms[local_index]->getType(),
257 <                   atoms[local_index]->getX(),
258 <                   atoms[local_index]->getY(),
259 <                   atoms[local_index]->getZ(),
260 <                   atoms[local_index]->get_vx(),
261 <                   atoms[local_index]->get_vy(),
262 <                   atoms[local_index]->get_vz()); // check here.
263 <          strcpy( writeLine, tempBuffer );
240 >      
241 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
242 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
243 >
244 >      if(!myStatus) anonymousNodeDie();
245 >      
246 >      if(myStatus < 0) break;
247 >
248 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
249 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
250 >      
251 >      myStatus = 1;
252 >      local_index=-1;        
253 >      for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
254 >        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
255 >      }
256 >      if (local_index != -1) {
257 >        //format the line
258 >        sprintf( tempBuffer,
259 >                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
260 >                 atoms[local_index]->getType(),
261 >                 atoms[local_index]->getX(),
262 >                 atoms[local_index]->getY(),
263 >                 atoms[local_index]->getZ(),
264 >                 atoms[local_index]->get_vx(),
265 >                 atoms[local_index]->get_vy(),
266 >                 atoms[local_index]->get_vz()); // check here.
267 >        strcpy( writeLine, tempBuffer );
268 >        
269 >        if( atoms[local_index]->isDirectional() ){
270            
271 <          if( atoms[local_index]->isDirectional() ){
272 <            
273 <            dAtom = (DirectionalAtom *)atoms[local_index];
274 <            dAtom->getQ( q );
275 <            
276 <            sprintf( tempBuffer,
277 <                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
278 <                     q[0],
279 <                     q[1],
280 <                     q[2],
281 <                     q[3],
282 <                     dAtom->getJx(),
283 <                     dAtom->getJy(),
284 <                     dAtom->getJz());
285 <            strcat( writeLine, tempBuffer );
286 <          }
287 <          else
288 <            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
289 <          // std::cerr << "node: " << mpiSim->getMyNode() << " sending this line" << writeLine;
290 <          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
291 <                               TAKE_THIS_TAG_CHAR);
292 <        } else {
293 <          strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
294 <          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
295 <                               TAKE_THIS_TAG_CHAR);
296 <        }
271 >          dAtom = (DirectionalAtom *)atoms[local_index];
272 >          dAtom->getQ( q );
273 >          
274 >          sprintf( tempBuffer,
275 >                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
276 >                   q[0],
277 >                   q[1],
278 >                   q[2],
279 >                   q[3],
280 >                   dAtom->getJx(),
281 >                   dAtom->getJy(),
282 >                   dAtom->getJz());
283 >          strcat( writeLine, tempBuffer );
284 >        }
285 >        else{
286 >          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
287 >        }
288 >      }
289 >      else {
290 >        sprintf(painCave.errMsg,
291 >                "Atom %d not found on processor %d\n",
292 >                which_atom, worldRank );
293 >        myStatus = 0;
294 >        simError();
295 >
296 >        strcpy( writeLine, "Hello, I'm an error.\n");
297        }
298 +
299 +      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
300 +               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
301 +      MPI_Send( &myStatus, 1, MPI_INT, 0,
302 +                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
303      }
304    }  
305    outFile.flush();
306    sprintf( checkPointMsg,
307             "Sucessfully took a dump.\n");
308    MPIcheckPoint();
309 +
310 + // last  thing last, enable  fatalities.
311 +  painCave.isEventLoop = 0;
312 +
313   #endif // is_mpi
314   }
315  
# Line 357 | Line 402 | void DumpWriter::writeFinal(){
402  
403   #else // is_mpi
404    
405 <  MPI::Status istatus;
405 >  // first thing first, suspend fatalities.
406 >  painCave.isEventLoop = 1;
407 >
408 >  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
409 >  int haveError;
410 >
411 >  MPI_Status istatus;
412    int *AtomToProcMap = mpiSim->getAtomToProcMap();
413  
414    // write out header and node 0's coordinates
415    
416 +  haveError = 0;
417    if( worldRank == 0 ){
418      finalOut << mpiSim->getTotAtoms() << "\n";
419      
# Line 413 | Line 465 | void DumpWriter::writeFinal(){
465              strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
466          }
467          else {
468 <          strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
468 >          sprintf(painCave.errMsg,
469 >                  "Atom %d not found on processor %d\n",
470 >                  i, worldRank );
471 >          haveError= 1;
472 >          simError();
473          }
474 +
475 +        if(haveError) nodeZeroError();
476      
477 <      } else {
477 >      }
478 >      else {
479          
480 <        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT);
481 <        MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
482 <                                TAKE_THIS_TAG_CHAR, istatus);
480 >        myStatus = 1;
481 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
482 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
483 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
484 >                 MPI_COMM_WORLD);
485 >        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
486 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
487 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
488 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
489 >        
490 >        if(!myStatus) nodeZeroError();
491        }
492        
493        finalOut << writeLine;
494      }
495      
496      // kill everyone off:
497 <    game_over = -1;
498 <    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {
499 <      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT);
497 >    myStatus = -1;
498 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
499 >      MPI_Send(&myStatus, 1, MPI_INT, j,
500 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
501      }
502  
503    } else {
504      
505      done = 0;
506      while (!done) {
439      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
440                           TAKE_THIS_TAG_INT, istatus);
507  
508 <      if (which_atom == -1) {
509 <        done=1;
510 <        continue;
511 <      } else {
508 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
509 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
510 >      
511 >      if(!myStatus) anonymousNodeDie();
512 >      
513 >      if(myStatus < 0) break;
514 >      
515 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
516 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
517 >      
518 >      myStatus = 1;
519 >      local_index=-1;        
520 >      for (j=0; j < mpiSim->getMyNlocal(); j++) {
521 >        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
522 >      }
523 >      if (local_index != -1) {
524  
525 <        local_index=-1;        
526 <        for (j=0; j < mpiSim->getMyNlocal(); j++) {
527 <          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
528 <        }
529 <        if (local_index != -1) {
530 <
531 <          //format the line
532 <          sprintf( tempBuffer,
533 <                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
534 <                   atoms[local_index]->getType(),
535 <                   atoms[local_index]->getX(),
536 <                   atoms[local_index]->getY(),
537 <                   atoms[local_index]->getZ(),
460 <                   atoms[local_index]->get_vx(),
461 <                   atoms[local_index]->get_vy(),
462 <                   atoms[local_index]->get_vz()); // check here.
463 <          strcpy( writeLine, tempBuffer );
525 >        //format the line
526 >        sprintf( tempBuffer,
527 >                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
528 >                 atoms[local_index]->getType(),
529 >                 atoms[local_index]->getX(),
530 >                 atoms[local_index]->getY(),
531 >                 atoms[local_index]->getZ(),
532 >                 atoms[local_index]->get_vx(),
533 >                 atoms[local_index]->get_vy(),
534 >                 atoms[local_index]->get_vz()); // check here.
535 >        strcpy( writeLine, tempBuffer );
536 >        
537 >        if( atoms[local_index]->isDirectional() ){
538            
539 <          if( atoms[local_index]->isDirectional() ){
540 <            
541 <            dAtom = (DirectionalAtom *)atoms[local_index];
542 <            dAtom->getQ( q );
543 <            
544 <            sprintf( tempBuffer,
545 <                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
546 <                     q[0],
547 <                     q[1],
548 <                     q[2],
549 <                     q[3],
550 <                     dAtom->getJx(),
551 <                     dAtom->getJy(),
552 <                     dAtom->getJz());
553 <            strcat( writeLine, tempBuffer );
554 <          }
555 <          else
556 <            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
557 <          
558 <          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
559 <                               TAKE_THIS_TAG_CHAR);
560 <        } else {
561 <          strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
562 <          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
563 <                               TAKE_THIS_TAG_CHAR);
564 <        }
539 >          dAtom = (DirectionalAtom *)atoms[local_index];
540 >          dAtom->getQ( q );
541 >          
542 >          sprintf( tempBuffer,
543 >                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
544 >                   q[0],
545 >                   q[1],
546 >                   q[2],
547 >                   q[3],
548 >                   dAtom->getJx(),
549 >                   dAtom->getJy(),
550 >                   dAtom->getJz());
551 >          strcat( writeLine, tempBuffer );
552 >        }
553 >        else{
554 >          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
555 >        }
556 >      }
557 >      else {
558 >        sprintf(painCave.errMsg,
559 >                "Atom %d not found on processor %d\n",
560 >                which_atom, worldRank );
561 >        myStatus = 0;
562 >        simError();
563 >        
564 >        strcpy( writeLine, "Hello, I'm an error.\n");
565        }
566 +
567 +      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
568 +               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
569 +      MPI_Send( &myStatus, 1, MPI_INT, 0,
570 +                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
571      }
572    }
573    finalOut.flush();
574    sprintf( checkPointMsg,
575             "Sucessfully took a dump.\n");
576    MPIcheckPoint();
577 <
577 >  
578    if( worldRank == 0 ) finalOut.close();    
579   #endif // is_mpi
580   }
581 +
582 +
583 +
584 + #ifdef IS_MPI
585 +
586 + // a couple of functions to let us escape the write loop
587 +
588 + void dWrite::nodeZeroError( void ){
589 +  int j, myStatus;
590 +  
591 +  myStatus = 0;
592 +  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
593 +    MPI_Send( &myStatus, 1, MPI_INT, j,
594 +              TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
595 +  }  
596 +  
597 +
598 +  MPI_Finalize();
599 +  exit (0);
600 +  
601 + }
602 +
603 + void dWrite::anonymousNodeDie( void ){
604 +
605 +  MPI_Finalize();
606 +  exit (0);
607 + }
608 +
609 + #endif //is_mpi

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines