# | Line 11 | Line 11 | |
---|---|---|
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 | |
# | Line 68 | Line 71 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
71 | ||
72 | char *eof_test; // ptr to see when we reach the end of the file | |
73 | char *parseErr; | |
74 | + | int procIndex; |
75 | ||
76 | + | entry_plug = the_entry_plug; |
77 | ||
73 | – | entry_plug = the_entry_plug |
78 | ||
75 | – | |
79 | #ifndef IS_MPI | |
80 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
81 | if( eof_test == NULL ){ | |
# | Line 133 | Line 136 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
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 ){ | |
# | Line 149 | Line 157 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
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", | |
# | Line 168 | Line 179 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
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 < 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 = nodeAtomsStart; i <= nodeAtomsEnd; 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 | > | nodeAtomsStart = mpiSim->getMyAtomStart(); |
264 | > | nodeAtomsEnd = 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 | ||
300 | ||
301 | < | char* IntitializeFromFile::parseDumpLine(char* readLine, int atomIndex){ |
301 | > | char* InitializeFromFile::parseDumpLine(char* readLine, int atomIndex){ |
302 | ||
303 | char *foo; // the pointer to the current string token | |
304 | ||
# | Line 210 | Line 314 | char* IntitializeFromFile::parseDumpLine(char* readLin | |
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 |
320 | > | #endif // is_mpi |
321 | ||
322 | ||
323 | // set the string tokenizer |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |