| 11 | 
  | 
#include "ReadWrite.hpp" | 
| 12 | 
  | 
#include "simError.h" | 
| 13 | 
  | 
 | 
| 14 | 
+ | 
#ifdef IS_MPI | 
| 15 | 
+ | 
#include "mpiSimulation.hpp" | 
| 16 | 
+ | 
#endif // is_mpi | 
| 17 | 
  | 
 | 
| 18 | 
  | 
InitializeFromFile :: InitializeFromFile( char *in_name ){ | 
| 19 | 
  | 
#ifdef IS_MPI | 
| 136 | 
  | 
  // MPI Section of code.......... | 
| 137 | 
  | 
#else //IS_MPI | 
| 138 | 
  | 
 | 
| 139 | 
+ | 
  int masterIndex; | 
| 140 | 
+ | 
  int nodeAtomsStart; | 
| 141 | 
+ | 
  int nodeAtomsEnd; | 
| 142 | 
+ | 
  int mpiErr; | 
| 143 | 
+ | 
  int sendError; | 
| 144 | 
  | 
 | 
| 145 | 
+ | 
  MPI_Status istatus[MPI_STATUS_SIZE]; | 
| 146 | 
  | 
 | 
| 138 | 
– | 
 | 
| 147 | 
  | 
  if (worldRank == 0) { | 
| 148 | 
  | 
    eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | 
| 149 | 
  | 
    if( eof_test == NULL ){ | 
| 157 | 
  | 
     | 
| 158 | 
  | 
    Atom **atoms = entry_plug->atoms; | 
| 159 | 
  | 
    DirectionalAtom* dAtom; | 
| 160 | 
+ | 
  | 
| 161 | 
+ | 
    // Check to see that the number of atoms in the intial configuration file is the | 
| 162 | 
+ | 
    // same as declared in simBass. | 
| 163 | 
  | 
     | 
| 164 | 
< | 
    if( n_atoms != entry_plug->mpiSim->getTotAtoms() ){ | 
| 164 | 
> | 
    if( n_atoms != mpiSim->getTotAtoms() ){ | 
| 165 | 
  | 
      sprintf( painCave.errMsg, | 
| 166 | 
  | 
               "Initialize from File error. %s n_atoms, %d, " | 
| 167 | 
  | 
               "does not match the BASS file's n_atoms, %d.\n", | 
| 179 | 
  | 
      painCave.isFatal = 1; | 
| 180 | 
  | 
      simError(); | 
| 181 | 
  | 
    } | 
| 182 | 
< | 
  } | 
| 183 | 
< | 
 | 
| 184 | 
< | 
  for( i=0; i < n_atoms; i++){ | 
| 182 | 
> | 
   | 
| 183 | 
> | 
    // Read Proc 0 share of the xyz file... | 
| 184 | 
> | 
    masterIndex = 0; | 
| 185 | 
> | 
    for( i=0; i <= mpiSim->getMyAtomEnd(); i++){ | 
| 186 | 
  | 
     | 
| 187 | 
< | 
    eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | 
| 188 | 
< | 
    if(eof_test == NULL){ | 
| 189 | 
< | 
      sprintf(painCave.errMsg, | 
| 190 | 
< | 
              "error in reading file %s\n" | 
| 191 | 
< | 
              "natoms  = %d; index = %d\n" | 
| 192 | 
< | 
              "error reading the line from the file.\n", | 
| 193 | 
< | 
              c_in_name, n_atoms, i ); | 
| 194 | 
< | 
      painCave.isFatal = 1; | 
| 195 | 
< | 
      simError(); | 
| 196 | 
< | 
    } | 
| 187 | 
> | 
      eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | 
| 188 | 
> | 
      if(eof_test == NULL){ | 
| 189 | 
> | 
        sprintf(painCave.errMsg, | 
| 190 | 
> | 
                "error in reading file %s\n" | 
| 191 | 
> | 
                "natoms  = %d; index = %d\n" | 
| 192 | 
> | 
                "error reading the line from the file.\n", | 
| 193 | 
> | 
                c_in_name, n_atoms, i ); | 
| 194 | 
> | 
        painCave.isFatal = 1; | 
| 195 | 
> | 
        simError(); | 
| 196 | 
> | 
      } | 
| 197 | 
  | 
     | 
| 198 | 
< | 
    parseErr = parseDumpLine( read_buffer, i ); | 
| 199 | 
< | 
    if( parseErr != NULL ){ | 
| 200 | 
< | 
      strcpy( painCave.errMsg, parseErr ); | 
| 201 | 
< | 
      painCave.isFatal = 1; | 
| 202 | 
< | 
      simError(); | 
| 203 | 
< | 
    }     | 
| 198 | 
> | 
      parseErr = parseDumpLine( read_buffer, i ); | 
| 199 | 
> | 
      if( parseErr != NULL ){ | 
| 200 | 
> | 
        strcpy( painCave.errMsg, parseErr ); | 
| 201 | 
> | 
        painCave.isFatal = 1; | 
| 202 | 
> | 
        simError(); | 
| 203 | 
> | 
      }     | 
| 204 | 
> | 
      masterIndex++; | 
| 205 | 
> | 
    } | 
| 206 | 
> | 
  } | 
| 207 | 
> | 
 | 
| 208 | 
> | 
  sprintf(checkPointMsg, | 
| 209 | 
> | 
          "Node 0 has successfully read positions from input file."); | 
| 210 | 
> | 
  mpiCheckPoint(); | 
| 211 | 
> | 
 | 
| 212 | 
> | 
  for (procIndex = 1; procIndex < entryPlug->mpiSim->getNumberProcessors(); | 
| 213 | 
> | 
         procIndex++){ | 
| 214 | 
> | 
    if (worldRank == 0) { | 
| 215 | 
> | 
 | 
| 216 | 
> | 
      mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, | 
| 217 | 
> | 
               istatus); | 
| 218 | 
> | 
 | 
| 219 | 
> | 
      mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, | 
| 220 | 
> | 
               istatus); | 
| 221 | 
> | 
      // Make sure where node 0 is reading from, matches where the receiving node | 
| 222 | 
> | 
      // expects it to be. | 
| 223 | 
> | 
 | 
| 224 | 
> | 
      if (masterIndex != nodeAtomsStart){ | 
| 225 | 
> | 
        sendError = 1; | 
| 226 | 
> | 
        mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); | 
| 227 | 
> | 
        sprintf(painCave.errMsg, | 
| 228 | 
> | 
                "Initialize from file error: atoms start index (%d) for " | 
| 229 | 
> | 
                "node %d not equal to master index (%d)",nodeAtomsStart,procIndex,masterIndex ); | 
| 230 | 
> | 
        painCave.isFatal = 1; | 
| 231 | 
> | 
        simError(); | 
| 232 | 
> | 
      } | 
| 233 | 
> | 
      sendError = 0; | 
| 234 | 
> | 
      mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); | 
| 235 | 
> | 
       | 
| 236 | 
> | 
      for ( i = nodeAtomStart; i <= nodeAtomEnd, i++){ | 
| 237 | 
> | 
        eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | 
| 238 | 
> | 
        if(eof_test == NULL){ | 
| 239 | 
> | 
           | 
| 240 | 
> | 
          sprintf(read_buffer,"ERROR"); | 
| 241 | 
> | 
          mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); | 
| 242 | 
> | 
           | 
| 243 | 
> | 
          sprintf(painCave.errMsg, | 
| 244 | 
> | 
                  "error in reading file %s\n" | 
| 245 | 
> | 
                  "natoms  = %d; index = %d\n" | 
| 246 | 
> | 
                  "error reading the line from the file.\n", | 
| 247 | 
> | 
                  c_in_name, n_atoms, i ); | 
| 248 | 
> | 
          painCave.isFatal = 1; | 
| 249 | 
> | 
          simError(); | 
| 250 | 
> | 
        } | 
| 251 | 
> | 
         | 
| 252 | 
> | 
        mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); | 
| 253 | 
> | 
        mpiErr = MPI_Recv(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, | 
| 254 | 
> | 
                          istatus); | 
| 255 | 
> | 
        if (sendError) mpiCheckpoint(); | 
| 256 | 
> | 
 | 
| 257 | 
> | 
        masterIndex++; | 
| 258 | 
> | 
      } | 
| 259 | 
> | 
    } | 
| 260 | 
> | 
 | 
| 261 | 
> | 
 | 
| 262 | 
> | 
    else if(worldRank == procIndex){ | 
| 263 | 
> | 
      nodeAtomStart = mpiSim->getMyAtomStart(); | 
| 264 | 
> | 
      nodeAtomEnd = mpiSim->getMyAtomEnd(); | 
| 265 | 
> | 
      mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); | 
| 266 | 
> | 
      mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); | 
| 267 | 
> | 
       | 
| 268 | 
> | 
      mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD, | 
| 269 | 
> | 
               istatus); | 
| 270 | 
> | 
      if (sendError) mpiCheckpoint(); | 
| 271 | 
> | 
 | 
| 272 | 
> | 
      for ( i = 0; i < entry_plug->n_atoms, i++){ | 
| 273 | 
> | 
 | 
| 274 | 
> | 
        mpiErr = MPI_Recv(&read_buffer,BUFFERSIZE,MPI_CHAR,0,MPI_ANY_TAG,MPI_COMM_WORLD, | 
| 275 | 
> | 
                          istatus); | 
| 276 | 
> | 
         | 
| 277 | 
> | 
        if(!strcmp(read_buffer, "ERROR")) mpiCheckPoint(); | 
| 278 | 
> | 
         | 
| 279 | 
> | 
        parseErr = parseDumpLine( read_buffer, i ); | 
| 280 | 
> | 
        if( parseErr != NULL ){ | 
| 281 | 
> | 
          sendError = 1; | 
| 282 | 
> | 
          mpiErr = MPI_Send(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); | 
| 283 | 
> | 
 | 
| 284 | 
> | 
 | 
| 285 | 
> | 
          strcpy( painCave.errMsg, parseErr ); | 
| 286 | 
> | 
          painCave.isFatal = 1; | 
| 287 | 
> | 
          simError(); | 
| 288 | 
> | 
        } | 
| 289 | 
> | 
        sendError = 0; | 
| 290 | 
> | 
        mpiErr = MPI_Send(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); | 
| 291 | 
> | 
      } | 
| 292 | 
> | 
    } | 
| 293 | 
> | 
    sprintf(checkPointMsg,"Node %d received initial configuration.",procIndex); | 
| 294 | 
> | 
    mpiCheckPoint(); | 
| 295 | 
  | 
  } | 
| 296 | 
+ | 
 | 
| 297 | 
  | 
#endif | 
| 298 | 
  | 
} | 
| 299 | 
  | 
 | 
| 314 | 
  | 
  int n_atoms; | 
| 315 | 
  | 
 | 
| 316 | 
  | 
#ifdef IS_MPI | 
| 317 | 
< | 
  n_atoms = entry_plug->mpiSim->getTotAtoms(); | 
| 317 | 
> | 
  n_atoms = mpiSim->getTotAtoms(); | 
| 318 | 
  | 
#else | 
| 319 | 
  | 
  n_atoms = entry_plug->n_atoms; | 
| 320 | 
  | 
#endi // is_mpi |