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 378 by mmeineke, Fri Mar 21 17:42:12 2003 UTC vs.
Revision 440 by mmeineke, Tue Apr 1 16:49:17 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines