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 586 by mmeineke, Wed Jul 9 22:14:06 2003 UTC vs.
Revision 913 by chuckv, Thu Jan 8 22:25:52 2004 UTC

# Line 1 | Line 1
1 < #include <cstring>
1 > #define _FILE_OFFSET_BITS 64
2 >
3 > #include <string.h>
4   #include <iostream>
5   #include <fstream>
6  
7   #ifdef IS_MPI
8   #include <mpi.h>
9   #include "mpiSimulation.hpp"
8 #define TAKE_THIS_TAG_CHAR 1
9 #define TAKE_THIS_TAG_INT 2
10  
11   namespace dWrite{
12 <  void nodeZeroError( void );
13 <  void anonymousNodeDie( void );
12 >  void DieDieDie( void );
13   }
14  
15   using namespace dWrite;
# Line 26 | 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 65 | 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, j, which_node, done, which_atom, local_index;
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
90 >
91    double q[4];
92    DirectionalAtom* dAtom;
76  int nAtoms = entry_plug->n_atoms;
93    Atom** atoms = entry_plug->atoms;
94 <    
94 >  double pos[3], vel[3];
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";
83    
84  outFile << currentTime << ";\t"
85          << entry_plug->Hmat[0] << "\t"
86          << entry_plug->Hmat[1] << "\t"
87          << entry_plug->Hmat[2] << ";\t"
103  
104 <          << entry_plug->Hmat[3] << "\t"
105 <          << entry_plug->Hmat[4] << "\t"
106 <          << entry_plug->Hmat[5] << ";\t"
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"
108  
109 <          << entry_plug->Hmat[6] << "\t"
110 <          << entry_plug->Hmat[7] << "\t"
111 <          << entry_plug->Hmat[8] << ";\n";
112 <    
109 >          << entry_plug->Hmat[0][1] << "\t"
110 >          << entry_plug->Hmat[1][1] << "\t"
111 >          << entry_plug->Hmat[2][1] << ";\t"
112 >
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 >
120    for( i=0; i<nAtoms; i++ ){
98      
121  
122 +    atoms[i]->getPos(pos);
123 +    atoms[i]->getVel(vel);
124 +
125      sprintf( tempBuffer,
126               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
127               atoms[i]->getType(),
128 <             atoms[i]->getX(),
129 <             atoms[i]->getY(),
130 <             atoms[i]->getZ(),
131 <             atoms[i]->get_vx(),
132 <             atoms[i]->get_vy(),
133 <             atoms[i]->get_vz());
128 >             pos[0],
129 >             pos[1],
130 >             pos[2],
131 >             vel[0],
132 >             vel[1],
133 >             vel[2]);
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 126 | 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  
139  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"
181 <            << entry_plug->Hmat[0] << "\t"
182 <            << entry_plug->Hmat[1] << "\t"
183 <            << entry_plug->Hmat[2] << "\t"
184 <      
185 <            << entry_plug->Hmat[3] << "\t"
186 <            << entry_plug->Hmat[4] << "\t"
187 <            << entry_plug->Hmat[5] << "\t"
188 <      
189 <            << entry_plug->Hmat[6] << "\t"
190 <            << entry_plug->Hmat[7] << "\t"
191 <            << entry_plug->Hmat[8] << "\n";
192 <    ;
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 >
185 >            << entry_plug->Hmat[0][1] << "\t"
186 >            << entry_plug->Hmat[1][1] << "\t"
187 >            << entry_plug->Hmat[2][1] << ";\t"
188 >
189 >            << entry_plug->Hmat[0][2] << "\t"
190 >            << entry_plug->Hmat[1][2] << "\t"
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 <          sprintf( tempBuffer,
249 <                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
250 <                   atoms[local_index]->getType(),
251 <                   atoms[local_index]->getX(),
252 <                   atoms[local_index]->getY(),
253 <                   atoms[local_index]->getZ(),
254 <                   atoms[local_index]->get_vx(),
255 <                   atoms[local_index]->get_vy(),
256 <                   atoms[local_index]->get_vz()); // check here.
257 <          strcpy( writeLine, tempBuffer );
258 <          
247 >
248 >          atomTypeString = atoms[local_index]->getType();
249 >
250 >          atoms[local_index]->getPos(pos);
251 >          atoms[local_index]->getVel(vel);
252 >
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 <            
206 <          }
207 <          else
208 <            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
209 <        }
210 <        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 <        }
287 <        
288 <        if(haveError) nodeZeroError();
286 >        }
287 >
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 <      }
221 <      else {
222 <        myStatus = 1;
223 <        MPI_Send(&myStatus, 1, MPI_INT, which_node,
224 <                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
225 <        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
226 <                 MPI_COMM_WORLD);
227 <        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
228 <                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
229 <        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
230 <                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
231 <        
232 <        if(!myStatus) nodeZeroError();
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        }
235      
236      outFile << writeLine;
237      outFile.flush();
324      }
239    
240    // kill everyone off:
241    myStatus = -1;
242    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
243      MPI_Send(&myStatus, 1, MPI_INT, j,
244               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
245    }
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;
250 <    while (!done) {
335 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
336        
337 <      MPI_Recv(&myStatus, 1, MPI_INT, 0,
253 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
254 <
255 <      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;
348 <      }
349 <      if (local_index != -1) {
350 <        //format the line
351 <        sprintf( tempBuffer,
352 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
353 <                 atoms[local_index]->getType(),
354 <                 atoms[local_index]->getX(),
355 <                 atoms[local_index]->getY(),
356 <                 atoms[local_index]->getZ(),
357 <                 atoms[local_index]->get_vx(),
358 <                 atoms[local_index]->get_vy(),
359 <                 atoms[local_index]->get_vz()); // check here.
360 <        strcpy( writeLine, tempBuffer );
361 <        
362 <        if( atoms[local_index]->isDirectional() ){
363 <          
364 <          dAtom = (DirectionalAtom *)atoms[local_index];
365 <          dAtom->getQ( q );
366 <          
367 <          sprintf( tempBuffer,
368 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
369 <                   q[0],
370 <                   q[1],
371 <                   q[2],
372 <                   q[3],
373 <                   dAtom->getJx(),
374 <                   dAtom->getJy(),
375 <                   dAtom->getJz());
376 <          strcat( writeLine, tempBuffer );
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);
351 >
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          }
296        else{
297          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
298        }
299      }
300      else {
301        sprintf(painCave.errMsg,
302                "Atom %d not found on processor %d\n",
303                which_atom, worldRank );
304        myStatus = 0;
305        simError();
386  
387 <        strcpy( writeLine, "Hello, I'm an error.\n");
308 <      }
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      }
315  }  
316  outFile.flush();
317  sprintf( checkPointMsg,
318           "Sucessfully took a dump.\n");
319  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 330 | 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;
338  int nAtoms = entry_plug->n_atoms;
442    Atom** atoms = entry_plug->atoms;
443 <  int i, j, which_node, done, game_over, which_atom, local_index;
341 <  
342 <  
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 +
459 +  double pos[3], vel[3];
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 354 | 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 <    
491 <  finalOut << finalTime << "\t"
492 <           << entry_plug->Hmat[0] << "\t"
493 <           << entry_plug->Hmat[1] << "\t"
494 <           << entry_plug->Hmat[2] << "\t"
495 <    
496 <           << entry_plug->Hmat[3] << "\t"
497 <           << entry_plug->Hmat[4] << "\t"
498 <           << entry_plug->Hmat[5] << "\t"
499 <    
500 <           << entry_plug->Hmat[6] << "\t"
501 <           << entry_plug->Hmat[7] << "\t"
502 <           << entry_plug->Hmat[8] << "\n";
503 <  
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 >
496 >           << entry_plug->Hmat[0][1] << "\t"
497 >           << entry_plug->Hmat[1][1] << "\t"
498 >           << entry_plug->Hmat[2][1] << ";\t"
499 >
500 >           << entry_plug->Hmat[0][2] << "\t"
501 >           << entry_plug->Hmat[1][2] << "\t"
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 >
513      sprintf( tempBuffer,
514               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
515               atoms[i]->getType(),
516 <             atoms[i]->getX(),
517 <             atoms[i]->getY(),
518 <             atoms[i]->getZ(),
519 <             atoms[i]->get_vx(),
520 <             atoms[i]->get_vy(),
521 <             atoms[i]->get_vz());
516 >             pos[0],
517 >             pos[1],
518 >             pos[2],
519 >             vel[0],
520 >             vel[1],
521 >             vel[2]);
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 414 | 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 432 | Line 557 | void DumpWriter::writeFinal(double finalTime){
557    int *AtomToProcMap = mpiSim->getAtomToProcMap();
558  
559    // write out header and node 0's coordinates
560 <  
436 <  haveError = 0;
560 >
561    if( worldRank == 0 ){
562      finalOut << mpiSim->getTotAtoms() << "\n";
563 <    
564 <    finalOut << finalTime << "\t"
565 <             << entry_plug->Hmat[0] << "\t"
566 <             << entry_plug->Hmat[1] << "\t"
567 <             << entry_plug->Hmat[2] << "\t"
568 <      
569 <             << entry_plug->Hmat[3] << "\t"
570 <             << entry_plug->Hmat[4] << "\t"
571 <             << entry_plug->Hmat[5] << "\t"
572 <      
573 <             << entry_plug->Hmat[6] << "\t"
574 <             << entry_plug->Hmat[7] << "\t"
575 <             << entry_plug->Hmat[8] << "\n";
576 <    
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] << ";";
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:
455 <      
456 <      which_node = AtomToProcMap[i];    
457 <      
458 <      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          }
619 <        if (local_index != -1) {        
620 <          sprintf( tempBuffer,
621 <                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
622 <                   atoms[local_index]->getType(),
623 <                   atoms[local_index]->getX(),
624 <                   atoms[local_index]->getY(),
625 <                   atoms[local_index]->getZ(),
626 <                   atoms[local_index]->get_vx(),
627 <                   atoms[local_index]->get_vy(),
628 <                   atoms[local_index]->get_vz());
629 <          strcpy( writeLine, tempBuffer );
630 <          
631 <          if( atoms[local_index]->isDirectional() ){
632 <            
633 <            dAtom = (DirectionalAtom *)atoms[local_index];
634 <            dAtom->getQ( q );
635 <            
636 <            sprintf( tempBuffer,
637 <                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
638 <                     q[0],
639 <                     q[1],
640 <                     q[2],
641 <                     q[3],
642 <                     dAtom->getJx(),
643 <                     dAtom->getJy(),
644 <                     dAtom->getJz());
645 <            strcat( writeLine, tempBuffer );
646 <          }
647 <          else
648 <            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
649 <        }
650 <        else {
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 >          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 <      }
507 <      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        }
521      
522      finalOut << writeLine;
698      }
524    
525    // kill everyone off:
526    myStatus = -1;
527    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
528      MPI_Send(&myStatus, 1, MPI_INT, j,
529               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
530    }
699  
700 <  } else {
700 >    finalOut.flush();
701 >    sprintf( checkPointMsg,
702 >             "Sucessfully took a dump.\n");
703 >    MPIcheckPoint();        
704      
705 <    done = 0;
535 <    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;
543 <      
544 <      MPI_Recv(&which_atom, 1, MPI_INT, 0,
545 <               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
546 <      
547 <      myStatus = 1;
548 <      local_index=-1;        
549 <      for (j=0; j < mpiSim->getMyNlocal(); j++) {
550 <        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
551 <      }
552 <      if (local_index != -1) {
713 >      if (AtomToProcMap[i] == worldRank) {
714  
715 <        //format the line
716 <        sprintf( tempBuffer,
717 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
718 <                 atoms[local_index]->getType(),
719 <                 atoms[local_index]->getX(),
720 <                 atoms[local_index]->getY(),
721 <                 atoms[local_index]->getZ(),
722 <                 atoms[local_index]->get_vx(),
723 <                 atoms[local_index]->get_vy(),
724 <                 atoms[local_index]->get_vz()); // check here.
725 <        strcpy( writeLine, tempBuffer );
726 <        
727 <        if( atoms[local_index]->isDirectional() ){
728 <          
729 <          dAtom = (DirectionalAtom *)atoms[local_index];
730 <          dAtom->getQ( q );
731 <          
732 <          sprintf( tempBuffer,
733 <                   "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
734 <                   q[0],
735 <                   q[1],
736 <                   q[2],
737 <                   q[3],
738 <                   dAtom->getJx(),
739 <                   dAtom->getJy(),
740 <                   dAtom->getJz());
741 <          strcat( writeLine, tempBuffer );
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 >          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          }
582        else{
583          strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
584        }
585      }
586      else {
587        sprintf(painCave.errMsg,
588                "Atom %d not found on processor %d\n",
589                which_atom, worldRank );
590        myStatus = 0;
591        simError();
592        
593        strcpy( writeLine, "Hello, I'm an error.\n");
594      }
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    }
602  finalOut.flush();
603  sprintf( checkPointMsg,
604           "Sucessfully took a dump.\n");
605  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 614 | 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 ){
618 <  int j, myStatus;
619 <  
620 <  myStatus = 0;
621 <  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
622 <    MPI_Send( &myStatus, 1, MPI_INT, j,
623 <              TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
624 <  }  
625 <  
807 > void dWrite::DieDieDie( void ){
808  
809    MPI_Finalize();
810    exit (0);
629  
811   }
812  
632 void dWrite::anonymousNodeDie( void ){
633
634  MPI_Finalize();
635  exit (0);
636 }
637
813   #endif //is_mpi

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines