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 829 by gezelter, Tue Oct 28 16:03:37 2003 UTC vs.
Revision 837 by tim, Wed Oct 29 00:19:10 2003 UTC

# Line 28 | Line 28 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
28   #ifdef IS_MPI
29    if(worldRank == 0 ){
30   #endif // is_mpi
31 <    
31 >
32      strcpy( outName, entry_plug->sampleName );
33 <    
33 >
34      outFile.open(outName, ios::out | ios::trunc );
35 <    
35 >
36      if( !outFile ){
37 <      
37 >
38        sprintf( painCave.errMsg,
39                 "Could not open \"%s\" for dump output.\n",
40                 outName);
# Line 67 | Line 67 | void DumpWriter::writeDump( double currentTime ){
67   }
68  
69   void DumpWriter::writeDump( double currentTime ){
70 <  
70 >
71    const int BUFFERSIZE = 2000;
72    char tempBuffer[BUFFERSIZE];
73    char writeLine[BUFFERSIZE];
# Line 83 | Line 83 | void DumpWriter::writeDump( double currentTime ){
83    DirectionalAtom* dAtom;
84    Atom** atoms = entry_plug->atoms;
85    double pos[3], vel[3];
86 <    
87 <  
86 >
87 >
88    // write current frame to the eor file
89  
90    this->writeFinal( currentTime );
91  
92   #ifndef IS_MPI
93 <    
93 >
94    outFile << nAtoms << "\n";
95 <    
96 <  outFile << currentTime << ";\t"
95 >
96 >  outFile << currentTime << ";\t"
97            << entry_plug->Hmat[0][0] << "\t"
98            << entry_plug->Hmat[1][0] << "\t"
99            << entry_plug->Hmat[2][0] << ";\t"
# Line 104 | Line 104 | void DumpWriter::writeDump( double currentTime ){
104  
105            << entry_plug->Hmat[0][2] << "\t"
106            << entry_plug->Hmat[1][2] << "\t"
107 <          << entry_plug->Hmat[2][2] << ";\n";
108 <    
107 >          << entry_plug->Hmat[2][2] << ";";
108 >  //write out additional parameters, such as chi and eta
109 >  outFile << entry_plug->the_integrator->getAdditionalParameters();
110 >  outFile << endl;
111 >
112    for( i=0; i<nAtoms; i++ ){
113 <      
113 >
114      atoms[i]->getPos(pos);
115      atoms[i]->getVel(vel);
116  
# Line 123 | Line 126 | void DumpWriter::writeDump( double currentTime ){
126      strcpy( writeLine, tempBuffer );
127  
128      if( atoms[i]->isDirectional() ){
129 <        
129 >
130        dAtom = (DirectionalAtom *)atoms[i];
131        dAtom->getQ( q );
132 <        
132 >
133        sprintf( tempBuffer,
134                 "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
135                 q[0],
# Line 140 | Line 143 | void DumpWriter::writeDump( double currentTime ){
143      }
144      else
145        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
146 <      
146 >
147      outFile << writeLine;
148    }
149    outFile.flush();
# Line 155 | Line 158 | void DumpWriter::writeDump( double currentTime ){
158  
159    MPI_Status istatus;
160    int *AtomToProcMap = mpiSim->getAtomToProcMap();
161 <  
161 >
162    // write out header and node 0's coordinates
163 <  
163 >
164    if( worldRank == 0 ){
165      outFile << mpiSim->getTotAtoms() << "\n";
166 <  
167 <    outFile << currentTime << ";\t"
166 >
167 >    outFile << currentTime << ";\t"
168              << entry_plug->Hmat[0][0] << "\t"
169              << entry_plug->Hmat[1][0] << "\t"
170              << entry_plug->Hmat[2][0] << ";\t"
171 <      
171 >
172              << entry_plug->Hmat[0][1] << "\t"
173              << entry_plug->Hmat[1][1] << "\t"
174              << entry_plug->Hmat[2][1] << ";\t"
175 <      
175 >
176              << entry_plug->Hmat[0][2] << "\t"
177              << entry_plug->Hmat[1][2] << "\t"
178 <            << entry_plug->Hmat[2][2] << ";\n";
179 <    
178 >            << entry_plug->Hmat[2][2] << ";";
179 >
180 >    outFile << entry_plug->the_integrator->getAdditionalParameters();
181 >    outFile << endl;
182      outFile.flush();
183      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
184        // Get the Node number which has this atom;
185 <      
186 <      which_node = AtomToProcMap[i];    
187 <      
185 >
186 >      which_node = AtomToProcMap[i];
187 >
188        if (which_node == 0 ) {
189 <        
189 >
190          haveError = 0;
191          which_atom = i;
192 <        local_index=-1;        
192 >        local_index=-1;
193          for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
194            if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
195          }
196          if (local_index != -1) {
197            //format the line
198 <          
198 >
199            atoms[local_index]->getPos(pos);
200            atoms[local_index]->getVel(vel);
201  
# Line 204 | Line 209 | void DumpWriter::writeDump( double currentTime ){
209                     vel[1],
210                     vel[2]); // check here.
211            strcpy( writeLine, tempBuffer );
212 <          
212 >
213            if( atoms[local_index]->isDirectional() ){
214 <            
214 >
215              dAtom = (DirectionalAtom *)atoms[local_index];
216              dAtom->getQ( q );
217 <            
217 >
218              sprintf( tempBuffer,
219                       "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
220                       q[0],
# Line 220 | Line 225 | void DumpWriter::writeDump( double currentTime ){
225                       dAtom->getJy(),
226                       dAtom->getJz());
227              strcat( writeLine, tempBuffer );
228 <            
228 >
229            }
230            else
231 <            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
231 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
232          }
233          else {
234            sprintf(painCave.errMsg,
# Line 231 | Line 236 | void DumpWriter::writeDump( double currentTime ){
236                    i, worldRank );
237            haveError= 1;
238            simError();
239 <        }
240 <        
239 >        }
240 >
241          if(haveError) nodeZeroError();
242  
243        }
244        else {
245          myStatus = 1;
246 <        MPI_Send(&myStatus, 1, MPI_INT, which_node,
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,
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,
252 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
253                   TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
254 <        
254 >
255          if(!myStatus) nodeZeroError();
256  
257        }
258 <      
258 >
259        outFile << writeLine;
260        outFile.flush();
261      }
262 <    
262 >
263      // kill everyone off:
264      myStatus = -1;
265 <    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
266 <      MPI_Send(&myStatus, 1, MPI_INT, j,
265 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {
266 >      MPI_Send(&myStatus, 1, MPI_INT, j,
267                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
268      }
269  
270    } else {
271 <    
271 >
272      done = 0;
273      while (!done) {
274 <      
275 <      MPI_Recv(&myStatus, 1, MPI_INT, 0,
274 >
275 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
276                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
277  
278        if(!myStatus) anonymousNodeDie();
279 <      
279 >
280        if(myStatus < 0) break;
281  
282 <      MPI_Recv(&which_atom, 1, MPI_INT, 0,
282 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
283                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
284 <      
284 >
285        myStatus = 1;
286 <      local_index=-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        }
# Line 298 | Line 303 | void DumpWriter::writeDump( double currentTime ){
303                   vel[1],
304                   vel[2]); // check here.
305          strcpy( writeLine, tempBuffer );
306 <        
306 >
307          if( atoms[local_index]->isDirectional() ){
308 <          
308 >
309            dAtom = (DirectionalAtom *)atoms[local_index];
310            dAtom->getQ( q );
311 <          
311 >
312            sprintf( tempBuffer,
313                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
314                     q[0],
# Line 318 | Line 323 | void DumpWriter::writeDump( double currentTime ){
323          else{
324            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
325          }
326 <      }
326 >      }
327        else {
328          sprintf(painCave.errMsg,
329                  "Atom %d not found on processor %d\n",
# Line 329 | Line 334 | void DumpWriter::writeDump( double currentTime ){
334          strcpy( writeLine, "Hello, I'm an error.\n");
335        }
336  
337 <      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
337 >      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
338                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
339 <      MPI_Send( &myStatus, 1, MPI_INT, 0,
339 >      MPI_Send( &myStatus, 1, MPI_INT, 0,
340                  TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
341      }
342 <  }  
342 >  }
343    outFile.flush();
344    sprintf( checkPointMsg,
345             "Sucessfully took a dump.\n");
# Line 353 | Line 358 | void DumpWriter::writeFinal(double finalTime){
358  
359    const int BUFFERSIZE = 2000;
360    char tempBuffer[BUFFERSIZE];
361 <  char writeLine[BUFFERSIZE];  
361 >  char writeLine[BUFFERSIZE];
362  
363    double q[4];
364    DirectionalAtom* dAtom;
# Line 364 | Line 369 | void DumpWriter::writeFinal(double finalTime){
369   #else //is_mpi
370    int nAtoms = entry_plug->n_atoms;
371   #endif //is_mpi
372 <  
372 >
373    double pos[3], vel[3];
374 <  
374 >
375   #ifdef IS_MPI
376    if(worldRank == 0 ){
377   #endif // is_mpi
378 <    
378 >
379      strcpy( finalName, entry_plug->finalName );
380 <    
380 >
381      finalOut.open( finalName, ios::out | ios::trunc );
382      if( !finalOut ){
383        sprintf( painCave.errMsg,
# Line 381 | Line 386 | void DumpWriter::writeFinal(double finalTime){
386        painCave.isFatal = 1;
387        simError();
388      }
389 <    
389 >
390      // finalOut.setf( ios::scientific );
391 <    
391 >
392   #ifdef IS_MPI
393    }
394 <  
394 >
395    sprintf(checkPointMsg,"Opened file for final configuration\n");
396 <  MPIcheckPoint();  
397 <  
396 >  MPIcheckPoint();
397 >
398   #endif //is_mpi
399  
400 <  
400 >
401   #ifndef IS_MPI
402 <    
402 >
403    finalOut << nAtoms << "\n";
404 <    
404 >
405    finalOut << finalTime << ";\t"
406             << entry_plug->Hmat[0][0] << "\t"
407             << entry_plug->Hmat[1][0] << "\t"
408             << entry_plug->Hmat[2][0] << ";\t"
409 <    
409 >
410             << entry_plug->Hmat[0][1] << "\t"
411             << entry_plug->Hmat[1][1] << "\t"
412             << entry_plug->Hmat[2][1] << ";\t"
413 <    
413 >
414             << entry_plug->Hmat[0][2] << "\t"
415             << entry_plug->Hmat[1][2] << "\t"
416 <           << entry_plug->Hmat[2][2] << ";\n";
417 <  
416 >           << entry_plug->Hmat[2][2] << ";";
417 >
418 >  //write out additional parameters, such as chi and eta
419 >  finalOut << entry_plug->the_integrator->getAdditionalParameters();
420 >  finalOut << endl;
421 >
422    for( i=0; i<nAtoms; i++ ){
423 <      
423 >
424      atoms[i]->getPos(pos);
425      atoms[i]->getVel(vel);
426 <    
426 >
427      sprintf( tempBuffer,
428               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
429               atoms[i]->getType(),
# Line 427 | Line 436 | void DumpWriter::writeFinal(double finalTime){
436      strcpy( writeLine, tempBuffer );
437  
438      if( atoms[i]->isDirectional() ){
439 <        
439 >
440        dAtom = (DirectionalAtom *)atoms[i];
441        dAtom->getQ( q );
442 <        
442 >
443        sprintf( tempBuffer,
444                 "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
445                 q[0],
# Line 444 | Line 453 | void DumpWriter::writeFinal(double finalTime){
453      }
454      else
455        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
456 <      
456 >
457      finalOut << writeLine;
458    }
459    finalOut.flush();
460    finalOut.close();
461  
462   #else // is_mpi
463 <  
463 >
464    // first thing first, suspend fatalities.
465    painCave.isEventLoop = 1;
466  
# Line 462 | Line 471 | void DumpWriter::writeFinal(double finalTime){
471    int *AtomToProcMap = mpiSim->getAtomToProcMap();
472  
473    // write out header and node 0's coordinates
474 <  
474 >
475    haveError = 0;
476    if( worldRank == 0 ){
477      finalOut << mpiSim->getTotAtoms() << "\n";
478 <    
478 >
479      finalOut << finalTime << ";\t"
480               << entry_plug->Hmat[0][0] << "\t"
481               << entry_plug->Hmat[1][0] << "\t"
482               << entry_plug->Hmat[2][0] << ";\t"
483 <      
483 >
484               << entry_plug->Hmat[0][1] << "\t"
485               << entry_plug->Hmat[1][1] << "\t"
486               << entry_plug->Hmat[2][1] << ";\t"
487 <      
487 >
488               << entry_plug->Hmat[0][2] << "\t"
489               << entry_plug->Hmat[1][2] << "\t"
490 <             << entry_plug->Hmat[2][2] << ";\n";
491 <    
490 >             << entry_plug->Hmat[2][2] << ";";
491 >
492 >    //write out additional parameters, such as chi and eta
493 >    finalOut << entry_plug->the_integrator->getAdditionalParameters();
494 >    finalOut << endl;
495 >
496      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
497        // Get the Node number which has this molecule:
498 <      
499 <      which_node = AtomToProcMap[i];    
500 <      
498 >
499 >      which_node = AtomToProcMap[i];
500 >
501        if (which_node == mpiSim->getMyNode()) {
502  
503          which_atom = i;
504 <        local_index=-1;        
504 >        local_index=-1;
505          for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
506            if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
507          }
508 <        if (local_index != -1) {    
508 >        if (local_index != -1) {
509  
510            atoms[local_index]->getPos(pos);
511            atoms[local_index]->getVel(vel);
512 <          
512 >
513            sprintf( tempBuffer,
514                     "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
515                     atoms[local_index]->getType(),
# Line 507 | Line 520 | void DumpWriter::writeFinal(double finalTime){
520                     vel[1],
521                     vel[2]);
522            strcpy( writeLine, tempBuffer );
523 <          
523 >
524            if( atoms[local_index]->isDirectional() ){
525 <            
525 >
526              dAtom = (DirectionalAtom *)atoms[local_index];
527              dAtom->getQ( q );
528 <            
528 >
529              sprintf( tempBuffer,
530                       "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
531                       q[0],
# Line 525 | Line 538 | void DumpWriter::writeFinal(double finalTime){
538              strcat( writeLine, tempBuffer );
539            }
540            else
541 <            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
541 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
542          }
543          else {
544            sprintf(painCave.errMsg,
# Line 533 | Line 546 | void DumpWriter::writeFinal(double finalTime){
546                    i, worldRank );
547            haveError= 1;
548            simError();
549 <        }
549 >        }
550  
551          if(haveError) nodeZeroError();
552 <    
553 <      }
552 >
553 >      }
554        else {
555 <        
555 >
556          myStatus = 1;
557 <        MPI_Send(&myStatus, 1, MPI_INT, which_node,
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,
563 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
564                   TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
565 <        
565 >
566          if(!myStatus) nodeZeroError();
567        }
568 <      
568 >
569        finalOut << writeLine;
570      }
571 <    
571 >
572      // kill everyone off:
573      myStatus = -1;
574 <    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
575 <      MPI_Send(&myStatus, 1, MPI_INT, j,
574 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {
575 >      MPI_Send(&myStatus, 1, MPI_INT, j,
576                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
577      }
578  
579    } else {
580 <    
580 >
581      done = 0;
582      while (!done) {
583  
584 <      MPI_Recv(&myStatus, 1, MPI_INT, 0,
584 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
585                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
586 <      
586 >
587        if(!myStatus) anonymousNodeDie();
588 <      
588 >
589        if(myStatus < 0) break;
590 <      
591 <      MPI_Recv(&which_atom, 1, MPI_INT, 0,
590 >
591 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
592                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
593 <      
593 >
594        myStatus = 1;
595 <      local_index=-1;        
595 >      local_index=-1;
596        for (j=0; j < mpiSim->getMyNlocal(); j++) {
597          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
598        }
# Line 599 | Line 612 | void DumpWriter::writeFinal(double finalTime){
612                   vel[1],
613                   vel[2]); // check here.
614          strcpy( writeLine, tempBuffer );
615 <        
615 >
616          if( atoms[local_index]->isDirectional() ){
617 <          
617 >
618            dAtom = (DirectionalAtom *)atoms[local_index];
619            dAtom->getQ( q );
620 <          
620 >
621            sprintf( tempBuffer,
622                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
623                     q[0],
# Line 619 | Line 632 | void DumpWriter::writeFinal(double finalTime){
632          else{
633            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
634          }
635 <      }
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();
642 <        
642 >
643          strcpy( writeLine, "Hello, I'm an error.\n");
644        }
645  
646 <      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
646 >      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
647                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
648 <      MPI_Send( &myStatus, 1, MPI_INT, 0,
648 >      MPI_Send( &myStatus, 1, MPI_INT, 0,
649                  TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
650      }
651    }
# Line 640 | Line 653 | void DumpWriter::writeFinal(double finalTime){
653    sprintf( checkPointMsg,
654             "Sucessfully took a dump.\n");
655    MPIcheckPoint();
656 <  
657 <  if( worldRank == 0 ) finalOut.close();    
656 >
657 >  if( worldRank == 0 ) finalOut.close();
658   #endif // is_mpi
659   }
660  
# Line 653 | Line 666 | void dWrite::nodeZeroError( void ){
666  
667   void dWrite::nodeZeroError( void ){
668    int j, myStatus;
669 <  
669 >
670    myStatus = 0;
671 <  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
672 <    MPI_Send( &myStatus, 1, MPI_INT, j,
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 <  }  
662 <  
674 >  }
675  
676 +
677    MPI_Finalize();
678    exit (0);
679 <  
679 >
680   }
681  
682   void dWrite::anonymousNodeDie( void ){

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines