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 913 by chuckv, Thu Jan 8 22:25:52 2004 UTC

# Line 7 | Line 7
7   #ifdef IS_MPI
8   #include <mpi.h>
9   #include "mpiSimulation.hpp"
10 #define TAKE_THIS_TAG_CHAR 1
11 #define TAKE_THIS_TAG_INT 2
10  
11   namespace dWrite{
12 <  void nodeZeroError( void );
15 <  void anonymousNodeDie( void );
12 >  void DieDieDie( void );
13   }
14  
15   using namespace dWrite;
# Line 28 | Line 25 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
25   #ifdef IS_MPI
26    if(worldRank == 0 ){
27   #endif // is_mpi
28 <    
28 >
29      strcpy( outName, entry_plug->sampleName );
30 <    
30 >
31      outFile.open(outName, ios::out | ios::trunc );
32 <    
32 >
33      if( !outFile ){
34 <      
34 >
35        sprintf( painCave.errMsg,
36                 "Could not open \"%s\" for dump output.\n",
37                 outName);
# Line 67 | Line 64 | void DumpWriter::writeDump( double currentTime ){
64   }
65  
66   void DumpWriter::writeDump( double currentTime ){
67 <  
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 83 | Line 92 | void DumpWriter::writeDump( double currentTime ){
92    DirectionalAtom* dAtom;
93    Atom** atoms = entry_plug->atoms;
94    double pos[3], vel[3];
95 <    
87 <  
95 >
96    // write current frame to the eor file
97  
98    this->writeFinal( currentTime );
99  
100   #ifndef IS_MPI
101 <    
101 >
102    outFile << nAtoms << "\n";
103 <    
104 <  outFile << currentTime << ";\t"
103 >
104 >  outFile << currentTime << ";\t"
105            << entry_plug->Hmat[0][0] << "\t"
106            << entry_plug->Hmat[1][0] << "\t"
107            << entry_plug->Hmat[2][0] << ";\t"
# Line 104 | Line 112 | void DumpWriter::writeDump( double currentTime ){
112  
113            << entry_plug->Hmat[0][2] << "\t"
114            << entry_plug->Hmat[1][2] << "\t"
115 <          << entry_plug->Hmat[2][2] << ";\n";
116 <    
115 >          << entry_plug->Hmat[2][2] << ";";
116 >  //write out additional parameters, such as chi and eta
117 >  outFile << entry_plug->the_integrator->getAdditionalParameters();
118 >  outFile << endl;
119 >
120    for( i=0; i<nAtoms; i++ ){
121 <      
121 >
122      atoms[i]->getPos(pos);
123      atoms[i]->getVel(vel);
124  
# Line 123 | Line 134 | void DumpWriter::writeDump( double currentTime ){
134      strcpy( writeLine, tempBuffer );
135  
136      if( atoms[i]->isDirectional() ){
137 <        
137 >
138        dAtom = (DirectionalAtom *)atoms[i];
139        dAtom->getQ( q );
140 <        
140 >
141        sprintf( tempBuffer,
142                 "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
143                 q[0],
# Line 140 | Line 151 | void DumpWriter::writeDump( double currentTime ){
151      }
152      else
153        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
154 <      
154 >
155      outFile << writeLine;
156    }
157    outFile.flush();
158  
159   #else // is_mpi
160  
161 <  // first thing first, suspend fatalities.
162 <  painCave.isEventLoop = 1;
161 >  /* code to find maximum tag value */
162 >  int *tagub, flag, MAXTAG;
163 >  MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag);
164 >  if (flag) {
165 >    MAXTAG = *tagub;
166 >  } else {
167 >    MAXTAG = 32767;
168 >  }
169  
153  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
170    int haveError;
171  
172    MPI_Status istatus;
173    int *AtomToProcMap = mpiSim->getAtomToProcMap();
174 <  
174 >
175    // write out header and node 0's coordinates
176 <  
176 >
177    if( worldRank == 0 ){
178      outFile << mpiSim->getTotAtoms() << "\n";
179 <  
180 <    outFile << currentTime << ";\t"
179 >
180 >    outFile << currentTime << ";\t"
181              << entry_plug->Hmat[0][0] << "\t"
182              << entry_plug->Hmat[1][0] << "\t"
183              << entry_plug->Hmat[2][0] << ";\t"
184 <      
184 >
185              << entry_plug->Hmat[0][1] << "\t"
186              << entry_plug->Hmat[1][1] << "\t"
187              << entry_plug->Hmat[2][1] << ";\t"
188 <      
188 >
189              << entry_plug->Hmat[0][2] << "\t"
190              << entry_plug->Hmat[1][2] << "\t"
191 <            << entry_plug->Hmat[2][2] << ";\n";
192 <    
191 >            << entry_plug->Hmat[2][2] << ";";
192 >
193 >    outFile << entry_plug->the_integrator->getAdditionalParameters();
194 >    outFile << endl;
195      outFile.flush();
196 +
197 +    tag = 0;
198 +
199      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
200 +
201 +      if (tag + 2 >= MAXTAG) {
202 +        // The tag was going to exceed the maximum value, so wrap around to 0:
203 +        tag = 0;
204 +        // Send the newly zeroed tag on to the other nodes:
205 +        MPI_Bcast(&tag, 1, MPI_INT, 0, MPI_COMM_WORLD);
206 +      }
207 +      
208        // Get the Node number which has this atom;
209        
210 <      which_node = AtomToProcMap[i];    
210 >      which_node = AtomToProcMap[i];
211        
212 <      if (which_node == 0 ) {
213 <        
212 >      if (which_node != 0) {
213 >        
214 >        MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node,
215 >                 atomTypeTag, MPI_COMM_WORLD, &istatus);
216 >        
217 >        strncpy(atomTypeString, MPIatomTypeString, MINIBUFFERSIZE);
218 >        
219 >        // Null terminate the atomTypeString just in case:
220 >
221 >        atomTypeString[strlen(atomTypeString) - 1] = '\0';
222 >
223 >        MPI_Recv(&isDirectional, 1, MPI_INT, which_node,
224 >                 atomIsDirectionalTag, MPI_COMM_WORLD, &istatus);
225 >        
226 >        MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node,
227 >                 atomTransDataTag, MPI_COMM_WORLD, &istatus);
228 >
229 >        if (isDirectional) {
230 >
231 >          MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node,
232 >                   atomOrientDataTag, MPI_COMM_WORLD, &istatus);
233 >
234 >        }
235 >
236 >      } else {
237 >        
238          haveError = 0;
239          which_atom = i;
240 <        local_index=-1;        
240 >        local_index=-1;
241 >
242          for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
243            if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
244          }
245 +
246          if (local_index != -1) {
247 <          //format the line
248 <          
247 >
248 >          atomTypeString = atoms[local_index]->getType();
249 >
250            atoms[local_index]->getPos(pos);
251            atoms[local_index]->getVel(vel);
252  
253 <          sprintf( tempBuffer,
254 <                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
255 <                   atoms[local_index]->getType(),
256 <                   pos[0],
257 <                   pos[1],
258 <                   pos[2],
259 <                   vel[0],
260 <                   vel[1],
261 <                   vel[2]); // check here.
262 <          strcpy( writeLine, tempBuffer );
207 <          
253 >          atomTransData[0] = pos[0];
254 >          atomTransData[1] = pos[1];
255 >          atomTransData[2] = pos[2];
256 >
257 >          atomTransData[3] = vel[0];
258 >          atomTransData[4] = vel[1];
259 >          atomTransData[5] = vel[2];
260 >          
261 >          isDirectional = 0;
262 >
263            if( atoms[local_index]->isDirectional() ){
264 +
265 +            isDirectional = 1;
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 <            
224 <          }
225 <          else
226 <            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
227 <        }
228 <        else {
270 >            atomOrientData[0] = q[0];
271 >            atomOrientData[1] = q[1];
272 >            atomOrientData[2] = q[2];
273 >            atomOrientData[3] = q[3];
274 >
275 >            atomOrientData[4] = dAtom->getJx();
276 >            atomOrientData[5] = dAtom->getJy();
277 >            atomOrientData[6] = dAtom->getJz();
278 >          }
279 >
280 >        } else {
281            sprintf(painCave.errMsg,
282                    "Atom %d not found on processor %d\n",
283                    i, worldRank );
284            haveError= 1;
285            simError();
286 <        }
235 <        
236 <        if(haveError) nodeZeroError();
286 >        }
287  
288 <      }
289 <      else {
290 <        myStatus = 1;
291 <        MPI_Send(&myStatus, 1, MPI_INT, which_node,
292 <                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
293 <        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
294 <                 MPI_COMM_WORLD);
295 <        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
296 <                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
297 <        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
298 <                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
299 <        
300 <        if(!myStatus) nodeZeroError();
288 >        if(haveError) DieDieDie();
289 >                              
290 >        // If we've survived to here, format the line:
291 >        
292 >        sprintf( tempBuffer,
293 >                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
294 >                 atomTypeString,
295 >                 atomTransData[0],
296 >                 atomTransData[1],
297 >                 atomTransData[2],
298 >                 atomTransData[3],
299 >                 atomTransData[4],
300 >                 atomTransData[5]);
301  
302 +        strcpy( writeLine, tempBuffer );
303 +
304 +        if (isDirectional) {
305 +
306 +          sprintf( tempBuffer,
307 +                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
308 +                   atomOrientData[0],
309 +                   atomOrientData[1],
310 +                   atomOrientData[2],
311 +                   atomOrientData[3],
312 +                   atomOrientData[4],
313 +                   atomOrientData[5],
314 +                   atomOrientData[6]);
315 +          strcat( writeLine, tempBuffer );
316 +
317 +        } else {
318 +          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
319 +        }
320 +
321 +        outFile << writeLine;
322 +        outFile.flush();
323        }
253      
254      outFile << writeLine;
255      outFile.flush();
324      }
257    
258    // kill everyone off:
259    myStatus = -1;
260    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
261      MPI_Send(&myStatus, 1, MPI_INT, j,
262               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
263    }
325  
326 +    outFile.flush();
327 +    sprintf( checkPointMsg,
328 +             "Sucessfully took a dump.\n");
329 +    MPIcheckPoint();        
330 +    
331    } else {
332 +
333 +    // worldRank != 0, so I'm a remote node.  
334      
335 <    done = 0;
268 <    while (!done) {
335 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
336        
337 <      MPI_Recv(&myStatus, 1, MPI_INT, 0,
271 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
272 <
273 <      if(!myStatus) anonymousNodeDie();
337 >      // Am I the node which has this atom?
338        
339 <      if(myStatus < 0) break;
339 >      if (AtomToProcMap[i] == worldRank) {
340  
341 <      MPI_Recv(&which_atom, 1, MPI_INT, 0,
342 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
343 <      
344 <      myStatus = 1;
345 <      local_index=-1;        
346 <      for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
347 <        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
284 <      }
285 <      if (local_index != -1) {
286 <        //format the line
341 >        local_index=-1;
342 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
343 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
344 >        }
345 >        if (local_index != -1) {
346 >        
347 >          atomTypeString = atoms[local_index]->getType();
348  
349 <        atoms[local_index]->getPos(pos);
350 <        atoms[local_index]->getVel(vel);
349 >          atoms[local_index]->getPos(pos);
350 >          atoms[local_index]->getVel(vel);
351  
352 <        sprintf( tempBuffer,
353 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
354 <                 atoms[local_index]->getType(),
355 <                 pos[0],
356 <                 pos[1],
357 <                 pos[2],
358 <                 vel[0],
359 <                 vel[1],
360 <                 vel[2]); // check here.
361 <        strcpy( writeLine, tempBuffer );
362 <        
363 <        if( atoms[local_index]->isDirectional() ){
364 <          
365 <          dAtom = (DirectionalAtom *)atoms[local_index];
366 <          dAtom->getQ( q );
367 <          
368 <          sprintf( tempBuffer,
369 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
370 <                   q[0],
371 <                   q[1],
372 <                   q[2],
373 <                   q[3],
374 <                   dAtom->getJx(),
375 <                   dAtom->getJy(),
376 <                   dAtom->getJz());
377 <          strcat( writeLine, tempBuffer );
352 >          atomTransData[0] = pos[0];
353 >          atomTransData[1] = pos[1];
354 >          atomTransData[2] = pos[2];
355 >
356 >          atomTransData[3] = vel[0];
357 >          atomTransData[4] = vel[1];
358 >          atomTransData[5] = vel[2];
359 >          
360 >          isDirectional = 0;
361 >
362 >          if( atoms[local_index]->isDirectional() ){
363 >
364 >            isDirectional = 1;
365 >            
366 >            dAtom = (DirectionalAtom *)atoms[local_index];
367 >            dAtom->getQ( q );
368 >            
369 >            atomOrientData[0] = q[0];
370 >            atomOrientData[1] = q[1];
371 >            atomOrientData[2] = q[2];
372 >            atomOrientData[3] = q[3];
373 >
374 >            atomOrientData[4] = dAtom->getJx();
375 >            atomOrientData[5] = dAtom->getJy();
376 >            atomOrientData[6] = dAtom->getJz();
377 >          }
378 >
379 >        } else {
380 >          sprintf(painCave.errMsg,
381 >                  "Atom %d not found on processor %d\n",
382 >                  i, worldRank );
383 >          haveError= 1;
384 >          simError();
385          }
318        else{
319          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
320        }
321      }
322      else {
323        sprintf(painCave.errMsg,
324                "Atom %d not found on processor %d\n",
325                which_atom, worldRank );
326        myStatus = 0;
327        simError();
386  
387 <        strcpy( writeLine, "Hello, I'm an error.\n");
330 <      }
387 >        // I've survived this far, so send off the data!
388  
389 <      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
390 <               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
391 <      MPI_Send( &myStatus, 1, MPI_INT, 0,
392 <                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
389 >        atomTypeTag          = 4*i;
390 >        atomIsDirectionalTag = 4*i + 1;
391 >        atomTransDataTag     = 4*i + 2;
392 >        atomOrientDataTag    = 4*i + 3;
393 >
394 >
395 >        strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
396 >
397 >        // null terminate the string before sending (just in case):
398 >        MPIatomTypeString[MINIBUFFERSIZE-1] = '\0';
399 >
400 >        MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
401 >                 atomTypeTag, MPI_COMM_WORLD);
402 >        
403 >        MPI_Send(&isDirectional, 1, MPI_INT, 0,
404 >                 atomIsDirectionalTag, MPI_COMM_WORLD);
405 >        
406 >        MPI_Send(atomTransData, 6, MPI_DOUBLE, 0,
407 >                 atomTransDataTag, MPI_COMM_WORLD);
408 >
409 >        if (isDirectional) {
410 >
411 >          MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0,
412 >                   atomOrientDataTag, MPI_COMM_WORLD);
413 >          
414 >        }
415 >      
416 >      }
417      }
337  }  
338  outFile.flush();
339  sprintf( checkPointMsg,
340           "Sucessfully took a dump.\n");
341  MPIcheckPoint();
418  
419 < // last  thing last, enable  fatalities.
419 >    sprintf( checkPointMsg,
420 >             "Sucessfully took a dump.\n");
421 >    MPIcheckPoint();        
422 >    
423 >  }
424 >  
425    painCave.isEventLoop = 0;
426  
427   #endif // is_mpi
# Line 352 | Line 433 | void DumpWriter::writeFinal(double finalTime){
433    ofstream finalOut;
434  
435    const int BUFFERSIZE = 2000;
436 +  const int MINIBUFFERSIZE = 100;
437    char tempBuffer[BUFFERSIZE];
438 <  char writeLine[BUFFERSIZE];  
438 >  char writeLine[BUFFERSIZE];
439  
440    double q[4];
441    DirectionalAtom* dAtom;
# Line 361 | Line 443 | void DumpWriter::writeFinal(double finalTime){
443    int i;
444   #ifdef IS_MPI
445    int j, which_node, done, which_atom, local_index;
446 +  double atomTransData[6];
447 +  double atomOrientData[7];
448 +  int isDirectional;
449 +  char* atomTypeString;
450 +  char MPIatomTypeString[MINIBUFFERSIZE];
451 +  int atomTypeTag;
452 +  int atomIsDirectionalTag;
453 +  int atomTransDataTag;
454 +  int atomOrientDataTag;
455   #else //is_mpi
456    int nAtoms = entry_plug->n_atoms;
457   #endif //is_mpi
458 <  
458 >
459    double pos[3], vel[3];
460 <  
460 >
461   #ifdef IS_MPI
462    if(worldRank == 0 ){
463   #endif // is_mpi
464 <    
464 >
465      strcpy( finalName, entry_plug->finalName );
466 <    
466 >
467      finalOut.open( finalName, ios::out | ios::trunc );
468      if( !finalOut ){
469        sprintf( painCave.errMsg,
# Line 381 | Line 472 | void DumpWriter::writeFinal(double finalTime){
472        painCave.isFatal = 1;
473        simError();
474      }
475 <    
475 >
476      // finalOut.setf( ios::scientific );
477 <    
477 >
478   #ifdef IS_MPI
479    }
480 <  
480 >
481    sprintf(checkPointMsg,"Opened file for final configuration\n");
482 <  MPIcheckPoint();  
483 <  
482 >  MPIcheckPoint();
483 >
484   #endif //is_mpi
485  
486 <  
486 >
487   #ifndef IS_MPI
488 <    
488 >
489    finalOut << nAtoms << "\n";
490 <    
490 >
491    finalOut << finalTime << ";\t"
492             << entry_plug->Hmat[0][0] << "\t"
493             << entry_plug->Hmat[1][0] << "\t"
494             << entry_plug->Hmat[2][0] << ";\t"
495 <    
495 >
496             << entry_plug->Hmat[0][1] << "\t"
497             << entry_plug->Hmat[1][1] << "\t"
498             << entry_plug->Hmat[2][1] << ";\t"
499 <    
499 >
500             << entry_plug->Hmat[0][2] << "\t"
501             << entry_plug->Hmat[1][2] << "\t"
502 <           << entry_plug->Hmat[2][2] << ";\n";
503 <  
502 >           << entry_plug->Hmat[2][2] << ";";
503 >
504 >  //write out additional parameters, such as chi and eta
505 >  finalOut << entry_plug->the_integrator->getAdditionalParameters();
506 >  finalOut << endl;
507 >
508    for( i=0; i<nAtoms; i++ ){
509 <      
509 >
510      atoms[i]->getPos(pos);
511      atoms[i]->getVel(vel);
512 <    
512 >
513      sprintf( tempBuffer,
514               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
515               atoms[i]->getType(),
# Line 427 | Line 522 | void DumpWriter::writeFinal(double finalTime){
522      strcpy( writeLine, tempBuffer );
523  
524      if( atoms[i]->isDirectional() ){
525 <        
525 >
526        dAtom = (DirectionalAtom *)atoms[i];
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 444 | Line 539 | void DumpWriter::writeFinal(double finalTime){
539      }
540      else
541        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
542 <      
542 >
543      finalOut << writeLine;
544    }
545    finalOut.flush();
546    finalOut.close();
547  
548   #else // is_mpi
549 <  
549 >
550    // first thing first, suspend fatalities.
551    painCave.isEventLoop = 1;
552  
# Line 462 | Line 557 | void DumpWriter::writeFinal(double finalTime){
557    int *AtomToProcMap = mpiSim->getAtomToProcMap();
558  
559    // write out header and node 0's coordinates
560 <  
466 <  haveError = 0;
560 >
561    if( worldRank == 0 ){
562      finalOut << mpiSim->getTotAtoms() << "\n";
563 <    
563 >
564      finalOut << finalTime << ";\t"
565 <             << entry_plug->Hmat[0][0] << "\t"
566 <             << entry_plug->Hmat[1][0] << "\t"
567 <             << entry_plug->Hmat[2][0] << ";\t"
568 <      
569 <             << entry_plug->Hmat[0][1] << "\t"
570 <             << entry_plug->Hmat[1][1] << "\t"
571 <             << entry_plug->Hmat[2][1] << ";\t"
572 <      
573 <             << entry_plug->Hmat[0][2] << "\t"
574 <             << entry_plug->Hmat[1][2] << "\t"
575 <             << entry_plug->Hmat[2][2] << ";\n";
576 <    
565 >            << entry_plug->Hmat[0][0] << "\t"
566 >            << entry_plug->Hmat[1][0] << "\t"
567 >            << entry_plug->Hmat[2][0] << ";\t"
568 >
569 >            << entry_plug->Hmat[0][1] << "\t"
570 >            << entry_plug->Hmat[1][1] << "\t"
571 >            << entry_plug->Hmat[2][1] << ";\t"
572 >
573 >            << entry_plug->Hmat[0][2] << "\t"
574 >            << entry_plug->Hmat[1][2] << "\t"
575 >            << entry_plug->Hmat[2][2] << ";";
576 >
577 >    finalOut << entry_plug->the_integrator->getAdditionalParameters();
578 >    finalOut << endl;
579 >    finalOut.flush();
580      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
581 <      // Get the Node number which has this molecule:
485 <      
486 <      which_node = AtomToProcMap[i];    
487 <      
488 <      if (which_node == mpiSim->getMyNode()) {
581 >      // Get the Node number which has this atom;
582  
583 +      which_node = AtomToProcMap[i];
584 +
585 +      if (which_node != 0) {
586 +        
587 +        atomTypeTag          = 4*i;
588 +        atomIsDirectionalTag = 4*i + 1;
589 +        atomTransDataTag     = 4*i + 2;
590 +        atomOrientDataTag    = 4*i + 3;
591 +
592 +        MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node,
593 +                 atomTypeTag, MPI_COMM_WORLD, &istatus);
594 +        
595 +        strncpy(atomTypeString, MPIatomTypeString, MINIBUFFERSIZE);
596 +
597 +        MPI_Recv(&isDirectional, 1, MPI_INT, which_node,
598 +                 atomIsDirectionalTag, MPI_COMM_WORLD, &istatus);
599 +        
600 +        MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node,
601 +                 atomTransDataTag, MPI_COMM_WORLD, &istatus);
602 +
603 +        if (isDirectional) {
604 +
605 +          MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node,
606 +                   atomOrientDataTag, MPI_COMM_WORLD, &istatus);
607 +
608 +        }
609 +
610 +      } else {
611 +        
612 +        haveError = 0;
613          which_atom = i;
614 <        local_index=-1;        
614 >        local_index=-1;
615 >
616          for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
617            if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
618          }
495        if (local_index != -1) {    
619  
620 +        if (local_index != -1) {
621 +
622 +          atomTypeString = atoms[local_index]->getType();
623 +
624            atoms[local_index]->getPos(pos);
625            atoms[local_index]->getVel(vel);
626 <          
627 <          sprintf( tempBuffer,
628 <                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
629 <                   atoms[local_index]->getType(),
630 <                   pos[0],
631 <                   pos[1],
632 <                   pos[2],
633 <                   vel[0],
634 <                   vel[1],
635 <                   vel[2]);
636 <          strcpy( writeLine, tempBuffer );
637 <          
638 <          if( atoms[local_index]->isDirectional() ){
639 <            
640 <            dAtom = (DirectionalAtom *)atoms[local_index];
641 <            dAtom->getQ( q );
642 <            
643 <            sprintf( tempBuffer,
644 <                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
645 <                     q[0],
646 <                     q[1],
647 <                     q[2],
648 <                     q[3],
649 <                     dAtom->getJx(),
650 <                     dAtom->getJy(),
651 <                     dAtom->getJz());
652 <            strcat( writeLine, tempBuffer );
653 <          }
654 <          else
528 <            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
529 <        }
530 <        else {
626 >
627 >          atomTransData[0] = pos[0];
628 >          atomTransData[1] = pos[1];
629 >          atomTransData[2] = pos[2];
630 >
631 >          atomTransData[3] = vel[0];
632 >          atomTransData[4] = vel[1];
633 >          atomTransData[5] = vel[2];
634 >          
635 >          isDirectional = 0;
636 >
637 >          if( atoms[local_index]->isDirectional() ){
638 >
639 >            isDirectional = 1;
640 >            
641 >            dAtom = (DirectionalAtom *)atoms[local_index];
642 >            dAtom->getQ( q );
643 >            
644 >            atomOrientData[0] = q[0];
645 >            atomOrientData[1] = q[1];
646 >            atomOrientData[2] = q[2];
647 >            atomOrientData[3] = q[3];
648 >
649 >            atomOrientData[4] = dAtom->getJx();
650 >            atomOrientData[5] = dAtom->getJy();
651 >            atomOrientData[6] = dAtom->getJz();
652 >          }
653 >
654 >        } else {
655            sprintf(painCave.errMsg,
656                    "Atom %d not found on processor %d\n",
657                    i, worldRank );
658            haveError= 1;
659            simError();
660 <        }
660 >        }
661  
662 <        if(haveError) nodeZeroError();
663 <    
664 <      }
541 <      else {
662 >        if(haveError) DieDieDie();
663 >                              
664 >        // If we've survived to here, format the line:
665          
666 <        myStatus = 1;
667 <        MPI_Send(&myStatus, 1, MPI_INT, which_node,
668 <                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
669 <        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
670 <                 MPI_COMM_WORLD);
671 <        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
672 <                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
673 <        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
674 <                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
675 <        
676 <        if(!myStatus) nodeZeroError();
666 >        sprintf( tempBuffer,
667 >                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
668 >                 atomTypeString,
669 >                 atomTransData[0],
670 >                 atomTransData[1],
671 >                 atomTransData[2],
672 >                 atomTransData[3],
673 >                 atomTransData[4],
674 >                 atomTransData[5]);
675 >
676 >        strcpy( writeLine, tempBuffer );
677 >
678 >        if (isDirectional) {
679 >
680 >          sprintf( tempBuffer,
681 >                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
682 >                   atomOrientData[0],
683 >                   atomOrientData[1],
684 >                   atomOrientData[2],
685 >                   atomOrientData[3],
686 >                   atomOrientData[4],
687 >                   atomOrientData[5],
688 >                   atomOrientData[6]);
689 >          strcat( writeLine, tempBuffer );
690 >
691 >        } else {
692 >          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
693 >        }
694 >
695 >        finalOut << writeLine;
696 >        finalOut.flush();
697        }
555      
556      finalOut << writeLine;
698      }
558    
559    // kill everyone off:
560    myStatus = -1;
561    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
562      MPI_Send(&myStatus, 1, MPI_INT, j,
563               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
564    }
699  
700 <  } else {
700 >    finalOut.flush();
701 >    sprintf( checkPointMsg,
702 >             "Sucessfully took a dump.\n");
703 >    MPIcheckPoint();        
704      
705 <    done = 0;
569 <    while (!done) {
705 >  } else {
706  
707 <      MPI_Recv(&myStatus, 1, MPI_INT, 0,
708 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
707 >    // worldRank != 0, so I'm a remote node.  
708 >    
709 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
710        
711 <      if(!myStatus) anonymousNodeDie();
711 >      // Am I the node which has this atom?
712        
713 <      if(myStatus < 0) break;
577 <      
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;        
583 <      for (j=0; j < mpiSim->getMyNlocal(); j++) {
584 <        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
585 <      }
586 <      if (local_index != -1) {
713 >      if (AtomToProcMap[i] == worldRank) {
714  
715 <        atoms[local_index]->getPos(pos);
716 <        atoms[local_index]->getVel(vel);
715 >        local_index=-1;
716 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
717 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
718 >        }
719 >        if (local_index != -1) {
720 >        
721 >          atomTypeString = atoms[local_index]->getType();
722  
723 <        //format the line
724 <        sprintf( tempBuffer,
725 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
726 <                 atoms[local_index]->getType(),
727 <                 pos[0],
728 <                 pos[1],
729 <                 pos[2],
730 <                 vel[0],
731 <                 vel[1],
732 <                 vel[2]); // check here.
733 <        strcpy( writeLine, tempBuffer );
734 <        
735 <        if( atoms[local_index]->isDirectional() ){
736 <          
737 <          dAtom = (DirectionalAtom *)atoms[local_index];
738 <          dAtom->getQ( q );
739 <          
740 <          sprintf( tempBuffer,
741 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
742 <                   q[0],
743 <                   q[1],
744 <                   q[2],
745 <                   q[3],
746 <                   dAtom->getJx(),
747 <                   dAtom->getJy(),
748 <                   dAtom->getJz());
749 <          strcat( writeLine, tempBuffer );
723 >          atoms[local_index]->getPos(pos);
724 >          atoms[local_index]->getVel(vel);
725 >
726 >          atomTransData[0] = pos[0];
727 >          atomTransData[1] = pos[1];
728 >          atomTransData[2] = pos[2];
729 >
730 >          atomTransData[3] = vel[0];
731 >          atomTransData[4] = vel[1];
732 >          atomTransData[5] = vel[2];
733 >          
734 >          isDirectional = 0;
735 >
736 >          if( atoms[local_index]->isDirectional() ){
737 >
738 >            isDirectional = 1;
739 >            
740 >            dAtom = (DirectionalAtom *)atoms[local_index];
741 >            dAtom->getQ( q );
742 >            
743 >            atomOrientData[0] = q[0];
744 >            atomOrientData[1] = q[1];
745 >            atomOrientData[2] = q[2];
746 >            atomOrientData[3] = q[3];
747 >
748 >            atomOrientData[4] = dAtom->getJx();
749 >            atomOrientData[5] = dAtom->getJy();
750 >            atomOrientData[6] = dAtom->getJz();
751 >          }
752 >
753 >        } else {
754 >          sprintf(painCave.errMsg,
755 >                  "Atom %d not found on processor %d\n",
756 >                  i, worldRank );
757 >          haveError= 1;
758 >          simError();
759          }
619        else{
620          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
621        }
622      }
623      else {
624        sprintf(painCave.errMsg,
625                "Atom %d not found on processor %d\n",
626                which_atom, worldRank );
627        myStatus = 0;
628        simError();
629        
630        strcpy( writeLine, "Hello, I'm an error.\n");
631      }
760  
761 <      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
762 <               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
763 <      MPI_Send( &myStatus, 1, MPI_INT, 0,
764 <                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
761 >        // I've survived this far, so send off the data!
762 >
763 >        atomTypeTag          = 4*i;
764 >        atomIsDirectionalTag = 4*i + 1;
765 >        atomTransDataTag     = 4*i + 2;
766 >        atomOrientDataTag    = 4*i + 3;
767 >
768 >        strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
769 >
770 >        MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
771 >                 atomTypeTag, MPI_COMM_WORLD);
772 >        
773 >        MPI_Send(&isDirectional, 1, MPI_INT, 0,
774 >                 atomIsDirectionalTag, MPI_COMM_WORLD);
775 >        
776 >        MPI_Send(atomTransData, 6, MPI_DOUBLE, 0,
777 >                 atomTransDataTag, MPI_COMM_WORLD);
778 >
779 >        if (isDirectional) {
780 >
781 >          MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0,
782 >                   atomOrientDataTag, MPI_COMM_WORLD);
783 >          
784 >        }
785 >      
786 >      }
787      }
788 +
789 +    sprintf( checkPointMsg,
790 +             "Sucessfully wrote final file.\n");
791 +    MPIcheckPoint();        
792 +    
793    }
639  finalOut.flush();
640  sprintf( checkPointMsg,
641           "Sucessfully took a dump.\n");
642  MPIcheckPoint();
794    
795 <  if( worldRank == 0 ) finalOut.close();    
795 >  painCave.isEventLoop = 0;
796 >
797 >  if( worldRank == 0 ) finalOut.close();
798   #endif // is_mpi
799   }
800  
# Line 651 | Line 804 | void dWrite::nodeZeroError( void ){
804  
805   // a couple of functions to let us escape the write loop
806  
807 < void dWrite::nodeZeroError( void ){
655 <  int j, myStatus;
656 <  
657 <  myStatus = 0;
658 <  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
659 <    MPI_Send( &myStatus, 1, MPI_INT, j,
660 <              TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
661 <  }  
662 <  
807 > void dWrite::DieDieDie( void ){
808  
809    MPI_Finalize();
810    exit (0);
666  
811   }
812  
669 void dWrite::anonymousNodeDie( void ){
670
671  MPI_Finalize();
672  exit (0);
673 }
674
813   #endif //is_mpi

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines