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 910 by gezelter, Thu Jan 8 18:05:37 2004 UTC vs.
Revision 929 by tim, Tue Jan 13 15:46:49 2004 UTC

# Line 3 | Line 3
3   #include <string.h>
4   #include <iostream>
5   #include <fstream>
6 + #include <algorithm>
7 + #include <utility>
8  
9   #ifdef IS_MPI
10   #include <mpi.h>
# Line 26 | Line 28 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
28    if(worldRank == 0 ){
29   #endif // is_mpi
30  
29    strcpy( outName, entry_plug->sampleName );
31  
32 <    outFile.open(outName, ios::out | ios::trunc );
32 >    dumpFile.open(entry_plug->sampleName, ios::out | ios::trunc );
33  
34 <    if( !outFile ){
34 >    if( !dumpFile ){
35  
36        sprintf( painCave.errMsg,
37                 "Could not open \"%s\" for dump output.\n",
38 <               outName);
38 >               entry_plug->sampleName);
39        painCave.isFatal = 1;
40        simError();
41      }
# Line 44 | Line 45 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
45   #ifdef IS_MPI
46    }
47  
48 +  //sort the local atoms by global index
49 +  sortByGlobalIndex();
50 +  
51    sprintf( checkPointMsg,
52             "Sucessfully opened output file for dumping.\n");
53    MPIcheckPoint();
# Line 56 | Line 60 | DumpWriter::~DumpWriter( ){
60    if(worldRank == 0 ){
61   #endif // is_mpi
62  
63 <    outFile.close();
63 >    dumpFile.close();
64  
65   #ifdef IS_MPI
66    }
67   #endif // is_mpi
68   }
69  
70 < void DumpWriter::writeDump( double currentTime ){
70 > #ifdef IS_MPI
71  
72 + /**
73 + * A hook function to load balancing
74 + */
75 +
76 + void DumpWriter::update(){
77 +  sortByGlobalIndex();          
78 + }
79 +  
80 + /**
81 + * Auxiliary sorting function
82 + */
83 +
84 + bool indexSortingCriterion(const pair<int, int>& p1, const pair<int, int>& p2){
85 +  return p1.second < p2.second;
86 + }
87 +
88 + /**
89 + * Sorting the local index by global index
90 + */
91 +
92 + void DumpWriter::sortByGlobalIndex(){
93 +  Atom** atoms = entry_plug->atoms;
94 +  
95 +  indexArray.clear();
96 +  
97 +  for(int i = 0; i < mpiSim->getMyNlocal();i++)
98 +    indexArray.push_back(make_pair(i, atoms[i]->getGlobalIndex()));
99 +  
100 +  sort(indexArray.begin(), indexArray.end(), indexSortingCriterion);    
101 + }
102 + #endif
103 +
104 + void DumpWriter::writeDump(double currentTime){
105 +  
106 + // write to eor file
107 +  writeFinal(currentTime);
108 +
109 + //write to dump file
110 +  writeFrame(dumpFile, currentTime);
111 +        
112 + }
113 +
114 + void DumpWriter::writeFinal(double currentTime){
115 +
116 +  ofstream finalOut;    
117 +  
118 +  //Open eor file
119 + #ifdef IS_MPI
120 +  if(worldRank == 0 ){
121 + #endif // is_mpi
122 +
123 +    finalOut.open( entry_plug->finalName, ios::out | ios::trunc );
124 +    if( !finalOut ){
125 +      sprintf( painCave.errMsg,
126 +               "Could not open \"%s\" for final dump output.\n",
127 +               entry_plug->finalName );
128 +      painCave.isFatal = 1;
129 +      simError();
130 +    }
131 +    
132 + #ifdef IS_MPI
133 +  }
134 + #endif
135 +  
136 +  //write to eor file  
137 +  writeFrame(finalOut, currentTime);
138 +  
139 +  //close eor file      
140 + #ifdef IS_MPI
141 +  if(worldRank == 0 ){
142 +    finalOut.close();
143 +  }
144 + #endif // is_mpi
145 +
146 + }
147 +
148 + void DumpWriter::writeFrame( ofstream& outFile, double currentTime ){
149 +
150    const int BUFFERSIZE = 2000;
151 <  const int MINIBUFFERSIZE = 10;
151 >  const int MINIBUFFERSIZE = 100;
152  
153    char tempBuffer[BUFFERSIZE];
154    char writeLine[BUFFERSIZE];
155  
156    int i;
157 +
158   #ifdef IS_MPI
159 <  int j, which_node, done, which_atom, local_index;
160 <  double atomTransData[6];
161 <  double atomOrientData[7];
159 >  
160 >  int *potatoes;
161 >  int myPotato;
162 >
163 >  int nProc;
164 >  int j, which_node, done, which_atom, local_index, currentIndex;
165 >  double atomData6[6];
166 >  double atomData13[13];
167    int isDirectional;
168    char* atomTypeString;
169    char MPIatomTypeString[MINIBUFFERSIZE];
170 <  int me;
83 <  int atomTypeTag;
84 <  int atomIsDirectionalTag;
85 <  int atomTransDataTag;
86 <  int atomOrientDataTag;
170 >
171   #else //is_mpi
172    int nAtoms = entry_plug->n_atoms;
173   #endif //is_mpi
# Line 93 | Line 177 | void DumpWriter::writeDump( double currentTime ){
177    Atom** atoms = entry_plug->atoms;
178    double pos[3], vel[3];
179  
96  // write current frame to the eor file
97
98  this->writeFinal( currentTime );
99
180   #ifndef IS_MPI
181  
182    outFile << nAtoms << "\n";
# Line 154 | Line 234 | void DumpWriter::writeDump( double currentTime ){
234  
235      outFile << writeLine;
236    }
157  outFile.flush();
237  
238   #else // is_mpi
239  
240 <  // first thing first, suspend fatalities.
241 <  painCave.isEventLoop = 1;
240 >  /* code to find maximum tag value */
241 >  
242 >  int *tagub, flag, MAXTAG;
243 >  MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag);
244 >  if (flag) {
245 >    MAXTAG = *tagub;
246 >  } else {
247 >    MAXTAG = 32767;
248 >  }  
249  
164  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
250    int haveError;
251  
252    MPI_Status istatus;
# Line 170 | Line 255 | void DumpWriter::writeDump( double currentTime ){
255    // write out header and node 0's coordinates
256  
257    if( worldRank == 0 ){
258 +
259 +    // Node 0 needs a list of the magic potatoes for each processor;
260 +
261 +    nProc = mpiSim->getNumberProcessors();
262 +    potatoes = new int[nProc];
263 +
264 +    for (i = 0; i < nProc; i++)
265 +      potatoes[i] = 0;
266 +    
267      outFile << mpiSim->getTotAtoms() << "\n";
268  
269      outFile << currentTime << ";\t"
# Line 188 | Line 282 | void DumpWriter::writeDump( double currentTime ){
282      outFile << entry_plug->the_integrator->getAdditionalParameters();
283      outFile << endl;
284      outFile.flush();
285 +    
286 +    currentIndex = 0;
287      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
288 +      
289        // Get the Node number which has this atom;
290 <
290 >      
291        which_node = AtomToProcMap[i];
292 <
292 >      
293        if (which_node != 0) {
197        
198        atomTypeTag          = 4*i;
199        atomIsDirectionalTag = 4*i + 1;
200        atomTransDataTag     = 4*i + 2;
201        atomOrientDataTag    = 4*i + 3;
294  
295 +        if (potatoes[which_node] + 3 >= MAXTAG) {
296 +          // The potato was going to exceed the maximum value,
297 +          // so wrap this processor potato back to 0:        
298 +
299 +          potatoes[which_node] = 0;          
300 +          MPI_Send(0, 1, MPI_INT, which_node, 0, MPI_COMM_WORLD);
301 +          
302 +        }
303 +
304 +        myPotato = potatoes[which_node];        
305 +        
306          MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node,
307 <                 atomTypeTag, MPI_COMM_WORLD, &istatus);
307 >                 myPotato, MPI_COMM_WORLD, &istatus);
308          
309 <        strncpy(atomTypeString, MPIatomTypeString, MINIBUFFERSIZE);
309 >        atomTypeString = MPIatomTypeString;
310 >        
311 >        myPotato++;
312  
313          MPI_Recv(&isDirectional, 1, MPI_INT, which_node,
314 <                 atomIsDirectionalTag, MPI_COMM_WORLD, &istatus);
315 <        
316 <        MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node,
212 <                 atomTransDataTag, MPI_COMM_WORLD, &istatus);
314 >                 myPotato, MPI_COMM_WORLD, &istatus);
315 >              
316 >        myPotato++;
317  
318 <        if (isDirectional) {
319 <
320 <          MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node,
321 <                   atomOrientDataTag, MPI_COMM_WORLD, &istatus);
322 <
318 >        if (isDirectional) {          
319 >          MPI_Recv(atomData13, 13, MPI_DOUBLE, which_node,
320 >                   myPotato, MPI_COMM_WORLD, &istatus);
321 >        } else {
322 >          MPI_Recv(atomData6, 6, MPI_DOUBLE, which_node,
323 >                   myPotato, MPI_COMM_WORLD, &istatus);          
324          }
325 +        
326 +        myPotato++;
327 +        potatoes[which_node] = myPotato;
328  
329        } else {
330          
331          haveError = 0;
332          which_atom = i;
333 <        local_index=-1;
334 <
335 <        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
336 <          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
337 <        }
230 <
231 <        if (local_index != -1) {
232 <
333 >        
334 >        local_index = indexArray[currentIndex].first;        
335 >                
336 >        if (which_atom == indexArray[currentIndex].second) {
337 >          
338            atomTypeString = atoms[local_index]->getType();
339  
340            atoms[local_index]->getPos(pos);
341 <          atoms[local_index]->getVel(vel);
341 >          atoms[local_index]->getVel(vel);          
342  
343 <          atomTransData[0] = pos[0];
344 <          atomTransData[1] = pos[1];
345 <          atomTransData[2] = pos[2];
343 >          atomData6[0] = pos[0];
344 >          atomData6[1] = pos[1];
345 >          atomData6[2] = pos[2];
346  
347 <          atomTransData[3] = vel[0];
348 <          atomTransData[4] = vel[1];
349 <          atomTransData[5] = vel[2];
347 >          atomData6[3] = vel[0];
348 >          atomData6[4] = vel[1];
349 >          atomData6[5] = vel[2];
350            
351            isDirectional = 0;
352  
# Line 251 | Line 356 | void DumpWriter::writeDump( double currentTime ){
356              
357              dAtom = (DirectionalAtom *)atoms[local_index];
358              dAtom->getQ( q );
254            
255            atomOrientData[0] = q[0];
256            atomOrientData[1] = q[1];
257            atomOrientData[2] = q[2];
258            atomOrientData[3] = q[3];
359  
360 <            atomOrientData[4] = dAtom->getJx();
361 <            atomOrientData[5] = dAtom->getJy();
362 <            atomOrientData[6] = dAtom->getJz();
360 >            for (int j = 0; j < 6 ; j++)
361 >              atomData13[j] = atomData6[j];            
362 >            
363 >            atomData13[6] = q[0];
364 >            atomData13[7] = q[1];
365 >            atomData13[8] = q[2];
366 >            atomData13[9] = q[3];
367 >            
368 >            atomData13[10] = dAtom->getJx();
369 >            atomData13[11] = dAtom->getJy();
370 >            atomData13[12] = dAtom->getJz();
371            }
372 <
372 >          
373          } else {
374            sprintf(painCave.errMsg,
375                    "Atom %d not found on processor %d\n",
# Line 269 | Line 377 | void DumpWriter::writeDump( double currentTime ){
377            haveError= 1;
378            simError();
379          }
380 <
380 >        
381          if(haveError) DieDieDie();
274                              
275        // If we've survived to here, format the line:
382          
383 <        sprintf( tempBuffer,
384 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
385 <                 atomTypeString,
386 <                 atomTransData[0],
387 <                 atomTransData[1],
388 <                 atomTransData[2],
389 <                 atomTransData[3],
390 <                 atomTransData[4],
391 <                 atomTransData[5]);
383 >        currentIndex ++;
384 >      }
385 >      // If we've survived to here, format the line:
386 >      
387 >      if (!isDirectional) {
388 >        
389 >        sprintf( writeLine,
390 >                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
391 >                 atomTypeString,
392 >                 atomData6[0],
393 >                 atomData6[1],
394 >                 atomData6[2],
395 >                 atomData6[3],
396 >                 atomData6[4],
397 >                 atomData6[5]);
398  
399 <        strcpy( writeLine, tempBuffer );
400 <
401 <        if (isDirectional) {
402 <
403 <          sprintf( tempBuffer,
404 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
405 <                   atomOrientData[0],
406 <                   atomOrientData[1],
407 <                   atomOrientData[2],
408 <                   atomOrientData[3],
409 <                   atomOrientData[4],
410 <                   atomOrientData[5],
411 <                   atomOrientData[6]);
412 <          strcat( writeLine, tempBuffer );
413 <
414 <        } else {
415 <          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
416 <        }
417 <
418 <        outFile << writeLine;
419 <        outFile.flush();
399 >        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
400 >        
401 >      } else {
402 >        
403 >        sprintf( writeLine,
404 >                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
405 >                 atomTypeString,
406 >                 atomData13[0],
407 >                 atomData13[1],
408 >                 atomData13[2],
409 >                 atomData13[3],
410 >                 atomData13[4],
411 >                 atomData13[5],
412 >                 atomData13[6],
413 >                 atomData13[7],
414 >                 atomData13[8],
415 >                 atomData13[9],
416 >                 atomData13[10],
417 >                 atomData13[11],
418 >                 atomData13[12]);
419 >        
420        }
421 +      
422 +      outFile << writeLine;
423      }
424 +    
425  
426      outFile.flush();
427      sprintf( checkPointMsg,
428               "Sucessfully took a dump.\n");
429      MPIcheckPoint();        
430 <    
430 >    delete[] potatoes;
431    } else {
432  
433      // worldRank != 0, so I'm a remote node.  
434 +
435 +    // Set my magic potato to 0:
436 +
437 +    myPotato = 0;
438 +    currentIndex = 0;
439      
440      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
441        
# Line 323 | Line 443 | void DumpWriter::writeDump( double currentTime ){
443        
444        if (AtomToProcMap[i] == worldRank) {
445  
446 <        local_index=-1;
447 <        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
448 <          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
446 >        if (myPotato + 3 >= MAXTAG) {
447 >
448 >          // The potato was going to exceed the maximum value,
449 >          // so wrap this processor potato back to 0 (and block until
450 >          // node 0 says we can go:
451 >
452 >          MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus);
453 >          
454          }
455 <        if (local_index != -1) {
455 >        which_atom = i;
456 >        local_index = indexArray[currentIndex].first;        
457 >                
458 >        if (which_atom == indexArray[currentIndex].second) {
459          
460            atomTypeString = atoms[local_index]->getType();
461  
462            atoms[local_index]->getPos(pos);
463            atoms[local_index]->getVel(vel);
464  
465 <          atomTransData[0] = pos[0];
466 <          atomTransData[1] = pos[1];
467 <          atomTransData[2] = pos[2];
465 >          atomData6[0] = pos[0];
466 >          atomData6[1] = pos[1];
467 >          atomData6[2] = pos[2];
468  
469 <          atomTransData[3] = vel[0];
470 <          atomTransData[4] = vel[1];
471 <          atomTransData[5] = vel[2];
469 >          atomData6[3] = vel[0];
470 >          atomData6[4] = vel[1];
471 >          atomData6[5] = vel[2];
472            
473            isDirectional = 0;
474  
# Line 351 | Line 479 | void DumpWriter::writeDump( double currentTime ){
479              dAtom = (DirectionalAtom *)atoms[local_index];
480              dAtom->getQ( q );
481              
482 <            atomOrientData[0] = q[0];
483 <            atomOrientData[1] = q[1];
484 <            atomOrientData[2] = q[2];
485 <            atomOrientData[3] = q[3];
482 >            for (int j = 0; j < 6 ; j++)
483 >              atomData13[j] = atomData6[j];
484 >            
485 >            atomData13[6] = q[0];
486 >            atomData13[7] = q[1];
487 >            atomData13[8] = q[2];
488 >            atomData13[9] = q[3];
489  
490 <            atomOrientData[4] = dAtom->getJx();
491 <            atomOrientData[5] = dAtom->getJy();
492 <            atomOrientData[6] = dAtom->getJz();
490 >            atomData13[10] = dAtom->getJx();
491 >            atomData13[11] = dAtom->getJy();
492 >            atomData13[12] = dAtom->getJz();
493            }
494  
495          } else {
# Line 369 | Line 500 | void DumpWriter::writeDump( double currentTime ){
500            simError();
501          }
502  
372        // I've survived this far, so send off the data!
373
374        atomTypeTag          = 4*i;
375        atomIsDirectionalTag = 4*i + 1;
376        atomTransDataTag     = 4*i + 2;
377        atomOrientDataTag    = 4*i + 3;
378
379
503          strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
504  
505 +        // null terminate the string before sending (just in case):
506 +        MPIatomTypeString[MINIBUFFERSIZE-1] = '\0';
507 +
508          MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
509 <                 atomTypeTag, MPI_COMM_WORLD);
509 >                 myPotato, MPI_COMM_WORLD);
510          
511 +        myPotato++;
512 +
513          MPI_Send(&isDirectional, 1, MPI_INT, 0,
514 <                 atomIsDirectionalTag, MPI_COMM_WORLD);
514 >                 myPotato, MPI_COMM_WORLD);
515          
516 <        MPI_Send(atomTransData, 6, MPI_DOUBLE, 0,
517 <                 atomTransDataTag, MPI_COMM_WORLD);
390 <
516 >        myPotato++;
517 >        
518          if (isDirectional) {
519  
520 <          MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0,
521 <                   atomOrientDataTag, MPI_COMM_WORLD);
520 >          MPI_Send(atomData13, 13, MPI_DOUBLE, 0,
521 >                   myPotato, MPI_COMM_WORLD);
522            
396        }
397      
398      }
399    }
400
401    sprintf( checkPointMsg,
402             "Sucessfully took a dump.\n");
403    MPIcheckPoint();        
404    
405  }
406  
407  painCave.isEventLoop = 0;
408
409 #endif // is_mpi
410 }
411
412 void DumpWriter::writeFinal(double finalTime){
413
414  char finalName[500];
415  ofstream finalOut;
416
417  const int BUFFERSIZE = 2000;
418  const int MINIBUFFERSIZE = 10;
419  char tempBuffer[BUFFERSIZE];
420  char writeLine[BUFFERSIZE];
421
422  double q[4];
423  DirectionalAtom* dAtom;
424  Atom** atoms = entry_plug->atoms;
425  int i;
426 #ifdef IS_MPI
427  int j, which_node, done, which_atom, local_index;
428  double atomTransData[6];
429  double atomOrientData[7];
430  int isDirectional;
431  char* atomTypeString;
432  char MPIatomTypeString[MINIBUFFERSIZE];
433  int atomTypeTag;
434  int atomIsDirectionalTag;
435  int atomTransDataTag;
436  int atomOrientDataTag;
437 #else //is_mpi
438  int nAtoms = entry_plug->n_atoms;
439 #endif //is_mpi
440
441  double pos[3], vel[3];
442
443 #ifdef IS_MPI
444  if(worldRank == 0 ){
445 #endif // is_mpi
446
447    strcpy( finalName, entry_plug->finalName );
448
449    finalOut.open( finalName, ios::out | ios::trunc );
450    if( !finalOut ){
451      sprintf( painCave.errMsg,
452               "Could not open \"%s\" for final dump output.\n",
453               finalName );
454      painCave.isFatal = 1;
455      simError();
456    }
457
458    // finalOut.setf( ios::scientific );
459
460 #ifdef IS_MPI
461  }
462
463  sprintf(checkPointMsg,"Opened file for final configuration\n");
464  MPIcheckPoint();
465
466 #endif //is_mpi
467
468
469 #ifndef IS_MPI
470
471  finalOut << nAtoms << "\n";
472
473  finalOut << finalTime << ";\t"
474           << entry_plug->Hmat[0][0] << "\t"
475           << entry_plug->Hmat[1][0] << "\t"
476           << entry_plug->Hmat[2][0] << ";\t"
477
478           << entry_plug->Hmat[0][1] << "\t"
479           << entry_plug->Hmat[1][1] << "\t"
480           << entry_plug->Hmat[2][1] << ";\t"
481
482           << entry_plug->Hmat[0][2] << "\t"
483           << entry_plug->Hmat[1][2] << "\t"
484           << entry_plug->Hmat[2][2] << ";";
485
486  //write out additional parameters, such as chi and eta
487  finalOut << entry_plug->the_integrator->getAdditionalParameters();
488  finalOut << endl;
489
490  for( i=0; i<nAtoms; i++ ){
491
492    atoms[i]->getPos(pos);
493    atoms[i]->getVel(vel);
494
495    sprintf( tempBuffer,
496             "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
497             atoms[i]->getType(),
498             pos[0],
499             pos[1],
500             pos[2],
501             vel[0],
502             vel[1],
503             vel[2]);
504    strcpy( writeLine, tempBuffer );
505
506    if( atoms[i]->isDirectional() ){
507
508      dAtom = (DirectionalAtom *)atoms[i];
509      dAtom->getQ( q );
510
511      sprintf( tempBuffer,
512               "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
513               q[0],
514               q[1],
515               q[2],
516               q[3],
517               dAtom->getJx(),
518               dAtom->getJy(),
519               dAtom->getJz());
520      strcat( writeLine, tempBuffer );
521    }
522    else
523      strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
524
525    finalOut << writeLine;
526  }
527  finalOut.flush();
528  finalOut.close();
529
530 #else // is_mpi
531
532  // first thing first, suspend fatalities.
533  painCave.isEventLoop = 1;
534
535  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
536  int haveError;
537
538  MPI_Status istatus;
539  int *AtomToProcMap = mpiSim->getAtomToProcMap();
540
541  // write out header and node 0's coordinates
542
543  if( worldRank == 0 ){
544    finalOut << mpiSim->getTotAtoms() << "\n";
545
546    finalOut << finalTime << ";\t"
547            << entry_plug->Hmat[0][0] << "\t"
548            << entry_plug->Hmat[1][0] << "\t"
549            << entry_plug->Hmat[2][0] << ";\t"
550
551            << entry_plug->Hmat[0][1] << "\t"
552            << entry_plug->Hmat[1][1] << "\t"
553            << entry_plug->Hmat[2][1] << ";\t"
554
555            << entry_plug->Hmat[0][2] << "\t"
556            << entry_plug->Hmat[1][2] << "\t"
557            << entry_plug->Hmat[2][2] << ";";
558
559    finalOut << entry_plug->the_integrator->getAdditionalParameters();
560    finalOut << endl;
561    finalOut.flush();
562    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
563      // Get the Node number which has this atom;
564
565      which_node = AtomToProcMap[i];
566
567      if (which_node != 0) {
568        
569        atomTypeTag          = 4*i;
570        atomIsDirectionalTag = 4*i + 1;
571        atomTransDataTag     = 4*i + 2;
572        atomOrientDataTag    = 4*i + 3;
573
574        MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node,
575                 atomTypeTag, MPI_COMM_WORLD, &istatus);
576        
577        strncpy(atomTypeString, MPIatomTypeString, MINIBUFFERSIZE);
578
579        MPI_Recv(&isDirectional, 1, MPI_INT, which_node,
580                 atomIsDirectionalTag, MPI_COMM_WORLD, &istatus);
581        
582        MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node,
583                 atomTransDataTag, MPI_COMM_WORLD, &istatus);
584
585        if (isDirectional) {
586
587          MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node,
588                   atomOrientDataTag, MPI_COMM_WORLD, &istatus);
589
590        }
591
592      } else {
593        
594        haveError = 0;
595        which_atom = i;
596        local_index=-1;
597
598        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
599          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
600        }
601
602        if (local_index != -1) {
603
604          atomTypeString = atoms[local_index]->getType();
605
606          atoms[local_index]->getPos(pos);
607          atoms[local_index]->getVel(vel);
608
609          atomTransData[0] = pos[0];
610          atomTransData[1] = pos[1];
611          atomTransData[2] = pos[2];
612
613          atomTransData[3] = vel[0];
614          atomTransData[4] = vel[1];
615          atomTransData[5] = vel[2];
616          
617          isDirectional = 0;
618
619          if( atoms[local_index]->isDirectional() ){
620
621            isDirectional = 1;
622            
623            dAtom = (DirectionalAtom *)atoms[local_index];
624            dAtom->getQ( q );
625            
626            atomOrientData[0] = q[0];
627            atomOrientData[1] = q[1];
628            atomOrientData[2] = q[2];
629            atomOrientData[3] = q[3];
630
631            atomOrientData[4] = dAtom->getJx();
632            atomOrientData[5] = dAtom->getJy();
633            atomOrientData[6] = dAtom->getJz();
634          }
635
523          } else {
637          sprintf(painCave.errMsg,
638                  "Atom %d not found on processor %d\n",
639                  i, worldRank );
640          haveError= 1;
641          simError();
642        }
524  
525 <        if(haveError) DieDieDie();
526 <                              
646 <        // If we've survived to here, format the line:
647 <        
648 <        sprintf( tempBuffer,
649 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
650 <                 atomTypeString,
651 <                 atomTransData[0],
652 <                 atomTransData[1],
653 <                 atomTransData[2],
654 <                 atomTransData[3],
655 <                 atomTransData[4],
656 <                 atomTransData[5]);
657 <
658 <        strcpy( writeLine, tempBuffer );
659 <
660 <        if (isDirectional) {
661 <
662 <          sprintf( tempBuffer,
663 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
664 <                   atomOrientData[0],
665 <                   atomOrientData[1],
666 <                   atomOrientData[2],
667 <                   atomOrientData[3],
668 <                   atomOrientData[4],
669 <                   atomOrientData[5],
670 <                   atomOrientData[6]);
671 <          strcat( writeLine, tempBuffer );
672 <
673 <        } else {
674 <          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
525 >          MPI_Send(atomData6, 6, MPI_DOUBLE, 0,
526 >                   myPotato, MPI_COMM_WORLD);
527          }
528  
529 <        finalOut << writeLine;
530 <        finalOut.flush();
529 >        myPotato++;  
530 >        currentIndex++;    
531        }
532      }
533  
682    finalOut.flush();
534      sprintf( checkPointMsg,
535               "Sucessfully took a dump.\n");
536      MPIcheckPoint();        
537      
538 <  } else {
688 <
689 <    // worldRank != 0, so I'm a remote node.  
690 <    
691 <    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
692 <      
693 <      // Am I the node which has this atom?
694 <      
695 <      if (AtomToProcMap[i] == worldRank) {
696 <
697 <        local_index=-1;
698 <        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
699 <          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
700 <        }
701 <        if (local_index != -1) {
702 <        
703 <          atomTypeString = atoms[local_index]->getType();
704 <
705 <          atoms[local_index]->getPos(pos);
706 <          atoms[local_index]->getVel(vel);
707 <
708 <          atomTransData[0] = pos[0];
709 <          atomTransData[1] = pos[1];
710 <          atomTransData[2] = pos[2];
711 <
712 <          atomTransData[3] = vel[0];
713 <          atomTransData[4] = vel[1];
714 <          atomTransData[5] = vel[2];
715 <          
716 <          isDirectional = 0;
717 <
718 <          if( atoms[local_index]->isDirectional() ){
719 <
720 <            isDirectional = 1;
721 <            
722 <            dAtom = (DirectionalAtom *)atoms[local_index];
723 <            dAtom->getQ( q );
724 <            
725 <            atomOrientData[0] = q[0];
726 <            atomOrientData[1] = q[1];
727 <            atomOrientData[2] = q[2];
728 <            atomOrientData[3] = q[3];
729 <
730 <            atomOrientData[4] = dAtom->getJx();
731 <            atomOrientData[5] = dAtom->getJy();
732 <            atomOrientData[6] = dAtom->getJz();
733 <          }
734 <
735 <        } else {
736 <          sprintf(painCave.errMsg,
737 <                  "Atom %d not found on processor %d\n",
738 <                  i, worldRank );
739 <          haveError= 1;
740 <          simError();
741 <        }
742 <
743 <        // I've survived this far, so send off the data!
744 <
745 <        atomTypeTag          = 4*i;
746 <        atomIsDirectionalTag = 4*i + 1;
747 <        atomTransDataTag     = 4*i + 2;
748 <        atomOrientDataTag    = 4*i + 3;
749 <
750 <        strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
751 <
752 <        MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
753 <                 atomTypeTag, MPI_COMM_WORLD);
754 <        
755 <        MPI_Send(&isDirectional, 1, MPI_INT, 0,
756 <                 atomIsDirectionalTag, MPI_COMM_WORLD);
757 <        
758 <        MPI_Send(atomTransData, 6, MPI_DOUBLE, 0,
759 <                 atomTransDataTag, MPI_COMM_WORLD);
760 <
761 <        if (isDirectional) {
762 <
763 <          MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0,
764 <                   atomOrientDataTag, MPI_COMM_WORLD);
765 <          
766 <        }
767 <      
768 <      }
769 <    }
770 <
771 <    sprintf( checkPointMsg,
772 <             "Sucessfully wrote final file.\n");
773 <    MPIcheckPoint();        
774 <    
775 <  }
538 >  }
539    
777  painCave.isEventLoop = 0;
778
779  if( worldRank == 0 ) finalOut.close();
540   #endif // is_mpi
541   }
542  
783
784
543   #ifdef IS_MPI
544  
545   // a couple of functions to let us escape the write loop

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines