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 378 by mmeineke, Fri Mar 21 17:42:12 2003 UTC vs.
Revision 419 by gezelter, Thu Mar 27 15:07:29 2003 UTC

# Line 12 | Line 12
12   #include "simError.h"
13  
14   #ifdef IS_MPI
15 + #include <mpi.h>
16 + #include <mpi++.h>
17   #include "mpiSimulation.hpp"
16
18   #define TAKE_THIS_TAG 0
19   #endif // is_mpi
20  
# Line 62 | Line 63 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
63  
64   void InitializeFromFile :: read_xyz( SimInfo* the_entry_plug ){
65  
66 <  int i; // loop counter
66 >  int i, j, done, which_node, which_atom; // loop counter
67  
68    const int BUFFERSIZE = 2000; // size of the read buffer
69    int n_atoms; // the number of atoms
# Line 138 | Line 139 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
139    // MPI Section of code..........
140   #else //IS_MPI
141  
142 <  int masterIndex;
143 <  int nodeAtomsStart;
143 <  int nodeAtomsEnd;
144 <  int mpiErr;
145 <  int sendError;
142 >  MPI::Status istatus;
143 >  int *AtomToProcMap = mpiSim->getAtomToProcMap();
144  
147  MPI_Status istatus[MPI_STATUS_SIZE];
148
145    if (worldRank == 0) {
146      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
147      if( eof_test == NULL ){
# Line 182 | Line 178 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
178        simError();
179      }
180    
181 <    // Read Proc 0 share of the xyz file...
182 <    masterIndex = 0;
183 <    for( i=0; i <= mpiSim->getMyAtomEnd(); i++){
188 <    
181 >
182 >    for (i=0 ; i < mpiSim->getTotAtoms(); i++) {
183 >      
184        eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
185        if(eof_test == NULL){
186          sprintf(painCave.errMsg,
# Line 197 | Line 192 | void InitializeFromFile :: read_xyz( SimInfo* the_entr
192          simError();
193        }
194      
195 <      parseErr = parseDumpLine( read_buffer, i );
196 <      if( parseErr != NULL ){
197 <        strcpy( painCave.errMsg, parseErr );
198 <        painCave.isFatal = 1;
199 <        simError();
200 <      }    
201 <      masterIndex++;
202 <    }
203 <  }
204 <
205 <  sprintf(checkPointMsg,
206 <          "Node 0 has successfully read positions from input file.");
207 <  MPIcheckPoint();
213 <
214 <  for (procIndex = 1; procIndex < mpiSim->getNumberProcessors();
215 <         procIndex++){
216 <    if (worldRank == 0) {
217 <
218 <      mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD,
219 <               istatus);
220 <
221 <      mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD,
222 <               istatus);
223 <      // Make sure where node 0 is reading from, matches where the receiving node
224 <      // expects it to be.
225 <
226 <      if (masterIndex != nodeAtomsStart){
227 <        sendError = 1;
228 <        mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD);
229 <        sprintf(painCave.errMsg,
230 <                "Initialize from file error: atoms start index (%d) for "
231 <                "node %d not equal to master index (%d)",nodeAtomsStart,procIndex,masterIndex );
232 <        painCave.isFatal = 1;
233 <        simError();
234 <      }
235 <      sendError = 0;
236 <      mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD);
237 <      
238 <      for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){
239 <        eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file);
240 <        if(eof_test == NULL){
241 <          
242 <          sprintf(read_buffer,"ERROR");
243 <          mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD);
244 <          
245 <          sprintf(painCave.errMsg,
246 <                  "error in reading file %s\n"
247 <                  "natoms  = %d; index = %d\n"
248 <                  "error reading the line from the file.\n",
249 <                  c_in_name, n_atoms, i );
250 <          painCave.isFatal = 1;
251 <          simError();
252 <        }
253 <        
254 <        mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD);
255 <        mpiErr = MPI_Recv(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD,
256 <                          istatus);
257 <        if (sendError) MPIcheckPoint();
258 <
259 <        masterIndex++;
195 >      // Get the Node number which wants this atom:
196 >      which_node = AtomToProcMap[i];    
197 >      if (which_node == mpiSim->getMyNode()) {
198 >        parseErr = parseDumpLine( read_buffer, i );
199 >        if( parseErr != NULL ){
200 >          strcpy( painCave.errMsg, parseErr );
201 >          painCave.isFatal = 1;
202 >          simError();
203 >        }    
204 >      } else {
205 >        MPI::COMM_WORLD.Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node,
206 >                             TAKE_THIS_TAG);
207 >        MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG);
208        }
209      }
210 <
211 <
212 <    else if(worldRank == procIndex){
213 <      nodeAtomsStart = mpiSim->getMyAtomStart();
214 <      nodeAtomsEnd = mpiSim->getMyAtomEnd();
215 <      mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD);
216 <      mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD);
217 <      
218 <      mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD,
219 <               istatus);
220 <      if (sendError) MPIcheckPoint();
221 <
222 <      for ( i = 0; i < entry_plug->n_atoms; i++){
223 <
224 <        mpiErr = MPI_Recv(&read_buffer,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG,MPI_COMM_WORLD,
225 <                          istatus);
226 <        
227 <        if(!strcmp(read_buffer, "ERROR")) MPIcheckPoint();
228 <        
229 <        parseErr = parseDumpLine( read_buffer, i );
230 <        if( parseErr != NULL ){
231 <          sendError = 1;
232 <          mpiErr = MPI_Send(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD);
233 <
234 <
287 <          strcpy( painCave.errMsg, parseErr );
288 <          painCave.isFatal = 1;
289 <          simError();
290 <        }
291 <        sendError = 0;
292 <        mpiErr = MPI_Send(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD);
210 >    sprintf(read_buffer, "GAMEOVER");
211 >    for (j = 0; j < mpiSim->getNumberProcessors(); j++) {      
212 >      MPI::COMM_WORLD.Send(read_buffer, BUFFERSIZE, MPI_CHAR, j,
213 >                           TAKE_THIS_TAG);
214 >    }
215 >    
216 >  } else {
217 >    
218 >    done = 0;
219 >    while (!done) {
220 >      MPI::COMM_WORLD.Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0,
221 >                           TAKE_THIS_TAG, istatus);
222 >      if (strcmp(read_buffer, "GAMEOVER")) {
223 >        done = 1;
224 >        continue;
225 >      } else {
226 >        MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0,
227 >                             TAKE_THIS_TAG, istatus);
228 >        
229 >        parseErr = parseDumpLine( read_buffer, which_atom );
230 >        if( parseErr != NULL ){
231 >          strcpy( painCave.errMsg, parseErr );
232 >          painCave.isFatal = 1;
233 >          simError();
234 >        }
235        }
236      }
295    sprintf(checkPointMsg,"Node %d received initial configuration.",procIndex);
296    MPIcheckPoint();
237    }
238 <
238 >        
239   #endif
240   }
241  
242 + char* InitializeFromFile::parseDumpLine(char* readLine, int globalIndex){
243  
303 char* InitializeFromFile::parseDumpLine(char* readLine, int atomIndex){
304
244    char *foo; // the pointer to the current string token
245    
246    double rx, ry, rz; // position place holders
# Line 313 | Line 252 | char* InitializeFromFile::parseDumpLine(char* readLine
252    Atom **atoms = entry_plug->atoms;
253    DirectionalAtom* dAtom;
254    
255 <  int n_atoms;
255 >  int j, n_atoms, atomIndex;
256  
257   #ifdef IS_MPI
258    n_atoms = mpiSim->getTotAtoms();
259 +  atomIndex=-1;        
260 +  for (j=0; j < mpiSim->getMyNlocal(); j++) {
261 +    if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j;
262 +  }
263 +  if (atomIndex == -1) {
264 +    sprintf( painCave.errMsg,
265 +             "Initialize from file error. Atom at index %d "
266 +             "in file %s does not exist on processor %d .\n",
267 +             globalIndex, c_in_name, mpiSim->getMyNode() );
268 +    return strdup( painCave.errMsg );
269 +  }  
270   #else
271    n_atoms = entry_plug->n_atoms;
272 +  atomIndex = globalIndex;
273   #endif // is_mpi
274  
324
275    // set the string tokenizer
276    
277    foo = strtok(readLine, " ,;\t");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines