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 440 by mmeineke, Tue Apr 1 16:49:17 2003 UTC vs.
Revision 804 by mmeineke, Thu Oct 16 19:16:24 2003 UTC

# Line 1 | Line 1
1 + #define _FILE_OFFSET_BITS 64
2 +
3   #include <cstring>
4   #include <iostream>
5   #include <fstream>
6  
7   #ifdef IS_MPI
8   #include <mpi.h>
7 #include <mpi++.h>
9   #include "mpiSimulation.hpp"
10   #define TAKE_THIS_TAG_CHAR 1
11   #define TAKE_THIS_TAG_INT 2
# Line 28 | Line 29 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
29    if(worldRank == 0 ){
30   #endif // is_mpi
31      
31
32    
32      strcpy( outName, entry_plug->sampleName );
33      
34      outFile.open(outName, ios::out | ios::trunc );
# Line 42 | Line 41 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
41        painCave.isFatal = 1;
42        simError();
43      }
44 <  
44 >
45      //outFile.setf( ios::scientific );
46  
47   #ifdef IS_MPI
# Line 73 | Line 72 | void DumpWriter::writeDump( double currentTime ){
72    char tempBuffer[BUFFERSIZE];
73    char writeLine[BUFFERSIZE];
74  
75 <  int i, j, which_node, done, game_over, which_atom, local_index;
75 >  int i;
76 > #ifdef IS_MPI
77 >  int j, which_node, done, which_atom, local_index;
78 > #else //is_mpi
79 >  int nAtoms = entry_plug->n_atoms;
80 > #endif //is_mpi
81 >
82    double q[4];
83    DirectionalAtom* dAtom;
79  int nAtoms = entry_plug->n_atoms;
84    Atom** atoms = entry_plug->atoms;
85 +  double pos[3], vel[3];
86      
87 +  
88 +  // write current frame to the eor file
89  
90 +  this->writeFinal( currentTime );
91 +
92   #ifndef IS_MPI
93      
94    outFile << nAtoms << "\n";
95      
96 <  outFile << currentTime << "\t"
97 <          << entry_plug->box_x << "\t"
98 <          << entry_plug->box_y << "\t"
99 <          << entry_plug->box_z << "\n";
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"
100 >
101 >          << entry_plug->Hmat[0][1] << "\t"
102 >          << entry_plug->Hmat[1][1] << "\t"
103 >          << entry_plug->Hmat[2][1] << ";\t"
104 >
105 >          << entry_plug->Hmat[0][2] << "\t"
106 >          << entry_plug->Hmat[1][2] << "\t"
107 >          << entry_plug->Hmat[2][2] << ";\n";
108      
109    for( i=0; i<nAtoms; i++ ){
110        
111 +    atoms[i]->getPos(pos);
112 +    atoms[i]->getVel(vel);
113  
114      sprintf( tempBuffer,
115               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
116               atoms[i]->getType(),
117 <             atoms[i]->getX(),
118 <             atoms[i]->getY(),
119 <             atoms[i]->getZ(),
120 <             atoms[i]->get_vx(),
121 <             atoms[i]->get_vy(),
122 <             atoms[i]->get_vz());
117 >             pos[0],
118 >             pos[1],
119 >             pos[2],
120 >             vel[0],
121 >             vel[1],
122 >             vel[2]);
123      strcpy( writeLine, tempBuffer );
124  
125      if( atoms[i]->isDirectional() ){
# Line 134 | Line 153 | void DumpWriter::writeDump( double currentTime ){
153    int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
154    int haveError;
155  
156 <  MPI::Status istatus;
156 >  MPI_Status istatus;
157    int *AtomToProcMap = mpiSim->getAtomToProcMap();
158    
159    // write out header and node 0's coordinates
160    
161    if( worldRank == 0 ){
162      outFile << mpiSim->getTotAtoms() << "\n";
163 +  
164 +    outFile << currentTime << ";\t"
165 +            << entry_plug->Hmat[0][0] << "\t"
166 +            << entry_plug->Hmat[1][0] << "\t"
167 +            << entry_plug->Hmat[2][0] << ";\t"
168 +      
169 +            << entry_plug->Hmat[0][1] << "\t"
170 +            << entry_plug->Hmat[1][1] << "\t"
171 +            << entry_plug->Hmat[2][1] << ";\t"
172 +      
173 +            << entry_plug->Hmat[0][2] << "\t"
174 +            << entry_plug->Hmat[1][2] << "\t"
175 +            << entry_plug->Hmat[2][2] << ";\n";
176      
145    outFile << currentTime << "\t"
146            << entry_plug->box_x << "\t"
147            << entry_plug->box_y << "\t"
148            << entry_plug->box_z << "\n";
177      outFile.flush();
178      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
179        // Get the Node number which has this atom;
# Line 162 | Line 190 | void DumpWriter::writeDump( double currentTime ){
190          }
191          if (local_index != -1) {
192            //format the line
193 +          
194 +          atoms[local_index]->getPos(pos);
195 +          atoms[local_index]->getVel(vel);
196 +
197            sprintf( tempBuffer,
198                     "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
199                     atoms[local_index]->getType(),
200 <                   atoms[local_index]->getX(),
201 <                   atoms[local_index]->getY(),
202 <                   atoms[local_index]->getZ(),
203 <                   atoms[local_index]->get_vx(),
204 <                   atoms[local_index]->get_vy(),
205 <                   atoms[local_index]->get_vz()); // check here.
200 >                   pos[0],
201 >                   pos[1],
202 >                   pos[2],
203 >                   vel[0],
204 >                   vel[1],
205 >                   vel[2]); // check here.
206            strcpy( writeLine, tempBuffer );
207            
208            if( atoms[local_index]->isDirectional() ){
# Line 206 | Line 238 | void DumpWriter::writeDump( double currentTime ){
238        }
239        else {
240          myStatus = 1;
241 <        MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, which_node,
242 <                             TAKE_THIS_TAG_INT);
243 <        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT);
244 <        MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
245 <                             TAKE_THIS_TAG_CHAR, istatus);
246 <        MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, which_node,
247 <                             TAKE_THIS_TAG_INT, istatus);
241 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
242 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
243 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
244 >                 MPI_COMM_WORLD);
245 >        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
246 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
247 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
248 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
249          
250          if(!myStatus) nodeZeroError();
251  
# Line 225 | Line 258 | void DumpWriter::writeDump( double currentTime ){
258      // kill everyone off:
259      myStatus = -1;
260      for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
261 <      MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, j,
262 <                           TAKE_THIS_TAG_INT);
261 >      MPI_Send(&myStatus, 1, MPI_INT, j,
262 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
263      }
264  
265    } else {
# Line 234 | Line 267 | void DumpWriter::writeDump( double currentTime ){
267      done = 0;
268      while (!done) {
269        
270 <      MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, 0,
271 <                           TAKE_THIS_TAG_INT, istatus);
270 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
271 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
272  
273        if(!myStatus) anonymousNodeDie();
274        
275        if(myStatus < 0) break;
276  
277 <      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
278 <                           TAKE_THIS_TAG_INT, istatus);
277 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
278 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
279        
280        myStatus = 1;
281        local_index=-1;        
# Line 251 | Line 284 | void DumpWriter::writeDump( double currentTime ){
284        }
285        if (local_index != -1) {
286          //format the line
287 +
288 +        atoms[local_index]->getPos(pos);
289 +        atoms[local_index]->getVel(vel);
290 +
291          sprintf( tempBuffer,
292                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
293                   atoms[local_index]->getType(),
294 <                 atoms[local_index]->getX(),
295 <                 atoms[local_index]->getY(),
296 <                 atoms[local_index]->getZ(),
297 <                 atoms[local_index]->get_vx(),
298 <                 atoms[local_index]->get_vy(),
299 <                 atoms[local_index]->get_vz()); // check here.
294 >                 pos[0],
295 >                 pos[1],
296 >                 pos[2],
297 >                 vel[0],
298 >                 vel[1],
299 >                 vel[2]); // check here.
300          strcpy( writeLine, tempBuffer );
301          
302          if( atoms[local_index]->isDirectional() ){
# Line 292 | Line 329 | void DumpWriter::writeDump( double currentTime ){
329          strcpy( writeLine, "Hello, I'm an error.\n");
330        }
331  
332 <      MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
333 <                           TAKE_THIS_TAG_CHAR);
334 <      MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, 0,
335 <                            TAKE_THIS_TAG_INT);
332 >      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
333 >               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
334 >      MPI_Send( &myStatus, 1, MPI_INT, 0,
335 >                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
336      }
337    }  
338    outFile.flush();
# Line 309 | Line 346 | void DumpWriter::writeFinal(){
346   #endif // is_mpi
347   }
348  
349 < void DumpWriter::writeFinal(){
349 > void DumpWriter::writeFinal(double finalTime){
350  
351    char finalName[500];
352    ofstream finalOut;
# Line 320 | Line 357 | void DumpWriter::writeFinal(){
357  
358    double q[4];
359    DirectionalAtom* dAtom;
323  int nAtoms = entry_plug->n_atoms;
360    Atom** atoms = entry_plug->atoms;
361 <  int i, j, which_node, done, game_over, which_atom, local_index;
361 >  int i;
362 > #ifdef IS_MPI
363 >  int j, which_node, done, which_atom, local_index;
364 > #else //is_mpi
365 >  int nAtoms = entry_plug->n_atoms;
366 > #endif //is_mpi
367    
368 +  double pos[3], vel[3];
369    
370   #ifdef IS_MPI
371    if(worldRank == 0 ){
# Line 355 | Line 397 | void DumpWriter::writeFinal(){
397      
398    finalOut << nAtoms << "\n";
399      
400 <  finalOut << entry_plug->box_x << "\t"
401 <           << entry_plug->box_y << "\t"
402 <           << entry_plug->box_z << "\n";
400 >  finalOut << finalTime << ";\t"
401 >           << entry_plug->Hmat[0][0] << "\t"
402 >           << entry_plug->Hmat[1][0] << "\t"
403 >           << entry_plug->Hmat[2][0] << ";\t"
404 >    
405 >           << entry_plug->Hmat[0][1] << "\t"
406 >           << entry_plug->Hmat[1][1] << "\t"
407 >           << entry_plug->Hmat[2][1] << ";\t"
408 >    
409 >           << entry_plug->Hmat[0][2] << "\t"
410 >           << entry_plug->Hmat[1][2] << "\t"
411 >           << entry_plug->Hmat[2][2] << ";\n";
412    
413    for( i=0; i<nAtoms; i++ ){
414        
415 +    atoms[i]->getPos(pos);
416 +    atoms[i]->getVel(vel);
417 +    
418      sprintf( tempBuffer,
419               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
420               atoms[i]->getType(),
421 <             atoms[i]->getX(),
422 <             atoms[i]->getY(),
423 <             atoms[i]->getZ(),
424 <             atoms[i]->get_vx(),
425 <             atoms[i]->get_vy(),
426 <             atoms[i]->get_vz());
421 >             pos[0],
422 >             pos[1],
423 >             pos[2],
424 >             vel[0],
425 >             vel[1],
426 >             vel[2]);
427      strcpy( writeLine, tempBuffer );
428  
429      if( atoms[i]->isDirectional() ){
# Line 404 | Line 458 | void DumpWriter::writeFinal(){
458    int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
459    int haveError;
460  
461 <  MPI::Status istatus;
461 >  MPI_Status istatus;
462    int *AtomToProcMap = mpiSim->getAtomToProcMap();
463  
464    // write out header and node 0's coordinates
# Line 413 | Line 467 | void DumpWriter::writeFinal(){
467    if( worldRank == 0 ){
468      finalOut << mpiSim->getTotAtoms() << "\n";
469      
470 <    finalOut << entry_plug->box_x << "\t"
471 <            << entry_plug->box_y << "\t"
472 <            << entry_plug->box_z << "\n";
470 >    finalOut << finalTime << ";\t"
471 >             << entry_plug->Hmat[0][0] << "\t"
472 >             << entry_plug->Hmat[1][0] << "\t"
473 >             << entry_plug->Hmat[2][0] << ";\t"
474 >      
475 >             << entry_plug->Hmat[0][1] << "\t"
476 >             << entry_plug->Hmat[1][1] << "\t"
477 >             << entry_plug->Hmat[2][1] << ";\t"
478 >      
479 >             << entry_plug->Hmat[0][2] << "\t"
480 >             << entry_plug->Hmat[1][2] << "\t"
481 >             << entry_plug->Hmat[2][2] << ";\n";
482      
483      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
484        // Get the Node number which has this molecule:
# Line 429 | Line 492 | void DumpWriter::writeFinal(){
492          for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
493            if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
494          }
495 <        if (local_index != -1) {        
495 >        if (local_index != -1) {    
496 >
497 >          atoms[local_index]->getPos(pos);
498 >          atoms[local_index]->getVel(vel);
499 >          
500            sprintf( tempBuffer,
501                     "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
502                     atoms[local_index]->getType(),
503 <                   atoms[local_index]->getX(),
504 <                   atoms[local_index]->getY(),
505 <                   atoms[local_index]->getZ(),
506 <                   atoms[local_index]->get_vx(),
507 <                   atoms[local_index]->get_vy(),
508 <                   atoms[local_index]->get_vz());
503 >                   pos[0],
504 >                   pos[1],
505 >                   pos[2],
506 >                   vel[0],
507 >                   vel[1],
508 >                   vel[2]);
509            strcpy( writeLine, tempBuffer );
510            
511            if( atoms[local_index]->isDirectional() ){
# Line 474 | Line 541 | void DumpWriter::writeFinal(){
541        else {
542          
543          myStatus = 1;
544 <        MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, which_node,
545 <                             TAKE_THIS_TAG_INT);
546 <        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT);
547 <        MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
548 <                             TAKE_THIS_TAG_CHAR, istatus);
549 <        MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, which_node,
550 <                             TAKE_THIS_TAG_INT, istatus);
544 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
545 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
546 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
547 >                 MPI_COMM_WORLD);
548 >        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
549 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
550 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
551 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
552          
553          if(!myStatus) nodeZeroError();
554        }
# Line 491 | Line 559 | void DumpWriter::writeFinal(){
559      // kill everyone off:
560      myStatus = -1;
561      for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
562 <      MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, j,
563 <                           TAKE_THIS_TAG_INT);
562 >      MPI_Send(&myStatus, 1, MPI_INT, j,
563 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
564      }
565  
566    } else {
# Line 500 | Line 568 | void DumpWriter::writeFinal(){
568      done = 0;
569      while (!done) {
570  
571 <      MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, 0,
572 <                           TAKE_THIS_TAG_INT, istatus);
571 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
572 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
573        
574        if(!myStatus) anonymousNodeDie();
575        
576        if(myStatus < 0) break;
577        
578 <      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
579 <                           TAKE_THIS_TAG_INT, istatus);
578 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
579 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
580        
581        myStatus = 1;
582        local_index=-1;        
# Line 517 | Line 585 | void DumpWriter::writeFinal(){
585        }
586        if (local_index != -1) {
587  
588 +        atoms[local_index]->getPos(pos);
589 +        atoms[local_index]->getVel(vel);
590 +
591          //format the line
592          sprintf( tempBuffer,
593                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
594                   atoms[local_index]->getType(),
595 <                 atoms[local_index]->getX(),
596 <                 atoms[local_index]->getY(),
597 <                 atoms[local_index]->getZ(),
598 <                 atoms[local_index]->get_vx(),
599 <                 atoms[local_index]->get_vy(),
600 <                 atoms[local_index]->get_vz()); // check here.
595 >                 pos[0],
596 >                 pos[1],
597 >                 pos[2],
598 >                 vel[0],
599 >                 vel[1],
600 >                 vel[2]); // check here.
601          strcpy( writeLine, tempBuffer );
602          
603          if( atoms[local_index]->isDirectional() ){
# Line 559 | Line 630 | void DumpWriter::writeFinal(){
630          strcpy( writeLine, "Hello, I'm an error.\n");
631        }
632  
633 <      MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
634 <                           TAKE_THIS_TAG_CHAR);
635 <      MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, 0,
636 <                            TAKE_THIS_TAG_INT);
633 >      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
634 >               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
635 >      MPI_Send( &myStatus, 1, MPI_INT, 0,
636 >                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
637      }
638    }
639    finalOut.flush();
# Line 585 | Line 656 | void dWrite::nodeZeroError( void ){
656    
657    myStatus = 0;
658    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
659 <    MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j,
660 <                          TAKE_THIS_TAG_INT);
659 >    MPI_Send( &myStatus, 1, MPI_INT, j,
660 >              TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
661    }  
662    
663  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines