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 436 by chuckv, Fri Mar 28 21:45:03 2003 UTC vs.
Revision 447 by mmeineke, Thu Apr 3 20:21:54 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 121 | Line 127 | void DumpWriter::writeDump( double currentTime ){
127  
128   #else // is_mpi
129  
130 <  MPI::Status istatus;
130 >  // first thing first, suspend fatalities.
131 >  painCave.isEventLoop = 1;
132 >
133 >  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
134 >  int haveError;
135 >
136 >  MPI_Status istatus;
137    int *AtomToProcMap = mpiSim->getAtomToProcMap();
138    
139    // write out header and node 0's coordinates
# Line 141 | Line 153 | void DumpWriter::writeDump( double currentTime ){
153        
154        if (which_node == 0 ) {
155          
156 +        haveError = 0;
157          which_atom = i;
158          local_index=-1;        
159          for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
# Line 180 | Line 193 | void DumpWriter::writeDump( double currentTime ){
193              strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
194          }
195          else {
196 <          strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
196 >          sprintf(painCave.errMsg,
197 >                  "Atom %d not found on processor %d\n",
198 >                  i, worldRank );
199 >          haveError= 1;
200 >          simError();
201          }
202 <      }
202 >        
203 >        if(haveError) nodeZeroError();
204 >
205 >      }
206        else {
207 <        
208 <        //std::cerr << "node 0: sending node " << which_node << " request for atom " << i << "\n";
209 <        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT);
210 <        //std::cerr << "node 0: sent!\n";
211 <        MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
212 <                             TAKE_THIS_TAG_CHAR, istatus);
213 <        //std::cerr << "node 0: got this line: " << writeLine;
207 >        myStatus = 1;
208 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
209 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
210 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
211 >                 MPI_COMM_WORLD);
212 >        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
213 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
214 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
215 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
216 >        
217 >        if(!myStatus) nodeZeroError();
218 >
219        }
220        
221        outFile << writeLine;
# Line 198 | Line 223 | void DumpWriter::writeDump( double currentTime ){
223      }
224      
225      // kill everyone off:
226 <    game_over = -1;
226 >    myStatus = -1;
227      for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
228 <      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT);
228 >      MPI_Send(&myStatus, 1, MPI_INT, j,
229 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
230      }
231  
232    } else {
233      
234      done = 0;
235      while (!done) {
236 <      //std::cerr << "node: " << mpiSim->getMyNode() << " Waiting for receive \n";
237 <      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
238 <                           TAKE_THIS_TAG_INT, istatus);
239 <      //std::cerr << "node: " << mpiSim->getMyNode() << " got request for atom " << which_atom << "\n";
240 <      if (which_atom == -1) {
241 <        done=1;
242 <        continue;
243 <      } else {
244 <        local_index=-1;        
245 <        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
246 <          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
247 <        }
248 <        if (local_index != -1) {
249 <          //format the line
250 <          sprintf( tempBuffer,
225 <                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
226 <                   atoms[local_index]->getType(),
227 <                   atoms[local_index]->getX(),
228 <                   atoms[local_index]->getY(),
229 <                   atoms[local_index]->getZ(),
230 <                   atoms[local_index]->get_vx(),
231 <                   atoms[local_index]->get_vy(),
232 <                   atoms[local_index]->get_vz()); // check here.
233 <          strcpy( writeLine, tempBuffer );
234 <          
235 <          if( atoms[local_index]->isDirectional() ){
236 <            
237 <            dAtom = (DirectionalAtom *)atoms[local_index];
238 <            dAtom->getQ( q );
239 <            
240 <            sprintf( tempBuffer,
241 <                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
242 <                     q[0],
243 <                     q[1],
244 <                     q[2],
245 <                     q[3],
246 <                     dAtom->getJx(),
247 <                     dAtom->getJy(),
248 <                     dAtom->getJz());
249 <            strcat( writeLine, tempBuffer );
250 <          }
251 <          else
252 <            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
253 <          // std::cerr << "node: " << mpiSim->getMyNode() << " sending this line" << writeLine;
254 <          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
255 <                               TAKE_THIS_TAG_CHAR);
256 <        } else {
257 <          strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
258 <          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
259 <                               TAKE_THIS_TAG_CHAR);
260 <        }
236 >      
237 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
238 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
239 >
240 >      if(!myStatus) anonymousNodeDie();
241 >      
242 >      if(myStatus < 0) break;
243 >
244 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
245 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
246 >      
247 >      myStatus = 1;
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 );
264 +        
265 +        if( atoms[local_index]->isDirectional() ){
266 +          
267 +          dAtom = (DirectionalAtom *)atoms[local_index];
268 +          dAtom->getQ( q );
269 +          
270 +          sprintf( tempBuffer,
271 +                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
272 +                   q[0],
273 +                   q[1],
274 +                   q[2],
275 +                   q[3],
276 +                   dAtom->getJx(),
277 +                   dAtom->getJy(),
278 +                   dAtom->getJz());
279 +          strcat( writeLine, tempBuffer );
280 +        }
281 +        else{
282 +          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
283 +        }
284 +      }
285 +      else {
286 +        sprintf(painCave.errMsg,
287 +                "Atom %d not found on processor %d\n",
288 +                which_atom, worldRank );
289 +        myStatus = 0;
290 +        simError();
291 +
292 +        strcpy( writeLine, "Hello, I'm an error.\n");
293 +      }
294 +
295 +      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
296 +               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
297 +      MPI_Send( &myStatus, 1, MPI_INT, 0,
298 +                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
299      }
300    }  
301    outFile.flush();
302    sprintf( checkPointMsg,
303             "Sucessfully took a dump.\n");
304    MPIcheckPoint();
305 +
306 + // last  thing last, enable  fatalities.
307 +  painCave.isEventLoop = 0;
308 +
309   #endif // is_mpi
310   }
311  
# Line 357 | Line 398 | void DumpWriter::writeFinal(){
398  
399   #else // is_mpi
400    
401 <  MPI::Status istatus;
401 >  // first thing first, suspend fatalities.
402 >  painCave.isEventLoop = 1;
403 >
404 >  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
405 >  int haveError;
406 >
407 >  MPI_Status istatus;
408    int *AtomToProcMap = mpiSim->getAtomToProcMap();
409  
410    // write out header and node 0's coordinates
411    
412 +  haveError = 0;
413    if( worldRank == 0 ){
414      finalOut << mpiSim->getTotAtoms() << "\n";
415      
# Line 375 | Line 423 | void DumpWriter::writeFinal(){
423        which_node = AtomToProcMap[i];    
424        
425        if (which_node == mpiSim->getMyNode()) {
426 <        
427 <        sprintf( tempBuffer,
428 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
429 <                 atoms[i]->getType(),
430 <                 atoms[i]->getX(),
383 <                 atoms[i]->getY(),
384 <                 atoms[i]->getZ(),
385 <                 atoms[i]->get_vx(),
386 <                 atoms[i]->get_vy(),
387 <                 atoms[i]->get_vz());
388 <        strcpy( writeLine, tempBuffer );
389 <        
390 <        if( atoms[i]->isDirectional() ){
391 <          
392 <          dAtom = (DirectionalAtom *)atoms[i];
393 <          dAtom->getQ( q );
394 <          
395 <          sprintf( tempBuffer,
396 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
397 <                   q[0],
398 <                   q[1],
399 <                   q[2],
400 <                   q[3],
401 <                   dAtom->getJx(),
402 <                   dAtom->getJy(),
403 <                   dAtom->getJz());
404 <          strcat( writeLine, tempBuffer );
426 >
427 >        which_atom = i;
428 >        local_index=-1;        
429 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
430 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
431          }
432 <        else
433 <          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
434 <        
435 <      } else {
432 >        if (local_index != -1) {        
433 >          sprintf( tempBuffer,
434 >                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
435 >                   atoms[local_index]->getType(),
436 >                   atoms[local_index]->getX(),
437 >                   atoms[local_index]->getY(),
438 >                   atoms[local_index]->getZ(),
439 >                   atoms[local_index]->get_vx(),
440 >                   atoms[local_index]->get_vy(),
441 >                   atoms[local_index]->get_vz());
442 >          strcpy( writeLine, tempBuffer );
443 >          
444 >          if( atoms[local_index]->isDirectional() ){
445 >            
446 >            dAtom = (DirectionalAtom *)atoms[local_index];
447 >            dAtom->getQ( q );
448 >            
449 >            sprintf( tempBuffer,
450 >                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
451 >                     q[0],
452 >                     q[1],
453 >                     q[2],
454 >                     q[3],
455 >                     dAtom->getJx(),
456 >                     dAtom->getJy(),
457 >                     dAtom->getJz());
458 >            strcat( writeLine, tempBuffer );
459 >          }
460 >          else
461 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
462 >        }
463 >        else {
464 >          sprintf(painCave.errMsg,
465 >                  "Atom %d not found on processor %d\n",
466 >                  i, worldRank );
467 >          haveError= 1;
468 >          simError();
469 >        }
470 >
471 >        if(haveError) nodeZeroError();
472 >    
473 >      }
474 >      else {
475          
476 <        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT);
477 <        MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
478 <                                TAKE_THIS_TAG_CHAR, istatus);
476 >        myStatus = 1;
477 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
478 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
479 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
480 >                 MPI_COMM_WORLD);
481 >        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
482 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
483 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
484 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
485 >        
486 >        if(!myStatus) nodeZeroError();
487        }
488        
489        finalOut << writeLine;
490      }
491      
492      // kill everyone off:
493 <    game_over = -1;
494 <    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {
495 <      MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT);
493 >    myStatus = -1;
494 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
495 >      MPI_Send(&myStatus, 1, MPI_INT, j,
496 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
497      }
498  
499    } else {
500      
501      done = 0;
502      while (!done) {
429      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
430                           TAKE_THIS_TAG_INT, istatus);
503  
504 <      if (which_atom == -1) {
505 <        done=1;
506 <        continue;
507 <      } else {
504 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
505 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
506 >      
507 >      if(!myStatus) anonymousNodeDie();
508 >      
509 >      if(myStatus < 0) break;
510 >      
511 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
512 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
513 >      
514 >      myStatus = 1;
515 >      local_index=-1;        
516 >      for (j=0; j < mpiSim->getMyNlocal(); j++) {
517 >        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
518 >      }
519 >      if (local_index != -1) {
520  
521 <        local_index=-1;        
522 <        for (j=0; j < mpiSim->getMyNlocal(); j++) {
523 <          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
524 <        }
525 <        if (local_index != -1) {
526 <
527 <          //format the line
528 <          sprintf( tempBuffer,
529 <                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
530 <                   atoms[local_index]->getType(),
531 <                   atoms[local_index]->getX(),
532 <                   atoms[local_index]->getY(),
533 <                   atoms[local_index]->getZ(),
450 <                   atoms[local_index]->get_vx(),
451 <                   atoms[local_index]->get_vy(),
452 <                   atoms[local_index]->get_vz()); // check here.
453 <          strcpy( writeLine, tempBuffer );
521 >        //format the line
522 >        sprintf( tempBuffer,
523 >                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
524 >                 atoms[local_index]->getType(),
525 >                 atoms[local_index]->getX(),
526 >                 atoms[local_index]->getY(),
527 >                 atoms[local_index]->getZ(),
528 >                 atoms[local_index]->get_vx(),
529 >                 atoms[local_index]->get_vy(),
530 >                 atoms[local_index]->get_vz()); // check here.
531 >        strcpy( writeLine, tempBuffer );
532 >        
533 >        if( atoms[local_index]->isDirectional() ){
534            
535 <          if( atoms[local_index]->isDirectional() ){
536 <            
537 <            dAtom = (DirectionalAtom *)atoms[local_index];
538 <            dAtom->getQ( q );
539 <            
540 <            sprintf( tempBuffer,
541 <                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
542 <                     q[0],
543 <                     q[1],
544 <                     q[2],
545 <                     q[3],
546 <                     dAtom->getJx(),
547 <                     dAtom->getJy(),
548 <                     dAtom->getJz());
549 <            strcat( writeLine, tempBuffer );
550 <          }
551 <          else
552 <            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
553 <          
554 <          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
555 <                               TAKE_THIS_TAG_CHAR);
556 <        } else {
557 <          strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR");
558 <          MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
559 <                               TAKE_THIS_TAG_CHAR);
560 <        }
535 >          dAtom = (DirectionalAtom *)atoms[local_index];
536 >          dAtom->getQ( q );
537 >          
538 >          sprintf( tempBuffer,
539 >                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
540 >                   q[0],
541 >                   q[1],
542 >                   q[2],
543 >                   q[3],
544 >                   dAtom->getJx(),
545 >                   dAtom->getJy(),
546 >                   dAtom->getJz());
547 >          strcat( writeLine, tempBuffer );
548 >        }
549 >        else{
550 >          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
551 >        }
552 >      }
553 >      else {
554 >        sprintf(painCave.errMsg,
555 >                "Atom %d not found on processor %d\n",
556 >                which_atom, worldRank );
557 >        myStatus = 0;
558 >        simError();
559 >        
560 >        strcpy( writeLine, "Hello, I'm an error.\n");
561        }
562 +
563 +      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
564 +               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
565 +      MPI_Send( &myStatus, 1, MPI_INT, 0,
566 +                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
567      }
568    }
569    finalOut.flush();
570    sprintf( checkPointMsg,
571             "Sucessfully took a dump.\n");
572    MPIcheckPoint();
573 <
573 >  
574    if( worldRank == 0 ) finalOut.close();    
575   #endif // is_mpi
576   }
577 +
578 +
579 +
580 + #ifdef IS_MPI
581 +
582 + // a couple of functions to let us escape the write loop
583 +
584 + void dWrite::nodeZeroError( void ){
585 +  int j, myStatus;
586 +  
587 +  myStatus = 0;
588 +  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
589 +    MPI_Send( &myStatus, 1, MPI_INT, j,
590 +              TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
591 +  }  
592 +  
593 +
594 +  MPI_Finalize();
595 +  exit (0);
596 +  
597 + }
598 +
599 + void dWrite::anonymousNodeDie( void ){
600 +
601 +  MPI_Finalize();
602 +  exit (0);
603 + }
604 +
605 + #endif //is_mpi

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines