5 |
|
#ifdef IS_MPI |
6 |
|
#include <mpi.h> |
7 |
|
#include "mpiSimulation.hpp" |
8 |
< |
#define TAKE_THIS_TAG 0 |
8 |
> |
#define TAKE_THIS_TAG_CHAR 1 |
9 |
> |
#define TAKE_THIS_TAG_INT 2 |
10 |
> |
|
11 |
> |
namespace dWrite{ |
12 |
> |
void nodeZeroError( void ); |
13 |
> |
void anonymousNodeDie( void ); |
14 |
> |
} |
15 |
> |
|
16 |
> |
using namespace dWrite; |
17 |
|
#endif //is_mpi |
18 |
|
|
19 |
|
#include "ReadWrite.hpp" |
20 |
|
#include "simError.h" |
21 |
|
|
14 |
– |
|
15 |
– |
|
16 |
– |
|
17 |
– |
|
22 |
|
DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ |
23 |
|
|
24 |
|
entry_plug = the_entry_plug; |
25 |
|
|
26 |
+ |
std::cerr << "Look at me I'm a freebird!\n"; |
27 |
+ |
|
28 |
|
#ifdef IS_MPI |
29 |
|
if(worldRank == 0 ){ |
30 |
|
#endif // is_mpi |
43 |
|
painCave.isFatal = 1; |
44 |
|
simError(); |
45 |
|
} |
46 |
< |
|
46 |
> |
|
47 |
> |
std::cerr << "me TOO!\n"; |
48 |
> |
|
49 |
|
//outFile.setf( ios::scientific ); |
50 |
|
|
51 |
|
#ifdef IS_MPI |
76 |
|
char tempBuffer[BUFFERSIZE]; |
77 |
|
char writeLine[BUFFERSIZE]; |
78 |
|
|
79 |
< |
int i; |
79 |
> |
int i, j, which_node, done, which_atom, local_index; |
80 |
|
double q[4]; |
81 |
|
DirectionalAtom* dAtom; |
82 |
|
int nAtoms = entry_plug->n_atoms; |
131 |
|
|
132 |
|
#else // is_mpi |
133 |
|
|
134 |
< |
int masterIndex; |
135 |
< |
int nodeAtomsStart; |
128 |
< |
int nodeAtomsEnd; |
129 |
< |
int mpiErr; |
130 |
< |
int sendError; |
131 |
< |
int procIndex; |
132 |
< |
|
133 |
< |
MPI_Status istatus[MPI_STATUS_SIZE]; |
134 |
> |
// first thing first, suspend fatalities. |
135 |
> |
painCave.isEventLoop = 1; |
136 |
|
|
137 |
< |
|
138 |
< |
// write out header and node 0's coordinates |
137 |
> |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
138 |
> |
int haveError; |
139 |
|
|
140 |
+ |
MPI_Status istatus; |
141 |
+ |
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
142 |
+ |
|
143 |
+ |
// write out header and node 0's coordinates |
144 |
+ |
|
145 |
|
if( worldRank == 0 ){ |
146 |
|
outFile << mpiSim->getTotAtoms() << "\n"; |
147 |
< |
|
147 |
> |
|
148 |
|
outFile << currentTime << "\t" |
149 |
|
<< entry_plug->box_x << "\t" |
150 |
|
<< entry_plug->box_y << "\t" |
151 |
|
<< entry_plug->box_z << "\n"; |
152 |
< |
|
153 |
< |
masterIndex = 0; |
154 |
< |
for( i=0; i<nAtoms; i++ ){ |
152 |
> |
outFile.flush(); |
153 |
> |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
154 |
> |
// Get the Node number which has this atom; |
155 |
|
|
156 |
< |
sprintf( tempBuffer, |
157 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
158 |
< |
atoms[i]->getType(), |
152 |
< |
atoms[i]->getX(), |
153 |
< |
atoms[i]->getY(), |
154 |
< |
atoms[i]->getZ(), |
155 |
< |
atoms[i]->get_vx(), |
156 |
< |
atoms[i]->get_vy(), |
157 |
< |
atoms[i]->get_vz()); |
158 |
< |
strcpy( writeLine, tempBuffer ); |
156 |
> |
which_node = AtomToProcMap[i]; |
157 |
> |
|
158 |
> |
if (which_node == 0 ) { |
159 |
|
|
160 |
< |
if( atoms[i]->isDirectional() ){ |
160 |
> |
haveError = 0; |
161 |
> |
which_atom = i; |
162 |
> |
local_index=-1; |
163 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
164 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
165 |
> |
} |
166 |
> |
if (local_index != -1) { |
167 |
> |
//format the line |
168 |
> |
sprintf( tempBuffer, |
169 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
170 |
> |
atoms[local_index]->getType(), |
171 |
> |
atoms[local_index]->getX(), |
172 |
> |
atoms[local_index]->getY(), |
173 |
> |
atoms[local_index]->getZ(), |
174 |
> |
atoms[local_index]->get_vx(), |
175 |
> |
atoms[local_index]->get_vy(), |
176 |
> |
atoms[local_index]->get_vz()); // check here. |
177 |
> |
strcpy( writeLine, tempBuffer ); |
178 |
|
|
179 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
180 |
< |
dAtom->getQ( q ); |
181 |
< |
|
182 |
< |
sprintf( tempBuffer, |
183 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
184 |
< |
q[0], |
185 |
< |
q[1], |
186 |
< |
q[2], |
187 |
< |
q[3], |
188 |
< |
dAtom->getJx(), |
189 |
< |
dAtom->getJy(), |
190 |
< |
dAtom->getJz()); |
191 |
< |
strcat( writeLine, tempBuffer ); |
179 |
> |
if( atoms[local_index]->isDirectional() ){ |
180 |
> |
|
181 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
182 |
> |
dAtom->getQ( q ); |
183 |
> |
|
184 |
> |
sprintf( tempBuffer, |
185 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
186 |
> |
q[0], |
187 |
> |
q[1], |
188 |
> |
q[2], |
189 |
> |
q[3], |
190 |
> |
dAtom->getJx(), |
191 |
> |
dAtom->getJy(), |
192 |
> |
dAtom->getJz()); |
193 |
> |
strcat( writeLine, tempBuffer ); |
194 |
> |
|
195 |
> |
} |
196 |
> |
else |
197 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
198 |
> |
} |
199 |
> |
else { |
200 |
> |
sprintf(painCave.errMsg, |
201 |
> |
"Atom %d not found on processor %d\n", |
202 |
> |
i, worldRank ); |
203 |
> |
haveError= 1; |
204 |
> |
simError(); |
205 |
> |
} |
206 |
> |
|
207 |
> |
if(haveError) nodeZeroError(); |
208 |
> |
|
209 |
|
} |
210 |
< |
else |
211 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
210 |
> |
else { |
211 |
> |
myStatus = 1; |
212 |
> |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
213 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
214 |
> |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
215 |
> |
MPI_COMM_WORLD); |
216 |
> |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
217 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
218 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
219 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
220 |
|
|
221 |
+ |
if(!myStatus) nodeZeroError(); |
222 |
+ |
|
223 |
+ |
} |
224 |
+ |
|
225 |
|
outFile << writeLine; |
226 |
< |
masterIndex++; |
226 |
> |
outFile.flush(); |
227 |
|
} |
228 |
< |
outFile.flush(); |
229 |
< |
} |
228 |
> |
|
229 |
> |
// kill everyone off: |
230 |
> |
myStatus = -1; |
231 |
> |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
232 |
> |
MPI_Send(&myStatus, 1, MPI_INT, j, |
233 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
234 |
> |
} |
235 |
|
|
236 |
< |
sprintf( checkPointMsg, |
186 |
< |
"Sucessfully wrote node 0's dump configuration.\n"); |
187 |
< |
MPIcheckPoint(); |
236 |
> |
} else { |
237 |
|
|
238 |
< |
for (procIndex = 1; procIndex < mpiSim->getNumberProcessors(); |
239 |
< |
procIndex++){ |
238 |
> |
done = 0; |
239 |
> |
while (!done) { |
240 |
> |
|
241 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
242 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
243 |
|
|
244 |
< |
if( worldRank == 0 ){ |
244 |
> |
if(!myStatus) anonymousNodeDie(); |
245 |
|
|
246 |
< |
mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex, |
247 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD,istatus); |
246 |
> |
if(myStatus < 0) break; |
247 |
> |
|
248 |
> |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
249 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
250 |
|
|
251 |
< |
mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex, |
252 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD, istatus); |
253 |
< |
|
254 |
< |
// Make sure where node 0 is writing to, matches where the |
201 |
< |
// receiving node expects it to be. |
202 |
< |
|
203 |
< |
if (masterIndex != nodeAtomsStart){ |
204 |
< |
sendError = 1; |
205 |
< |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, |
206 |
< |
MPI_COMM_WORLD); |
207 |
< |
sprintf(painCave.errMsg, |
208 |
< |
"DumpWriter error: atoms start index (%d) for " |
209 |
< |
"node %d not equal to master index (%d)", |
210 |
< |
nodeAtomsStart,procIndex,masterIndex ); |
211 |
< |
painCave.isFatal = 1; |
212 |
< |
simError(); |
251 |
> |
myStatus = 1; |
252 |
> |
local_index=-1; |
253 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
254 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
255 |
|
} |
256 |
< |
|
257 |
< |
sendError = 0; |
216 |
< |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, |
217 |
< |
MPI_COMM_WORLD); |
218 |
< |
|
219 |
< |
// recieve the nodes writeLines |
220 |
< |
|
221 |
< |
for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){ |
222 |
< |
|
223 |
< |
mpiErr = MPI_Recv(writeLine,BUFFERSIZE,MPI_CHAR,procIndex, |
224 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD,istatus ); |
225 |
< |
|
226 |
< |
outFile << writeLine; |
227 |
< |
masterIndex++; |
228 |
< |
} |
229 |
< |
} |
230 |
< |
|
231 |
< |
else if( worldRank == procIndex ){ |
232 |
< |
|
233 |
< |
nodeAtomsStart = mpiSim->getMyAtomStart(); |
234 |
< |
nodeAtomsEnd = mpiSim->getMyAtomEnd(); |
235 |
< |
|
236 |
< |
mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG, |
237 |
< |
MPI_COMM_WORLD); |
238 |
< |
mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG, |
239 |
< |
MPI_COMM_WORLD); |
240 |
< |
|
241 |
< |
sendError = -1; |
242 |
< |
mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG, |
243 |
< |
MPI_COMM_WORLD, istatus); |
244 |
< |
|
245 |
< |
if (sendError) MPIcheckPoint(); |
246 |
< |
|
247 |
< |
// send current node's configuration line by line. |
248 |
< |
|
249 |
< |
for( i=0; i<nAtoms; i++ ){ |
250 |
< |
|
256 |
> |
if (local_index != -1) { |
257 |
> |
//format the line |
258 |
|
sprintf( tempBuffer, |
259 |
|
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
260 |
< |
atoms[i]->getType(), |
261 |
< |
atoms[i]->getX(), |
262 |
< |
atoms[i]->getY(), |
263 |
< |
atoms[i]->getZ(), |
264 |
< |
atoms[i]->get_vx(), |
265 |
< |
atoms[i]->get_vy(), |
266 |
< |
atoms[i]->get_vz()); // check here. |
260 |
> |
atoms[local_index]->getType(), |
261 |
> |
atoms[local_index]->getX(), |
262 |
> |
atoms[local_index]->getY(), |
263 |
> |
atoms[local_index]->getZ(), |
264 |
> |
atoms[local_index]->get_vx(), |
265 |
> |
atoms[local_index]->get_vy(), |
266 |
> |
atoms[local_index]->get_vz()); // check here. |
267 |
|
strcpy( writeLine, tempBuffer ); |
268 |
+ |
|
269 |
+ |
if( atoms[local_index]->isDirectional() ){ |
270 |
|
|
271 |
< |
if( atoms[i]->isDirectional() ){ |
263 |
< |
|
264 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
271 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
272 |
|
dAtom->getQ( q ); |
273 |
< |
|
273 |
> |
|
274 |
|
sprintf( tempBuffer, |
275 |
|
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
276 |
|
q[0], |
282 |
|
dAtom->getJz()); |
283 |
|
strcat( writeLine, tempBuffer ); |
284 |
|
} |
285 |
< |
else |
285 |
> |
else{ |
286 |
|
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
287 |
< |
|
288 |
< |
mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG, |
289 |
< |
MPI_COMM_WORLD); |
287 |
> |
} |
288 |
> |
} |
289 |
> |
else { |
290 |
> |
sprintf(painCave.errMsg, |
291 |
> |
"Atom %d not found on processor %d\n", |
292 |
> |
which_atom, worldRank ); |
293 |
> |
myStatus = 0; |
294 |
> |
simError(); |
295 |
> |
|
296 |
> |
strcpy( writeLine, "Hello, I'm an error.\n"); |
297 |
|
} |
298 |
+ |
|
299 |
+ |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
300 |
+ |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
301 |
+ |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
302 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
303 |
|
} |
304 |
< |
|
305 |
< |
sprintf(checkPointMsg,"Node %d sent dump configuration.", |
306 |
< |
procIndex); |
307 |
< |
MPIcheckPoint(); |
308 |
< |
} |
309 |
< |
|
304 |
> |
} |
305 |
> |
outFile.flush(); |
306 |
> |
sprintf( checkPointMsg, |
307 |
> |
"Sucessfully took a dump.\n"); |
308 |
> |
MPIcheckPoint(); |
309 |
> |
|
310 |
> |
// last thing last, enable fatalities. |
311 |
> |
painCave.isEventLoop = 0; |
312 |
> |
|
313 |
|
#endif // is_mpi |
314 |
|
} |
315 |
|
|
294 |
– |
|
295 |
– |
|
316 |
|
void DumpWriter::writeFinal(){ |
317 |
|
|
318 |
+ |
char finalName[500]; |
319 |
+ |
ofstream finalOut; |
320 |
|
|
321 |
|
const int BUFFERSIZE = 2000; |
322 |
< |
char tempBuffer[500]; |
323 |
< |
char writeLine[BUFFERSIZE]; |
302 |
< |
|
303 |
< |
char finalName[500]; |
322 |
> |
char tempBuffer[BUFFERSIZE]; |
323 |
> |
char writeLine[BUFFERSIZE]; |
324 |
|
|
305 |
– |
int i; |
325 |
|
double q[4]; |
326 |
|
DirectionalAtom* dAtom; |
327 |
|
int nAtoms = entry_plug->n_atoms; |
328 |
|
Atom** atoms = entry_plug->atoms; |
329 |
+ |
int i, j, which_node, done, game_over, which_atom, local_index; |
330 |
|
|
311 |
– |
ofstream finalOut; |
331 |
|
|
332 |
|
#ifdef IS_MPI |
333 |
|
if(worldRank == 0 ){ |
354 |
|
|
355 |
|
#endif //is_mpi |
356 |
|
|
357 |
< |
|
339 |
< |
|
357 |
> |
|
358 |
|
#ifndef IS_MPI |
359 |
|
|
360 |
|
finalOut << nAtoms << "\n"; |
362 |
|
finalOut << entry_plug->box_x << "\t" |
363 |
|
<< entry_plug->box_y << "\t" |
364 |
|
<< entry_plug->box_z << "\n"; |
365 |
< |
|
365 |
> |
|
366 |
|
for( i=0; i<nAtoms; i++ ){ |
367 |
|
|
368 |
|
sprintf( tempBuffer, |
398 |
|
finalOut << writeLine; |
399 |
|
} |
400 |
|
finalOut.flush(); |
401 |
+ |
finalOut.close(); |
402 |
|
|
403 |
|
#else // is_mpi |
404 |
+ |
|
405 |
+ |
// first thing first, suspend fatalities. |
406 |
+ |
painCave.isEventLoop = 1; |
407 |
|
|
408 |
< |
int masterIndex; |
409 |
< |
int nodeAtomsStart; |
388 |
< |
int nodeAtomsEnd; |
389 |
< |
int mpiErr; |
390 |
< |
int sendError; |
391 |
< |
int procIndex; |
392 |
< |
|
393 |
< |
MPI_Status istatus[MPI_STATUS_SIZE]; |
394 |
< |
|
395 |
< |
|
396 |
< |
// write out header and node 0's coordinates |
408 |
> |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
409 |
> |
int haveError; |
410 |
|
|
411 |
+ |
MPI_Status istatus; |
412 |
+ |
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
413 |
+ |
|
414 |
+ |
// write out header and node 0's coordinates |
415 |
+ |
|
416 |
+ |
haveError = 0; |
417 |
|
if( worldRank == 0 ){ |
418 |
|
finalOut << mpiSim->getTotAtoms() << "\n"; |
419 |
< |
|
419 |
> |
|
420 |
|
finalOut << entry_plug->box_x << "\t" |
421 |
< |
<< entry_plug->box_y << "\t" |
422 |
< |
<< entry_plug->box_z << "\n"; |
421 |
> |
<< entry_plug->box_y << "\t" |
422 |
> |
<< entry_plug->box_z << "\n"; |
423 |
|
|
424 |
< |
masterIndex = 0; |
425 |
< |
|
407 |
< |
for( i=0; i<nAtoms; i++ ){ |
424 |
> |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
425 |
> |
// Get the Node number which has this molecule: |
426 |
|
|
427 |
< |
sprintf( tempBuffer, |
428 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
429 |
< |
atoms[i]->getType(), |
430 |
< |
atoms[i]->getX(), |
431 |
< |
atoms[i]->getY(), |
432 |
< |
atoms[i]->getZ(), |
433 |
< |
atoms[i]->get_vx(), |
434 |
< |
atoms[i]->get_vy(), |
435 |
< |
atoms[i]->get_vz()); |
436 |
< |
strcpy( writeLine, tempBuffer ); |
437 |
< |
|
438 |
< |
if( atoms[i]->isDirectional() ){ |
427 |
> |
which_node = AtomToProcMap[i]; |
428 |
> |
|
429 |
> |
if (which_node == mpiSim->getMyNode()) { |
430 |
> |
|
431 |
> |
which_atom = i; |
432 |
> |
local_index=-1; |
433 |
> |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
434 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
435 |
> |
} |
436 |
> |
if (local_index != -1) { |
437 |
> |
sprintf( tempBuffer, |
438 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
439 |
> |
atoms[local_index]->getType(), |
440 |
> |
atoms[local_index]->getX(), |
441 |
> |
atoms[local_index]->getY(), |
442 |
> |
atoms[local_index]->getZ(), |
443 |
> |
atoms[local_index]->get_vx(), |
444 |
> |
atoms[local_index]->get_vy(), |
445 |
> |
atoms[local_index]->get_vz()); |
446 |
> |
strcpy( writeLine, tempBuffer ); |
447 |
|
|
448 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
449 |
< |
dAtom->getQ( q ); |
450 |
< |
|
451 |
< |
sprintf( tempBuffer, |
452 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
453 |
< |
q[0], |
454 |
< |
q[1], |
455 |
< |
q[2], |
456 |
< |
q[3], |
457 |
< |
dAtom->getJx(), |
458 |
< |
dAtom->getJy(), |
459 |
< |
dAtom->getJz()); |
460 |
< |
strcat( writeLine, tempBuffer ); |
461 |
< |
} |
462 |
< |
else |
463 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
448 |
> |
if( atoms[local_index]->isDirectional() ){ |
449 |
> |
|
450 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
451 |
> |
dAtom->getQ( q ); |
452 |
> |
|
453 |
> |
sprintf( tempBuffer, |
454 |
> |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
455 |
> |
q[0], |
456 |
> |
q[1], |
457 |
> |
q[2], |
458 |
> |
q[3], |
459 |
> |
dAtom->getJx(), |
460 |
> |
dAtom->getJy(), |
461 |
> |
dAtom->getJz()); |
462 |
> |
strcat( writeLine, tempBuffer ); |
463 |
> |
} |
464 |
> |
else |
465 |
> |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
466 |
> |
} |
467 |
> |
else { |
468 |
> |
sprintf(painCave.errMsg, |
469 |
> |
"Atom %d not found on processor %d\n", |
470 |
> |
i, worldRank ); |
471 |
> |
haveError= 1; |
472 |
> |
simError(); |
473 |
> |
} |
474 |
> |
|
475 |
> |
if(haveError) nodeZeroError(); |
476 |
> |
|
477 |
> |
} |
478 |
> |
else { |
479 |
> |
|
480 |
> |
myStatus = 1; |
481 |
> |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
482 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
483 |
> |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
484 |
> |
MPI_COMM_WORLD); |
485 |
> |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
486 |
> |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
487 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
488 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
489 |
|
|
490 |
+ |
if(!myStatus) nodeZeroError(); |
491 |
+ |
} |
492 |
+ |
|
493 |
|
finalOut << writeLine; |
440 |
– |
masterIndex++; |
494 |
|
} |
442 |
– |
finalOut.flush(); |
443 |
– |
} |
495 |
|
|
496 |
< |
for (procIndex = 1; procIndex < mpiSim->getNumberProcessors(); |
497 |
< |
procIndex++){ |
496 |
> |
// kill everyone off: |
497 |
> |
myStatus = -1; |
498 |
> |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
499 |
> |
MPI_Send(&myStatus, 1, MPI_INT, j, |
500 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
501 |
> |
} |
502 |
|
|
503 |
< |
if( worldRank == 0 ){ |
504 |
< |
|
505 |
< |
mpiErr = MPI_Recv(&nodeAtomsStart,1,MPI_INT,procIndex, |
506 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD,istatus); |
503 |
> |
} else { |
504 |
> |
|
505 |
> |
done = 0; |
506 |
> |
while (!done) { |
507 |
|
|
508 |
< |
mpiErr = MPI_Recv(&nodeAtomsEnd,1,MPI_INT,procIndex, |
509 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD, istatus); |
510 |
< |
|
511 |
< |
// Make sure where node 0 is writing to, matches where the |
512 |
< |
// receiving node expects it to be. |
513 |
< |
|
514 |
< |
if (masterIndex != nodeAtomsStart){ |
515 |
< |
sendError = 1; |
516 |
< |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, |
517 |
< |
MPI_COMM_WORLD); |
518 |
< |
sprintf(painCave.errMsg, |
519 |
< |
"DumpWriter error: atoms start index (%d) for " |
520 |
< |
"node %d not equal to master index (%d)", |
521 |
< |
nodeAtomsStart,procIndex,masterIndex ); |
467 |
< |
painCave.isFatal = 1; |
468 |
< |
simError(); |
508 |
> |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
509 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
510 |
> |
|
511 |
> |
if(!myStatus) anonymousNodeDie(); |
512 |
> |
|
513 |
> |
if(myStatus < 0) break; |
514 |
> |
|
515 |
> |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
516 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
517 |
> |
|
518 |
> |
myStatus = 1; |
519 |
> |
local_index=-1; |
520 |
> |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
521 |
> |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
522 |
|
} |
523 |
< |
|
471 |
< |
sendError = 0; |
472 |
< |
mpiErr = MPI_Send(&sendError,1,MPI_INT,procIndex,TAKE_THIS_TAG, |
473 |
< |
MPI_COMM_WORLD); |
523 |
> |
if (local_index != -1) { |
524 |
|
|
525 |
< |
// recieve the nodes writeLines |
476 |
< |
|
477 |
< |
for ( i = nodeAtomsStart; i <= nodeAtomsEnd; i++){ |
478 |
< |
|
479 |
< |
mpiErr = MPI_Recv(writeLine,BUFFERSIZE,MPI_CHAR,procIndex, |
480 |
< |
TAKE_THIS_TAG,MPI_COMM_WORLD,istatus ); |
481 |
< |
|
482 |
< |
finalOut << writeLine; |
483 |
< |
masterIndex++; |
484 |
< |
} |
485 |
< |
|
486 |
< |
finalOut.flush(); |
487 |
< |
} |
488 |
< |
|
489 |
< |
else if( worldRank == procIndex ){ |
490 |
< |
|
491 |
< |
nodeAtomsStart = mpiSim->getMyAtomStart(); |
492 |
< |
nodeAtomsEnd = mpiSim->getMyAtomEnd(); |
493 |
< |
|
494 |
< |
mpiErr = MPI_Send(&nodeAtomsStart,1,MPI_INT,0,TAKE_THIS_TAG, |
495 |
< |
MPI_COMM_WORLD); |
496 |
< |
mpiErr = MPI_Send(&nodeAtomsEnd,1,MPI_INT,0,TAKE_THIS_TAG, |
497 |
< |
MPI_COMM_WORLD); |
498 |
< |
|
499 |
< |
mpiErr = MPI_Recv(&sendError,1,MPI_INT,0,TAKE_THIS_TAG, |
500 |
< |
MPI_COMM_WORLD, istatus); |
501 |
< |
if (sendError) MPIcheckPoint(); |
502 |
< |
|
503 |
< |
// send current node's configuration line by line. |
504 |
< |
|
505 |
< |
for( i=0; i<nAtoms; i++ ){ |
506 |
< |
|
525 |
> |
//format the line |
526 |
|
sprintf( tempBuffer, |
527 |
|
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
528 |
< |
atoms[i]->getType(), |
529 |
< |
atoms[i]->getX(), |
530 |
< |
atoms[i]->getY(), |
531 |
< |
atoms[i]->getZ(), |
532 |
< |
atoms[i]->get_vx(), |
533 |
< |
atoms[i]->get_vy(), |
534 |
< |
atoms[i]->get_vz()); |
528 |
> |
atoms[local_index]->getType(), |
529 |
> |
atoms[local_index]->getX(), |
530 |
> |
atoms[local_index]->getY(), |
531 |
> |
atoms[local_index]->getZ(), |
532 |
> |
atoms[local_index]->get_vx(), |
533 |
> |
atoms[local_index]->get_vy(), |
534 |
> |
atoms[local_index]->get_vz()); // check here. |
535 |
|
strcpy( writeLine, tempBuffer ); |
536 |
+ |
|
537 |
+ |
if( atoms[local_index]->isDirectional() ){ |
538 |
|
|
539 |
< |
if( atoms[i]->isDirectional() ){ |
519 |
< |
|
520 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
539 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
540 |
|
dAtom->getQ( q ); |
541 |
< |
|
541 |
> |
|
542 |
|
sprintf( tempBuffer, |
543 |
|
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
544 |
|
q[0], |
550 |
|
dAtom->getJz()); |
551 |
|
strcat( writeLine, tempBuffer ); |
552 |
|
} |
553 |
< |
else |
553 |
> |
else{ |
554 |
|
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
555 |
< |
|
556 |
< |
mpiErr = MPI_Send(writeLine,BUFFERSIZE,MPI_CHAR,0,TAKE_THIS_TAG, |
557 |
< |
MPI_COMM_WORLD); |
555 |
> |
} |
556 |
> |
} |
557 |
> |
else { |
558 |
> |
sprintf(painCave.errMsg, |
559 |
> |
"Atom %d not found on processor %d\n", |
560 |
> |
which_atom, worldRank ); |
561 |
> |
myStatus = 0; |
562 |
> |
simError(); |
563 |
> |
|
564 |
> |
strcpy( writeLine, "Hello, I'm an error.\n"); |
565 |
|
} |
566 |
+ |
|
567 |
+ |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
568 |
+ |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
569 |
+ |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
570 |
+ |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
571 |
|
} |
541 |
– |
|
542 |
– |
sprintf(checkPointMsg,"Node %d sent dump configuration.", |
543 |
– |
procIndex); |
544 |
– |
MPIcheckPoint(); |
572 |
|
} |
573 |
+ |
finalOut.flush(); |
574 |
+ |
sprintf( checkPointMsg, |
575 |
+ |
"Sucessfully took a dump.\n"); |
576 |
+ |
MPIcheckPoint(); |
577 |
+ |
|
578 |
+ |
if( worldRank == 0 ) finalOut.close(); |
579 |
+ |
#endif // is_mpi |
580 |
+ |
} |
581 |
|
|
547 |
– |
if( worldRank == 0 ) finalOut.close(); |
582 |
|
|
583 |
< |
|
584 |
< |
#endif // is_mpi |
583 |
> |
|
584 |
> |
#ifdef IS_MPI |
585 |
> |
|
586 |
> |
// a couple of functions to let us escape the write loop |
587 |
> |
|
588 |
> |
void dWrite::nodeZeroError( void ){ |
589 |
> |
int j, myStatus; |
590 |
> |
|
591 |
> |
myStatus = 0; |
592 |
> |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
593 |
> |
MPI_Send( &myStatus, 1, MPI_INT, j, |
594 |
> |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
595 |
> |
} |
596 |
> |
|
597 |
> |
|
598 |
> |
MPI_Finalize(); |
599 |
> |
exit (0); |
600 |
> |
|
601 |
|
} |
602 |
+ |
|
603 |
+ |
void dWrite::anonymousNodeDie( void ){ |
604 |
+ |
|
605 |
+ |
MPI_Finalize(); |
606 |
+ |
exit (0); |
607 |
+ |
} |
608 |
+ |
|
609 |
+ |
#endif //is_mpi |