| 133 |
|
// MPI Section of code.......... |
| 134 |
|
#else //IS_MPI |
| 135 |
|
|
| 136 |
+ |
int masterIndex; |
| 137 |
+ |
int nodeAtomsStart; |
| 138 |
+ |
int nodeAtomsEnd; |
| 139 |
+ |
int mpiErr; |
| 140 |
+ |
int sendError; |
| 141 |
|
|
| 142 |
+ |
MPI_Status istatus[MPI_STATUS_SIZE]; |
| 143 |
|
|
| 138 |
– |
|
| 144 |
|
if (worldRank == 0) { |
| 145 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
| 146 |
|
if( eof_test == NULL ){ |
| 154 |
|
|
| 155 |
|
Atom **atoms = entry_plug->atoms; |
| 156 |
|
DirectionalAtom* dAtom; |
| 157 |
+ |
|
| 158 |
+ |
// Check to see that the number of atoms in the intial configuration file is the |
| 159 |
+ |
// same as declared in simBass. |
| 160 |
|
|
| 161 |
|
if( n_atoms != entry_plug->mpiSim->getTotAtoms() ){ |
| 162 |
|
sprintf( painCave.errMsg, |
| 176 |
|
painCave.isFatal = 1; |
| 177 |
|
simError(); |
| 178 |
|
} |
| 179 |
< |
} |
| 180 |
< |
|
| 181 |
< |
for( i=0; i < n_atoms; i++){ |
| 179 |
> |
|
| 180 |
> |
// Read Proc 0 share of the xyz file... |
| 181 |
> |
masterIndex = 0; |
| 182 |
> |
for( i=0; i <= entry_plug->mpiSim->getMyAtomEnd(); i++){ |
| 183 |
|
|
| 184 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
| 185 |
< |
if(eof_test == NULL){ |
| 186 |
< |
sprintf(painCave.errMsg, |
| 187 |
< |
"error in reading file %s\n" |
| 188 |
< |
"natoms = %d; index = %d\n" |
| 189 |
< |
"error reading the line from the file.\n", |
| 190 |
< |
c_in_name, n_atoms, i ); |
| 191 |
< |
painCave.isFatal = 1; |
| 192 |
< |
simError(); |
| 193 |
< |
} |
| 184 |
> |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
| 185 |
> |
if(eof_test == NULL){ |
| 186 |
> |
sprintf(painCave.errMsg, |
| 187 |
> |
"error in reading file %s\n" |
| 188 |
> |
"natoms = %d; index = %d\n" |
| 189 |
> |
"error reading the line from the file.\n", |
| 190 |
> |
c_in_name, n_atoms, i ); |
| 191 |
> |
painCave.isFatal = 1; |
| 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 |
< |
} |
| 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(); |
| 208 |
+ |
|
| 209 |
+ |
for (procIndex = 1; procIndex < entryPlug->mpiSim->getNumberProcessors(); |
| 210 |
+ |
procIndex++){ |
| 211 |
+ |
if (worldRank == 0) { |
| 212 |
+ |
|
| 213 |
+ |
mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, |
| 214 |
+ |
istatus); |
| 215 |
+ |
|
| 216 |
+ |
mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, |
| 217 |
+ |
istatus); |
| 218 |
+ |
// Make sure where node 0 is reading from, matches where the receiving node |
| 219 |
+ |
// expects it to be. |
| 220 |
+ |
|
| 221 |
+ |
if (masterIndex != nodeAtomsStart){ |
| 222 |
+ |
sendError = 1; |
| 223 |
+ |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); |
| 224 |
+ |
sprintf(painCave.errMsg, |
| 225 |
+ |
"Initialize from file error: atoms start index (%d) for " |
| 226 |
+ |
"node %d not equal to master index (%d)",nodeAtomsStart,procIndex,masterIndex ); |
| 227 |
+ |
painCave.isFatal = 1; |
| 228 |
+ |
simError(); |
| 229 |
+ |
} |
| 230 |
+ |
sendError = 0; |
| 231 |
+ |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); |
| 232 |
+ |
|
| 233 |
+ |
for ( i = nodeAtomStart; i <= nodeAtomEnd, i++){ |
| 234 |
+ |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
| 235 |
+ |
if(eof_test == NULL){ |
| 236 |
+ |
|
| 237 |
+ |
sprintf(read_buffer,"ERROR"); |
| 238 |
+ |
mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); |
| 239 |
+ |
|
| 240 |
+ |
sprintf(painCave.errMsg, |
| 241 |
+ |
"error in reading file %s\n" |
| 242 |
+ |
"natoms = %d; index = %d\n" |
| 243 |
+ |
"error reading the line from the file.\n", |
| 244 |
+ |
c_in_name, n_atoms, i ); |
| 245 |
+ |
painCave.isFatal = 1; |
| 246 |
+ |
simError(); |
| 247 |
+ |
} |
| 248 |
+ |
|
| 249 |
+ |
mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD); |
| 250 |
+ |
mpiErr = MPI_Recv(&sendError,1,MPI_INT,procIndex,MPI_ANY_TAG,MPI_COMM_WORLD, |
| 251 |
+ |
istatus); |
| 252 |
+ |
if (sendError) mpiCheckpoint(); |
| 253 |
+ |
|
| 254 |
+ |
masterIndex++; |
| 255 |
+ |
} |
| 256 |
+ |
} |
| 257 |
+ |
|
| 258 |
+ |
|
| 259 |
+ |
else if(worldRank == procIndex){ |
| 260 |
+ |
nodeAtomStart = entry_plug->mpiSim->getMyAtomStart(); |
| 261 |
+ |
nodeAtomEnd = entry_plug->mpiSim->getMyAtomEnd(); |
| 262 |
+ |
mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); |
| 263 |
+ |
mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); |
| 264 |
+ |
|
| 265 |
+ |
mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD, |
| 266 |
+ |
istatus); |
| 267 |
+ |
if (sendError) mpiCheckpoint(); |
| 268 |
+ |
|
| 269 |
+ |
for ( i = 0; i < entry_plug->n_atoms, i++){ |
| 270 |
+ |
|
| 271 |
+ |
mpiErr = MPI_Recv(&read_buffer,BUFFERSIZE,MPI_CHAR,0,MPI_ANY_TAG,MPI_COMM_WORLD, |
| 272 |
+ |
istatus); |
| 273 |
+ |
|
| 274 |
+ |
if(!strcmp(read_buffer, "ERROR")) mpiCheckPoint(); |
| 275 |
+ |
|
| 276 |
+ |
parseErr = parseDumpLine( read_buffer, i ); |
| 277 |
+ |
if( parseErr != NULL ){ |
| 278 |
+ |
sendError = 1; |
| 279 |
+ |
mpiErr = MPI_Send(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); |
| 280 |
+ |
|
| 281 |
+ |
|
| 282 |
+ |
strcpy( painCave.errMsg, parseErr ); |
| 283 |
+ |
painCave.isFatal = 1; |
| 284 |
+ |
simError(); |
| 285 |
+ |
} |
| 286 |
+ |
sendError = 0; |
| 287 |
+ |
mpiErr = MPI_Send(&sendError,1,MPI_INT,0,MPI_ANY_TAG,MPI_COMM_WORLD); |
| 288 |
+ |
} |
| 289 |
+ |
} |
| 290 |
+ |
sprintf(checkPointMsg,"Node %d received initial configuration.",procIndex); |
| 291 |
+ |
mpiCheckPoint(); |
| 292 |
+ |
} |
| 293 |
+ |
|
| 294 |
|
#endif |
| 295 |
|
} |
| 296 |
|
|