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 670 by mmeineke, Thu Aug 7 21:47:18 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;
77    Atom** atoms = entry_plug->atoms;
78 +
79 +  double pos[3], vel[3];
80      
81  
82   #ifndef IS_MPI
83      
84    outFile << nAtoms << "\n";
85      
86 <  outFile << currentTime << "\t"
87 <          << entry_plug->box_x << "\t"
88 <          << entry_plug->box_y << "\t"
89 <          << entry_plug->box_z << "\n";
86 >  outFile << currentTime << ";\t"
87 >          << entry_plug->Hmat[0][0] << "\t"
88 >          << entry_plug->Hmat[1][0] << "\t"
89 >          << entry_plug->Hmat[2][0] << ";\t"
90 >
91 >          << entry_plug->Hmat[0][1] << "\t"
92 >          << entry_plug->Hmat[1][1] << "\t"
93 >          << entry_plug->Hmat[2][1] << ";\t"
94 >
95 >          << entry_plug->Hmat[0][2] << "\t"
96 >          << entry_plug->Hmat[1][2] << "\t"
97 >          << entry_plug->Hmat[2][2] << ";\n";
98      
99    for( i=0; i<nAtoms; i++ ){
100        
101 +    atoms[i]->getPos(pos);
102 +    atoms[i]->getVel(vel);
103  
104      sprintf( tempBuffer,
105               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
106               atoms[i]->getType(),
107 <             atoms[i]->getX(),
108 <             atoms[i]->getY(),
109 <             atoms[i]->getZ(),
110 <             atoms[i]->get_vx(),
111 <             atoms[i]->get_vy(),
112 <             atoms[i]->get_vz());
107 >             pos[0],
108 >             pos[1],
109 >             pos[2],
110 >             vel[0],
111 >             vel[1],
112 >             vel[2]);
113      strcpy( writeLine, tempBuffer );
114  
115      if( atoms[i]->isDirectional() ){
# Line 123 | Line 137 | void DumpWriter::writeDump( double currentTime ){
137  
138   #else // is_mpi
139  
140 <  int masterIndex;
141 <  int nodeAtomsStart;
128 <  int nodeAtomsEnd;
129 <  int mpiErr;
130 <  int sendError;
131 <  int procIndex;
132 <    
133 <  MPI_Status istatus[MPI_STATUS_SIZE];
140 >  // first thing first, suspend fatalities.
141 >  painCave.isEventLoop = 1;
142  
143 <    
144 <  // write out header and node 0's coordinates
143 >  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
144 >  int haveError;
145  
146 +  MPI_Status istatus;
147 +  int *AtomToProcMap = mpiSim->getAtomToProcMap();
148 +  
149 +  // write out header and node 0's coordinates
150 +  
151    if( worldRank == 0 ){
152      outFile << mpiSim->getTotAtoms() << "\n";
153 +  
154 +    outFile << currentTime << ";\t"
155 +            << entry_plug->Hmat[0][0] << "\t"
156 +            << entry_plug->Hmat[1][0] << "\t"
157 +            << entry_plug->Hmat[2][0] << ";\t"
158        
159 <    outFile << currentTime << "\t"
160 <            << entry_plug->box_x << "\t"
161 <            << entry_plug->box_y << "\t"
144 <            << entry_plug->box_z << "\n";
145 <
146 <    masterIndex = 0;
147 <    for( i=0; i<nAtoms; i++ ){
159 >            << entry_plug->Hmat[0][1] << "\t"
160 >            << entry_plug->Hmat[1][1] << "\t"
161 >            << entry_plug->Hmat[2][1] << ";\t"
162        
163 <      sprintf( tempBuffer,
164 <               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
165 <               atoms[i]->getType(),
166 <               atoms[i]->getX(),
167 <               atoms[i]->getY(),
168 <               atoms[i]->getZ(),
169 <               atoms[i]->get_vx(),
170 <               atoms[i]->get_vy(),
171 <               atoms[i]->get_vz());
172 <      strcpy( writeLine, tempBuffer );
163 >            << entry_plug->Hmat[0][2] << "\t"
164 >            << entry_plug->Hmat[1][2] << "\t"
165 >            << entry_plug->Hmat[2][2] << ";\n";
166 >    
167 >    outFile.flush();
168 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
169 >      // Get the Node number which has this atom;
170 >      
171 >      which_node = AtomToProcMap[i];    
172 >      
173 >      if (which_node == 0 ) {
174          
175 <      if( atoms[i]->isDirectional() ){
175 >        haveError = 0;
176 >        which_atom = i;
177 >        local_index=-1;        
178 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
179 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
180 >        }
181 >        if (local_index != -1) {
182 >          //format the line
183            
184 <        dAtom = (DirectionalAtom *)atoms[i];
185 <        dAtom->getQ( q );
184 >          atoms[local_index]->getPos(pos);
185 >          atoms[local_index]->getVel(vel);
186 >
187 >          sprintf( tempBuffer,
188 >                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
189 >                   atoms[local_index]->getType(),
190 >                   pos[0],
191 >                   pos[1],
192 >                   pos[2],
193 >                   vel[0],
194 >                   vel[1],
195 >                   vel[2]); // check here.
196 >          strcpy( writeLine, tempBuffer );
197            
198 <        sprintf( tempBuffer,
199 <                 "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
200 <                 q[0],
201 <                 q[1],
202 <                 q[2],
203 <                 q[3],
204 <                 dAtom->getJx(),
205 <                 dAtom->getJy(),
206 <                 dAtom->getJz());
207 <        strcat( writeLine, tempBuffer );
198 >          if( atoms[local_index]->isDirectional() ){
199 >            
200 >            dAtom = (DirectionalAtom *)atoms[local_index];
201 >            dAtom->getQ( q );
202 >            
203 >            sprintf( tempBuffer,
204 >                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
205 >                     q[0],
206 >                     q[1],
207 >                     q[2],
208 >                     q[3],
209 >                     dAtom->getJx(),
210 >                     dAtom->getJy(),
211 >                     dAtom->getJz());
212 >            strcat( writeLine, tempBuffer );
213 >            
214 >          }
215 >          else
216 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
217 >        }
218 >        else {
219 >          sprintf(painCave.errMsg,
220 >                  "Atom %d not found on processor %d\n",
221 >                  i, worldRank );
222 >          haveError= 1;
223 >          simError();
224 >        }
225 >        
226 >        if(haveError) nodeZeroError();
227 >
228        }
229 <      else
230 <        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
229 >      else {
230 >        myStatus = 1;
231 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
232 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
233 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
234 >                 MPI_COMM_WORLD);
235 >        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
236 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
237 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
238 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
239          
240 +        if(!myStatus) nodeZeroError();
241 +
242 +      }
243 +      
244        outFile << writeLine;
245 <      masterIndex++;
245 >      outFile.flush();
246      }
182    outFile.flush();
183  }
184
185  sprintf( checkPointMsg,
186           "Sucessfully wrote node 0's dump configuration.\n");
187  MPIcheckPoint();
247      
248 <  for (procIndex = 1; procIndex < mpiSim->getNumberProcessors();
249 <       procIndex++){
248 >    // kill everyone off:
249 >    myStatus = -1;
250 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
251 >      MPI_Send(&myStatus, 1, MPI_INT, j,
252 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
253 >    }
254  
255 <    if( worldRank == 0 ){
255 >  } else {
256 >    
257 >    done = 0;
258 >    while (!done) {
259        
260 <      mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,
261 <                        TAKE_THIS_TAG,MPI_COMM_WORLD,istatus);
260 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
261 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
262 >
263 >      if(!myStatus) anonymousNodeDie();
264        
265 <      mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,
266 <                        TAKE_THIS_TAG,MPI_COMM_WORLD, istatus);
265 >      if(myStatus < 0) break;
266 >
267 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
268 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
269        
270 <      // Make sure where node 0 is writing to, matches where the
271 <      // receiving node expects it to be.
272 <      
273 <      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();
270 >      myStatus = 1;
271 >      local_index=-1;        
272 >      for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
273 >        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
274        }
275 <      
276 <      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 <    }
275 >      if (local_index != -1) {
276 >        //format the line
277  
278 <    else if( worldRank == procIndex ){
278 >        atoms[local_index]->getPos(pos);
279 >        atoms[local_index]->getVel(vel);
280  
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
281          sprintf( tempBuffer,
282                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
283 <                 atoms[i]->getType(),
284 <                 atoms[i]->getX(),
285 <                 atoms[i]->getY(),
286 <                 atoms[i]->getZ(),
287 <                 atoms[i]->get_vx(),
288 <                 atoms[i]->get_vy(),
289 <                 atoms[i]->get_vz()); // check here.
283 >                 atoms[local_index]->getType(),
284 >                 pos[0],
285 >                 pos[1],
286 >                 pos[2],
287 >                 vel[0],
288 >                 vel[1],
289 >                 vel[2]); // check here.
290          strcpy( writeLine, tempBuffer );
291 +        
292 +        if( atoms[local_index]->isDirectional() ){
293            
294 <        if( atoms[i]->isDirectional() ){
263 <            
264 <          dAtom = (DirectionalAtom *)atoms[i];
294 >          dAtom = (DirectionalAtom *)atoms[local_index];
295            dAtom->getQ( q );
296 <            
296 >          
297            sprintf( tempBuffer,
298                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
299                     q[0],
# Line 275 | Line 305 | void DumpWriter::writeDump( double currentTime ){
305                     dAtom->getJz());
306            strcat( writeLine, tempBuffer );
307          }
308 <        else
308 >        else{
309            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
310 <          
311 <        mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG,
312 <                          MPI_COMM_WORLD);
310 >        }
311 >      }
312 >      else {
313 >        sprintf(painCave.errMsg,
314 >                "Atom %d not found on processor %d\n",
315 >                which_atom, worldRank );
316 >        myStatus = 0;
317 >        simError();
318 >
319 >        strcpy( writeLine, "Hello, I'm an error.\n");
320        }
321 +
322 +      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
323 +               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
324 +      MPI_Send( &myStatus, 1, MPI_INT, 0,
325 +                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
326      }
327 <      
328 <    sprintf(checkPointMsg,"Node %d sent dump configuration.",
329 <            procIndex);
330 <    MPIcheckPoint();
331 <  }
332 <    
327 >  }  
328 >  outFile.flush();
329 >  sprintf( checkPointMsg,
330 >           "Sucessfully took a dump.\n");
331 >  MPIcheckPoint();
332 >
333 > // last  thing last, enable  fatalities.
334 >  painCave.isEventLoop = 0;
335 >
336   #endif // is_mpi
337   }
338  
339 + void DumpWriter::writeFinal(double finalTime){
340  
341 +  char finalName[500];
342 +  ofstream finalOut;
343  
296 void DumpWriter::writeFinal(){
297
298
344    const int BUFFERSIZE = 2000;
345 <  char tempBuffer[500];
346 <  char writeLine[BUFFERSIZE];
302 <  
303 <  char finalName[500];
345 >  char tempBuffer[BUFFERSIZE];
346 >  char writeLine[BUFFERSIZE];  
347  
305  int i;
348    double q[4];
349    DirectionalAtom* dAtom;
350    int nAtoms = entry_plug->n_atoms;
351    Atom** atoms = entry_plug->atoms;
352 +  int i, j, which_node, done, game_over, which_atom, local_index;
353    
354 <  ofstream finalOut;
354 >  double pos[3], vel[3];
355    
356   #ifdef IS_MPI
357    if(worldRank == 0 ){
# Line 335 | Line 378 | void DumpWriter::writeFinal(){
378    
379   #endif //is_mpi
380  
381 <    
339 <
381 >  
382   #ifndef IS_MPI
383      
384    finalOut << nAtoms << "\n";
385      
386 <  finalOut << entry_plug->box_x << "\t"
387 <           << entry_plug->box_y << "\t"
388 <           << entry_plug->box_z << "\n";
386 >  finalOut << finalTime << ";\t"
387 >           << entry_plug->Hmat[0][0] << "\t"
388 >           << entry_plug->Hmat[1][0] << "\t"
389 >           << entry_plug->Hmat[2][0] << ";\t"
390      
391 +           << entry_plug->Hmat[0][1] << "\t"
392 +           << entry_plug->Hmat[1][1] << "\t"
393 +           << entry_plug->Hmat[2][1] << ";\t"
394 +    
395 +           << entry_plug->Hmat[0][2] << "\t"
396 +           << entry_plug->Hmat[1][2] << "\t"
397 +           << entry_plug->Hmat[2][2] << ";\n";
398 +  
399    for( i=0; i<nAtoms; i++ ){
400        
401 +    atoms[i]->getPos(pos);
402 +    atoms[i]->getVel(vel);
403 +    
404      sprintf( tempBuffer,
405               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
406               atoms[i]->getType(),
407 <             atoms[i]->getX(),
408 <             atoms[i]->getY(),
409 <             atoms[i]->getZ(),
410 <             atoms[i]->get_vx(),
411 <             atoms[i]->get_vy(),
412 <             atoms[i]->get_vz());
407 >             pos[0],
408 >             pos[1],
409 >             pos[2],
410 >             vel[0],
411 >             vel[1],
412 >             vel[2]);
413      strcpy( writeLine, tempBuffer );
414  
415      if( atoms[i]->isDirectional() ){
# Line 380 | Line 434 | void DumpWriter::writeFinal(){
434      finalOut << writeLine;
435    }
436    finalOut.flush();
437 +  finalOut.close();
438  
439   #else // is_mpi
440 +  
441 +  // first thing first, suspend fatalities.
442 +  painCave.isEventLoop = 1;
443  
444 <  int masterIndex;
445 <  int nodeAtomsStart;
388 <  int nodeAtomsEnd;
389 <  int mpiErr;
390 <  int sendError;
391 <  int procIndex;
392 <    
393 <  MPI_Status istatus[MPI_STATUS_SIZE];
444 >  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
445 >  int haveError;
446  
447 <    
448 <  // write out header and node 0's coordinates
447 >  MPI_Status istatus;
448 >  int *AtomToProcMap = mpiSim->getAtomToProcMap();
449  
450 +  // write out header and node 0's coordinates
451 +  
452 +  haveError = 0;
453    if( worldRank == 0 ){
454      finalOut << mpiSim->getTotAtoms() << "\n";
455 +    
456 +    finalOut << finalTime << ";\t"
457 +             << entry_plug->Hmat[0][0] << "\t"
458 +             << entry_plug->Hmat[1][0] << "\t"
459 +             << entry_plug->Hmat[2][0] << ";\t"
460        
461 <    finalOut << entry_plug->box_x << "\t"
462 <             << entry_plug->box_y << "\t"
463 <             << entry_plug->box_z << "\n";
461 >             << entry_plug->Hmat[0][1] << "\t"
462 >             << entry_plug->Hmat[1][1] << "\t"
463 >             << entry_plug->Hmat[2][1] << ";\t"
464 >      
465 >             << entry_plug->Hmat[0][2] << "\t"
466 >             << entry_plug->Hmat[1][2] << "\t"
467 >             << entry_plug->Hmat[2][2] << ";\n";
468      
469 <    masterIndex = 0;
470 <    
407 <    for( i=0; i<nAtoms; i++ ){
469 >    for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) {
470 >      // Get the Node number which has this molecule:
471        
472 <      sprintf( tempBuffer,
473 <               "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
474 <               atoms[i]->getType(),
475 <               atoms[i]->getX(),
476 <               atoms[i]->getY(),
477 <               atoms[i]->getZ(),
478 <               atoms[i]->get_vx(),
479 <               atoms[i]->get_vy(),
480 <               atoms[i]->get_vz());
481 <      strcpy( writeLine, tempBuffer );
482 <        
483 <      if( atoms[i]->isDirectional() ){
472 >      which_node = AtomToProcMap[i];    
473 >      
474 >      if (which_node == mpiSim->getMyNode()) {
475 >
476 >        which_atom = i;
477 >        local_index=-1;        
478 >        for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) {
479 >          if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
480 >        }
481 >        if (local_index != -1) {    
482 >
483 >          atoms[local_index]->getPos(pos);
484 >          atoms[local_index]->getVel(vel);
485            
486 <        dAtom = (DirectionalAtom *)atoms[i];
487 <        dAtom->getQ( q );
486 >          sprintf( tempBuffer,
487 >                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
488 >                   atoms[local_index]->getType(),
489 >                   pos[0],
490 >                   pos[1],
491 >                   pos[2],
492 >                   vel[0],
493 >                   vel[1],
494 >                   vel[2]);
495 >          strcpy( writeLine, tempBuffer );
496            
497 <        sprintf( tempBuffer,
498 <                 "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
499 <                 q[0],
500 <                 q[1],
501 <                 q[2],
502 <                 q[3],
503 <                 dAtom->getJx(),
504 <                 dAtom->getJy(),
505 <                 dAtom->getJz());
506 <        strcat( writeLine, tempBuffer );
507 <      }
508 <      else
509 <        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
497 >          if( atoms[local_index]->isDirectional() ){
498 >            
499 >            dAtom = (DirectionalAtom *)atoms[local_index];
500 >            dAtom->getQ( q );
501 >            
502 >            sprintf( tempBuffer,
503 >                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
504 >                     q[0],
505 >                     q[1],
506 >                     q[2],
507 >                     q[3],
508 >                     dAtom->getJx(),
509 >                     dAtom->getJy(),
510 >                     dAtom->getJz());
511 >            strcat( writeLine, tempBuffer );
512 >          }
513 >          else
514 >            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );      
515 >        }
516 >        else {
517 >          sprintf(painCave.errMsg,
518 >                  "Atom %d not found on processor %d\n",
519 >                  i, worldRank );
520 >          haveError= 1;
521 >          simError();
522 >        }
523 >
524 >        if(haveError) nodeZeroError();
525 >    
526 >      }
527 >      else {
528 >        
529 >        myStatus = 1;
530 >        MPI_Send(&myStatus, 1, MPI_INT, which_node,
531 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
532 >        MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT,
533 >                 MPI_COMM_WORLD);
534 >        MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node,
535 >                 TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus);
536 >        MPI_Recv(&myStatus, 1, MPI_INT, which_node,
537 >                 TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
538          
539 +        if(!myStatus) nodeZeroError();
540 +      }
541 +      
542        finalOut << writeLine;
440      masterIndex++;
543      }
442    finalOut.flush();
443  }
544      
545 <  for (procIndex = 1; procIndex < mpiSim->getNumberProcessors();
546 <       procIndex++){
545 >    // kill everyone off:
546 >    myStatus = -1;
547 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
548 >      MPI_Send(&myStatus, 1, MPI_INT, j,
549 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
550 >    }
551  
552 <    if( worldRank == 0 ){
553 <        
554 <      mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,
555 <                        TAKE_THIS_TAG,MPI_COMM_WORLD,istatus);
552 >  } else {
553 >    
554 >    done = 0;
555 >    while (!done) {
556  
557 <      mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,
558 <                        TAKE_THIS_TAG,MPI_COMM_WORLD, istatus);
559 <        
560 <      // Make sure where node 0 is writing to, matches where the
561 <      // receiving node expects it to be.
562 <        
563 <      if (masterIndex != nodeAtomsStart){
564 <        sendError = 1;
565 <        mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,
566 <                          MPI_COMM_WORLD);
567 <        sprintf(painCave.errMsg,
568 <                "DumpWriter error: atoms start index (%d) for "
569 <                "node %d not equal to master index (%d)",
570 <                nodeAtomsStart,procIndex,masterIndex );
467 <        painCave.isFatal = 1;
468 <        simError();
557 >      MPI_Recv(&myStatus, 1, MPI_INT, 0,
558 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
559 >      
560 >      if(!myStatus) anonymousNodeDie();
561 >      
562 >      if(myStatus < 0) break;
563 >      
564 >      MPI_Recv(&which_atom, 1, MPI_INT, 0,
565 >               TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus);
566 >      
567 >      myStatus = 1;
568 >      local_index=-1;        
569 >      for (j=0; j < mpiSim->getMyNlocal(); j++) {
570 >        if (atoms[j]->getGlobalIndex() == which_atom) local_index = j;
571        }
572 <        
471 <      sendError = 0;
472 <      mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,
473 <                        MPI_COMM_WORLD);
572 >      if (local_index != -1) {
573  
574 <      // recieve the nodes writeLines
574 >        atoms[local_index]->getPos(pos);
575 >        atoms[local_index]->getVel(vel);
576  
577 <      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 <          
577 >        //format the line
578          sprintf( tempBuffer,
579                   "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
580 <                 atoms[i]->getType(),
581 <                 atoms[i]->getX(),
582 <                 atoms[i]->getY(),
583 <                 atoms[i]->getZ(),
584 <                 atoms[i]->get_vx(),
585 <                 atoms[i]->get_vy(),
586 <                 atoms[i]->get_vz());
580 >                 atoms[local_index]->getType(),
581 >                 pos[0],
582 >                 pos[1],
583 >                 pos[2],
584 >                 vel[0],
585 >                 vel[1],
586 >                 vel[2]); // check here.
587          strcpy( writeLine, tempBuffer );
588 +        
589 +        if( atoms[local_index]->isDirectional() ){
590            
591 <        if( atoms[i]->isDirectional() ){
519 <            
520 <          dAtom = (DirectionalAtom *)atoms[i];
591 >          dAtom = (DirectionalAtom *)atoms[local_index];
592            dAtom->getQ( q );
593 <            
593 >          
594            sprintf( tempBuffer,
595                     "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
596                     q[0],
# Line 531 | Line 602 | void DumpWriter::writeFinal(){
602                     dAtom->getJz());
603            strcat( writeLine, tempBuffer );
604          }
605 <        else
605 >        else{
606            strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
607 <          
608 <        mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG,
609 <                          MPI_COMM_WORLD);
607 >        }
608 >      }
609 >      else {
610 >        sprintf(painCave.errMsg,
611 >                "Atom %d not found on processor %d\n",
612 >                which_atom, worldRank );
613 >        myStatus = 0;
614 >        simError();
615 >        
616 >        strcpy( writeLine, "Hello, I'm an error.\n");
617        }
618 +
619 +      MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0,
620 +               TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD);
621 +      MPI_Send( &myStatus, 1, MPI_INT, 0,
622 +                TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
623      }
541      
542    sprintf(checkPointMsg,"Node %d sent dump configuration.",
543            procIndex);
544    MPIcheckPoint();
624    }
625 +  finalOut.flush();
626 +  sprintf( checkPointMsg,
627 +           "Sucessfully took a dump.\n");
628 +  MPIcheckPoint();
629 +  
630 +  if( worldRank == 0 ) finalOut.close();    
631 + #endif // is_mpi
632 + }
633  
547  if( worldRank == 0 ) finalOut.close();
634  
635 <    
636 < #endif // is_mpi
635 >
636 > #ifdef IS_MPI
637 >
638 > // a couple of functions to let us escape the write loop
639 >
640 > void dWrite::nodeZeroError( void ){
641 >  int j, myStatus;
642 >  
643 >  myStatus = 0;
644 >  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
645 >    MPI_Send( &myStatus, 1, MPI_INT, j,
646 >              TAKE_THIS_TAG_INT, MPI_COMM_WORLD);
647 >  }  
648 >  
649 >
650 >  MPI_Finalize();
651 >  exit (0);
652 >  
653   }
654 +
655 + void dWrite::anonymousNodeDie( void ){
656 +
657 +  MPI_Finalize();
658 +  exit (0);
659 + }
660 +
661 + #endif //is_mpi

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines