11 |
|
#include "ReadWrite.hpp" |
12 |
|
#include "simError.h" |
13 |
|
|
14 |
+ |
#ifdef IS_MPI |
15 |
+ |
#include "mpiSimulation.hpp" |
16 |
|
|
17 |
+ |
#define TAKE_THIS_TAG 0 |
18 |
+ |
#endif // is_mpi |
19 |
+ |
|
20 |
|
InitializeFromFile :: InitializeFromFile( char *in_name ){ |
21 |
|
#ifdef IS_MPI |
22 |
|
if (worldRank == 0) { |
73 |
|
|
74 |
|
char *eof_test; // ptr to see when we reach the end of the file |
75 |
|
char *parseErr; |
76 |
+ |
int procIndex; |
77 |
|
|
78 |
+ |
entry_plug = the_entry_plug; |
79 |
|
|
73 |
– |
entry_plug = the_entry_plug |
80 |
|
|
75 |
– |
|
81 |
|
#ifndef IS_MPI |
82 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
83 |
|
if( eof_test == NULL ){ |
138 |
|
// MPI Section of code.......... |
139 |
|
#else //IS_MPI |
140 |
|
|
141 |
+ |
int masterIndex; |
142 |
+ |
int nodeAtomsStart; |
143 |
+ |
int nodeAtomsEnd; |
144 |
+ |
int mpiErr; |
145 |
+ |
int sendError; |
146 |
|
|
147 |
+ |
MPI_Status istatus[MPI_STATUS_SIZE]; |
148 |
|
|
138 |
– |
|
149 |
|
if (worldRank == 0) { |
150 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
151 |
|
if( eof_test == NULL ){ |
159 |
|
|
160 |
|
Atom **atoms = entry_plug->atoms; |
161 |
|
DirectionalAtom* dAtom; |
162 |
+ |
|
163 |
+ |
// Check to see that the number of atoms in the intial configuration file is the |
164 |
+ |
// same as declared in simBass. |
165 |
|
|
166 |
< |
if( n_atoms != entry_plug->mpiSim->getTotAtoms() ){ |
166 |
> |
if( n_atoms != mpiSim->getTotAtoms() ){ |
167 |
|
sprintf( painCave.errMsg, |
168 |
|
"Initialize from File error. %s n_atoms, %d, " |
169 |
|
"does not match the BASS file's n_atoms, %d.\n", |
181 |
|
painCave.isFatal = 1; |
182 |
|
simError(); |
183 |
|
} |
184 |
< |
} |
185 |
< |
|
186 |
< |
for( i=0; i < n_atoms; i++){ |
184 |
> |
|
185 |
> |
// Read Proc 0 share of the xyz file... |
186 |
> |
masterIndex = 0; |
187 |
> |
for( i=0; i <= mpiSim->getMyAtomEnd(); i++){ |
188 |
|
|
189 |
< |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
190 |
< |
if(eof_test == NULL){ |
191 |
< |
sprintf(painCave.errMsg, |
192 |
< |
"error in reading file %s\n" |
193 |
< |
"natoms = %d; index = %d\n" |
194 |
< |
"error reading the line from the file.\n", |
195 |
< |
c_in_name, n_atoms, i ); |
196 |
< |
painCave.isFatal = 1; |
197 |
< |
simError(); |
198 |
< |
} |
189 |
> |
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
190 |
> |
if(eof_test == NULL){ |
191 |
> |
sprintf(painCave.errMsg, |
192 |
> |
"error in reading file %s\n" |
193 |
> |
"natoms = %d; index = %d\n" |
194 |
> |
"error reading the line from the file.\n", |
195 |
> |
c_in_name, n_atoms, i ); |
196 |
> |
painCave.isFatal = 1; |
197 |
> |
simError(); |
198 |
> |
} |
199 |
|
|
200 |
< |
parseErr = parseDumpLine( read_buffer, i ); |
201 |
< |
if( parseErr != NULL ){ |
202 |
< |
strcpy( painCave.errMsg, parseErr ); |
203 |
< |
painCave.isFatal = 1; |
204 |
< |
simError(); |
205 |
< |
} |
200 |
> |
parseErr = parseDumpLine( read_buffer, i ); |
201 |
> |
if( parseErr != NULL ){ |
202 |
> |
strcpy( painCave.errMsg, parseErr ); |
203 |
> |
painCave.isFatal = 1; |
204 |
> |
simError(); |
205 |
> |
} |
206 |
> |
masterIndex++; |
207 |
> |
} |
208 |
> |
} |
209 |
> |
|
210 |
> |
sprintf(checkPointMsg, |
211 |
> |
"Node 0 has successfully read positions from input file."); |
212 |
> |
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++; |
260 |
> |
} |
261 |
> |
} |
262 |
> |
|
263 |
> |
|
264 |
> |
else if(worldRank == procIndex){ |
265 |
> |
nodeAtomsStart = mpiSim->getMyAtomStart(); |
266 |
> |
nodeAtomsEnd = mpiSim->getMyAtomEnd(); |
267 |
> |
mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD); |
268 |
> |
mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD); |
269 |
> |
|
270 |
> |
mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD, |
271 |
> |
istatus); |
272 |
> |
if (sendError) MPIcheckPoint(); |
273 |
> |
|
274 |
> |
for ( i = 0; i < entry_plug->n_atoms; i++){ |
275 |
> |
|
276 |
> |
mpiErr = MPI_Recv(&read_buffer,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG,MPI_COMM_WORLD, |
277 |
> |
istatus); |
278 |
> |
|
279 |
> |
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); |
293 |
> |
} |
294 |
> |
} |
295 |
> |
sprintf(checkPointMsg,"Node %d received initial configuration.",procIndex); |
296 |
> |
MPIcheckPoint(); |
297 |
|
} |
298 |
+ |
|
299 |
|
#endif |
300 |
|
} |
301 |
|
|
302 |
|
|
303 |
< |
char* IntitializeFromFile::parseDumpLine(char* readLine, int atomIndex){ |
303 |
> |
char* InitializeFromFile::parseDumpLine(char* readLine, int atomIndex){ |
304 |
|
|
305 |
|
char *foo; // the pointer to the current string token |
306 |
|
|
316 |
|
int n_atoms; |
317 |
|
|
318 |
|
#ifdef IS_MPI |
319 |
< |
n_atoms = entry_plug->mpiSim->getTotAtoms(); |
319 |
> |
n_atoms = mpiSim->getTotAtoms(); |
320 |
|
#else |
321 |
|
n_atoms = entry_plug->n_atoms; |
322 |
< |
#endi // is_mpi |
322 |
> |
#endif // is_mpi |
323 |
|
|
324 |
|
|
325 |
|
// set the string tokenizer |