| 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 |
|
|
| 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 |
| 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 ){ |
| 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, |
| 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(); |
| 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 |
< |
sendError = 0; |
| 210 |
< |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD); |
| 211 |
< |
|
| 212 |
< |
for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){ |
| 213 |
< |
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++; |
| 260 |
< |
} |
| 209 |
> |
} |
| 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 |
< |
else if(worldRank == procIndex){ |
| 219 |
< |
nodeAtomsStart = mpiSim->getMyAtomStart(); |
| 220 |
< |
nodeAtomsEnd = mpiSim->getMyAtomEnd(); |
| 221 |
< |
mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD); |
| 222 |
< |
mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD); |
| 223 |
< |
|
| 224 |
< |
mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD, |
| 225 |
< |
istatus); |
| 226 |
< |
if (sendError) MPIcheckPoint(); |
| 227 |
< |
|
| 228 |
< |
for ( i = 0; i < entry_plug->n_atoms; i++){ |
| 229 |
< |
|
| 230 |
< |
mpiErr = MPI_Recv(&read_buffer,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG,MPI_COMM_WORLD, |
| 231 |
< |
istatus); |
| 232 |
< |
|
| 233 |
< |
if(!strcmp(read_buffer, "ERROR")) MPIcheckPoint(); |
| 280 |
< |
|
| 281 |
< |
parseErr = parseDumpLine( read_buffer, i ); |
| 282 |
< |
if( parseErr != NULL ){ |
| 283 |
< |
sendError = 1; |
| 284 |
< |
mpiErr = MPI_Send(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD); |
| 285 |
< |
|
| 286 |
< |
|
| 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); |
| 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 |
> |
parseErr = parseDumpLine( read_buffer, which_atom ); |
| 229 |
> |
if( parseErr != NULL ){ |
| 230 |
> |
strcpy( painCave.errMsg, parseErr ); |
| 231 |
> |
painCave.isFatal = 1; |
| 232 |
> |
simError(); |
| 233 |
> |
} |
| 234 |
|
} |
| 235 |
|
} |
| 295 |
– |
sprintf(checkPointMsg,"Node %d received initial configuration.",procIndex); |
| 296 |
– |
MPIcheckPoint(); |
| 236 |
|
} |
| 237 |
< |
|
| 237 |
> |
|
| 238 |
|
#endif |
| 239 |
|
} |
| 240 |
|
|
| 302 |
– |
|
| 241 |
|
char* InitializeFromFile::parseDumpLine(char* readLine, int atomIndex){ |
| 242 |
|
|
| 243 |
|
char *foo; // the pointer to the current string token |