6 |
|
#include <mpi.h> |
7 |
|
#include <mpi++.h> |
8 |
|
#include "mpiSimulation.hpp" |
9 |
< |
#define TAKE_THIS_TAG 0 |
9 |
> |
#define TAKE_THIS_TAG_CHAR 1 |
10 |
> |
#define TAKE_THIS_TAG_INT 2 |
11 |
|
#endif //is_mpi |
12 |
|
|
13 |
|
#include "ReadWrite.hpp" |
66 |
|
char tempBuffer[BUFFERSIZE]; |
67 |
|
char writeLine[BUFFERSIZE]; |
68 |
|
|
69 |
< |
int i, j, which_node, done, game_over, which_atom; |
69 |
> |
int i, j, which_node, done, game_over, which_atom, local_index; |
70 |
|
double q[4]; |
71 |
|
DirectionalAtom* dAtom; |
72 |
|
int nAtoms = entry_plug->n_atoms; |
133 |
|
<< entry_plug->box_x << "\t" |
134 |
|
<< entry_plug->box_y << "\t" |
135 |
|
<< entry_plug->box_z << "\n"; |
136 |
< |
|
136 |
> |
outFile.flush(); |
137 |
|
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
138 |
< |
// Get the Node number which has this molecule: |
138 |
> |
// Get the Node number which has this atom; |
139 |
|
|
140 |
|
which_node = AtomToProcMap[i]; |
141 |
|
|
142 |
< |
if (which_node == mpiSim->getMyNode()) { |
142 |
< |
|
143 |
< |
sprintf( tempBuffer, |
144 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
145 |
< |
atoms[i]->getType(), |
146 |
< |
atoms[i]->getX(), |
147 |
< |
atoms[i]->getY(), |
148 |
< |
atoms[i]->getZ(), |
149 |
< |
atoms[i]->get_vx(), |
150 |
< |
atoms[i]->get_vy(), |
151 |
< |
atoms[i]->get_vz()); |
152 |
< |
strcpy( writeLine, tempBuffer ); |
142 |
> |
if (which_node == 0 ) { |
143 |
|
|
144 |
< |
if( atoms[i]->isDirectional() ){ |
145 |
< |
|
146 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
147 |
< |
dAtom->getQ( q ); |
158 |
< |
|
159 |
< |
sprintf( tempBuffer, |
160 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
161 |
< |
q[0], |
162 |
< |
q[1], |
163 |
< |
q[2], |
164 |
< |
q[3], |
165 |
< |
dAtom->getJx(), |
166 |
< |
dAtom->getJy(), |
167 |
< |
dAtom->getJz()); |
168 |
< |
strcat( writeLine, tempBuffer ); |
144 |
> |
which_atom = i; |
145 |
> |
local_index=-1; |
146 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
147 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
148 |
|
} |
149 |
< |
else |
150 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
149 |
> |
if (local_index != -1) { |
150 |
> |
//format the line |
151 |
> |
sprintf( tempBuffer, |
152 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
153 |
> |
atoms[local_index]->getType(), |
154 |
> |
atoms[local_index]->getX(), |
155 |
> |
atoms[local_index]->getY(), |
156 |
> |
atoms[local_index]->getZ(), |
157 |
> |
atoms[local_index]->get_vx(), |
158 |
> |
atoms[local_index]->get_vy(), |
159 |
> |
atoms[local_index]->get_vz()); // check here. |
160 |
> |
strcpy( writeLine, tempBuffer ); |
161 |
> |
|
162 |
> |
if( atoms[local_index]->isDirectional() ){ |
163 |
> |
|
164 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
165 |
> |
dAtom->getQ( q ); |
166 |
> |
|
167 |
> |
sprintf( tempBuffer, |
168 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
169 |
> |
q[0], |
170 |
> |
q[1], |
171 |
> |
q[2], |
172 |
> |
q[3], |
173 |
> |
dAtom->getJx(), |
174 |
> |
dAtom->getJy(), |
175 |
> |
dAtom->getJz()); |
176 |
> |
strcat( writeLine, tempBuffer ); |
177 |
> |
|
178 |
> |
} |
179 |
> |
else |
180 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
181 |
> |
} |
182 |
> |
else { |
183 |
> |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
184 |
> |
} |
185 |
> |
} |
186 |
> |
else { |
187 |
|
|
188 |
< |
} else { |
189 |
< |
|
190 |
< |
MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG); |
188 |
> |
//std::cerr << "node 0: sending node " << which_node << " request for atom " << i << "\n"; |
189 |
> |
MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT); |
190 |
> |
//std::cerr << "node 0: sent!\n"; |
191 |
|
MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
192 |
< |
TAKE_THIS_TAG, istatus); |
192 |
> |
TAKE_THIS_TAG_CHAR, istatus); |
193 |
> |
//std::cerr << "node 0: got this line: " << writeLine; |
194 |
|
} |
195 |
|
|
196 |
|
outFile << writeLine; |
197 |
+ |
outFile.flush(); |
198 |
|
} |
199 |
|
|
200 |
|
// kill everyone off: |
201 |
|
game_over = -1; |
202 |
|
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
203 |
< |
MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG); |
203 |
> |
MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT); |
204 |
|
} |
205 |
|
|
206 |
|
} else { |
207 |
|
|
208 |
|
done = 0; |
209 |
|
while (!done) { |
210 |
+ |
//std::cerr << "node: " << mpiSim->getMyNode() << " Waiting for receive \n"; |
211 |
|
MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
212 |
< |
TAKE_THIS_TAG, istatus); |
213 |
< |
|
212 |
> |
TAKE_THIS_TAG_INT, istatus); |
213 |
> |
//std::cerr << "node: " << mpiSim->getMyNode() << " got request for atom " << which_atom << "\n"; |
214 |
|
if (which_atom == -1) { |
215 |
|
done=1; |
216 |
|
continue; |
217 |
|
} else { |
218 |
< |
|
219 |
< |
//format the line |
220 |
< |
sprintf( tempBuffer, |
221 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
222 |
< |
atoms[which_atom]->getType(), |
223 |
< |
atoms[which_atom]->getX(), |
224 |
< |
atoms[which_atom]->getY(), |
225 |
< |
atoms[which_atom]->getZ(), |
226 |
< |
atoms[which_atom]->get_vx(), |
227 |
< |
atoms[which_atom]->get_vy(), |
228 |
< |
atoms[which_atom]->get_vz()); // check here. |
229 |
< |
strcpy( writeLine, tempBuffer ); |
218 |
> |
local_index=-1; |
219 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
220 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
221 |
> |
} |
222 |
> |
if (local_index != -1) { |
223 |
> |
//format the line |
224 |
> |
sprintf( tempBuffer, |
225 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
226 |
> |
atoms[local_index]->getType(), |
227 |
> |
atoms[local_index]->getX(), |
228 |
> |
atoms[local_index]->getY(), |
229 |
> |
atoms[local_index]->getZ(), |
230 |
> |
atoms[local_index]->get_vx(), |
231 |
> |
atoms[local_index]->get_vy(), |
232 |
> |
atoms[local_index]->get_vz()); // check here. |
233 |
> |
strcpy( writeLine, tempBuffer ); |
234 |
|
|
235 |
< |
if( atoms[which_atom]->isDirectional() ){ |
236 |
< |
|
237 |
< |
dAtom = (DirectionalAtom *)atoms[which_atom]; |
238 |
< |
dAtom->getQ( q ); |
239 |
< |
|
240 |
< |
sprintf( tempBuffer, |
241 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
242 |
< |
q[0], |
243 |
< |
q[1], |
244 |
< |
q[2], |
245 |
< |
q[3], |
246 |
< |
dAtom->getJx(), |
247 |
< |
dAtom->getJy(), |
248 |
< |
dAtom->getJz()); |
249 |
< |
strcat( writeLine, tempBuffer ); |
250 |
< |
} |
251 |
< |
else |
252 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
253 |
< |
|
254 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
255 |
< |
TAKE_THIS_TAG); |
235 |
> |
if( atoms[local_index]->isDirectional() ){ |
236 |
> |
|
237 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
238 |
> |
dAtom->getQ( q ); |
239 |
> |
|
240 |
> |
sprintf( tempBuffer, |
241 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
242 |
> |
q[0], |
243 |
> |
q[1], |
244 |
> |
q[2], |
245 |
> |
q[3], |
246 |
> |
dAtom->getJx(), |
247 |
> |
dAtom->getJy(), |
248 |
> |
dAtom->getJz()); |
249 |
> |
strcat( writeLine, tempBuffer ); |
250 |
> |
} |
251 |
> |
else |
252 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
253 |
> |
// std::cerr << "node: " << mpiSim->getMyNode() << " sending this line" << writeLine; |
254 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
255 |
> |
TAKE_THIS_TAG_CHAR); |
256 |
> |
} else { |
257 |
> |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
258 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
259 |
> |
TAKE_THIS_TAG_CHAR); |
260 |
> |
} |
261 |
|
} |
262 |
|
} |
263 |
|
} |
281 |
|
DirectionalAtom* dAtom; |
282 |
|
int nAtoms = entry_plug->n_atoms; |
283 |
|
Atom** atoms = entry_plug->atoms; |
284 |
< |
int i, j, which_node, done, game_over, which_atom; |
284 |
> |
int i, j, which_node, done, game_over, which_atom, local_index; |
285 |
|
|
286 |
|
|
287 |
|
#ifdef IS_MPI |
408 |
|
|
409 |
|
} else { |
410 |
|
|
411 |
< |
MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG); |
411 |
> |
MPI::COMM_WORLD.Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT); |
412 |
|
MPI::COMM_WORLD.Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
413 |
< |
TAKE_THIS_TAG, istatus); |
413 |
> |
TAKE_THIS_TAG_CHAR, istatus); |
414 |
|
} |
415 |
|
|
416 |
|
finalOut << writeLine; |
419 |
|
// kill everyone off: |
420 |
|
game_over = -1; |
421 |
|
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
422 |
< |
MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG); |
422 |
> |
MPI::COMM_WORLD.Send(&game_over, 1, MPI_INT, j, TAKE_THIS_TAG_INT); |
423 |
|
} |
424 |
|
|
425 |
|
} else { |
427 |
|
done = 0; |
428 |
|
while (!done) { |
429 |
|
MPI::COMM_WORLD.Recv(&which_atom, 1, MPI_INT, 0, |
430 |
< |
TAKE_THIS_TAG, istatus); |
430 |
> |
TAKE_THIS_TAG_INT, istatus); |
431 |
|
|
432 |
|
if (which_atom == -1) { |
433 |
|
done=1; |
434 |
|
continue; |
435 |
|
} else { |
436 |
|
|
437 |
< |
//format the line |
438 |
< |
sprintf( tempBuffer, |
439 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
440 |
< |
atoms[which_atom]->getType(), |
441 |
< |
atoms[which_atom]->getX(), |
442 |
< |
atoms[which_atom]->getY(), |
443 |
< |
atoms[which_atom]->getZ(), |
444 |
< |
atoms[which_atom]->get_vx(), |
445 |
< |
atoms[which_atom]->get_vy(), |
446 |
< |
atoms[which_atom]->get_vz()); // check here. |
447 |
< |
strcpy( writeLine, tempBuffer ); |
437 |
> |
local_index=-1; |
438 |
> |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
439 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
440 |
> |
} |
441 |
> |
if (local_index != -1) { |
442 |
> |
|
443 |
> |
//format the line |
444 |
> |
sprintf( tempBuffer, |
445 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
446 |
> |
atoms[local_index]->getType(), |
447 |
> |
atoms[local_index]->getX(), |
448 |
> |
atoms[local_index]->getY(), |
449 |
> |
atoms[local_index]->getZ(), |
450 |
> |
atoms[local_index]->get_vx(), |
451 |
> |
atoms[local_index]->get_vy(), |
452 |
> |
atoms[local_index]->get_vz()); // check here. |
453 |
> |
strcpy( writeLine, tempBuffer ); |
454 |
|
|
455 |
< |
if( atoms[which_atom]->isDirectional() ){ |
455 |
> |
if( atoms[local_index]->isDirectional() ){ |
456 |
> |
|
457 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
458 |
> |
dAtom->getQ( q ); |
459 |
|
|
460 |
< |
dAtom = (DirectionalAtom *)atoms[which_atom]; |
461 |
< |
dAtom->getQ( q ); |
462 |
< |
|
463 |
< |
sprintf( tempBuffer, |
464 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
465 |
< |
q[0], |
466 |
< |
q[1], |
467 |
< |
q[2], |
468 |
< |
q[3], |
469 |
< |
dAtom->getJx(), |
470 |
< |
dAtom->getJy(), |
471 |
< |
dAtom->getJz()); |
472 |
< |
strcat( writeLine, tempBuffer ); |
473 |
< |
} |
474 |
< |
else |
475 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
476 |
< |
|
477 |
< |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
478 |
< |
TAKE_THIS_TAG); |
460 |
> |
sprintf( tempBuffer, |
461 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
462 |
> |
q[0], |
463 |
> |
q[1], |
464 |
> |
q[2], |
465 |
> |
q[3], |
466 |
> |
dAtom->getJx(), |
467 |
> |
dAtom->getJy(), |
468 |
> |
dAtom->getJz()); |
469 |
> |
strcat( writeLine, tempBuffer ); |
470 |
> |
} |
471 |
> |
else |
472 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
473 |
> |
|
474 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
475 |
> |
TAKE_THIS_TAG_CHAR); |
476 |
> |
} else { |
477 |
> |
strcpy( writeLine, "ATOM NOT FOUND ON THIS PROCESSOR"); |
478 |
> |
MPI::COMM_WORLD.Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
479 |
> |
TAKE_THIS_TAG_CHAR); |
480 |
> |
} |
481 |
|
} |
482 |
|
} |
483 |
< |
} |
483 |
> |
} |
484 |
|
finalOut.flush(); |
485 |
|
sprintf( checkPointMsg, |
486 |
|
"Sucessfully took a dump.\n"); |