# | Line 13 | Line 13 | |
---|---|---|
13 | ||
14 | #ifdef IS_MPI | |
15 | #include <mpi.h> | |
16 | – | #include <mpi++.h> |
16 | #include "mpiSimulation.hpp" | |
17 | #define TAKE_THIS_TAG_CHAR 0 | |
18 | #define TAKE_THIS_TAG_INT 1 | |
# | Line 70 | Line 69 | InitializeFromFile :: ~InitializeFromFile( ){ | |
69 | } | |
70 | ||
71 | ||
72 | < | void InitializeFromFile :: read_xyz( SimInfo* the_entry_plug ){ |
72 | > | void InitializeFromFile :: read_xyz( SimInfo* the_simnfo ){ |
73 | ||
74 | int i, j, done, which_node, which_atom; // loop counter | |
75 | ||
# | Line 84 | Line 83 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
83 | char *eof_test; // ptr to see when we reach the end of the file | |
84 | char *parseErr; | |
85 | int procIndex; | |
86 | + | double boxMat[9]; |
87 | + | double theBoxMat3[3][3]; |
88 | ||
89 | < | entry_plug = the_entry_plug; |
89 | > | simnfo = the_simnfo; |
90 | ||
91 | ||
92 | #ifndef IS_MPI | |
# | Line 100 | Line 101 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
101 | ||
102 | n_atoms = atoi( read_buffer ); | |
103 | ||
104 | < | Atom **atoms = entry_plug->atoms; |
104 | > | Atom **atoms = simnfo->atoms; |
105 | DirectionalAtom* dAtom; | |
106 | ||
107 | < | if( n_atoms != entry_plug->n_atoms ){ |
107 | > | if( n_atoms != simnfo->n_atoms ){ |
108 | sprintf( painCave.errMsg, | |
109 | "Initialize from File error. %s n_atoms, %d, " | |
110 | "does not match the BASS file's n_atoms, %d.\n", | |
111 | < | c_in_name, n_atoms, entry_plug->n_atoms ); |
111 | > | c_in_name, n_atoms, simnfo->n_atoms ); |
112 | painCave.isFatal = 1; | |
113 | simError(); | |
114 | } | |
115 | ||
116 | < | //read and toss the comment line |
116 | > | //read the box mat from the comment line |
117 | ||
118 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
119 | if(eof_test == NULL){ | |
# | Line 122 | Line 123 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
123 | simError(); | |
124 | } | |
125 | ||
126 | + | parseErr = parseBoxLine( read_buffer, boxMat ); |
127 | + | if( parseErr != NULL ){ |
128 | + | strcpy( painCave.errMsg, parseErr ); |
129 | + | painCave.isFatal = 1; |
130 | + | simError(); |
131 | + | } |
132 | + | |
133 | + | for(i=0;i<3;i++) |
134 | + | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
135 | + | |
136 | + | simnfo->setBoxM( theBoxMat3 ); |
137 | + | |
138 | + | |
139 | for( i=0; i < n_atoms; i++){ | |
140 | ||
141 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
# | Line 141 | Line 155 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
155 | strcpy( painCave.errMsg, parseErr ); | |
156 | painCave.isFatal = 1; | |
157 | simError(); | |
158 | < | } |
158 | > | } |
159 | } | |
160 | ||
161 | ||
# | Line 154 | Line 168 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
168 | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone | |
169 | int haveError; | |
170 | ||
171 | < | MPI::Status istatus; |
171 | > | MPI_Status istatus; |
172 | int *AtomToProcMap = mpiSim->getAtomToProcMap(); | |
173 | ||
174 | ||
# | Line 171 | Line 185 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
185 | ||
186 | n_atoms = atoi( read_buffer ); | |
187 | ||
188 | < | Atom **atoms = entry_plug->atoms; |
188 | > | Atom **atoms = simnfo->atoms; |
189 | DirectionalAtom* dAtom; | |
190 | ||
191 | // Check to see that the number of atoms in the intial configuration file is the | |
# | Line 181 | Line 195 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
195 | sprintf( painCave.errMsg, | |
196 | "Initialize from File error. %s n_atoms, %d, " | |
197 | "does not match the BASS file's n_atoms, %d.\n", | |
198 | < | c_in_name, n_atoms, entry_plug->n_atoms ); |
198 | > | c_in_name, n_atoms, simnfo->n_atoms ); |
199 | haveError= 1; | |
200 | simError(); | |
201 | } | |
202 | ||
203 | < | //read and toss the comment line |
203 | > | //read the boxMat from the comment line |
204 | ||
205 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
206 | if(eof_test == NULL){ | |
207 | sprintf( painCave.errMsg, | |
208 | "error in reading commment in %s\n", c_in_name); | |
209 | < | haveError= 1; |
209 | > | haveError = 1; |
210 | simError(); | |
211 | } | |
212 | + | |
213 | + | parseErr = parseBoxLine( read_buffer, boxMat ); |
214 | + | if( parseErr != NULL ){ |
215 | + | strcpy( painCave.errMsg, parseErr ); |
216 | + | haveError = 1; |
217 | + | simError(); |
218 | + | } |
219 | + | |
220 | + | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
221 | ||
222 | if(haveError) nodeZeroError(); | |
223 | ||
# | Line 228 | Line 251 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
251 | else { | |
252 | ||
253 | myStatus = 1; | |
254 | < | MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, which_node, |
255 | < | TAKE_THIS_TAG_INT); |
256 | < | MPI::COMM_WORLD.Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
257 | < | TAKE_THIS_TAG_CHAR); |
258 | < | MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT); |
259 | < | MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, istatus); |
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 | if(!myStatus) nodeZeroError(); | |
264 | } | |
265 | } | |
266 | myStatus = -1; | |
267 | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { | |
268 | < | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j, |
269 | < | TAKE_THIS_TAG_INT); |
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 | + | |
276 | done = 0; | |
277 | while (!done) { | |
278 | ||
279 | < | MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, 0, |
280 | < | TAKE_THIS_TAG_INT, istatus); |
279 | > | MPI_Recv(&myStatus, 1, MPI_INT, 0, |
280 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
281 | ||
282 | if(!myStatus) anonymousNodeDie(); | |
283 | ||
284 | if(myStatus < 0) break; | |
285 | ||
286 | < | MPI::COMM_WORLD.Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
287 | < | TAKE_THIS_TAG_CHAR, istatus); |
288 | < | MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
289 | < | TAKE_THIS_TAG_INT, istatus); |
286 | > | MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
287 | > | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
288 | > | MPI_Recv(&which_atom, 1, MPI_INT, 0, |
289 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
290 | ||
291 | myStatus = 1; | |
292 | parseErr = parseDumpLine( read_buffer, which_atom ); | |
# | Line 269 | Line 296 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
296 | simError(); | |
297 | } | |
298 | ||
299 | < | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, 0, |
300 | < | TAKE_THIS_TAG_INT); |
299 | > | MPI_Send( &myStatus, 1, MPI_INT, 0, |
300 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
301 | ||
302 | } | |
303 | } | |
304 | ||
305 | // last thing last, enable fatalities. | |
306 | painCave.isEventLoop = 0; | |
307 | + | |
308 | + | for(i=0;i<3;i++) |
309 | + | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
310 | + | |
311 | + | simnfo->setBoxM( theBoxMat3 ); |
312 | + | |
313 | ||
314 | #endif | |
315 | } | |
# | Line 291 | Line 324 | char* InitializeFromFile::parseDumpLine(char* readLine | |
324 | double jx, jy, jz; // angular velocity placeholders; | |
325 | double qSqr, qLength; // needed to normalize the quaternion vector. | |
326 | ||
327 | < | Atom **atoms = entry_plug->atoms; |
327 | > | Atom **atoms = simnfo->atoms; |
328 | DirectionalAtom* dAtom; | |
329 | ||
330 | int j, n_atoms, atomIndex; | |
# | Line 310 | Line 343 | char* InitializeFromFile::parseDumpLine(char* readLine | |
343 | return strdup( painCave.errMsg ); | |
344 | } | |
345 | #else | |
346 | < | n_atoms = entry_plug->n_atoms; |
346 | > | n_atoms = simnfo->n_atoms; |
347 | atomIndex = globalIndex; | |
348 | #endif // is_mpi | |
349 | ||
# | Line 506 | Line 539 | char* InitializeFromFile::parseDumpLine(char* readLine | |
539 | } | |
540 | ||
541 | ||
542 | + | char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9]){ |
543 | + | |
544 | + | char *foo; // the pointer to the current string token |
545 | + | int j; |
546 | + | |
547 | + | // set the string tokenizer |
548 | + | |
549 | + | foo = strtok(readLine, " ,;\t"); |
550 | + | // ignore the first token which is the time stamp. |
551 | + | |
552 | + | |
553 | + | // get the Hx vector |
554 | + | |
555 | + | foo = strtok(NULL, " ,;\t"); |
556 | + | if(foo == NULL){ |
557 | + | sprintf( painCave.errMsg, |
558 | + | "error in reading Hx[0] from %s\n", |
559 | + | c_in_name ); |
560 | + | return strdup( painCave.errMsg ); |
561 | + | } |
562 | + | boxMat[0] = atof( foo ); |
563 | + | |
564 | + | foo = strtok(NULL, " ,;\t"); |
565 | + | if(foo == NULL){ |
566 | + | sprintf( painCave.errMsg, |
567 | + | "error in reading Hx[1] from %s\n", |
568 | + | c_in_name ); |
569 | + | return strdup( painCave.errMsg ); |
570 | + | } |
571 | + | boxMat[1] = atof( foo ); |
572 | + | |
573 | + | foo = strtok(NULL, " ,;\t"); |
574 | + | if(foo == NULL){ |
575 | + | sprintf( painCave.errMsg, |
576 | + | "error in reading Hx[2] from %s\n", |
577 | + | c_in_name ); |
578 | + | return strdup( painCave.errMsg ); |
579 | + | } |
580 | + | boxMat[2] = atof( foo ); |
581 | + | |
582 | + | // get the Hy vector |
583 | + | |
584 | + | foo = strtok(NULL, " ,;\t"); |
585 | + | if(foo == NULL){ |
586 | + | sprintf( painCave.errMsg, |
587 | + | "error in reading Hy[0] from %s\n", |
588 | + | c_in_name ); |
589 | + | return strdup( painCave.errMsg ); |
590 | + | } |
591 | + | boxMat[3] = atof( foo ); |
592 | + | |
593 | + | foo = strtok(NULL, " ,;\t"); |
594 | + | if(foo == NULL){ |
595 | + | sprintf( painCave.errMsg, |
596 | + | "error in reading Hy[1] from %s\n", |
597 | + | c_in_name ); |
598 | + | return strdup( painCave.errMsg ); |
599 | + | } |
600 | + | boxMat[4] = atof( foo ); |
601 | + | |
602 | + | foo = strtok(NULL, " ,;\t"); |
603 | + | if(foo == NULL){ |
604 | + | sprintf( painCave.errMsg, |
605 | + | "error in reading Hy[2] from %s\n", |
606 | + | c_in_name ); |
607 | + | return strdup( painCave.errMsg ); |
608 | + | } |
609 | + | boxMat[5] = atof( foo ); |
610 | + | |
611 | + | // get the Hz vector |
612 | + | |
613 | + | foo = strtok(NULL, " ,;\t"); |
614 | + | if(foo == NULL){ |
615 | + | sprintf( painCave.errMsg, |
616 | + | "error in reading Hz[0] from %s\n", |
617 | + | c_in_name ); |
618 | + | return strdup( painCave.errMsg ); |
619 | + | } |
620 | + | boxMat[6] = atof( foo ); |
621 | + | |
622 | + | foo = strtok(NULL, " ,;\t"); |
623 | + | if(foo == NULL){ |
624 | + | sprintf( painCave.errMsg, |
625 | + | "error in reading Hz[1] from %s\n", |
626 | + | c_in_name ); |
627 | + | return strdup( painCave.errMsg ); |
628 | + | } |
629 | + | boxMat[7] = atof( foo ); |
630 | + | |
631 | + | foo = strtok(NULL, " ,;\t"); |
632 | + | if(foo == NULL){ |
633 | + | sprintf( painCave.errMsg, |
634 | + | "error in reading Hz[2] from %s\n", |
635 | + | c_in_name ); |
636 | + | return strdup( painCave.errMsg ); |
637 | + | } |
638 | + | boxMat[8] = atof( foo ); |
639 | + | |
640 | + | return NULL; |
641 | + | } |
642 | + | |
643 | + | |
644 | #ifdef IS_MPI | |
645 | ||
646 | // a couple of functions to let us escape the read loop | |
# | Line 515 | Line 650 | void initFile::nodeZeroError( void ){ | |
650 | ||
651 | myStatus = 0; | |
652 | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { | |
653 | < | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j, |
654 | < | TAKE_THIS_TAG_INT); |
653 | > | MPI_Send( &myStatus, 1, MPI_INT, j, |
654 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
655 | } | |
656 | ||
657 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |