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 |
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 |
|
|
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 |
+ |
|
88 |
|
|
89 |
< |
entry_plug = the_entry_plug; |
89 |
> |
simnfo = the_simnfo; |
90 |
|
|
91 |
|
|
92 |
|
#ifndef IS_MPI |
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){ |
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 |
+ |
simnfo->setBoxM( boxMat ); |
134 |
+ |
|
135 |
+ |
|
136 |
|
for( i=0; i < n_atoms; i++){ |
137 |
|
|
138 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
152 |
|
strcpy( painCave.errMsg, parseErr ); |
153 |
|
painCave.isFatal = 1; |
154 |
|
simError(); |
155 |
< |
} |
155 |
> |
} |
156 |
|
} |
157 |
|
|
158 |
|
|
165 |
|
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
166 |
|
int haveError; |
167 |
|
|
168 |
< |
MPI::Status istatus; |
168 |
> |
MPI_Status istatus; |
169 |
|
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
170 |
|
|
171 |
|
|
182 |
|
|
183 |
|
n_atoms = atoi( read_buffer ); |
184 |
|
|
185 |
< |
Atom **atoms = entry_plug->atoms; |
185 |
> |
Atom **atoms = simnfo->atoms; |
186 |
|
DirectionalAtom* dAtom; |
187 |
|
|
188 |
|
// Check to see that the number of atoms in the intial configuration file is the |
192 |
|
sprintf( painCave.errMsg, |
193 |
|
"Initialize from File error. %s n_atoms, %d, " |
194 |
|
"does not match the BASS file's n_atoms, %d.\n", |
195 |
< |
c_in_name, n_atoms, entry_plug->n_atoms ); |
195 |
> |
c_in_name, n_atoms, simnfo->n_atoms ); |
196 |
|
haveError= 1; |
197 |
|
simError(); |
198 |
|
} |
199 |
|
|
200 |
< |
//read and toss the comment line |
200 |
> |
//read the boxMat from the comment line |
201 |
|
|
202 |
|
eof_test = fgets(read_buffer, sizeof(read_buffer), c_in_file); |
203 |
|
if(eof_test == NULL){ |
204 |
|
sprintf( painCave.errMsg, |
205 |
|
"error in reading commment in %s\n", c_in_name); |
206 |
< |
haveError= 1; |
206 |
> |
haveError = 1; |
207 |
|
simError(); |
208 |
|
} |
209 |
+ |
|
210 |
+ |
parseErr = parseBoxLine( read_buffer, boxMat ); |
211 |
+ |
if( parseErr != NULL ){ |
212 |
+ |
strcpy( painCave.errMsg, parseErr ); |
213 |
+ |
haveError = 1; |
214 |
+ |
simError(); |
215 |
+ |
} |
216 |
+ |
|
217 |
+ |
MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD ); |
218 |
|
|
219 |
|
if(haveError) nodeZeroError(); |
220 |
|
|
248 |
|
else { |
249 |
|
|
250 |
|
myStatus = 1; |
251 |
< |
MPI::COMM_WORLD.Send(&myStatus, 1, MPI_INT, which_node, |
252 |
< |
TAKE_THIS_TAG_INT); |
253 |
< |
MPI::COMM_WORLD.Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
254 |
< |
TAKE_THIS_TAG_CHAR); |
255 |
< |
MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT); |
256 |
< |
MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, istatus); |
251 |
> |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
252 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
253 |
> |
MPI_Send(read_buffer, BUFFERSIZE, MPI_CHAR, which_node, |
254 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
255 |
> |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
256 |
> |
MPI_COMM_WORLD); |
257 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
258 |
> |
MPI_COMM_WORLD, &istatus); |
259 |
|
|
260 |
|
if(!myStatus) nodeZeroError(); |
261 |
|
} |
262 |
|
} |
263 |
|
myStatus = -1; |
264 |
|
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
265 |
< |
MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j, |
266 |
< |
TAKE_THIS_TAG_INT); |
265 |
> |
MPI_Send( &myStatus, 1, MPI_INT, j, |
266 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
267 |
|
} |
268 |
|
|
269 |
|
} else { |
270 |
|
|
271 |
+ |
MPI_Bcast(boxMat, 9, MPI_DOUBLE, 0, MPI_COMM_WORLD); |
272 |
+ |
|
273 |
|
done = 0; |
274 |
|
while (!done) { |
275 |
|
|
276 |
< |
MPI::COMM_WORLD.Recv(&myStatus, 1, MPI_INT, 0, |
277 |
< |
TAKE_THIS_TAG_INT, istatus); |
276 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
277 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
278 |
|
|
279 |
|
if(!myStatus) anonymousNodeDie(); |
280 |
|
|
281 |
|
if(myStatus < 0) break; |
282 |
|
|
283 |
< |
MPI::COMM_WORLD.Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
284 |
< |
TAKE_THIS_TAG_CHAR, istatus); |
285 |
< |
MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
286 |
< |
TAKE_THIS_TAG_INT, istatus); |
283 |
> |
MPI_Recv(read_buffer, BUFFERSIZE, MPI_CHAR, 0, |
284 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
285 |
> |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
286 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
287 |
|
|
288 |
|
myStatus = 1; |
289 |
|
parseErr = parseDumpLine( read_buffer, which_atom ); |
293 |
|
simError(); |
294 |
|
} |
295 |
|
|
296 |
< |
MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, 0, |
297 |
< |
TAKE_THIS_TAG_INT); |
296 |
> |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
297 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
298 |
|
|
299 |
|
} |
300 |
|
} |
301 |
|
|
302 |
|
// last thing last, enable fatalities. |
303 |
|
painCave.isEventLoop = 0; |
304 |
+ |
simnfo->setBoxM( boxMat ); |
305 |
+ |
|
306 |
|
|
307 |
|
#endif |
308 |
|
} |
317 |
|
double jx, jy, jz; // angular velocity placeholders; |
318 |
|
double qSqr, qLength; // needed to normalize the quaternion vector. |
319 |
|
|
320 |
< |
Atom **atoms = entry_plug->atoms; |
320 |
> |
Atom **atoms = simnfo->atoms; |
321 |
|
DirectionalAtom* dAtom; |
322 |
|
|
323 |
|
int j, n_atoms, atomIndex; |
336 |
|
return strdup( painCave.errMsg ); |
337 |
|
} |
338 |
|
#else |
339 |
< |
n_atoms = entry_plug->n_atoms; |
339 |
> |
n_atoms = simnfo->n_atoms; |
340 |
|
atomIndex = globalIndex; |
341 |
|
#endif // is_mpi |
342 |
|
|
527 |
|
atoms[atomIndex]->set_vx( vx ); |
528 |
|
atoms[atomIndex]->set_vy( vy ); |
529 |
|
atoms[atomIndex]->set_vz( vz ); |
530 |
+ |
|
531 |
+ |
return NULL; |
532 |
+ |
} |
533 |
+ |
|
534 |
+ |
|
535 |
+ |
char* InitializeFromFile::parseBoxLine(char* readLine, double boxMat[9]){ |
536 |
+ |
|
537 |
+ |
char *foo; // the pointer to the current string token |
538 |
+ |
int j; |
539 |
+ |
|
540 |
+ |
// set the string tokenizer |
541 |
+ |
|
542 |
+ |
foo = strtok(readLine, " ,;\t"); |
543 |
+ |
// ignore the first token which is the time stamp. |
544 |
|
|
545 |
+ |
|
546 |
+ |
// get the Hx vector |
547 |
+ |
|
548 |
+ |
foo = strtok(NULL, " ,;\t"); |
549 |
+ |
if(foo == NULL){ |
550 |
+ |
sprintf( painCave.errMsg, |
551 |
+ |
"error in reading Hx[0] from %s\n", |
552 |
+ |
c_in_name ); |
553 |
+ |
return strdup( painCave.errMsg ); |
554 |
+ |
} |
555 |
+ |
boxMat[0] = atof( foo ); |
556 |
+ |
|
557 |
+ |
foo = strtok(NULL, " ,;\t"); |
558 |
+ |
if(foo == NULL){ |
559 |
+ |
sprintf( painCave.errMsg, |
560 |
+ |
"error in reading Hx[1] from %s\n", |
561 |
+ |
c_in_name ); |
562 |
+ |
return strdup( painCave.errMsg ); |
563 |
+ |
} |
564 |
+ |
boxMat[1] = atof( foo ); |
565 |
+ |
|
566 |
+ |
foo = strtok(NULL, " ,;\t"); |
567 |
+ |
if(foo == NULL){ |
568 |
+ |
sprintf( painCave.errMsg, |
569 |
+ |
"error in reading Hx[2] from %s\n", |
570 |
+ |
c_in_name ); |
571 |
+ |
return strdup( painCave.errMsg ); |
572 |
+ |
} |
573 |
+ |
boxMat[2] = atof( foo ); |
574 |
+ |
|
575 |
+ |
// get the Hy vector |
576 |
+ |
|
577 |
+ |
foo = strtok(NULL, " ,;\t"); |
578 |
+ |
if(foo == NULL){ |
579 |
+ |
sprintf( painCave.errMsg, |
580 |
+ |
"error in reading Hy[0] from %s\n", |
581 |
+ |
c_in_name ); |
582 |
+ |
return strdup( painCave.errMsg ); |
583 |
+ |
} |
584 |
+ |
boxMat[3] = atof( foo ); |
585 |
+ |
|
586 |
+ |
foo = strtok(NULL, " ,;\t"); |
587 |
+ |
if(foo == NULL){ |
588 |
+ |
sprintf( painCave.errMsg, |
589 |
+ |
"error in reading Hy[1] from %s\n", |
590 |
+ |
c_in_name ); |
591 |
+ |
return strdup( painCave.errMsg ); |
592 |
+ |
} |
593 |
+ |
boxMat[4] = atof( foo ); |
594 |
+ |
|
595 |
+ |
foo = strtok(NULL, " ,;\t"); |
596 |
+ |
if(foo == NULL){ |
597 |
+ |
sprintf( painCave.errMsg, |
598 |
+ |
"error in reading Hy[2] from %s\n", |
599 |
+ |
c_in_name ); |
600 |
+ |
return strdup( painCave.errMsg ); |
601 |
+ |
} |
602 |
+ |
boxMat[5] = atof( foo ); |
603 |
+ |
|
604 |
+ |
// get the Hz vector |
605 |
+ |
|
606 |
+ |
foo = strtok(NULL, " ,;\t"); |
607 |
+ |
if(foo == NULL){ |
608 |
+ |
sprintf( painCave.errMsg, |
609 |
+ |
"error in reading Hz[0] from %s\n", |
610 |
+ |
c_in_name ); |
611 |
+ |
return strdup( painCave.errMsg ); |
612 |
+ |
} |
613 |
+ |
boxMat[6] = atof( foo ); |
614 |
+ |
|
615 |
+ |
foo = strtok(NULL, " ,;\t"); |
616 |
+ |
if(foo == NULL){ |
617 |
+ |
sprintf( painCave.errMsg, |
618 |
+ |
"error in reading Hz[1] from %s\n", |
619 |
+ |
c_in_name ); |
620 |
+ |
return strdup( painCave.errMsg ); |
621 |
+ |
} |
622 |
+ |
boxMat[7] = atof( foo ); |
623 |
+ |
|
624 |
+ |
foo = strtok(NULL, " ,;\t"); |
625 |
+ |
if(foo == NULL){ |
626 |
+ |
sprintf( painCave.errMsg, |
627 |
+ |
"error in reading Hz[2] from %s\n", |
628 |
+ |
c_in_name ); |
629 |
+ |
return strdup( painCave.errMsg ); |
630 |
+ |
} |
631 |
+ |
boxMat[8] = atof( foo ); |
632 |
+ |
|
633 |
|
return NULL; |
634 |
|
} |
635 |
|
|
643 |
|
|
644 |
|
myStatus = 0; |
645 |
|
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
646 |
< |
MPI::COMM_WORLD.Send( &myStatus, 1, MPI_INT, j, |
647 |
< |
TAKE_THIS_TAG_INT); |
646 |
> |
MPI_Send( &myStatus, 1, MPI_INT, j, |
647 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
648 |
|
} |
649 |
|
|
650 |
|
|