# | 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 | |
19 | ||
20 | < | void nodeZeroError( void ); |
21 | < | void anonymousNodeDie( void ); |
20 | > | namespace initFile{ |
21 | > | void nodeZeroError( void ); |
22 | > | void anonymousNodeDie( void ); |
23 | > | } |
24 | ||
25 | + | using namespace initFile; |
26 | + | |
27 | #endif // is_mpi | |
28 | ||
29 | < | InitializeFromFile :: InitializeFromFile( char *in_name ){ |
29 | > | InitializeFromFile::InitializeFromFile( char *in_name ){ |
30 | > | |
31 | #ifdef IS_MPI | |
32 | if (worldRank == 0) { | |
33 | #endif | |
# | Line 45 | Line 49 | InitializeFromFile :: InitializeFromFile( char *in_nam | |
49 | return; | |
50 | } | |
51 | ||
52 | < | InitializeFromFile :: ~InitializeFromFile( ){ |
52 | > | InitializeFromFile::~InitializeFromFile( ){ |
53 | #ifdef IS_MPI | |
54 | if (worldRank == 0) { | |
55 | #endif | |
# | Line 66 | Line 70 | InitializeFromFile :: ~InitializeFromFile( ){ | |
70 | } | |
71 | ||
72 | ||
73 | < | void InitializeFromFile :: read_xyz( SimInfo* the_entry_plug ){ |
73 | > | void InitializeFromFile :: readInit( SimInfo* the_simnfo ){ |
74 | ||
75 | int i, j, done, which_node, which_atom; // loop counter | |
76 | ||
# | Line 80 | Line 84 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
84 | char *eof_test; // ptr to see when we reach the end of the file | |
85 | char *parseErr; | |
86 | int procIndex; | |
87 | + | double currTime; |
88 | + | double boxMat[9]; |
89 | + | double theBoxMat3[3][3]; |
90 | ||
91 | < | entry_plug = the_entry_plug; |
91 | > | simnfo = the_simnfo; |
92 | ||
93 | ||
94 | #ifndef IS_MPI | |
# | Line 96 | Line 103 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
103 | ||
104 | n_atoms = atoi( read_buffer ); | |
105 | ||
106 | < | Atom **atoms = entry_plug->atoms; |
106 | > | Atom **atoms = simnfo->atoms; |
107 | DirectionalAtom* dAtom; | |
108 | ||
109 | < | if( n_atoms != entry_plug->n_atoms ){ |
109 | > | if( n_atoms != simnfo->n_atoms ){ |
110 | sprintf( painCave.errMsg, | |
111 | "Initialize from File error. %s n_atoms, %d, " | |
112 | "does not match the BASS file's n_atoms, %d.\n", | |
113 | < | c_in_name, n_atoms, entry_plug->n_atoms ); |
113 | > | c_in_name, n_atoms, simnfo->n_atoms ); |
114 | painCave.isFatal = 1; | |
115 | simError(); | |
116 | } | |
117 | ||
118 | < | //read and toss the comment line |
118 | > | //read the box mat from the comment line |
119 | ||
120 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
121 | if(eof_test == NULL){ | |
# | Line 118 | Line 125 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
125 | simError(); | |
126 | } | |
127 | ||
128 | + | parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
129 | + | if( parseErr != NULL ){ |
130 | + | strcpy( painCave.errMsg, parseErr ); |
131 | + | painCave.isFatal = 1; |
132 | + | simError(); |
133 | + | } |
134 | + | |
135 | + | for(i=0;i<3;i++) |
136 | + | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
137 | + | |
138 | + | simnfo->setBoxM( theBoxMat3 ); |
139 | + | simnfo->setTime( currTime ); |
140 | + | |
141 | + | |
142 | for( i=0; i < n_atoms; i++){ | |
143 | ||
144 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
# | Line 137 | Line 158 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
158 | strcpy( painCave.errMsg, parseErr ); | |
159 | painCave.isFatal = 1; | |
160 | simError(); | |
161 | < | } |
161 | > | } |
162 | } | |
163 | ||
164 | ||
# | Line 150 | Line 171 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
171 | int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone | |
172 | int haveError; | |
173 | ||
174 | < | MPI::Status istatus; |
174 | > | MPI_Status istatus; |
175 | int *AtomToProcMap = mpiSim->getAtomToProcMap(); | |
176 | ||
177 | ||
# | Line 167 | Line 188 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
188 | ||
189 | n_atoms = atoi( read_buffer ); | |
190 | ||
191 | < | Atom **atoms = entry_plug->atoms; |
191 | > | Atom **atoms = simnfo->atoms; |
192 | DirectionalAtom* dAtom; | |
193 | ||
194 | // Check to see that the number of atoms in the intial configuration file is the | |
# | Line 177 | Line 198 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
198 | sprintf( painCave.errMsg, | |
199 | "Initialize from File error. %s n_atoms, %d, " | |
200 | "does not match the BASS file's n_atoms, %d.\n", | |
201 | < | c_in_name, n_atoms, entry_plug->n_atoms ); |
201 | > | c_in_name, n_atoms, simnfo->n_atoms ); |
202 | haveError= 1; | |
203 | simError(); | |
204 | } | |
205 | ||
206 | < | //read and toss the comment line |
206 | > | //read the boxMat from the comment line |
207 | ||
208 | eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); | |
209 | if(eof_test == NULL){ | |
210 | sprintf( painCave.errMsg, | |
211 | "error in reading commment in %s\n", c_in_name); | |
212 | < | haveError= 1; |
212 | > | haveError = 1; |
213 | simError(); | |
214 | } | |
215 | + | |
216 | + | parseErr = parseBoxLine( read_buffer, boxMat, currTime ); |
217 | + | if( parseErr != NULL ){ |
218 | + | strcpy( painCave.errMsg, parseErr ); |
219 | + | haveError = 1; |
220 | + | simError(); |
221 | + | } |
222 | + | |
223 | + | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
224 | + | MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
225 | ||
226 | if(haveError) nodeZeroError(); | |
227 | ||
# | Line 224 | Line 255 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
255 | else { | |
256 | ||
257 | myStatus = 1; | |
258 | < | MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, which_node, |
259 | < | TAKE_THIS_TAG_INT); |
260 | < | MPI::COMM_WORLD.Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
261 | < | TAKE_THIS_TAG_CHAR); |
262 | < | MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT); |
263 | < | MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, istatus); |
258 | > | MPI_Send(&myStatus, 1, MPI_INT, which_node, |
259 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
260 | > | MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
261 | > | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
262 | > | MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
263 | > | MPI_COMM_WORLD); |
264 | > | MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
265 | > | MPI_COMM_WORLD, &istatus); |
266 | ||
267 | if(!myStatus) nodeZeroError(); | |
268 | } | |
269 | } | |
270 | myStatus = -1; | |
271 | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { | |
272 | < | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j, |
273 | < | TAKE_THIS_TAG_INT); |
272 | > | MPI_Send( &myStatus, 1, MPI_INT, j, |
273 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
274 | } | |
275 | ||
276 | } else { | |
277 | ||
278 | + | MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
279 | + | MPI_Bcast(&currTime, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
280 | + | |
281 | done = 0; | |
282 | while (!done) { | |
283 | ||
284 | < | MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, 0, |
285 | < | TAKE_THIS_TAG_INT, istatus); |
284 | > | MPI_Recv(&myStatus, 1, MPI_INT, 0, |
285 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
286 | ||
287 | if(!myStatus) anonymousNodeDie(); | |
288 | ||
289 | if(myStatus < 0) break; | |
290 | ||
291 | < | MPI::COMM_WORLD.Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
292 | < | TAKE_THIS_TAG_CHAR, istatus); |
293 | < | MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
294 | < | TAKE_THIS_TAG_INT, istatus); |
291 | > | MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
292 | > | TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
293 | > | MPI_Recv(&which_atom, 1, MPI_INT, 0, |
294 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
295 | ||
296 | myStatus = 1; | |
297 | parseErr = parseDumpLine( read_buffer, which_atom ); | |
# | Line 265 | Line 301 | void InitializeFromFile :: read_xyz( SimInfo* the_entr | |
301 | simError(); | |
302 | } | |
303 | ||
304 | < | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, 0, |
305 | < | TAKE_THIS_TAG_INT); |
304 | > | MPI_Send( &myStatus, 1, MPI_INT, 0, |
305 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
306 | ||
307 | } | |
308 | } | |
309 | ||
310 | // last thing last, enable fatalities. | |
311 | painCave.isEventLoop = 0; | |
312 | + | |
313 | + | for(i=0;i<3;i++) |
314 | + | for(j=0;j<3;j++) theBoxMat3[i][j] = boxMat[3*j+i]; |
315 | + | |
316 | + | simnfo->setBoxM( theBoxMat3 ); |
317 | + | simnfo->setTime( currTime ); |
318 | + | |
319 | ||
320 | #endif | |
321 | } | |
# | Line 281 | Line 324 | char* InitializeFromFile::parseDumpLine(char* readLine | |
324 | ||
325 | char *foo; // the pointer to the current string token | |
326 | ||
327 | < | double rx, ry, rz; // position place holders |
328 | < | double vx, vy, vz; // velocity placeholders |
327 | > | double pos[3]; // position place holders |
328 | > | double vel[3]; // velocity placeholders |
329 | double q[4]; // the quaternions | |
330 | double jx, jy, jz; // angular velocity placeholders; | |
331 | double qSqr, qLength; // needed to normalize the quaternion vector. | |
332 | ||
333 | < | Atom **atoms = entry_plug->atoms; |
333 | > | Atom **atoms = simnfo->atoms; |
334 | DirectionalAtom* dAtom; | |
335 | ||
336 | int j, n_atoms, atomIndex; | |
# | Line 306 | Line 349 | char* InitializeFromFile::parseDumpLine(char* readLine | |
349 | return strdup( painCave.errMsg ); | |
350 | } | |
351 | #else | |
352 | < | n_atoms = entry_plug->n_atoms; |
352 | > | n_atoms = simnfo->n_atoms; |
353 | atomIndex = globalIndex; | |
354 | #endif // is_mpi | |
355 | ||
# | Line 335 | Line 378 | char* InitializeFromFile::parseDumpLine(char* readLine | |
378 | c_in_name, n_atoms, atomIndex ); | |
379 | return strdup( painCave.errMsg ); | |
380 | } | |
381 | < | rx = atof( foo ); |
381 | > | pos[0] = atof( foo ); |
382 | ||
383 | foo = strtok(NULL, " ,;\t"); | |
384 | if(foo == NULL){ | |
# | Line 345 | Line 388 | char* InitializeFromFile::parseDumpLine(char* readLine | |
388 | c_in_name, n_atoms, atomIndex ); | |
389 | return strdup( painCave.errMsg ); | |
390 | } | |
391 | < | ry = atof( foo ); |
391 | > | pos[1] = atof( foo ); |
392 | ||
393 | foo = strtok(NULL, " ,;\t"); | |
394 | if(foo == NULL){ | |
# | Line 355 | Line 398 | char* InitializeFromFile::parseDumpLine(char* readLine | |
398 | c_in_name, n_atoms, atomIndex ); | |
399 | return strdup( painCave.errMsg ); | |
400 | } | |
401 | < | rz = atof( foo ); |
401 | > | pos[2] = atof( foo ); |
402 | ||
403 | ||
404 | // get the velocities | |
# | Line 368 | Line 411 | char* InitializeFromFile::parseDumpLine(char* readLine | |
411 | c_in_name, n_atoms, atomIndex ); | |
412 | return strdup( painCave.errMsg ); | |
413 | } | |
414 | < | vx = atof( foo ); |
414 | > | vel[0] = atof( foo ); |
415 | ||
416 | foo = strtok(NULL, " ,;\t"); | |
417 | if(foo == NULL){ | |
# | Line 378 | Line 421 | char* InitializeFromFile::parseDumpLine(char* readLine | |
421 | c_in_name, n_atoms, atomIndex ); | |
422 | return strdup( painCave.errMsg ); | |
423 | } | |
424 | < | vy = atof( foo ); |
424 | > | vel[1] = atof( foo ); |
425 | ||
426 | foo = strtok(NULL, " ,;\t"); | |
427 | if(foo == NULL){ | |
# | Line 388 | Line 431 | char* InitializeFromFile::parseDumpLine(char* readLine | |
431 | c_in_name, n_atoms, atomIndex ); | |
432 | return strdup( painCave.errMsg ); | |
433 | } | |
434 | < | vz = atof( foo ); |
434 | > | vel[2] = atof( foo ); |
435 | ||
436 | ||
437 | // get the quaternions | |
# | Line 490 | Line 533 | char* InitializeFromFile::parseDumpLine(char* readLine | |
533 | ||
534 | // add the positions and velocities to the atom | |
535 | ||
536 | < | atoms[atomIndex]->setX( rx ); |
537 | < | atoms[atomIndex]->setY( ry ); |
495 | < | atoms[atomIndex]->setZ( rz ); |
496 | < | |
497 | < | atoms[atomIndex]->set_vx( vx ); |
498 | < | atoms[atomIndex]->set_vy( vy ); |
499 | < | atoms[atomIndex]->set_vz( vz ); |
536 | > | atoms[atomIndex]->setPos( pos ); |
537 | > | atoms[atomIndex]->setVel( vel ); |
538 | ||
539 | return NULL; | |
540 | } | |
541 | ||
542 | ||
543 | + | char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9], |
544 | + | double &time ){ |
545 | + | |
546 | + | char *foo; // the pointer to the current string token |
547 | + | int j; |
548 | + | |
549 | + | // set the string tokenizer |
550 | + | |
551 | + | foo = strtok(readLine, " ,;\t"); |
552 | + | // set the timeToken. |
553 | + | |
554 | + | if(foo == NULL){ |
555 | + | sprintf( painCave.errMsg, |
556 | + | "error in reading Time from %s\n", |
557 | + | c_in_name ); |
558 | + | return strdup( painCave.errMsg ); |
559 | + | } |
560 | + | time = atof( foo ); |
561 | + | |
562 | + | // get the Hx vector |
563 | + | |
564 | + | foo = strtok(NULL, " ,;\t"); |
565 | + | if(foo == NULL){ |
566 | + | sprintf( painCave.errMsg, |
567 | + | "error in reading Hx[0] from %s\n", |
568 | + | c_in_name ); |
569 | + | return strdup( painCave.errMsg ); |
570 | + | } |
571 | + | boxMat[0] = atof( foo ); |
572 | + | |
573 | + | foo = strtok(NULL, " ,;\t"); |
574 | + | if(foo == NULL){ |
575 | + | sprintf( painCave.errMsg, |
576 | + | "error in reading Hx[1] from %s\n", |
577 | + | c_in_name ); |
578 | + | return strdup( painCave.errMsg ); |
579 | + | } |
580 | + | boxMat[1] = atof( foo ); |
581 | + | |
582 | + | foo = strtok(NULL, " ,;\t"); |
583 | + | if(foo == NULL){ |
584 | + | sprintf( painCave.errMsg, |
585 | + | "error in reading Hx[2] from %s\n", |
586 | + | c_in_name ); |
587 | + | return strdup( painCave.errMsg ); |
588 | + | } |
589 | + | boxMat[2] = atof( foo ); |
590 | + | |
591 | + | // get the Hy vector |
592 | + | |
593 | + | foo = strtok(NULL, " ,;\t"); |
594 | + | if(foo == NULL){ |
595 | + | sprintf( painCave.errMsg, |
596 | + | "error in reading Hy[0] from %s\n", |
597 | + | c_in_name ); |
598 | + | return strdup( painCave.errMsg ); |
599 | + | } |
600 | + | boxMat[3] = atof( foo ); |
601 | + | |
602 | + | foo = strtok(NULL, " ,;\t"); |
603 | + | if(foo == NULL){ |
604 | + | sprintf( painCave.errMsg, |
605 | + | "error in reading Hy[1] from %s\n", |
606 | + | c_in_name ); |
607 | + | return strdup( painCave.errMsg ); |
608 | + | } |
609 | + | boxMat[4] = atof( foo ); |
610 | + | |
611 | + | foo = strtok(NULL, " ,;\t"); |
612 | + | if(foo == NULL){ |
613 | + | sprintf( painCave.errMsg, |
614 | + | "error in reading Hy[2] from %s\n", |
615 | + | c_in_name ); |
616 | + | return strdup( painCave.errMsg ); |
617 | + | } |
618 | + | boxMat[5] = atof( foo ); |
619 | + | |
620 | + | // get the Hz vector |
621 | + | |
622 | + | foo = strtok(NULL, " ,;\t"); |
623 | + | if(foo == NULL){ |
624 | + | sprintf( painCave.errMsg, |
625 | + | "error in reading Hz[0] from %s\n", |
626 | + | c_in_name ); |
627 | + | return strdup( painCave.errMsg ); |
628 | + | } |
629 | + | boxMat[6] = atof( foo ); |
630 | + | |
631 | + | foo = strtok(NULL, " ,;\t"); |
632 | + | if(foo == NULL){ |
633 | + | sprintf( painCave.errMsg, |
634 | + | "error in reading Hz[1] from %s\n", |
635 | + | c_in_name ); |
636 | + | return strdup( painCave.errMsg ); |
637 | + | } |
638 | + | boxMat[7] = atof( foo ); |
639 | + | |
640 | + | foo = strtok(NULL, " ,;\t"); |
641 | + | if(foo == NULL){ |
642 | + | sprintf( painCave.errMsg, |
643 | + | "error in reading Hz[2] from %s\n", |
644 | + | c_in_name ); |
645 | + | return strdup( painCave.errMsg ); |
646 | + | } |
647 | + | boxMat[8] = atof( foo ); |
648 | + | |
649 | + | return NULL; |
650 | + | } |
651 | + | |
652 | + | |
653 | #ifdef IS_MPI | |
654 | ||
655 | // a couple of functions to let us escape the read loop | |
656 | ||
657 | < | void nodeZeroError( void ){ |
657 | > | void initFile::nodeZeroError( void ){ |
658 | int j, myStatus; | |
659 | ||
660 | myStatus = 0; | |
661 | for (j = 0; j < mpiSim->getNumberProcessors(); j++) { | |
662 | < | MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j, |
663 | < | TAKE_THIS_TAG_INT); |
662 | > | MPI_Send( &myStatus, 1, MPI_INT, j, |
663 | > | TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
664 | } | |
665 | ||
666 | ||
# | Line 521 | Line 669 | void nodeZeroError( void ){ | |
669 | ||
670 | } | |
671 | ||
672 | < | void anonymousNodeDie( void ){ |
672 | > | void initFile::anonymousNodeDie( void ){ |
673 | ||
674 | MPI_Finalize(); | |
675 | exit (0); |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |