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

Comparing trunk/OOPSE/libmdtools/InitializeFromFile.cpp (file contents):
Revision 417 by gezelter, Thu Mar 27 01:49:45 2003 UTC vs.
Revision 440 by mmeineke, Tue Apr 1 16:49:17 2003 UTC

# Line 15 | Line 15
15   #include <mpi.h>
16   #include <mpi++.h>
17   #include "mpiSimulation.hpp"
18 < #define TAKE_THIS_TAG 0
18 > #define TAKE_THIS_TAG_CHAR 0
19 > #define TAKE_THIS_TAG_INT 1
20 >
21 > namespace initFile{
22 >  void nodeZeroError( void );
23 >  void anonymousNodeDie( void );
24 > }
25 >
26 > using namespace initFile;
27 >
28   #endif // is_mpi
29  
30   InitializeFromFile :: InitializeFromFile( char *in_name ){
# Line 139 | Line 148 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
148    // MPI Section of code..........
149   #else //IS_MPI
150  
151 +  // first thing first, suspend fatalities.
152 +  painCave.isEventLoop = 1;
153 +
154 +  int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone
155 +  int haveError;
156 +  
157    MPI::Status istatus;
158    int *AtomToProcMap = mpiSim->getAtomToProcMap();
159  
160 +  
161 +  haveError = 0;
162    if (worldRank == 0) {
163 +
164      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
165      if( eof_test == NULL ){
166        sprintf( painCave.errMsg,
167                 "Error reading 1st line of %d \n ",c_in_name);
168 <      painCave.isFatal = 1;
168 >      haveError = 1;
169        simError();
170      }
171      
# Line 164 | Line 182 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
182                 "Initialize from File error. %s n_atoms, %d, "
183                 "does not match the BASS file's n_atoms, %d.\n",
184                 c_in_name, n_atoms, entry_plug->n_atoms );
185 <      painCave.isFatal = 1;
185 >      haveError= 1;
186        simError();
187      }
188      
# Line 174 | Line 192 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
192      if(eof_test == NULL){
193        sprintf( painCave.errMsg,
194                 "error in reading commment in %s\n", c_in_name);
195 <      painCave.isFatal = 1;
195 >      haveError= 1;
196        simError();
197      }
198    
199 +    if(haveError) nodeZeroError();
200  
201      for (i=0 ; i < mpiSim->getTotAtoms(); i++) {
202        
# Line 188 | Line 207 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
207                  "natoms  = %d; index = %d\n"
208                  "error reading the line from the file.\n",
209                  c_in_name, n_atoms, i );
210 <        painCave.isFatal = 1;
210 >        haveError= 1;
211          simError();
212        }
213      
214 +      if(haveError) nodeZeroError();
215 +
216        // Get the Node number which wants this atom:
217        which_node = AtomToProcMap[i];    
218 <      if (which_node == mpiSim->getMyNode()) {
218 >      if (which_node == 0) {
219          parseErr = parseDumpLine( read_buffer, i );
220          if( parseErr != NULL ){
221            strcpy( painCave.errMsg, parseErr );
222 <          painCave.isFatal = 1;
222 >          haveError = 1;
223            simError();
224          }    
225 <      } else {
225 >        if(haveError) nodeZeroError();
226 >      }
227 >      
228 >      else {
229 >      
230 >        myStatus = 1;
231 >        MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, which_node,
232 >                             TAKE_THIS_TAG_INT);
233          MPI::COMM_WORLD.Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
234 <                             TAKE_THIS_TAG);
235 <        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG);
234 >                             TAKE_THIS_TAG_CHAR);
235 >        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT);
236 >        MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, istatus);
237 >        
238 >        if(!myStatus) nodeZeroError();
239        }
240      }
241 <    sprintf(read_buffer, "GAMEOVER");
241 >    myStatus = -1;
242      for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
243 <      MPI::COMM_WORLD.Send(read_buffer, BUFFERSIZE, MPI_CHAR, j,
244 <                           TAKE_THIS_TAG);
243 >      MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j,
244 >                            TAKE_THIS_TAG_INT);
245      }
246 <
246 >    
247    } else {
248 <
248 >    
249      done = 0;
250      while (!done) {
251 +
252 +      MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, 0,
253 +                           TAKE_THIS_TAG_INT, istatus);
254 +      
255 +      if(!myStatus) anonymousNodeDie();
256 +      
257 +      if(myStatus < 0) break;
258 +
259        MPI::COMM_WORLD.Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0,
260 <                           TAKE_THIS_TAG, istatus);
261 <      if (strcmp(read_buffer, "GAMEOVER")) {
262 <        done = 1;
263 <        continue;
264 <      } else {
265 <        MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
266 <                             TAKE_THIS_TAG, istatus);
267 <        parseErr = parseDumpLine( read_buffer, which_atom );
268 <        if( parseErr != NULL ){
269 <          strcpy( painCave.errMsg, parseErr );
231 <          painCave.isFatal = 1;
232 <          simError();
233 <        }
260 >                           TAKE_THIS_TAG_CHAR, istatus);
261 >      MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
262 >                           TAKE_THIS_TAG_INT, istatus);
263 >      
264 >      myStatus = 1;
265 >      parseErr = parseDumpLine( read_buffer, which_atom );
266 >      if( parseErr != NULL ){
267 >        strcpy( painCave.errMsg, parseErr );
268 >        myStatus = 0;;
269 >        simError();
270        }
271 +      
272 +      MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, 0,
273 +                            TAKE_THIS_TAG_INT);
274 +      
275      }
276    }
277 <        
277 >    
278 > // last  thing last, enable  fatalities.
279 >  painCave.isEventLoop = 0;
280 >  
281   #endif
282   }
283  
284 < char* InitializeFromFile::parseDumpLine(char* readLine, int atomIndex){
284 > char* InitializeFromFile::parseDumpLine(char* readLine, int globalIndex){
285  
286    char *foo; // the pointer to the current string token
287    
# Line 251 | Line 294 | char* InitializeFromFile::parseDumpLine(char* readLine
294    Atom **atoms = entry_plug->atoms;
295    DirectionalAtom* dAtom;
296    
297 <  int n_atoms;
297 >  int j, n_atoms, atomIndex;
298  
299   #ifdef IS_MPI
300    n_atoms = mpiSim->getTotAtoms();
301 +  atomIndex=-1;        
302 +  for (j=0; j < mpiSim->getMyNlocal(); j++) {
303 +    if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j;
304 +  }
305 +  if (atomIndex == -1) {
306 +    sprintf( painCave.errMsg,
307 +             "Initialize from file error. Atom at index %d "
308 +             "in file %s does not exist on processor %d .\n",
309 +             globalIndex, c_in_name, mpiSim->getMyNode() );
310 +    return strdup( painCave.errMsg );
311 +  }  
312   #else
313    n_atoms = entry_plug->n_atoms;
314 +  atomIndex = globalIndex;
315   #endif // is_mpi
316  
262
317    // set the string tokenizer
318    
319    foo = strtok(readLine, " ,;\t");
# Line 450 | Line 504 | char* InitializeFromFile::parseDumpLine(char* readLine
504  
505    return NULL;
506   }
507 +
508 +
509 + #ifdef IS_MPI
510 +
511 + // a couple of functions to let us escape the read loop
512 +
513 + void initFile::nodeZeroError( void ){
514 +  int j, myStatus;
515 +  
516 +  myStatus = 0;
517 +  for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
518 +    MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j,
519 +                          TAKE_THIS_TAG_INT);
520 +  }  
521 +  
522 +
523 +  MPI_Finalize();
524 +  exit (0);
525 +  
526 + }
527 +
528 + void initFile::anonymousNodeDie( void ){
529 +
530 +  MPI_Finalize();
531 +  exit (0);
532 + }
533 +
534 + #endif //is_mpi

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines