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 912 by gezelter, Thu Jan 8 18:59:36 2004 UTC vs.
Revision 934 by tim, Tue Jan 13 20:04:28 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      }
42  
43 <    //outFile.setf( ios::scientific );
43 >    finalOut.open( entry_plug->finalName, ios::out | ios::trunc );
44 >    if( !finalOut ){
45 >      sprintf( painCave.errMsg,
46 >               "Could not open \"%s\" for final dump output.\n",
47 >               entry_plug->finalName );
48 >      painCave.isFatal = 1;
49 >      simError();
50 >    }
51  
52   #ifdef IS_MPI
53    }
54  
55 +  //sort the local atoms by global index
56 +  sortByGlobalIndex();
57 +  
58    sprintf( checkPointMsg,
59             "Sucessfully opened output file for dumping.\n");
60    MPIcheckPoint();
# Line 56 | Line 67 | DumpWriter::~DumpWriter( ){
67    if(worldRank == 0 ){
68   #endif // is_mpi
69  
70 <    outFile.close();
70 >    dumpFile.close();
71 >    finalOut.close();
72  
73   #ifdef IS_MPI
74    }
75   #endif // is_mpi
76   }
77  
78 < void DumpWriter::writeDump( double currentTime ){
78 > #ifdef IS_MPI
79  
80 + /**
81 + * A hook function to load balancing
82 + */
83 +
84 + void DumpWriter::update(){
85 +  sortByGlobalIndex();          
86 + }
87 +  
88 + /**
89 + * Auxiliary sorting function
90 + */
91 +
92 + bool indexSortingCriterion(const pair<int, int>& p1, const pair<int, int>& p2){
93 +  return p1.second < p2.second;
94 + }
95 +
96 + /**
97 + * Sorting the local index by global index
98 + */
99 +
100 + void DumpWriter::sortByGlobalIndex(){
101 +  Atom** atoms = entry_plug->atoms;
102 +  
103 +  indexArray.clear();
104 +  
105 +  for(int i = 0; i < mpiSim->getMyNlocal();i++)
106 +    indexArray.push_back(make_pair(i, atoms[i]->getGlobalIndex()));
107 +  
108 +  sort(indexArray.begin(), indexArray.end(), indexSortingCriterion);    
109 + }
110 + #endif
111 +
112 + void DumpWriter::writeDump(double currentTime){
113 +
114 +  vector<ofstream*> fileStreams;
115 +
116 + #ifdef IS_MPI
117 +  if(worldRank == 0 ){
118 +    finalOut.seekp(0);
119 +  }
120 + #endif // is_mpi
121 +
122 +  fileStreams.push_back(&finalOut);
123 +  fileStreams.push_back(&dumpFile);
124 +
125 +  writeFrame(fileStreams, currentTime);
126 +        
127 + }
128 +
129 + void DumpWriter::writeFinal(double currentTime){
130 +
131 +  vector<ofstream*> fileStreams;
132 +
133 + #ifdef IS_MPI
134 +  if(worldRank == 0 ){
135 +    finalOut.seekp(0);
136 +  }
137 + #endif // is_mpi
138 +  
139 +  fileStreams.push_back(&finalOut);  
140 +  writeFrame(fileStreams, currentTime);
141 +  
142 + }
143 +
144 + void DumpWriter::writeFrame( vector<ofstream*>& outFile, double currentTime ){
145 +
146    const int BUFFERSIZE = 2000;
147    const int MINIBUFFERSIZE = 100;
148  
149    char tempBuffer[BUFFERSIZE];
150    char writeLine[BUFFERSIZE];
151  
152 <  int i;
152 >  int i, k;
153 >
154   #ifdef IS_MPI
155 <  int j, which_node, done, which_atom, local_index;
156 <  double atomTransData[6];
157 <  double atomOrientData[7];
155 >  
156 >  int *potatoes;
157 >  int myPotato;
158 >
159 >  int nProc;
160 >  int j, which_node, done, which_atom, local_index, currentIndex;
161 >  double atomData6[6];
162 >  double atomData13[13];
163    int isDirectional;
164    char* atomTypeString;
165    char MPIatomTypeString[MINIBUFFERSIZE];
166 <  int me;
83 <  int atomTypeTag;
84 <  int atomIsDirectionalTag;
85 <  int atomTransDataTag;
86 <  int atomOrientDataTag;
166 >
167   #else //is_mpi
168    int nAtoms = entry_plug->n_atoms;
169   #endif //is_mpi
# Line 93 | Line 173 | void DumpWriter::writeDump( double currentTime ){
173    Atom** atoms = entry_plug->atoms;
174    double pos[3], vel[3];
175  
96  // write current frame to the eor file
97
98  this->writeFinal( currentTime );
99
176   #ifndef IS_MPI
177 +  
178 +  for(k = 0; k < outFile.size(); k++){
179 +    *outFile[k] << nAtoms << "\n";
180  
181 <  outFile << nAtoms << "\n";
181 >    *outFile[k] << currentTime << ";\t"
182 >               << entry_plug->Hmat[0][0] << "\t"
183 >                     << entry_plug->Hmat[1][0] << "\t"
184 >                     << entry_plug->Hmat[2][0] << ";\t"
185 >              
186 >               << entry_plug->Hmat[0][1] << "\t"
187 >                     << entry_plug->Hmat[1][1] << "\t"
188 >                     << entry_plug->Hmat[2][1] << ";\t"
189  
190 <  outFile << currentTime << ";\t"
191 <          << entry_plug->Hmat[0][0] << "\t"
192 <          << entry_plug->Hmat[1][0] << "\t"
107 <          << entry_plug->Hmat[2][0] << ";\t"
190 >                     << entry_plug->Hmat[0][2] << "\t"
191 >                     << entry_plug->Hmat[1][2] << "\t"
192 >                     << entry_plug->Hmat[2][2] << ";";
193  
194 <          << entry_plug->Hmat[0][1] << "\t"
195 <          << entry_plug->Hmat[1][1] << "\t"
196 <          << entry_plug->Hmat[2][1] << ";\t"
197 <
113 <          << entry_plug->Hmat[0][2] << "\t"
114 <          << entry_plug->Hmat[1][2] << "\t"
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 <
194 >    //write out additional parameters, such as chi and eta
195 >    *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl;
196 >  }
197 >  
198    for( i=0; i<nAtoms; i++ ){
199  
200      atoms[i]->getPos(pos);
# Line 152 | Line 230 | void DumpWriter::writeDump( double currentTime ){
230      else
231        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
232  
233 <    outFile << writeLine;
233 >    for(k = 0; k < outFile.size(); k++)
234 >      *outFile[k] << writeLine;
235    }
157  outFile.flush();
236  
237   #else // is_mpi
238  
239 <  // first thing first, suspend fatalities.
240 <  painCave.isEventLoop = 1;
239 >  /* code to find maximum tag value */
240 >  
241 >  int *tagub, flag, MAXTAG;
242 >  MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag);
243 >  if (flag) {
244 >    MAXTAG = *tagub;
245 >  } else {
246 >    MAXTAG = 32767;
247 >  }  
248  
164  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
249    int haveError;
250  
251    MPI_Status istatus;
# Line 170 | Line 254 | void DumpWriter::writeDump( double currentTime ){
254    // write out header and node 0's coordinates
255  
256    if( worldRank == 0 ){
173    outFile << mpiSim->getTotAtoms() << "\n";
257  
258 <    outFile << currentTime << ";\t"
176 <            << entry_plug->Hmat[0][0] << "\t"
177 <            << entry_plug->Hmat[1][0] << "\t"
178 <            << entry_plug->Hmat[2][0] << ";\t"
258 >    // Node 0 needs a list of the magic potatoes for each processor;
259  
260 <            << entry_plug->Hmat[0][1] << "\t"
261 <            << entry_plug->Hmat[1][1] << "\t"
182 <            << entry_plug->Hmat[2][1] << ";\t"
260 >    nProc = mpiSim->getNumberProcessors();
261 >    potatoes = new int[nProc];
262  
263 <            << entry_plug->Hmat[0][2] << "\t"
264 <            << entry_plug->Hmat[1][2] << "\t"
265 <            << entry_plug->Hmat[2][2] << ";";
263 >    //write out the comment lines
264 >    for (i = 0; i < nProc; i++)
265 >      potatoes[i] = 0;
266 >    
267 >      for(k = 0; k < outFile.size(); k++){
268 >        *outFile[k] << mpiSim->getTotAtoms() << "\n";
269  
270 <    outFile << entry_plug->the_integrator->getAdditionalParameters();
271 <    outFile << endl;
272 <    outFile.flush();
270 >        *outFile[k] << currentTime << ";\t"
271 >                         << entry_plug->Hmat[0][0] << "\t"
272 >                         << entry_plug->Hmat[1][0] << "\t"
273 >                         << entry_plug->Hmat[2][0] << ";\t"
274 >
275 >                         << entry_plug->Hmat[0][1] << "\t"
276 >                         << entry_plug->Hmat[1][1] << "\t"
277 >                         << entry_plug->Hmat[2][1] << ";\t"
278 >
279 >                         << entry_plug->Hmat[0][2] << "\t"
280 >                         << entry_plug->Hmat[1][2] << "\t"
281 >                         << entry_plug->Hmat[2][2] << ";";
282 >  
283 >        *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl;
284 >    }
285 >
286 >    currentIndex = 0;
287 >
288      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
289 +      
290        // Get the Node number which has this atom;
291 <
291 >      
292        which_node = AtomToProcMap[i];
293 <
293 >      
294        if (which_node != 0) {
197        
198        atomTypeTag          = 4*i;
199        atomIsDirectionalTag = 4*i + 1;
200        atomTransDataTag     = 4*i + 2;
201        atomOrientDataTag    = 4*i + 3;
295  
296 <        MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node,
297 <                 atomTypeTag, MPI_COMM_WORLD, &istatus);
298 <        
206 <        strncpy(atomTypeString, MPIatomTypeString, MINIBUFFERSIZE);
207 <        
208 <        // Null terminate the atomTypeString just in case:
296 >        if (potatoes[which_node] + 3 >= MAXTAG) {
297 >          // The potato was going to exceed the maximum value,
298 >          // so wrap this processor potato back to 0:        
299  
300 <        atomTypeString[strlen(atomTypeString) - 1] = '\0';
300 >          potatoes[which_node] = 0;          
301 >          MPI_Send(0, 1, MPI_INT, which_node, 0, MPI_COMM_WORLD);
302 >          
303 >        }
304  
305 <        MPI_Recv(&isDirectional, 1, MPI_INT, which_node,
213 <                 atomIsDirectionalTag, MPI_COMM_WORLD, &istatus);
305 >        myPotato = potatoes[which_node];        
306          
307 <        MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node,
308 <                 atomTransDataTag, MPI_COMM_WORLD, &istatus);
307 >        MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node,
308 >                 myPotato, MPI_COMM_WORLD, &istatus);
309 >        
310 >        atomTypeString = MPIatomTypeString;
311 >        
312 >        myPotato++;
313  
314 <        if (isDirectional) {
314 >        MPI_Recv(&isDirectional, 1, MPI_INT, which_node,
315 >                 myPotato, MPI_COMM_WORLD, &istatus);
316 >              
317 >        myPotato++;
318  
319 <          MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node,
320 <                   atomOrientDataTag, MPI_COMM_WORLD, &istatus);
321 <
319 >        if (isDirectional) {          
320 >          MPI_Recv(atomData13, 13, MPI_DOUBLE, which_node,
321 >                   myPotato, MPI_COMM_WORLD, &istatus);
322 >        } else {
323 >          MPI_Recv(atomData6, 6, MPI_DOUBLE, which_node,
324 >                   myPotato, MPI_COMM_WORLD, &istatus);          
325          }
326 +        
327 +        myPotato++;
328 +        potatoes[which_node] = myPotato;
329  
330        } else {
331          
332 <        haveError = 0;
333 <        which_atom = i;
334 <        local_index=-1;
335 <
336 <        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
337 <          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
338 <        }
234 <
235 <        if (local_index != -1) {
236 <
332 >        haveError = 0;
333 >              which_atom = i;
334 >        
335 >        local_index = indexArray[currentIndex].first;        
336 >                
337 >        if (which_atom == indexArray[currentIndex].second) {
338 >          
339            atomTypeString = atoms[local_index]->getType();
340  
341 <          atoms[local_index]->getPos(pos);
342 <          atoms[local_index]->getVel(vel);
341 >                atoms[local_index]->getPos(pos);
342 >                atoms[local_index]->getVel(vel);          
343  
344 <          atomTransData[0] = pos[0];
345 <          atomTransData[1] = pos[1];
346 <          atomTransData[2] = pos[2];
344 >          atomData6[0] = pos[0];
345 >          atomData6[1] = pos[1];
346 >          atomData6[2] = pos[2];
347  
348 <          atomTransData[3] = vel[0];
349 <          atomTransData[4] = vel[1];
350 <          atomTransData[5] = vel[2];
348 >          atomData6[3] = vel[0];
349 >          atomData6[4] = vel[1];
350 >          atomData6[5] = vel[2];
351            
352            isDirectional = 0;
353  
# Line 255 | Line 357 | void DumpWriter::writeDump( double currentTime ){
357              
358              dAtom = (DirectionalAtom *)atoms[local_index];
359              dAtom->getQ( q );
258            
259            atomOrientData[0] = q[0];
260            atomOrientData[1] = q[1];
261            atomOrientData[2] = q[2];
262            atomOrientData[3] = q[3];
360  
361 <            atomOrientData[4] = dAtom->getJx();
362 <            atomOrientData[5] = dAtom->getJy();
266 <            atomOrientData[6] = dAtom->getJz();
267 <          }
268 <
269 <        } else {
270 <          sprintf(painCave.errMsg,
271 <                  "Atom %d not found on processor %d\n",
272 <                  i, worldRank );
273 <          haveError= 1;
274 <          simError();
275 <        }
276 <
277 <        if(haveError) DieDieDie();
278 <                              
279 <        // If we've survived to here, format the line:
280 <        
281 <        sprintf( tempBuffer,
282 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
283 <                 atomTypeString,
284 <                 atomTransData[0],
285 <                 atomTransData[1],
286 <                 atomTransData[2],
287 <                 atomTransData[3],
288 <                 atomTransData[4],
289 <                 atomTransData[5]);
290 <
291 <        strcpy( writeLine, tempBuffer );
292 <
293 <        if (isDirectional) {
294 <
295 <          sprintf( tempBuffer,
296 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
297 <                   atomOrientData[0],
298 <                   atomOrientData[1],
299 <                   atomOrientData[2],
300 <                   atomOrientData[3],
301 <                   atomOrientData[4],
302 <                   atomOrientData[5],
303 <                   atomOrientData[6]);
304 <          strcat( writeLine, tempBuffer );
305 <
306 <        } else {
307 <          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
308 <        }
309 <
310 <        outFile << writeLine;
311 <        outFile.flush();
312 <      }
313 <    }
314 <
315 <    outFile.flush();
316 <    sprintf( checkPointMsg,
317 <             "Sucessfully took a dump.\n");
318 <    MPIcheckPoint();        
319 <    
320 <  } else {
321 <
322 <    // worldRank != 0, so I'm a remote node.  
323 <    
324 <    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
325 <      
326 <      // Am I the node which has this atom?
327 <      
328 <      if (AtomToProcMap[i] == worldRank) {
329 <
330 <        local_index=-1;
331 <        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
332 <          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
333 <        }
334 <        if (local_index != -1) {
335 <        
336 <          atomTypeString = atoms[local_index]->getType();
337 <
338 <          atoms[local_index]->getPos(pos);
339 <          atoms[local_index]->getVel(vel);
340 <
341 <          atomTransData[0] = pos[0];
342 <          atomTransData[1] = pos[1];
343 <          atomTransData[2] = pos[2];
344 <
345 <          atomTransData[3] = vel[0];
346 <          atomTransData[4] = vel[1];
347 <          atomTransData[5] = vel[2];
348 <          
349 <          isDirectional = 0;
350 <
351 <          if( atoms[local_index]->isDirectional() ){
352 <
353 <            isDirectional = 1;
361 >            for (int j = 0; j < 6 ; j++)
362 >              atomData13[j] = atomData6[j];            
363              
364 <            dAtom = (DirectionalAtom *)atoms[local_index];
365 <            dAtom->getQ( q );
364 >            atomData13[6] = q[0];
365 >            atomData13[7] = q[1];
366 >            atomData13[8] = q[2];
367 >            atomData13[9] = q[3];
368              
369 <            atomOrientData[0] = q[0];
370 <            atomOrientData[1] = q[1];
371 <            atomOrientData[2] = q[2];
361 <            atomOrientData[3] = q[3];
362 <
363 <            atomOrientData[4] = dAtom->getJx();
364 <            atomOrientData[5] = dAtom->getJy();
365 <            atomOrientData[6] = dAtom->getJz();
369 >            atomData13[10] = dAtom->getJx();
370 >            atomData13[11] = dAtom->getJy();
371 >            atomData13[12] = dAtom->getJz();
372            }
373 <
373 >          
374          } else {
375 <          sprintf(painCave.errMsg,
376 <                  "Atom %d not found on processor %d\n",
377 <                  i, worldRank );
378 <          haveError= 1;
379 <          simError();
380 <        }
375 <
376 <        // I've survived this far, so send off the data!
377 <
378 <        atomTypeTag          = 4*i;
379 <        atomIsDirectionalTag = 4*i + 1;
380 <        atomTransDataTag     = 4*i + 2;
381 <        atomOrientDataTag    = 4*i + 3;
382 <
383 <
384 <        strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
385 <
386 <        // null terminate the string before sending (just in case):
387 <        MPIatomTypeString[MINIBUFFERSIZE-1] = '\0';
388 <
389 <        MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
390 <                 atomTypeTag, MPI_COMM_WORLD);
375 >          sprintf(painCave.errMsg,
376 >                              "Atom %d not found on processor %d\n",
377 >                              i, worldRank );
378 >                haveError= 1;
379 >                simError();
380 >              }
381          
382 <        MPI_Send(&isDirectional, 1, MPI_INT, 0,
383 <                 atomIsDirectionalTag, MPI_COMM_WORLD);
384 <        
395 <        MPI_Send(atomTransData, 6, MPI_DOUBLE, 0,
396 <                 atomTransDataTag, MPI_COMM_WORLD);
397 <
398 <        if (isDirectional) {
399 <
400 <          MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0,
401 <                   atomOrientDataTag, MPI_COMM_WORLD);
402 <          
403 <        }
404 <      
382 >        if(haveError) DieDieDie();
383 >        
384 >        currentIndex ++;
385        }
386 <    }
386 >      // If we've survived to here, format the line:
387 >      
388 >      if (!isDirectional) {
389 >        
390 >        sprintf( writeLine,
391 >                             "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
392 >                             atomTypeString,
393 >                             atomData6[0],
394 >                             atomData6[1],
395 >                             atomData6[2],
396 >                             atomData6[3],
397 >                             atomData6[4],
398 >                             atomData6[5]);
399  
400 <    sprintf( checkPointMsg,
401 <             "Sucessfully took a dump.\n");
410 <    MPIcheckPoint();        
411 <    
412 <  }
413 <  
414 <  painCave.isEventLoop = 0;
415 <
416 < #endif // is_mpi
417 < }
418 <
419 < void DumpWriter::writeFinal(double finalTime){
420 <
421 <  char finalName[500];
422 <  ofstream finalOut;
423 <
424 <  const int BUFFERSIZE = 2000;
425 <  const int MINIBUFFERSIZE = 100;
426 <  char tempBuffer[BUFFERSIZE];
427 <  char writeLine[BUFFERSIZE];
428 <
429 <  double q[4];
430 <  DirectionalAtom* dAtom;
431 <  Atom** atoms = entry_plug->atoms;
432 <  int i;
433 < #ifdef IS_MPI
434 <  int j, which_node, done, which_atom, local_index;
435 <  double atomTransData[6];
436 <  double atomOrientData[7];
437 <  int isDirectional;
438 <  char* atomTypeString;
439 <  char MPIatomTypeString[MINIBUFFERSIZE];
440 <  int atomTypeTag;
441 <  int atomIsDirectionalTag;
442 <  int atomTransDataTag;
443 <  int atomOrientDataTag;
444 < #else //is_mpi
445 <  int nAtoms = entry_plug->n_atoms;
446 < #endif //is_mpi
447 <
448 <  double pos[3], vel[3];
449 <
450 < #ifdef IS_MPI
451 <  if(worldRank == 0 ){
452 < #endif // is_mpi
453 <
454 <    strcpy( finalName, entry_plug->finalName );
455 <
456 <    finalOut.open( finalName, ios::out | ios::trunc );
457 <    if( !finalOut ){
458 <      sprintf( painCave.errMsg,
459 <               "Could not open \"%s\" for final dump output.\n",
460 <               finalName );
461 <      painCave.isFatal = 1;
462 <      simError();
463 <    }
464 <
465 <    // finalOut.setf( ios::scientific );
466 <
467 < #ifdef IS_MPI
468 <  }
469 <
470 <  sprintf(checkPointMsg,"Opened file for final configuration\n");
471 <  MPIcheckPoint();
472 <
473 < #endif //is_mpi
474 <
475 <
476 < #ifndef IS_MPI
477 <
478 <  finalOut << nAtoms << "\n";
479 <
480 <  finalOut << finalTime << ";\t"
481 <           << entry_plug->Hmat[0][0] << "\t"
482 <           << entry_plug->Hmat[1][0] << "\t"
483 <           << entry_plug->Hmat[2][0] << ";\t"
484 <
485 <           << entry_plug->Hmat[0][1] << "\t"
486 <           << entry_plug->Hmat[1][1] << "\t"
487 <           << entry_plug->Hmat[2][1] << ";\t"
488 <
489 <           << entry_plug->Hmat[0][2] << "\t"
490 <           << entry_plug->Hmat[1][2] << "\t"
491 <           << entry_plug->Hmat[2][2] << ";";
492 <
493 <  //write out additional parameters, such as chi and eta
494 <  finalOut << entry_plug->the_integrator->getAdditionalParameters();
495 <  finalOut << endl;
496 <
497 <  for( i=0; i<nAtoms; i++ ){
498 <
499 <    atoms[i]->getPos(pos);
500 <    atoms[i]->getVel(vel);
501 <
502 <    sprintf( tempBuffer,
503 <             "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
504 <             atoms[i]->getType(),
505 <             pos[0],
506 <             pos[1],
507 <             pos[2],
508 <             vel[0],
509 <             vel[1],
510 <             vel[2]);
511 <    strcpy( writeLine, tempBuffer );
512 <
513 <    if( atoms[i]->isDirectional() ){
514 <
515 <      dAtom = (DirectionalAtom *)atoms[i];
516 <      dAtom->getQ( q );
517 <
518 <      sprintf( tempBuffer,
519 <               "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
520 <               q[0],
521 <               q[1],
522 <               q[2],
523 <               q[3],
524 <               dAtom->getJx(),
525 <               dAtom->getJy(),
526 <               dAtom->getJz());
527 <      strcat( writeLine, tempBuffer );
528 <    }
529 <    else
530 <      strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
531 <
532 <    finalOut << writeLine;
533 <  }
534 <  finalOut.flush();
535 <  finalOut.close();
536 <
537 < #else // is_mpi
538 <
539 <  // first thing first, suspend fatalities.
540 <  painCave.isEventLoop = 1;
541 <
542 <  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
543 <  int haveError;
544 <
545 <  MPI_Status istatus;
546 <  int *AtomToProcMap = mpiSim->getAtomToProcMap();
547 <
548 <  // write out header and node 0's coordinates
549 <
550 <  if( worldRank == 0 ){
551 <    finalOut << mpiSim->getTotAtoms() << "\n";
552 <
553 <    finalOut << finalTime << ";\t"
554 <            << entry_plug->Hmat[0][0] << "\t"
555 <            << entry_plug->Hmat[1][0] << "\t"
556 <            << entry_plug->Hmat[2][0] << ";\t"
557 <
558 <            << entry_plug->Hmat[0][1] << "\t"
559 <            << entry_plug->Hmat[1][1] << "\t"
560 <            << entry_plug->Hmat[2][1] << ";\t"
561 <
562 <            << entry_plug->Hmat[0][2] << "\t"
563 <            << entry_plug->Hmat[1][2] << "\t"
564 <            << entry_plug->Hmat[2][2] << ";";
565 <
566 <    finalOut << entry_plug->the_integrator->getAdditionalParameters();
567 <    finalOut << endl;
568 <    finalOut.flush();
569 <    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
570 <      // Get the Node number which has this atom;
571 <
572 <      which_node = AtomToProcMap[i];
573 <
574 <      if (which_node != 0) {
575 <        
576 <        atomTypeTag          = 4*i;
577 <        atomIsDirectionalTag = 4*i + 1;
578 <        atomTransDataTag     = 4*i + 2;
579 <        atomOrientDataTag    = 4*i + 3;
580 <
581 <        MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node,
582 <                 atomTypeTag, MPI_COMM_WORLD, &istatus);
583 <        
584 <        strncpy(atomTypeString, MPIatomTypeString, MINIBUFFERSIZE);
585 <
586 <        MPI_Recv(&isDirectional, 1, MPI_INT, which_node,
587 <                 atomIsDirectionalTag, MPI_COMM_WORLD, &istatus);
588 <        
589 <        MPI_Recv(atomTransData, 6, MPI_DOUBLE, which_node,
590 <                 atomTransDataTag, MPI_COMM_WORLD, &istatus);
591 <
592 <        if (isDirectional) {
593 <
594 <          MPI_Recv(atomOrientData, 7, MPI_DOUBLE, which_node,
595 <                   atomOrientDataTag, MPI_COMM_WORLD, &istatus);
596 <
597 <        }
598 <
400 >              strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
401 >        
402        } else {
403 <        
404 <        haveError = 0;
405 <        which_atom = i;
406 <        local_index=-1;
407 <
408 <        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
409 <          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
410 <        }
411 <
412 <        if (local_index != -1) {
413 <
414 <          atomTypeString = atoms[local_index]->getType();
415 <
416 <          atoms[local_index]->getPos(pos);
417 <          atoms[local_index]->getVel(vel);
418 <
419 <          atomTransData[0] = pos[0];
617 <          atomTransData[1] = pos[1];
618 <          atomTransData[2] = pos[2];
619 <
620 <          atomTransData[3] = vel[0];
621 <          atomTransData[4] = vel[1];
622 <          atomTransData[5] = vel[2];
623 <          
624 <          isDirectional = 0;
625 <
626 <          if( atoms[local_index]->isDirectional() ){
627 <
628 <            isDirectional = 1;
629 <            
630 <            dAtom = (DirectionalAtom *)atoms[local_index];
631 <            dAtom->getQ( q );
632 <            
633 <            atomOrientData[0] = q[0];
634 <            atomOrientData[1] = q[1];
635 <            atomOrientData[2] = q[2];
636 <            atomOrientData[3] = q[3];
637 <
638 <            atomOrientData[4] = dAtom->getJx();
639 <            atomOrientData[5] = dAtom->getJy();
640 <            atomOrientData[6] = dAtom->getJz();
641 <          }
642 <
643 <        } else {
644 <          sprintf(painCave.errMsg,
645 <                  "Atom %d not found on processor %d\n",
646 <                  i, worldRank );
647 <          haveError= 1;
648 <          simError();
649 <        }
650 <
651 <        if(haveError) DieDieDie();
652 <                              
653 <        // If we've survived to here, format the line:
403 >        
404 >              sprintf( writeLine,
405 >                             "%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",
406 >                             atomTypeString,
407 >                             atomData13[0],
408 >                             atomData13[1],
409 >                             atomData13[2],
410 >                             atomData13[3],
411 >                             atomData13[4],
412 >                             atomData13[5],
413 >                             atomData13[6],
414 >                             atomData13[7],
415 >                             atomData13[8],
416 >                             atomData13[9],
417 >                             atomData13[10],
418 >                             atomData13[11],
419 >                             atomData13[12]);
420          
655        sprintf( tempBuffer,
656                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
657                 atomTypeString,
658                 atomTransData[0],
659                 atomTransData[1],
660                 atomTransData[2],
661                 atomTransData[3],
662                 atomTransData[4],
663                 atomTransData[5]);
664
665        strcpy( writeLine, tempBuffer );
666
667        if (isDirectional) {
668
669          sprintf( tempBuffer,
670                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
671                   atomOrientData[0],
672                   atomOrientData[1],
673                   atomOrientData[2],
674                   atomOrientData[3],
675                   atomOrientData[4],
676                   atomOrientData[5],
677                   atomOrientData[6]);
678          strcat( writeLine, tempBuffer );
679
680        } else {
681          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
682        }
683
684        finalOut << writeLine;
685        finalOut.flush();
421        }
422 +      
423 +      for(k = 0; k < outFile.size(); k++)
424 +        *outFile[k] << writeLine;
425      }
426 <
427 <    finalOut.flush();
426 >    
427 >    for(k = 0; k < outFile.size(); k++)
428 >      outFile[k]->flush();
429 >    
430      sprintf( checkPointMsg,
431               "Sucessfully took a dump.\n");
432 +
433      MPIcheckPoint();        
434 <    
434 >
435 >    delete[] potatoes;
436 >
437    } else {
438  
439      // worldRank != 0, so I'm a remote node.  
440 +
441 +    // Set my magic potato to 0:
442 +
443 +    myPotato = 0;
444 +    currentIndex = 0;
445      
446      for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
447        
# Line 701 | Line 449 | void DumpWriter::writeFinal(double finalTime){
449        
450        if (AtomToProcMap[i] == worldRank) {
451  
452 <        local_index=-1;
453 <        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
454 <          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
452 >        if (myPotato + 3 >= MAXTAG) {
453 >
454 >          // The potato was going to exceed the maximum value,
455 >          // so wrap this processor potato back to 0 (and block until
456 >          // node 0 says we can go:
457 >
458 >          MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus);
459 >          
460          }
461 <        if (local_index != -1) {
461 >        which_atom = i;
462 >        local_index = indexArray[currentIndex].first;        
463 >                
464 >        if (which_atom == indexArray[currentIndex].second) {
465          
466            atomTypeString = atoms[local_index]->getType();
467  
468 <          atoms[local_index]->getPos(pos);
469 <          atoms[local_index]->getVel(vel);
468 >                atoms[local_index]->getPos(pos);
469 >                atoms[local_index]->getVel(vel);
470  
471 <          atomTransData[0] = pos[0];
472 <          atomTransData[1] = pos[1];
473 <          atomTransData[2] = pos[2];
471 >          atomData6[0] = pos[0];
472 >          atomData6[1] = pos[1];
473 >          atomData6[2] = pos[2];
474  
475 <          atomTransData[3] = vel[0];
476 <          atomTransData[4] = vel[1];
477 <          atomTransData[5] = vel[2];
475 >          atomData6[3] = vel[0];
476 >          atomData6[4] = vel[1];
477 >          atomData6[5] = vel[2];
478            
479            isDirectional = 0;
480  
# Line 729 | Line 485 | void DumpWriter::writeFinal(double finalTime){
485              dAtom = (DirectionalAtom *)atoms[local_index];
486              dAtom->getQ( q );
487              
488 <            atomOrientData[0] = q[0];
489 <            atomOrientData[1] = q[1];
490 <            atomOrientData[2] = q[2];
491 <            atomOrientData[3] = q[3];
492 <
493 <            atomOrientData[4] = dAtom->getJx();
494 <            atomOrientData[5] = dAtom->getJy();
495 <            atomOrientData[6] = dAtom->getJz();
488 >            for (int j = 0; j < 6 ; j++)
489 >              atomData13[j] = atomData6[j];
490 >            
491 >            atomData13[6] = q[0];
492 >            atomData13[7] = q[1];
493 >            atomData13[8] = q[2];
494 >            atomData13[9] = q[3];
495 >  
496 >            atomData13[10] = dAtom->getJx();
497 >            atomData13[11] = dAtom->getJy();
498 >            atomData13[12] = dAtom->getJz();
499            }
500  
501          } else {
502 <          sprintf(painCave.errMsg,
503 <                  "Atom %d not found on processor %d\n",
504 <                  i, worldRank );
505 <          haveError= 1;
506 <          simError();
507 <        }
502 >                sprintf(painCave.errMsg,
503 >                              "Atom %d not found on processor %d\n",
504 >                              i, worldRank );
505 >                haveError= 1;
506 >                simError();
507 >              }
508  
750        // I've survived this far, so send off the data!
751
752        atomTypeTag          = 4*i;
753        atomIsDirectionalTag = 4*i + 1;
754        atomTransDataTag     = 4*i + 2;
755        atomOrientDataTag    = 4*i + 3;
756
509          strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
510  
511 +        // null terminate the string before sending (just in case):
512 +        MPIatomTypeString[MINIBUFFERSIZE-1] = '\0';
513 +
514          MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
515 <                 atomTypeTag, MPI_COMM_WORLD);
515 >                             myPotato, MPI_COMM_WORLD);
516          
517 +        myPotato++;
518 +
519          MPI_Send(&isDirectional, 1, MPI_INT, 0,
520 <                 atomIsDirectionalTag, MPI_COMM_WORLD);
520 >                             myPotato, MPI_COMM_WORLD);
521          
522 <        MPI_Send(atomTransData, 6, MPI_DOUBLE, 0,
523 <                 atomTransDataTag, MPI_COMM_WORLD);
767 <
522 >        myPotato++;
523 >        
524          if (isDirectional) {
525  
526 <          MPI_Send(atomOrientData, 7, MPI_DOUBLE, 0,
527 <                   atomOrientDataTag, MPI_COMM_WORLD);
526 >          MPI_Send(atomData13, 13, MPI_DOUBLE, 0,
527 >                   myPotato, MPI_COMM_WORLD);
528            
529 +        } else {
530 +
531 +          MPI_Send(atomData6, 6, MPI_DOUBLE, 0,
532 +                   myPotato, MPI_COMM_WORLD);
533          }
534 <      
534 >
535 >        myPotato++;  
536 >        currentIndex++;    
537        }
538      }
539  
540      sprintf( checkPointMsg,
541 <             "Sucessfully wrote final file.\n");
541 >             "Sucessfully took a dump.\n");
542      MPIcheckPoint();        
543      
544 <  }
544 >  }
545    
784  painCave.isEventLoop = 0;
785
786  if( worldRank == 0 ) finalOut.close();
546   #endif // is_mpi
547   }
548  
790
791
549   #ifdef IS_MPI
550  
551   // a couple of functions to let us escape the write loop

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines