--- trunk/mdtools/md_code/InitializeFromFile.cpp 2002/12/13 17:59:52 209 +++ trunk/mdtools/md_code/InitializeFromFile.cpp 2002/12/13 21:17:00 212 @@ -133,9 +133,14 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr // MPI Section of code.......... #else //IS_MPI + int masterIndex; + int nodeAtomsStart; + int nodeAtomsEnd; + int mpiErr; + int sendError; + MPI_Status istatus[MPI_STATUS_SIZE]; - if (worldRank == 0) { eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); if( eof_test == NULL ){ @@ -149,6 +154,9 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr Atom **atoms = entry_plug->atoms; DirectionalAtom* dAtom; + + // Check to see that the number of atoms in the intial configuration file is the + // same as declared in simBass. if( n_atoms != entry_plug->mpiSim->getTotAtoms() ){ sprintf( painCave.errMsg, @@ -168,28 +176,121 @@ void InitializeFromFile :: read_xyz( SimInfo* the_entr painCave.isFatal = 1; simError(); } - } - - for( i=0; i < n_atoms; i++){ + + // Read Proc 0 share of the xyz file... + masterIndex = 0; + for( i=0; i <= entry_plug->mpiSim->getMyAtomEnd(); i++){ - eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); - if(eof_test == NULL){ - sprintf(painCave.errMsg, - "error in reading file %s\n" - "natoms = %d; index = %d\n" - "error reading the line from the file.\n", - c_in_name, n_atoms, i ); - painCave.isFatal = 1; - simError(); - } + eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); + if(eof_test == NULL){ + sprintf(painCave.errMsg, + "error in reading file %s\n" + "natoms = %d; index = %d\n" + "error reading the line from the file.\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); + } - parseErr = parseDumpLine( read_buffer, i ); - if( parseErr != NULL ){ - strcpy( painCave.errMsg, parseErr ); - painCave.isFatal = 1; - simError(); - } + parseErr = parseDumpLine( read_buffer, i ); + if( parseErr != NULL ){ + strcpy( painCave.errMsg, parseErr ); + painCave.isFatal = 1; + simError(); + } + masterIndex++; + } } + + sprintf(checkPointMsg, + "Node 0 has successfully read positions from input file."); + mpiCheckPoint(); + + for (procIndex = 1; procIndex < entryPlug->mpiSim->getNumberProcessors(); + procIndex++){ + if (worldRank == 0) { + + mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, + istatus); + + mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, + istatus); + // Make sure where node 0 is reading from, matches where the receiving node + // expects it to be. + + if (masterIndex != nodeAtomsStart){ + sendError = 1; + mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); + sprintf(painCave.errMsg, + "Initialize from file error: atoms start index (%d) for " + "node %d not equal to master index (%d)",nodeAtomsStart,procIndex,masterIndex ); + painCave.isFatal = 1; + simError(); + } + sendError = 0; + mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); + + for ( i = nodeAtomStart; i <= nodeAtomEnd, i++){ + eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); + if(eof_test == NULL){ + + sprintf(read_buffer,"ERROR"); + mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); + + sprintf(painCave.errMsg, + "error in reading file %s\n" + "natoms = %d; index = %d\n" + "error reading the line from the file.\n", + c_in_name, n_atoms, i ); + painCave.isFatal = 1; + simError(); + } + + mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); + mpiErr = MPI_Recv(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, + istatus); + if (sendError) mpiCheckpoint(); + + masterIndex++; + } + } + + + else if(worldRank == procIndex){ + nodeAtomStart = entry_plug->mpiSim->getMyAtomStart(); + nodeAtomEnd = entry_plug->mpiSim->getMyAtomEnd(); + mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); + mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); + + mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD, + istatus); + if (sendError) mpiCheckpoint(); + + for ( i = 0; i < entry_plug->n_atoms, i++){ + + mpiErr = MPI_Recv(&read_buffer,BUFFERSIZE,MPI_CHAR,0,MPI_ANY_TAG,MPI_COMM_WORLD, + istatus); + + if(!strcmp(read_buffer, "ERROR")) mpiCheckPoint(); + + parseErr = parseDumpLine( read_buffer, i ); + if( parseErr != NULL ){ + sendError = 1; + mpiErr = MPI_Send(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); + + + strcpy( painCave.errMsg, parseErr ); + painCave.isFatal = 1; + simError(); + } + sendError = 0; + mpiErr = MPI_Send(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); + } + } + sprintf(checkPointMsg,"Node %d received initial configuration.",procIndex); + mpiCheckPoint(); + } + #endif }