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 572 by mmeineke, Wed Jul 2 21:26:55 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 80 | Line 82 | void DumpWriter::writeDump( double currentTime ){
82    outFile << nAtoms << "\n";
83      
84    outFile << currentTime << "\t"
85 <          << entry_plug->box_x << "\t"
86 <          << entry_plug->box_y << "\t"
87 <          << entry_plug->box_z << "\n";
85 >          << entry_plug->Hmat[0] << "\t"
86 >          << entry_plug->Hmat[1] << "\t"
87 >          << entry_plug->Hmat[2] << "\t"
88 >
89 >          << entry_plug->Hmat[3] << "\t"
90 >          << entry_plug->Hmat[4] << "\t"
91 >          << entry_plug->Hmat[5] << "\t"
92 >
93 >          << entry_plug->Hmat[6] << "\t"
94 >          << entry_plug->Hmat[7] << "\t"
95 >          << entry_plug->Hmat[8] << "\n";
96      
97    for( i=0; i<nAtoms; i++ ){
98        
# Line 123 | Line 133 | void DumpWriter::writeDump( double currentTime ){
133  
134   #else // is_mpi
135  
136 <  int masterIndex;
137 <  int nodeAtomsStart;
128 <  int nodeAtomsEnd;
129 <  int mpiErr;
130 <  int sendError;
131 <  int procIndex;
132 <    
133 <  MPI_Status istatus[MPI_STATUS_SIZE];
136 >  // first thing first, suspend fatalities.
137 >  painCave.isEventLoop = 1;
138  
139 <    
140 <  // write out header and node 0's coordinates
139 >  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
140 >  int haveError;
141  
142 +  MPI_Status istatus;
143 +  int *AtomToProcMap = mpiSim->getAtomToProcMap();
144 +  
145 +  // write out header and node 0's coordinates
146 +  
147    if( worldRank == 0 ){
148      outFile << mpiSim->getTotAtoms() << "\n";
149 <      
149 >  
150      outFile << currentTime << "\t"
151 <            << entry_plug->box_x << "\t"
152 <            << entry_plug->box_y << "\t"
153 <            << entry_plug->box_z << "\n";
145 <
146 <    masterIndex = 0;
147 <    for( i=0; i<nAtoms; i++ ){
151 >            << entry_plug->Hmat[0] << "\t"
152 >            << entry_plug->Hmat[1] << "\t"
153 >            << entry_plug->Hmat[2] << "\t"
154        
155 <      sprintf( tempBuffer,
156 <               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
157 <               atoms[i]->getType(),
158 <               atoms[i]->getX(),
159 <               atoms[i]->getY(),
160 <               atoms[i]->getZ(),
161 <               atoms[i]->get_vx(),
162 <               atoms[i]->get_vy(),
163 <               atoms[i]->get_vz());
164 <      strcpy( writeLine, tempBuffer );
155 >            << entry_plug->Hmat[3] << "\t"
156 >            << entry_plug->Hmat[4] << "\t"
157 >            << entry_plug->Hmat[5] << "\t"
158 >      
159 >            << entry_plug->Hmat[6] << "\t"
160 >            << entry_plug->Hmat[7] << "\t"
161 >            << entry_plug->Hmat[8] << "\n";
162 >    ;
163 >    outFile.flush();
164 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
165 >      // Get the Node number which has this atom;
166 >      
167 >      which_node = AtomToProcMap[i];    
168 >      
169 >      if (which_node == 0 ) {
170          
171 <      if( atoms[i]->isDirectional() ){
171 >        haveError = 0;
172 >        which_atom = i;
173 >        local_index=-1;        
174 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
175 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
176 >        }
177 >        if (local_index != -1) {
178 >          //format the line
179 >          sprintf( tempBuffer,
180 >                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
181 >                   atoms[local_index]->getType(),
182 >                   atoms[local_index]->getX(),
183 >                   atoms[local_index]->getY(),
184 >                   atoms[local_index]->getZ(),
185 >                   atoms[local_index]->get_vx(),
186 >                   atoms[local_index]->get_vy(),
187 >                   atoms[local_index]->get_vz()); // check here.
188 >          strcpy( writeLine, tempBuffer );
189            
190 <        dAtom = (DirectionalAtom *)atoms[i];
191 <        dAtom->getQ( q );
192 <          
193 <        sprintf( tempBuffer,
194 <                 "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
195 <                 q[0],
196 <                 q[1],
197 <                 q[2],
198 <                 q[3],
199 <                 dAtom->getJx(),
200 <                 dAtom->getJy(),
201 <                 dAtom->getJz());
202 <        strcat( writeLine, tempBuffer );
190 >          if( atoms[local_index]->isDirectional() ){
191 >            
192 >            dAtom = (DirectionalAtom *)atoms[local_index];
193 >            dAtom->getQ( q );
194 >            
195 >            sprintf( tempBuffer,
196 >                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
197 >                     q[0],
198 >                     q[1],
199 >                     q[2],
200 >                     q[3],
201 >                     dAtom->getJx(),
202 >                     dAtom->getJy(),
203 >                     dAtom->getJz());
204 >            strcat( writeLine, tempBuffer );
205 >            
206 >          }
207 >          else
208 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
209 >        }
210 >        else {
211 >          sprintf(painCave.errMsg,
212 >                  "Atom %d not found on processor %d\n",
213 >                  i, worldRank );
214 >          haveError= 1;
215 >          simError();
216 >        }
217 >        
218 >        if(haveError) nodeZeroError();
219 >
220        }
221 <      else
222 <        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
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();
233 +
234 +      }
235 +      
236        outFile << writeLine;
237 <      masterIndex++;
237 >      outFile.flush();
238      }
182    outFile.flush();
183  }
184
185  sprintf( checkPointMsg,
186           "Sucessfully wrote node 0's dump configuration.\n");
187  MPIcheckPoint();
239      
240 <  for (procIndex = 1; procIndex < mpiSim->getNumberProcessors();
241 <       procIndex++){
242 <
243 <    if( worldRank == 0 ){
244 <      
194 <      mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,
195 <                        TAKE_THIS_TAG,MPI_COMM_WORLD,istatus);
196 <      
197 <      mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,
198 <                        TAKE_THIS_TAG,MPI_COMM_WORLD, istatus);
199 <      
200 <      // 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();
213 <      }
214 <      
215 <      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 <      }
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      }
246  
247 <    else if( worldRank == procIndex ){
247 >  } else {
248 >    
249 >    done = 0;
250 >    while (!done) {
251 >      
252 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
253 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
254  
255 <      nodeAtomsStart = mpiSim->getMyAtomStart();
256 <      nodeAtomsEnd = mpiSim->getMyAtomEnd();
255 >      if(!myStatus) anonymousNodeDie();
256 >      
257 >      if(myStatus < 0) break;
258  
259 <      mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG,
260 <                        MPI_COMM_WORLD);
261 <      mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG,
262 <                        MPI_COMM_WORLD);
263 <        
264 <      sendError = -1;
265 <      mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,
266 <                        MPI_COMM_WORLD, istatus);
267 <
268 <      if (sendError) MPIcheckPoint();
246 <
247 <      // send current node's configuration line by line.
248 <
249 <      for( i=0; i<nAtoms; i++ ){
250 <
259 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
260 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
261 >      
262 >      myStatus = 1;
263 >      local_index=-1;        
264 >      for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
265 >        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
266 >      }
267 >      if (local_index != -1) {
268 >        //format the line
269          sprintf( tempBuffer,
270                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
271 <                 atoms[i]->getType(),
272 <                 atoms[i]->getX(),
273 <                 atoms[i]->getY(),
274 <                 atoms[i]->getZ(),
275 <                 atoms[i]->get_vx(),
276 <                 atoms[i]->get_vy(),
277 <                 atoms[i]->get_vz()); // check here.
271 >                 atoms[local_index]->getType(),
272 >                 atoms[local_index]->getX(),
273 >                 atoms[local_index]->getY(),
274 >                 atoms[local_index]->getZ(),
275 >                 atoms[local_index]->get_vx(),
276 >                 atoms[local_index]->get_vy(),
277 >                 atoms[local_index]->get_vz()); // check here.
278          strcpy( writeLine, tempBuffer );
279 +        
280 +        if( atoms[local_index]->isDirectional() ){
281            
282 <        if( atoms[i]->isDirectional() ){
263 <            
264 <          dAtom = (DirectionalAtom *)atoms[i];
282 >          dAtom = (DirectionalAtom *)atoms[local_index];
283            dAtom->getQ( q );
284 <            
284 >          
285            sprintf( tempBuffer,
286                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
287                     q[0],
# Line 275 | Line 293 | void DumpWriter::writeDump( double currentTime ){
293                     dAtom->getJz());
294            strcat( writeLine, tempBuffer );
295          }
296 <        else
296 >        else{
297            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
298 <          
299 <        mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG,
300 <                          MPI_COMM_WORLD);
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();
306 >
307 >        strcpy( writeLine, "Hello, I'm an error.\n");
308        }
309 +
310 +      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
311 +               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
312 +      MPI_Send( &myStatus, 1, MPI_INT, 0,
313 +                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
314      }
315 <      
316 <    sprintf(checkPointMsg,"Node %d sent dump configuration.",
317 <            procIndex);
318 <    MPIcheckPoint();
319 <  }
320 <    
315 >  }  
316 >  outFile.flush();
317 >  sprintf( checkPointMsg,
318 >           "Sucessfully took a dump.\n");
319 >  MPIcheckPoint();
320 >
321 > // last  thing last, enable  fatalities.
322 >  painCave.isEventLoop = 0;
323 >
324   #endif // is_mpi
325   }
326  
327 + void DumpWriter::writeFinal(double finalTime){
328  
329 +  char finalName[500];
330 +  ofstream finalOut;
331  
296 void DumpWriter::writeFinal(){
297
298
332    const int BUFFERSIZE = 2000;
333 <  char tempBuffer[500];
334 <  char writeLine[BUFFERSIZE];
302 <  
303 <  char finalName[500];
333 >  char tempBuffer[BUFFERSIZE];
334 >  char writeLine[BUFFERSIZE];  
335  
305  int i;
336    double q[4];
337    DirectionalAtom* dAtom;
338    int nAtoms = entry_plug->n_atoms;
339    Atom** atoms = entry_plug->atoms;
340 +  int i, j, which_node, done, game_over, which_atom, local_index;
341    
311  ofstream finalOut;
342    
343   #ifdef IS_MPI
344    if(worldRank == 0 ){
# Line 335 | Line 365 | void DumpWriter::writeFinal(){
365    
366   #endif //is_mpi
367  
368 <    
339 <
368 >  
369   #ifndef IS_MPI
370      
371    finalOut << nAtoms << "\n";
372      
373 <  finalOut << entry_plug->box_x << "\t"
374 <           << entry_plug->box_y << "\t"
375 <           << entry_plug->box_z << "\n";
373 >  finalOut << finalTime << "\t"
374 >           << entry_plug->Hmat[0] << "\t"
375 >           << entry_plug->Hmat[1] << "\t"
376 >           << entry_plug->Hmat[2] << "\t"
377      
378 +           << entry_plug->Hmat[3] << "\t"
379 +           << entry_plug->Hmat[4] << "\t"
380 +           << entry_plug->Hmat[5] << "\t"
381 +    
382 +           << entry_plug->Hmat[6] << "\t"
383 +           << entry_plug->Hmat[7] << "\t"
384 +           << entry_plug->Hmat[8] << "\n";
385 +  
386    for( i=0; i<nAtoms; i++ ){
387        
388      sprintf( tempBuffer,
# Line 380 | Line 418 | void DumpWriter::writeFinal(){
418      finalOut << writeLine;
419    }
420    finalOut.flush();
421 +  finalOut.close();
422  
423   #else // is_mpi
424 +  
425 +  // first thing first, suspend fatalities.
426 +  painCave.isEventLoop = 1;
427  
428 <  int masterIndex;
429 <  int nodeAtomsStart;
388 <  int nodeAtomsEnd;
389 <  int mpiErr;
390 <  int sendError;
391 <  int procIndex;
392 <    
393 <  MPI_Status istatus[MPI_STATUS_SIZE];
428 >  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
429 >  int haveError;
430  
431 <    
432 <  // write out header and node 0's coordinates
431 >  MPI_Status istatus;
432 >  int *AtomToProcMap = mpiSim->getAtomToProcMap();
433  
434 +  // write out header and node 0's coordinates
435 +  
436 +  haveError = 0;
437    if( worldRank == 0 ){
438      finalOut << mpiSim->getTotAtoms() << "\n";
439 +    
440 +    finalOut << finalTime << "\t"
441 +             << entry_plug->Hmat[0] << "\t"
442 +             << entry_plug->Hmat[1] << "\t"
443 +             << entry_plug->Hmat[2] << "\t"
444        
445 <    finalOut << entry_plug->box_x << "\t"
446 <             << entry_plug->box_y << "\t"
447 <             << entry_plug->box_z << "\n";
445 >             << entry_plug->Hmat[3] << "\t"
446 >             << entry_plug->Hmat[4] << "\t"
447 >             << entry_plug->Hmat[5] << "\t"
448 >      
449 >             << entry_plug->Hmat[6] << "\t"
450 >             << entry_plug->Hmat[7] << "\t"
451 >             << entry_plug->Hmat[8] << "\n";
452      
453 <    masterIndex = 0;
454 <    
407 <    for( i=0; i<nAtoms; i++ ){
453 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
454 >      // Get the Node number which has this molecule:
455        
456 <      sprintf( tempBuffer,
457 <               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
458 <               atoms[i]->getType(),
459 <               atoms[i]->getX(),
460 <               atoms[i]->getY(),
461 <               atoms[i]->getZ(),
462 <               atoms[i]->get_vx(),
463 <               atoms[i]->get_vy(),
464 <               atoms[i]->get_vz());
465 <      strcpy( writeLine, tempBuffer );
466 <        
467 <      if( atoms[i]->isDirectional() ){
456 >      which_node = AtomToProcMap[i];    
457 >      
458 >      if (which_node == mpiSim->getMyNode()) {
459 >
460 >        which_atom = i;
461 >        local_index=-1;        
462 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
463 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
464 >        }
465 >        if (local_index != -1) {        
466 >          sprintf( tempBuffer,
467 >                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
468 >                   atoms[local_index]->getType(),
469 >                   atoms[local_index]->getX(),
470 >                   atoms[local_index]->getY(),
471 >                   atoms[local_index]->getZ(),
472 >                   atoms[local_index]->get_vx(),
473 >                   atoms[local_index]->get_vy(),
474 >                   atoms[local_index]->get_vz());
475 >          strcpy( writeLine, tempBuffer );
476            
477 <        dAtom = (DirectionalAtom *)atoms[i];
478 <        dAtom->getQ( q );
479 <          
480 <        sprintf( tempBuffer,
481 <                 "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
482 <                 q[0],
483 <                 q[1],
484 <                 q[2],
485 <                 q[3],
486 <                 dAtom->getJx(),
487 <                 dAtom->getJy(),
488 <                 dAtom->getJz());
489 <        strcat( writeLine, tempBuffer );
490 <      }
491 <      else
492 <        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
477 >          if( atoms[local_index]->isDirectional() ){
478 >            
479 >            dAtom = (DirectionalAtom *)atoms[local_index];
480 >            dAtom->getQ( q );
481 >            
482 >            sprintf( tempBuffer,
483 >                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
484 >                     q[0],
485 >                     q[1],
486 >                     q[2],
487 >                     q[3],
488 >                     dAtom->getJx(),
489 >                     dAtom->getJy(),
490 >                     dAtom->getJz());
491 >            strcat( writeLine, tempBuffer );
492 >          }
493 >          else
494 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
495 >        }
496 >        else {
497 >          sprintf(painCave.errMsg,
498 >                  "Atom %d not found on processor %d\n",
499 >                  i, worldRank );
500 >          haveError= 1;
501 >          simError();
502 >        }
503 >
504 >        if(haveError) nodeZeroError();
505 >    
506 >      }
507 >      else {
508 >        
509 >        myStatus = 1;
510 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
511 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
512 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
513 >                 MPI_COMM_WORLD);
514 >        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
515 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
516 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
517 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
518          
519 +        if(!myStatus) nodeZeroError();
520 +      }
521 +      
522        finalOut << writeLine;
440      masterIndex++;
523      }
442    finalOut.flush();
443  }
524      
525 <  for (procIndex = 1; procIndex < mpiSim->getNumberProcessors();
526 <       procIndex++){
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 >    }
531  
532 <    if( worldRank == 0 ){
533 <        
534 <      mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,
535 <                        TAKE_THIS_TAG,MPI_COMM_WORLD,istatus);
532 >  } else {
533 >    
534 >    done = 0;
535 >    while (!done) {
536  
537 <      mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,
538 <                        TAKE_THIS_TAG,MPI_COMM_WORLD, istatus);
539 <        
540 <      // Make sure where node 0 is writing to, matches where the
541 <      // receiving node expects it to be.
542 <        
543 <      if (masterIndex != nodeAtomsStart){
544 <        sendError = 1;
545 <        mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,
546 <                          MPI_COMM_WORLD);
547 <        sprintf(painCave.errMsg,
548 <                "DumpWriter error: atoms start index (%d) for "
549 <                "node %d not equal to master index (%d)",
550 <                nodeAtomsStart,procIndex,masterIndex );
467 <        painCave.isFatal = 1;
468 <        simError();
537 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
538 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
539 >      
540 >      if(!myStatus) anonymousNodeDie();
541 >      
542 >      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 <        
471 <      sendError = 0;
472 <      mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,
473 <                        MPI_COMM_WORLD);
552 >      if (local_index != -1) {
553  
554 <      // 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 <          
554 >        //format the line
555          sprintf( tempBuffer,
556                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
557 <                 atoms[i]->getType(),
558 <                 atoms[i]->getX(),
559 <                 atoms[i]->getY(),
560 <                 atoms[i]->getZ(),
561 <                 atoms[i]->get_vx(),
562 <                 atoms[i]->get_vy(),
563 <                 atoms[i]->get_vz());
557 >                 atoms[local_index]->getType(),
558 >                 atoms[local_index]->getX(),
559 >                 atoms[local_index]->getY(),
560 >                 atoms[local_index]->getZ(),
561 >                 atoms[local_index]->get_vx(),
562 >                 atoms[local_index]->get_vy(),
563 >                 atoms[local_index]->get_vz()); // check here.
564          strcpy( writeLine, tempBuffer );
565 +        
566 +        if( atoms[local_index]->isDirectional() ){
567            
568 <        if( atoms[i]->isDirectional() ){
519 <            
520 <          dAtom = (DirectionalAtom *)atoms[i];
568 >          dAtom = (DirectionalAtom *)atoms[local_index];
569            dAtom->getQ( q );
570 <            
570 >          
571            sprintf( tempBuffer,
572                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
573                     q[0],
# Line 531 | Line 579 | void DumpWriter::writeFinal(){
579                     dAtom->getJz());
580            strcat( writeLine, tempBuffer );
581          }
582 <        else
582 >        else{
583            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
584 <          
585 <        mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG,
586 <                          MPI_COMM_WORLD);
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        }
595 +
596 +      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
597 +               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
598 +      MPI_Send( &myStatus, 1, MPI_INT, 0,
599 +                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
600      }
541      
542    sprintf(checkPointMsg,"Node %d sent dump configuration.",
543            procIndex);
544    MPIcheckPoint();
601    }
602 +  finalOut.flush();
603 +  sprintf( checkPointMsg,
604 +           "Sucessfully took a dump.\n");
605 +  MPIcheckPoint();
606 +  
607 +  if( worldRank == 0 ) finalOut.close();    
608 + #endif // is_mpi
609 + }
610  
547  if( worldRank == 0 ) finalOut.close();
611  
612 <    
613 < #endif // is_mpi
612 >
613 > #ifdef IS_MPI
614 >
615 > // a couple of functions to let us escape the write loop
616 >
617 > 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 >  
626 >
627 >  MPI_Finalize();
628 >  exit (0);
629 >  
630   }
631 +
632 + void dWrite::anonymousNodeDie( void ){
633 +
634 +  MPI_Finalize();
635 +  exit (0);
636 + }
637 +
638 + #endif //is_mpi

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines