ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/DumpWriter.cpp
(Generate patch)

Comparing:
branches/mmeineke/OOPSE/libmdtools/DumpWriter.cpp (file contents), Revision 377 by mmeineke, Fri Mar 21 17:42:12 2003 UTC vs.
trunk/OOPSE/libmdtools/DumpWriter.cpp (file contents), Revision 483 by gezelter, Wed Apr 9 04:06:43 2003 UTC

# Line 5 | Line 5
5   #ifdef IS_MPI
6   #include <mpi.h>
7   #include "mpiSimulation.hpp"
8 < #define TAKE_THIS_TAG 0
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 );
14 > }
15 >
16 > using namespace dWrite;
17   #endif //is_mpi
18  
19   #include "ReadWrite.hpp"
20   #include "simError.h"
21  
14
15
16
17
22   DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
23  
24    entry_plug = the_entry_plug;
# Line 23 | Line 27 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
27    if(worldRank == 0 ){
28   #endif // is_mpi
29      
26
27    
30      strcpy( outName, entry_plug->sampleName );
31      
32      outFile.open(outName, ios::out | ios::trunc );
# Line 37 | Line 39 | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
39        painCave.isFatal = 1;
40        simError();
41      }
42 <  
42 >
43      //outFile.setf( ios::scientific );
44  
45   #ifdef IS_MPI
# Line 68 | Line 70 | void DumpWriter::writeDump( double currentTime ){
70    char tempBuffer[BUFFERSIZE];
71    char writeLine[BUFFERSIZE];
72  
73 <  int i;
73 >  int i, j, which_node, done, which_atom, local_index;
74    double q[4];
75    DirectionalAtom* dAtom;
76    int nAtoms = entry_plug->n_atoms;
# Line 123 | Line 125 | void DumpWriter::writeDump( double currentTime ){
125  
126   #else // is_mpi
127  
128 <  int masterIndex;
129 <  int nodeAtomsStart;
128 <  int nodeAtomsEnd;
129 <  int mpiErr;
130 <  int sendError;
131 <  int procIndex;
132 <    
133 <  MPI_Status istatus[MPI_STATUS_SIZE];
128 >  // first thing first, suspend fatalities.
129 >  painCave.isEventLoop = 1;
130  
131 <    
132 <  // write out header and node 0's coordinates
131 >  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
132 >  int haveError;
133  
134 +  MPI_Status istatus;
135 +  int *AtomToProcMap = mpiSim->getAtomToProcMap();
136 +  
137 +  // write out header and node 0's coordinates
138 +  
139    if( worldRank == 0 ){
140      outFile << mpiSim->getTotAtoms() << "\n";
141 <      
141 >    
142      outFile << currentTime << "\t"
143              << entry_plug->box_x << "\t"
144              << entry_plug->box_y << "\t"
145              << entry_plug->box_z << "\n";
146 <
147 <    masterIndex = 0;
148 <    for( i=0; i<nAtoms; i++ ){
146 >    outFile.flush();
147 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
148 >      // Get the Node number which has this atom;
149        
150 <      sprintf( tempBuffer,
151 <               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
152 <               atoms[i]->getType(),
152 <               atoms[i]->getX(),
153 <               atoms[i]->getY(),
154 <               atoms[i]->getZ(),
155 <               atoms[i]->get_vx(),
156 <               atoms[i]->get_vy(),
157 <               atoms[i]->get_vz());
158 <      strcpy( writeLine, tempBuffer );
150 >      which_node = AtomToProcMap[i];    
151 >      
152 >      if (which_node == 0 ) {
153          
154 <      if( atoms[i]->isDirectional() ){
154 >        haveError = 0;
155 >        which_atom = i;
156 >        local_index=-1;        
157 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
158 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
159 >        }
160 >        if (local_index != -1) {
161 >          //format the line
162 >          sprintf( tempBuffer,
163 >                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
164 >                   atoms[local_index]->getType(),
165 >                   atoms[local_index]->getX(),
166 >                   atoms[local_index]->getY(),
167 >                   atoms[local_index]->getZ(),
168 >                   atoms[local_index]->get_vx(),
169 >                   atoms[local_index]->get_vy(),
170 >                   atoms[local_index]->get_vz()); // check here.
171 >          strcpy( writeLine, tempBuffer );
172            
173 <        dAtom = (DirectionalAtom *)atoms[i];
174 <        dAtom->getQ( q );
175 <          
176 <        sprintf( tempBuffer,
177 <                 "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
178 <                 q[0],
179 <                 q[1],
180 <                 q[2],
181 <                 q[3],
182 <                 dAtom->getJx(),
183 <                 dAtom->getJy(),
184 <                 dAtom->getJz());
185 <        strcat( writeLine, tempBuffer );
173 >          if( atoms[local_index]->isDirectional() ){
174 >            
175 >            dAtom = (DirectionalAtom *)atoms[local_index];
176 >            dAtom->getQ( q );
177 >            
178 >            sprintf( tempBuffer,
179 >                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
180 >                     q[0],
181 >                     q[1],
182 >                     q[2],
183 >                     q[3],
184 >                     dAtom->getJx(),
185 >                     dAtom->getJy(),
186 >                     dAtom->getJz());
187 >            strcat( writeLine, tempBuffer );
188 >            
189 >          }
190 >          else
191 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
192 >        }
193 >        else {
194 >          sprintf(painCave.errMsg,
195 >                  "Atom %d not found on processor %d\n",
196 >                  i, worldRank );
197 >          haveError= 1;
198 >          simError();
199 >        }
200 >        
201 >        if(haveError) nodeZeroError();
202 >
203        }
204 <      else
205 <        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
204 >      else {
205 >        myStatus = 1;
206 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
207 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
208 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
209 >                 MPI_COMM_WORLD);
210 >        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
211 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
212 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
213 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
214          
215 +        if(!myStatus) nodeZeroError();
216 +
217 +      }
218 +      
219        outFile << writeLine;
220 <      masterIndex++;
220 >      outFile.flush();
221      }
222 <    outFile.flush();
223 <  }
222 >    
223 >    // kill everyone off:
224 >    myStatus = -1;
225 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
226 >      MPI_Send(&myStatus, 1, MPI_INT, j,
227 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
228 >    }
229  
230 <  sprintf( checkPointMsg,
186 <           "Sucessfully wrote node 0's dump configuration.\n");
187 <  MPIcheckPoint();
230 >  } else {
231      
232 <  for (procIndex = 1; procIndex < mpiSim->getNumberProcessors();
233 <       procIndex++){
232 >    done = 0;
233 >    while (!done) {
234 >      
235 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
236 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
237  
238 <    if( worldRank == 0 ){
238 >      if(!myStatus) anonymousNodeDie();
239        
240 <      mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,
241 <                        TAKE_THIS_TAG,MPI_COMM_WORLD,istatus);
240 >      if(myStatus < 0) break;
241 >
242 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
243 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
244        
245 <      mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,
246 <                        TAKE_THIS_TAG,MPI_COMM_WORLD, istatus);
247 <      
248 <      // Make sure where node 0 is writing to, matches where the
201 <      // receiving node expects it to be.
202 <      
203 <      if (masterIndex != nodeAtomsStart){
204 <        sendError = 1;
205 <        mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,
206 <                          MPI_COMM_WORLD);
207 <        sprintf(painCave.errMsg,
208 <                "DumpWriter error: atoms start index (%d) for "
209 <                "node %d not equal to master index (%d)",
210 <                nodeAtomsStart,procIndex,masterIndex );
211 <        painCave.isFatal = 1;
212 <        simError();
245 >      myStatus = 1;
246 >      local_index=-1;        
247 >      for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
248 >        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
249        }
250 <      
251 <      sendError = 0;
216 <      mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,
217 <                        MPI_COMM_WORLD);
218 <      
219 <      // recieve the nodes writeLines
220 <      
221 <      for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){
222 <        
223 <        mpiErr = MPI_Recv(writeLine,BUFFERSIZE,MPI_CHAR,procIndex,
224 <                          TAKE_THIS_TAG,MPI_COMM_WORLD,istatus );
225 <        
226 <        outFile << writeLine;
227 <        masterIndex++;
228 <      }
229 <    }
230 <
231 <    else if( worldRank == procIndex ){
232 <
233 <      nodeAtomsStart = mpiSim->getMyAtomStart();
234 <      nodeAtomsEnd = mpiSim->getMyAtomEnd();
235 <
236 <      mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG,
237 <                        MPI_COMM_WORLD);
238 <      mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG,
239 <                        MPI_COMM_WORLD);
240 <        
241 <      sendError = -1;
242 <      mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,
243 <                        MPI_COMM_WORLD, istatus);
244 <
245 <      if (sendError) MPIcheckPoint();
246 <
247 <      // send current node's configuration line by line.
248 <
249 <      for( i=0; i<nAtoms; i++ ){
250 <
250 >      if (local_index != -1) {
251 >        //format the line
252          sprintf( tempBuffer,
253                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
254 <                 atoms[i]->getType(),
255 <                 atoms[i]->getX(),
256 <                 atoms[i]->getY(),
257 <                 atoms[i]->getZ(),
258 <                 atoms[i]->get_vx(),
259 <                 atoms[i]->get_vy(),
260 <                 atoms[i]->get_vz()); // check here.
254 >                 atoms[local_index]->getType(),
255 >                 atoms[local_index]->getX(),
256 >                 atoms[local_index]->getY(),
257 >                 atoms[local_index]->getZ(),
258 >                 atoms[local_index]->get_vx(),
259 >                 atoms[local_index]->get_vy(),
260 >                 atoms[local_index]->get_vz()); // check here.
261          strcpy( writeLine, tempBuffer );
262 +        
263 +        if( atoms[local_index]->isDirectional() ){
264            
265 <        if( atoms[i]->isDirectional() ){
263 <            
264 <          dAtom = (DirectionalAtom *)atoms[i];
265 >          dAtom = (DirectionalAtom *)atoms[local_index];
266            dAtom->getQ( q );
267 <            
267 >          
268            sprintf( tempBuffer,
269                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
270                     q[0],
# Line 275 | Line 276 | void DumpWriter::writeDump( double currentTime ){
276                     dAtom->getJz());
277            strcat( writeLine, tempBuffer );
278          }
279 <        else
279 >        else{
280            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
281 <          
282 <        mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG,
283 <                          MPI_COMM_WORLD);
281 >        }
282 >      }
283 >      else {
284 >        sprintf(painCave.errMsg,
285 >                "Atom %d not found on processor %d\n",
286 >                which_atom, worldRank );
287 >        myStatus = 0;
288 >        simError();
289 >
290 >        strcpy( writeLine, "Hello, I'm an error.\n");
291        }
292 +
293 +      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
294 +               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
295 +      MPI_Send( &myStatus, 1, MPI_INT, 0,
296 +                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
297      }
298 <      
299 <    sprintf(checkPointMsg,"Node %d sent dump configuration.",
300 <            procIndex);
301 <    MPIcheckPoint();
302 <  }
303 <    
298 >  }  
299 >  outFile.flush();
300 >  sprintf( checkPointMsg,
301 >           "Sucessfully took a dump.\n");
302 >  MPIcheckPoint();
303 >
304 > // last  thing last, enable  fatalities.
305 >  painCave.isEventLoop = 0;
306 >
307   #endif // is_mpi
308   }
309  
294
295
310   void DumpWriter::writeFinal(){
311  
312 +  char finalName[500];
313 +  ofstream finalOut;
314  
315    const int BUFFERSIZE = 2000;
316 <  char tempBuffer[500];
317 <  char writeLine[BUFFERSIZE];
302 <  
303 <  char finalName[500];
316 >  char tempBuffer[BUFFERSIZE];
317 >  char writeLine[BUFFERSIZE];  
318  
305  int i;
319    double q[4];
320    DirectionalAtom* dAtom;
321    int nAtoms = entry_plug->n_atoms;
322    Atom** atoms = entry_plug->atoms;
323 +  int i, j, which_node, done, game_over, which_atom, local_index;
324    
311  ofstream finalOut;
325    
326   #ifdef IS_MPI
327    if(worldRank == 0 ){
# Line 335 | Line 348 | void DumpWriter::writeFinal(){
348    
349   #endif //is_mpi
350  
351 <    
339 <
351 >  
352   #ifndef IS_MPI
353      
354    finalOut << nAtoms << "\n";
# Line 344 | Line 356 | void DumpWriter::writeFinal(){
356    finalOut << entry_plug->box_x << "\t"
357             << entry_plug->box_y << "\t"
358             << entry_plug->box_z << "\n";
359 <    
359 >  
360    for( i=0; i<nAtoms; i++ ){
361        
362      sprintf( tempBuffer,
# Line 380 | Line 392 | void DumpWriter::writeFinal(){
392      finalOut << writeLine;
393    }
394    finalOut.flush();
395 +  finalOut.close();
396  
397   #else // is_mpi
398 +  
399 +  // first thing first, suspend fatalities.
400 +  painCave.isEventLoop = 1;
401  
402 <  int masterIndex;
403 <  int nodeAtomsStart;
388 <  int nodeAtomsEnd;
389 <  int mpiErr;
390 <  int sendError;
391 <  int procIndex;
392 <    
393 <  MPI_Status istatus[MPI_STATUS_SIZE];
402 >  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
403 >  int haveError;
404  
405 <    
406 <  // write out header and node 0's coordinates
405 >  MPI_Status istatus;
406 >  int *AtomToProcMap = mpiSim->getAtomToProcMap();
407  
408 +  // write out header and node 0's coordinates
409 +  
410 +  haveError = 0;
411    if( worldRank == 0 ){
412      finalOut << mpiSim->getTotAtoms() << "\n";
413 <      
413 >    
414      finalOut << entry_plug->box_x << "\t"
415 <             << entry_plug->box_y << "\t"
416 <             << entry_plug->box_z << "\n";
415 >            << entry_plug->box_y << "\t"
416 >            << entry_plug->box_z << "\n";
417      
418 <    masterIndex = 0;
419 <    
407 <    for( i=0; i<nAtoms; i++ ){
418 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
419 >      // Get the Node number which has this molecule:
420        
421 <      sprintf( tempBuffer,
422 <               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
423 <               atoms[i]->getType(),
424 <               atoms[i]->getX(),
425 <               atoms[i]->getY(),
426 <               atoms[i]->getZ(),
427 <               atoms[i]->get_vx(),
428 <               atoms[i]->get_vy(),
429 <               atoms[i]->get_vz());
430 <      strcpy( writeLine, tempBuffer );
431 <        
432 <      if( atoms[i]->isDirectional() ){
421 >      which_node = AtomToProcMap[i];    
422 >      
423 >      if (which_node == mpiSim->getMyNode()) {
424 >
425 >        which_atom = i;
426 >        local_index=-1;        
427 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
428 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
429 >        }
430 >        if (local_index != -1) {        
431 >          sprintf( tempBuffer,
432 >                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
433 >                   atoms[local_index]->getType(),
434 >                   atoms[local_index]->getX(),
435 >                   atoms[local_index]->getY(),
436 >                   atoms[local_index]->getZ(),
437 >                   atoms[local_index]->get_vx(),
438 >                   atoms[local_index]->get_vy(),
439 >                   atoms[local_index]->get_vz());
440 >          strcpy( writeLine, tempBuffer );
441            
442 <        dAtom = (DirectionalAtom *)atoms[i];
443 <        dAtom->getQ( q );
444 <          
445 <        sprintf( tempBuffer,
446 <                 "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
447 <                 q[0],
448 <                 q[1],
449 <                 q[2],
450 <                 q[3],
451 <                 dAtom->getJx(),
452 <                 dAtom->getJy(),
453 <                 dAtom->getJz());
454 <        strcat( writeLine, tempBuffer );
455 <      }
456 <      else
457 <        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
442 >          if( atoms[local_index]->isDirectional() ){
443 >            
444 >            dAtom = (DirectionalAtom *)atoms[local_index];
445 >            dAtom->getQ( q );
446 >            
447 >            sprintf( tempBuffer,
448 >                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
449 >                     q[0],
450 >                     q[1],
451 >                     q[2],
452 >                     q[3],
453 >                     dAtom->getJx(),
454 >                     dAtom->getJy(),
455 >                     dAtom->getJz());
456 >            strcat( writeLine, tempBuffer );
457 >          }
458 >          else
459 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
460 >        }
461 >        else {
462 >          sprintf(painCave.errMsg,
463 >                  "Atom %d not found on processor %d\n",
464 >                  i, worldRank );
465 >          haveError= 1;
466 >          simError();
467 >        }
468 >
469 >        if(haveError) nodeZeroError();
470 >    
471 >      }
472 >      else {
473 >        
474 >        myStatus = 1;
475 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
476 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
477 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
478 >                 MPI_COMM_WORLD);
479 >        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
480 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
481 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
482 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
483          
484 +        if(!myStatus) nodeZeroError();
485 +      }
486 +      
487        finalOut << writeLine;
440      masterIndex++;
488      }
442    finalOut.flush();
443  }
489      
490 <  for (procIndex = 1; procIndex < mpiSim->getNumberProcessors();
491 <       procIndex++){
490 >    // kill everyone off:
491 >    myStatus = -1;
492 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
493 >      MPI_Send(&myStatus, 1, MPI_INT, j,
494 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
495 >    }
496  
497 <    if( worldRank == 0 ){
498 <        
499 <      mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,
500 <                        TAKE_THIS_TAG,MPI_COMM_WORLD,istatus);
497 >  } else {
498 >    
499 >    done = 0;
500 >    while (!done) {
501  
502 <      mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,
503 <                        TAKE_THIS_TAG,MPI_COMM_WORLD, istatus);
504 <        
505 <      // Make sure where node 0 is writing to, matches where the
506 <      // receiving node expects it to be.
507 <        
508 <      if (masterIndex != nodeAtomsStart){
509 <        sendError = 1;
510 <        mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,
511 <                          MPI_COMM_WORLD);
512 <        sprintf(painCave.errMsg,
513 <                "DumpWriter error: atoms start index (%d) for "
514 <                "node %d not equal to master index (%d)",
515 <                nodeAtomsStart,procIndex,masterIndex );
467 <        painCave.isFatal = 1;
468 <        simError();
502 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
503 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
504 >      
505 >      if(!myStatus) anonymousNodeDie();
506 >      
507 >      if(myStatus < 0) break;
508 >      
509 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
510 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
511 >      
512 >      myStatus = 1;
513 >      local_index=-1;        
514 >      for (j=0; j < mpiSim->getMyNlocal(); j++) {
515 >        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
516        }
517 <        
471 <      sendError = 0;
472 <      mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,
473 <                        MPI_COMM_WORLD);
517 >      if (local_index != -1) {
518  
519 <      // recieve the nodes writeLines
476 <
477 <      for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){
478 <          
479 <        mpiErr = MPI_Recv(writeLine,BUFFERSIZE,MPI_CHAR,procIndex,
480 <                          TAKE_THIS_TAG,MPI_COMM_WORLD,istatus );
481 <
482 <        finalOut << writeLine;
483 <        masterIndex++;
484 <      }
485 <
486 <      finalOut.flush();
487 <    }
488 <
489 <    else if( worldRank == procIndex ){
490 <
491 <      nodeAtomsStart = mpiSim->getMyAtomStart();
492 <      nodeAtomsEnd = mpiSim->getMyAtomEnd();
493 <        
494 <      mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG,
495 <                        MPI_COMM_WORLD);
496 <      mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG,
497 <                        MPI_COMM_WORLD);
498 <        
499 <      mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,
500 <                        MPI_COMM_WORLD, istatus);
501 <      if (sendError) MPIcheckPoint();
502 <
503 <      // send current node's configuration line by line.
504 <
505 <      for( i=0; i<nAtoms; i++ ){
506 <          
519 >        //format the line
520          sprintf( tempBuffer,
521                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
522 <                 atoms[i]->getType(),
523 <                 atoms[i]->getX(),
524 <                 atoms[i]->getY(),
525 <                 atoms[i]->getZ(),
526 <                 atoms[i]->get_vx(),
527 <                 atoms[i]->get_vy(),
528 <                 atoms[i]->get_vz());
522 >                 atoms[local_index]->getType(),
523 >                 atoms[local_index]->getX(),
524 >                 atoms[local_index]->getY(),
525 >                 atoms[local_index]->getZ(),
526 >                 atoms[local_index]->get_vx(),
527 >                 atoms[local_index]->get_vy(),
528 >                 atoms[local_index]->get_vz()); // check here.
529          strcpy( writeLine, tempBuffer );
530 +        
531 +        if( atoms[local_index]->isDirectional() ){
532            
533 <        if( atoms[i]->isDirectional() ){
519 <            
520 <          dAtom = (DirectionalAtom *)atoms[i];
533 >          dAtom = (DirectionalAtom *)atoms[local_index];
534            dAtom->getQ( q );
535 <            
535 >          
536            sprintf( tempBuffer,
537                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
538                     q[0],
# Line 531 | Line 544 | void DumpWriter::writeFinal(){
544                     dAtom->getJz());
545            strcat( writeLine, tempBuffer );
546          }
547 <        else
547 >        else{
548            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
549 <          
550 <        mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG,
551 <                          MPI_COMM_WORLD);
549 >        }
550 >      }
551 >      else {
552 >        sprintf(painCave.errMsg,
553 >                "Atom %d not found on processor %d\n",
554 >                which_atom, worldRank );
555 >        myStatus = 0;
556 >        simError();
557 >        
558 >        strcpy( writeLine, "Hello, I'm an error.\n");
559        }
560 +
561 +      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
562 +               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
563 +      MPI_Send( &myStatus, 1, MPI_INT, 0,
564 +                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
565      }
541      
542    sprintf(checkPointMsg,"Node %d sent dump configuration.",
543            procIndex);
544    MPIcheckPoint();
566    }
567 +  finalOut.flush();
568 +  sprintf( checkPointMsg,
569 +           "Sucessfully took a dump.\n");
570 +  MPIcheckPoint();
571 +  
572 +  if( worldRank == 0 ) finalOut.close();    
573 + #endif // is_mpi
574 + }
575  
547  if( worldRank == 0 ) finalOut.close();
576  
577 <    
578 < #endif // is_mpi
577 >
578 > #ifdef IS_MPI
579 >
580 > // a couple of functions to let us escape the write loop
581 >
582 > void dWrite::nodeZeroError( void ){
583 >  int j, myStatus;
584 >  
585 >  myStatus = 0;
586 >  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
587 >    MPI_Send( &myStatus, 1, MPI_INT, j,
588 >              TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
589 >  }  
590 >  
591 >
592 >  MPI_Finalize();
593 >  exit (0);
594 >  
595   }
596 +
597 + void dWrite::anonymousNodeDie( void ){
598 +
599 +  MPI_Finalize();
600 +  exit (0);
601 + }
602 +
603 + #endif //is_mpi

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines