# | Line 1 | Line 1 | |
---|---|---|
1 | + | #define _FILE_OFFSET_BITS 64 |
2 | #include <iostream> | |
3 | < | #include <cmath> |
3 | > | #include <math.h> |
4 | ||
5 | #include <stdio.h> | |
6 | #include <stdlib.h> | |
# | Line 12 | Line 13 | |
13 | #include "simError.h" | |
14 | ||
15 | #ifdef IS_MPI | |
16 | + | #include <mpi.h> |
17 | #include "mpiSimulation.hpp" | |
18 | + | #define TAKE_THIS_TAG_CHAR 0 |
19 | + | #define TAKE_THIS_TAG_INT 1 |
20 | ||
21 | < | #define TAKE_THIS_TAG 0 |
21 | > | namespace initFile{ |
22 | > | void nodeZeroError( void ); |
23 | > | void anonymousNodeDie( void ); |
24 | > | } |
25 | > | |
26 | > | using namespace initFile; |
27 | > | |
28 | #endif // is_mpi | |
29 | ||
30 | < | InitializeFromFile :: InitializeFromFile( char *in_name ){ |
30 | > | InitializeFromFile::InitializeFromFile( char *in_name ){ |
31 | > | |
32 | #ifdef IS_MPI | |
33 | if (worldRank == 0) { | |
34 | #endif | |
# | Line 39 | Line 50 | InitializeFromFile :: InitializeFromFile( char *in_nam | |
50 | return; | |
51 | } | |
52 | ||
53 | < | InitializeFromFile :: ~InitializeFromFile( ){ |
53 | > | InitializeFromFile::~InitializeFromFile( ){ |
54 | #ifdef IS_MPI | |
55 | if (worldRank == 0) { | |
56 | #endif | |
# | Line 60 | Line 71 | InitializeFromFile :: ~InitializeFromFile( ){ | |
71 | } | |
72 | ||
73 | ||
74 | < | void InitializeFromFile :: read_xyz( SimInfo* the_entry_plug ){ |
74 | > | void InitializeFromFile :: readInit( SimInfo* the_simnfo ){ |
75 | ||
76 | < | int i; // loop counter |
76 | > | int i, j; |
77 | > | |
78 | > | #ifdef IS_MPI |
79 | > | int done, which_node, which_atom; // loop counter |
80 | > | #endif //is_mpi |
81 | ||
82 | const int BUFFERSIZE = 2000; // size of the read buffer | |
83 | int n_atoms; // the number of atoms | |
84 | char read_buffer[BUFFERSIZE]; //the line buffer for reading | |
70 | – | #ifdef IS_MPI |
71 | – | char send_buffer[BUFFERSIZE]; |
72 | – | #endif |
85 | ||
86 | char *eof_test; // ptr to see when we reach the end of the file | |
87 | char *parseErr; | |
76 | – | int procIndex; |
88 | ||
89 | < | entry_plug = the_entry_plug; |
89 | > | double currTime; |
90 | > | double boxMat[9]; |
91 | > | double theBoxMat3[3][3]; |
92 | ||
93 | + | simnfo = the_simnfo; |
94 | ||
95 | + | |
96 | #ifndef IS_MPI | |
97 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
98 | if( eof_test == NULL ){ | |
# | Line 90 | Line 105 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
105 | ||
106 | n_atoms = atoi( read_buffer ); | |
107 | ||
108 | < | Atom **atoms = entry_plug->atoms; |
94 | < | DirectionalAtom* dAtom; |
95 | < | |
96 | < | if( n_atoms != entry_plug->n_atoms ){ |
108 | > | if( n_atoms != simnfo->n_atoms ){ |
109 | sprintf( painCave.errMsg, | |
110 | "Initialize from File error. %s n_atoms, %d, " | |
111 | "does not match the BASS file's n_atoms, %d.\n", | |
112 | < | c_in_name, n_atoms, entry_plug->n_atoms ); |
112 | > | c_in_name, n_atoms, simnfo->n_atoms ); |
113 | painCave.isFatal = 1; | |
114 | simError(); | |
115 | } | |
116 | ||
117 | < | //read and toss the comment line |
117 | > | //read the box mat from the comment line |
118 | ||
119 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
120 | if(eof_test == NULL){ | |
# | Line 112 | Line 124 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
124 | simError(); | |
125 | } | |
126 | ||
127 | + | parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
128 | + | if( parseErr != NULL ){ |
129 | + | strcpy( painCave.errMsg, parseErr ); |
130 | + | painCave.isFatal = 1; |
131 | + | simError(); |
132 | + | } |
133 | + | |
134 | + | for(i=0;i<3;i++) |
135 | + | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
136 | + | |
137 | + | simnfo->setBoxM( theBoxMat3 ); |
138 | + | simnfo->setTime( currTime ); |
139 | + | |
140 | + | |
141 | for( i=0; i < n_atoms; i++){ | |
142 | ||
143 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
# | Line 131 | Line 157 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
157 | strcpy( painCave.errMsg, parseErr ); | |
158 | painCave.isFatal = 1; | |
159 | simError(); | |
160 | < | } |
160 | > | } |
161 | } | |
162 | ||
163 | ||
164 | // MPI Section of code.......... | |
165 | #else //IS_MPI | |
166 | ||
167 | < | int masterIndex; |
168 | < | int nodeAtomsStart; |
143 | < | int nodeAtomsEnd; |
144 | < | int mpiErr; |
145 | < | int sendError; |
167 | > | // first thing first, suspend fatalities. |
168 | > | painCave.isEventLoop = 1; |
169 | ||
170 | < | MPI_Status istatus[MPI_STATUS_SIZE]; |
170 | > | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
171 | > | int haveError; |
172 | > | |
173 | > | MPI_Status istatus; |
174 | > | int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
175 | ||
176 | + | |
177 | + | haveError = 0; |
178 | if (worldRank == 0) { | |
179 | + | |
180 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
181 | if( eof_test == NULL ){ | |
182 | sprintf( painCave.errMsg, | |
183 | < | "Error reading 1st line of %d \n ",c_in_name); |
184 | < | painCave.isFatal = 1; |
183 | > | "Error reading 1st line of %s \n ",c_in_name); |
184 | > | haveError = 1; |
185 | simError(); | |
186 | } | |
187 | ||
188 | n_atoms = atoi( read_buffer ); | |
189 | ||
160 | – | Atom **atoms = entry_plug->atoms; |
161 | – | DirectionalAtom* dAtom; |
162 | – | |
190 | // Check to see that the number of atoms in the intial configuration file is the | |
191 | // same as declared in simBass. | |
192 | ||
# | Line 167 | Line 194 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
194 | sprintf( painCave.errMsg, | |
195 | "Initialize from File error. %s n_atoms, %d, " | |
196 | "does not match the BASS file's n_atoms, %d.\n", | |
197 | < | c_in_name, n_atoms, entry_plug->n_atoms ); |
198 | < | painCave.isFatal = 1; |
197 | > | c_in_name, n_atoms, simnfo->n_atoms ); |
198 | > | haveError= 1; |
199 | simError(); | |
200 | } | |
201 | ||
202 | < | //read and toss the comment line |
202 | > | //read the boxMat from the comment line |
203 | ||
204 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
205 | if(eof_test == NULL){ | |
206 | sprintf( painCave.errMsg, | |
207 | "error in reading commment in %s\n", c_in_name); | |
208 | < | painCave.isFatal = 1; |
208 | > | haveError = 1; |
209 | simError(); | |
210 | } | |
184 | – | |
185 | – | // Read Proc 0 share of the xyz file... |
186 | – | masterIndex = 0; |
187 | – | for( i=0; i <= mpiSim->getMyAtomEnd(); i++){ |
211 | ||
212 | + | parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
213 | + | if( parseErr != NULL ){ |
214 | + | strcpy( painCave.errMsg, parseErr ); |
215 | + | haveError = 1; |
216 | + | simError(); |
217 | + | } |
218 | + | |
219 | + | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
220 | + | MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
221 | + | |
222 | + | if(haveError) nodeZeroError(); |
223 | + | |
224 | + | for (i=0 ; i < mpiSim->getTotAtoms(); i++) { |
225 | + | |
226 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
227 | if(eof_test == NULL){ | |
228 | sprintf(painCave.errMsg, | |
# | Line 193 | Line 230 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
230 | "natoms = %d; index = %d\n" | |
231 | "error reading the line from the file.\n", | |
232 | c_in_name, n_atoms, i ); | |
233 | < | painCave.isFatal = 1; |
233 | > | haveError= 1; |
234 | simError(); | |
235 | } | |
236 | ||
237 | < | 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 | < | } |
237 | > | if(haveError) nodeZeroError(); |
238 | ||
239 | < | sprintf(checkPointMsg, |
240 | < | "Node 0 has successfully read positions from input file."); |
241 | < | MPIcheckPoint(); |
242 | < | |
243 | < | for (procIndex = 1; procIndex < mpiSim->getNumberProcessors(); |
244 | < | procIndex++){ |
245 | < | if (worldRank == 0) { |
246 | < | |
247 | < | mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD, |
248 | < | istatus); |
249 | < | |
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); |
239 | > | // Get the Node number which wants this atom: |
240 | > | which_node = AtomToProcMap[i]; |
241 | > | if (which_node == 0) { |
242 | > | parseErr = parseDumpLine( read_buffer, i ); |
243 | > | if( parseErr != NULL ){ |
244 | > | strcpy( painCave.errMsg, parseErr ); |
245 | > | haveError = 1; |
246 | > | simError(); |
247 | > | } |
248 | > | if(haveError) nodeZeroError(); |
249 | > | } |
250 | ||
251 | < | for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){ |
252 | < | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
253 | < | if(eof_test == NULL){ |
254 | < | |
255 | < | sprintf(read_buffer,"ERROR"); |
256 | < | mpiErr = MPI_Send(read_buffer,BUFFERSIZE,MPI_CHAR,procIndex,TAKE_THIS_TAG,MPI_COMM_WORLD); |
257 | < | |
258 | < | sprintf(painCave.errMsg, |
259 | < | "error in reading file %s\n" |
260 | < | "natoms = %d; index = %d\n" |
261 | < | "error reading the line from the file.\n", |
249 | < | c_in_name, n_atoms, i ); |
250 | < | painCave.isFatal = 1; |
251 | < | simError(); |
252 | < | } |
251 | > | else { |
252 | > | |
253 | > | myStatus = 1; |
254 | > | MPI_Send(&myStatus, 1, MPI_INT, which_node, |
255 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
256 | > | MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
257 | > | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
258 | > | MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
259 | > | MPI_COMM_WORLD); |
260 | > | MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
261 | > | MPI_COMM_WORLD, &istatus); |
262 | ||
263 | < | 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++; |
263 | > | if(!myStatus) nodeZeroError(); |
264 | } | |
265 | } | |
266 | + | myStatus = -1; |
267 | + | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
268 | + | MPI_Send( &myStatus, 1, MPI_INT, j, |
269 | + | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
270 | + | } |
271 | + | |
272 | + | } else { |
273 | + | |
274 | + | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
275 | + | MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
276 | ||
277 | + | done = 0; |
278 | + | while (!done) { |
279 | ||
280 | < | else if(worldRank == procIndex){ |
281 | < | 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); |
280 | > | MPI_Recv(&myStatus, 1, MPI_INT, 0, |
281 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
282 | ||
283 | < | mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD, |
284 | < | istatus); |
285 | < | 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); |
283 | > | if(!myStatus) anonymousNodeDie(); |
284 | > | |
285 | > | if(myStatus < 0) break; |
286 | ||
287 | < | |
288 | < | strcpy( painCave.errMsg, parseErr ); |
289 | < | painCave.isFatal = 1; |
290 | < | simError(); |
291 | < | } |
292 | < | sendError = 0; |
293 | < | mpiErr = MPI_Send(&sendError,1,MPI_INT,0,TAKE_THIS_TAG,MPI_COMM_WORLD); |
287 | > | MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
288 | > | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
289 | > | MPI_Recv(&which_atom, 1, MPI_INT, 0, |
290 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
291 | > | |
292 | > | myStatus = 1; |
293 | > | parseErr = parseDumpLine( read_buffer, which_atom ); |
294 | > | if( parseErr != NULL ){ |
295 | > | strcpy( painCave.errMsg, parseErr ); |
296 | > | myStatus = 0;; |
297 | > | simError(); |
298 | } | |
299 | + | |
300 | + | MPI_Send( &myStatus, 1, MPI_INT, 0, |
301 | + | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
302 | + | |
303 | } | |
295 | – | sprintf(checkPointMsg,"Node %d received initial configuration.",procIndex); |
296 | – | MPIcheckPoint(); |
304 | } | |
305 | + | |
306 | + | // last thing last, enable fatalities. |
307 | + | painCave.isEventLoop = 0; |
308 | ||
309 | + | for(i=0;i<3;i++) |
310 | + | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
311 | + | |
312 | + | simnfo->setBoxM( theBoxMat3 ); |
313 | + | simnfo->setTime( currTime ); |
314 | + | |
315 | + | |
316 | #endif | |
317 | } | |
318 | ||
319 | + | char* InitializeFromFile::parseDumpLine(char* readLine, int globalIndex){ |
320 | ||
303 | – | char* InitializeFromFile::parseDumpLine(char* readLine, int atomIndex){ |
304 | – | |
321 | char *foo; // the pointer to the current string token | |
322 | ||
323 | < | double rx, ry, rz; // position place holders |
324 | < | double vx, vy, vz; // velocity placeholders |
323 | > | double pos[3]; // position place holders |
324 | > | double vel[3]; // velocity placeholders |
325 | double q[4]; // the quaternions | |
326 | double jx, jy, jz; // angular velocity placeholders; | |
327 | double qSqr, qLength; // needed to normalize the quaternion vector. | |
328 | ||
329 | < | Atom **atoms = entry_plug->atoms; |
329 | > | Atom **atoms = simnfo->atoms; |
330 | DirectionalAtom* dAtom; | |
331 | ||
332 | < | int n_atoms; |
332 | > | int n_atoms, atomIndex; |
333 | ||
334 | #ifdef IS_MPI | |
335 | + | int j; |
336 | + | |
337 | n_atoms = mpiSim->getTotAtoms(); | |
338 | + | atomIndex=-1; |
339 | + | for (j=0; j < mpiSim->getMyNlocal(); j++) { |
340 | + | if (atoms[j]->getGlobalIndex() == globalIndex) atomIndex = j; |
341 | + | } |
342 | + | if (atomIndex == -1) { |
343 | + | sprintf( painCave.errMsg, |
344 | + | "Initialize from file error. Atom at index %d " |
345 | + | "in file %s does not exist on processor %d .\n", |
346 | + | globalIndex, c_in_name, mpiSim->getMyNode() ); |
347 | + | return strdup( painCave.errMsg ); |
348 | + | } |
349 | #else | |
350 | < | n_atoms = entry_plug->n_atoms; |
350 | > | n_atoms = simnfo->n_atoms; |
351 | > | atomIndex = globalIndex; |
352 | #endif // is_mpi | |
353 | ||
324 | – | |
354 | // set the string tokenizer | |
355 | ||
356 | foo = strtok(readLine, " ,;\t"); | |
# | Line 347 | Line 376 | char* InitializeFromFile::parseDumpLine(char* readLine | |
376 | c_in_name, n_atoms, atomIndex ); | |
377 | return strdup( painCave.errMsg ); | |
378 | } | |
379 | < | rx = atof( foo ); |
379 | > | pos[0] = atof( foo ); |
380 | ||
381 | foo = strtok(NULL, " ,;\t"); | |
382 | if(foo == NULL){ | |
# | Line 357 | Line 386 | char* InitializeFromFile::parseDumpLine(char* readLine | |
386 | c_in_name, n_atoms, atomIndex ); | |
387 | return strdup( painCave.errMsg ); | |
388 | } | |
389 | < | ry = atof( foo ); |
389 | > | pos[1] = atof( foo ); |
390 | ||
391 | foo = strtok(NULL, " ,;\t"); | |
392 | if(foo == NULL){ | |
# | Line 367 | Line 396 | char* InitializeFromFile::parseDumpLine(char* readLine | |
396 | c_in_name, n_atoms, atomIndex ); | |
397 | return strdup( painCave.errMsg ); | |
398 | } | |
399 | < | rz = atof( foo ); |
399 | > | pos[2] = atof( foo ); |
400 | ||
401 | ||
402 | // get the velocities | |
# | Line 380 | Line 409 | char* InitializeFromFile::parseDumpLine(char* readLine | |
409 | c_in_name, n_atoms, atomIndex ); | |
410 | return strdup( painCave.errMsg ); | |
411 | } | |
412 | < | vx = atof( foo ); |
412 | > | vel[0] = atof( foo ); |
413 | ||
414 | foo = strtok(NULL, " ,;\t"); | |
415 | if(foo == NULL){ | |
# | Line 390 | Line 419 | char* InitializeFromFile::parseDumpLine(char* readLine | |
419 | c_in_name, n_atoms, atomIndex ); | |
420 | return strdup( painCave.errMsg ); | |
421 | } | |
422 | < | vy = atof( foo ); |
422 | > | vel[1] = atof( foo ); |
423 | ||
424 | foo = strtok(NULL, " ,;\t"); | |
425 | if(foo == NULL){ | |
# | Line 400 | Line 429 | char* InitializeFromFile::parseDumpLine(char* readLine | |
429 | c_in_name, n_atoms, atomIndex ); | |
430 | return strdup( painCave.errMsg ); | |
431 | } | |
432 | < | vz = atof( foo ); |
432 | > | vel[2] = atof( foo ); |
433 | ||
434 | ||
435 | // get the quaternions | |
# | Line 502 | Line 531 | char* InitializeFromFile::parseDumpLine(char* readLine | |
531 | ||
532 | // add the positions and velocities to the atom | |
533 | ||
534 | < | atoms[atomIndex]->setX( rx ); |
535 | < | atoms[atomIndex]->setY( ry ); |
507 | < | atoms[atomIndex]->setZ( rz ); |
508 | < | |
509 | < | atoms[atomIndex]->set_vx( vx ); |
510 | < | atoms[atomIndex]->set_vy( vy ); |
511 | < | atoms[atomIndex]->set_vz( vz ); |
534 | > | atoms[atomIndex]->setPos( pos ); |
535 | > | atoms[atomIndex]->setVel( vel ); |
536 | ||
537 | return NULL; | |
538 | } | |
539 | + | |
540 | + | |
541 | + | char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9], |
542 | + | double &time ){ |
543 | + | |
544 | + | char *foo; // the pointer to the current string token |
545 | + | |
546 | + | // set the string tokenizer |
547 | + | |
548 | + | foo = strtok(readLine, " ,;\t"); |
549 | + | // set the timeToken. |
550 | + | |
551 | + | if(foo == NULL){ |
552 | + | sprintf( painCave.errMsg, |
553 | + | "error in reading Time from %s\n", |
554 | + | c_in_name ); |
555 | + | return strdup( painCave.errMsg ); |
556 | + | } |
557 | + | time = atof( foo ); |
558 | + | |
559 | + | // get the Hx vector |
560 | + | |
561 | + | foo = strtok(NULL, " ,;\t"); |
562 | + | if(foo == NULL){ |
563 | + | sprintf( painCave.errMsg, |
564 | + | "error in reading Hx[0] from %s\n", |
565 | + | c_in_name ); |
566 | + | return strdup( painCave.errMsg ); |
567 | + | } |
568 | + | boxMat[0] = atof( foo ); |
569 | + | |
570 | + | foo = strtok(NULL, " ,;\t"); |
571 | + | if(foo == NULL){ |
572 | + | sprintf( painCave.errMsg, |
573 | + | "error in reading Hx[1] from %s\n", |
574 | + | c_in_name ); |
575 | + | return strdup( painCave.errMsg ); |
576 | + | } |
577 | + | boxMat[1] = atof( foo ); |
578 | + | |
579 | + | foo = strtok(NULL, " ,;\t"); |
580 | + | if(foo == NULL){ |
581 | + | sprintf( painCave.errMsg, |
582 | + | "error in reading Hx[2] from %s\n", |
583 | + | c_in_name ); |
584 | + | return strdup( painCave.errMsg ); |
585 | + | } |
586 | + | boxMat[2] = atof( foo ); |
587 | + | |
588 | + | // get the Hy vector |
589 | + | |
590 | + | foo = strtok(NULL, " ,;\t"); |
591 | + | if(foo == NULL){ |
592 | + | sprintf( painCave.errMsg, |
593 | + | "error in reading Hy[0] from %s\n", |
594 | + | c_in_name ); |
595 | + | return strdup( painCave.errMsg ); |
596 | + | } |
597 | + | boxMat[3] = atof( foo ); |
598 | + | |
599 | + | foo = strtok(NULL, " ,;\t"); |
600 | + | if(foo == NULL){ |
601 | + | sprintf( painCave.errMsg, |
602 | + | "error in reading Hy[1] from %s\n", |
603 | + | c_in_name ); |
604 | + | return strdup( painCave.errMsg ); |
605 | + | } |
606 | + | boxMat[4] = atof( foo ); |
607 | + | |
608 | + | foo = strtok(NULL, " ,;\t"); |
609 | + | if(foo == NULL){ |
610 | + | sprintf( painCave.errMsg, |
611 | + | "error in reading Hy[2] from %s\n", |
612 | + | c_in_name ); |
613 | + | return strdup( painCave.errMsg ); |
614 | + | } |
615 | + | boxMat[5] = atof( foo ); |
616 | + | |
617 | + | // get the Hz vector |
618 | + | |
619 | + | foo = strtok(NULL, " ,;\t"); |
620 | + | if(foo == NULL){ |
621 | + | sprintf( painCave.errMsg, |
622 | + | "error in reading Hz[0] from %s\n", |
623 | + | c_in_name ); |
624 | + | return strdup( painCave.errMsg ); |
625 | + | } |
626 | + | boxMat[6] = atof( foo ); |
627 | + | |
628 | + | foo = strtok(NULL, " ,;\t"); |
629 | + | if(foo == NULL){ |
630 | + | sprintf( painCave.errMsg, |
631 | + | "error in reading Hz[1] from %s\n", |
632 | + | c_in_name ); |
633 | + | return strdup( painCave.errMsg ); |
634 | + | } |
635 | + | boxMat[7] = atof( foo ); |
636 | + | |
637 | + | foo = strtok(NULL, " ,;\t"); |
638 | + | if(foo == NULL){ |
639 | + | sprintf( painCave.errMsg, |
640 | + | "error in reading Hz[2] from %s\n", |
641 | + | c_in_name ); |
642 | + | return strdup( painCave.errMsg ); |
643 | + | } |
644 | + | boxMat[8] = atof( foo ); |
645 | + | |
646 | + | return NULL; |
647 | + | } |
648 | + | |
649 | + | |
650 | + | #ifdef IS_MPI |
651 | + | |
652 | + | // a couple of functions to let us escape the read loop |
653 | + | |
654 | + | void initFile::nodeZeroError( void ){ |
655 | + | int j, myStatus; |
656 | + | |
657 | + | myStatus = 0; |
658 | + | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
659 | + | MPI_Send( &myStatus, 1, MPI_INT, j, |
660 | + | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
661 | + | } |
662 | + | |
663 | + | |
664 | + | MPI_Finalize(); |
665 | + | exit (0); |
666 | + | |
667 | + | } |
668 | + | |
669 | + | void initFile::anonymousNodeDie( void ){ |
670 | + | |
671 | + | MPI_Finalize(); |
672 | + | exit (0); |
673 | + | } |
674 | + | |
675 | + | #endif //is_mpi |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |