1 |
< |
#include <cstring> |
1 |
> |
#define _FILE_OFFSET_BITS 64 |
2 |
> |
|
3 |
> |
#include <string.h> |
4 |
|
#include <iostream> |
5 |
|
#include <fstream> |
6 |
+ |
#include <algorithm> |
7 |
+ |
#include <utility> |
8 |
|
|
9 |
|
#ifdef IS_MPI |
10 |
|
#include <mpi.h> |
11 |
|
#include "mpiSimulation.hpp" |
8 |
– |
#define TAKE_THIS_TAG_CHAR 1 |
9 |
– |
#define TAKE_THIS_TAG_INT 2 |
12 |
|
|
13 |
|
namespace dWrite{ |
14 |
< |
void nodeZeroError( void ); |
13 |
< |
void anonymousNodeDie( void ); |
14 |
> |
void DieDieDie( void ); |
15 |
|
} |
16 |
|
|
17 |
|
using namespace dWrite; |
27 |
|
#ifdef IS_MPI |
28 |
|
if(worldRank == 0 ){ |
29 |
|
#endif // is_mpi |
30 |
< |
|
31 |
< |
strcpy( outName, entry_plug->sampleName ); |
32 |
< |
|
33 |
< |
outFile.open(outName, ios::out | ios::trunc ); |
34 |
< |
|
35 |
< |
if( !outFile ){ |
35 |
< |
|
30 |
> |
|
31 |
> |
|
32 |
> |
dumpFile.open(entry_plug->sampleName, ios::out | ios::trunc ); |
33 |
> |
|
34 |
> |
if( !dumpFile ){ |
35 |
> |
|
36 |
|
sprintf( painCave.errMsg, |
37 |
|
"Could not open \"%s\" for dump output.\n", |
38 |
< |
outName); |
38 |
> |
entry_plug->sampleName); |
39 |
|
painCave.isFatal = 1; |
40 |
|
simError(); |
41 |
|
} |
45 |
|
#ifdef IS_MPI |
46 |
|
} |
47 |
|
|
48 |
+ |
//sort the local atoms by global index |
49 |
+ |
sortByGlobalIndex(); |
50 |
+ |
|
51 |
|
sprintf( checkPointMsg, |
52 |
|
"Sucessfully opened output file for dumping.\n"); |
53 |
|
MPIcheckPoint(); |
60 |
|
if(worldRank == 0 ){ |
61 |
|
#endif // is_mpi |
62 |
|
|
63 |
< |
outFile.close(); |
63 |
> |
dumpFile.close(); |
64 |
|
|
65 |
|
#ifdef IS_MPI |
66 |
|
} |
67 |
|
#endif // is_mpi |
68 |
|
} |
69 |
|
|
70 |
< |
void DumpWriter::writeDump( double currentTime ){ |
70 |
> |
#ifdef IS_MPI |
71 |
> |
|
72 |
> |
/** |
73 |
> |
* A hook function to load balancing |
74 |
> |
*/ |
75 |
> |
|
76 |
> |
void DumpWriter::update(){ |
77 |
> |
sortByGlobalIndex(); |
78 |
> |
} |
79 |
|
|
80 |
+ |
/** |
81 |
+ |
* Auxiliary sorting function |
82 |
+ |
*/ |
83 |
+ |
|
84 |
+ |
bool indexSortingCriterion(const pair<int, int>& p1, const pair<int, int>& p2){ |
85 |
+ |
return p1.second < p2.second; |
86 |
+ |
} |
87 |
+ |
|
88 |
+ |
/** |
89 |
+ |
* Sorting the local index by global index |
90 |
+ |
*/ |
91 |
+ |
|
92 |
+ |
void DumpWriter::sortByGlobalIndex(){ |
93 |
+ |
Atom** atoms = entry_plug->atoms; |
94 |
+ |
|
95 |
+ |
indexArray.clear(); |
96 |
+ |
|
97 |
+ |
for(int i = 0; i < mpiSim->getMyNlocal();i++) |
98 |
+ |
indexArray.push_back(make_pair(i, atoms[i]->getGlobalIndex())); |
99 |
+ |
|
100 |
+ |
sort(indexArray.begin(), indexArray.end(), indexSortingCriterion); |
101 |
+ |
} |
102 |
+ |
#endif |
103 |
+ |
|
104 |
+ |
void DumpWriter::writeDump(double currentTime){ |
105 |
+ |
|
106 |
+ |
// write to eor file |
107 |
+ |
writeFinal(currentTime); |
108 |
+ |
|
109 |
+ |
//write to dump file |
110 |
+ |
writeFrame(dumpFile, currentTime); |
111 |
+ |
|
112 |
+ |
} |
113 |
+ |
|
114 |
+ |
void DumpWriter::writeFinal(double currentTime){ |
115 |
+ |
|
116 |
+ |
ofstream finalOut; |
117 |
+ |
|
118 |
+ |
//Open eor file |
119 |
+ |
#ifdef IS_MPI |
120 |
+ |
if(worldRank == 0 ){ |
121 |
+ |
#endif // is_mpi |
122 |
+ |
|
123 |
+ |
finalOut.open( entry_plug->finalName, ios::out | ios::trunc ); |
124 |
+ |
if( !finalOut ){ |
125 |
+ |
sprintf( painCave.errMsg, |
126 |
+ |
"Could not open \"%s\" for final dump output.\n", |
127 |
+ |
entry_plug->finalName ); |
128 |
+ |
painCave.isFatal = 1; |
129 |
+ |
simError(); |
130 |
+ |
} |
131 |
+ |
|
132 |
+ |
#ifdef IS_MPI |
133 |
+ |
} |
134 |
+ |
#endif |
135 |
+ |
|
136 |
+ |
//write to eor file |
137 |
+ |
writeFrame(finalOut, currentTime); |
138 |
+ |
|
139 |
+ |
//close eor file |
140 |
+ |
#ifdef IS_MPI |
141 |
+ |
if(worldRank == 0 ){ |
142 |
+ |
finalOut.close(); |
143 |
+ |
} |
144 |
+ |
#endif // is_mpi |
145 |
+ |
|
146 |
+ |
} |
147 |
+ |
|
148 |
+ |
void DumpWriter::writeFrame( ofstream& outFile, double currentTime ){ |
149 |
+ |
|
150 |
|
const int BUFFERSIZE = 2000; |
151 |
+ |
const int MINIBUFFERSIZE = 100; |
152 |
+ |
|
153 |
|
char tempBuffer[BUFFERSIZE]; |
154 |
|
char writeLine[BUFFERSIZE]; |
155 |
|
|
156 |
< |
int i, j, which_node, done, which_atom, local_index; |
156 |
> |
int i; |
157 |
> |
|
158 |
> |
#ifdef IS_MPI |
159 |
> |
|
160 |
> |
int *potatoes; |
161 |
> |
int myPotato; |
162 |
> |
|
163 |
> |
int nProc; |
164 |
> |
int j, which_node, done, which_atom, local_index, currentIndex; |
165 |
> |
double atomData6[6]; |
166 |
> |
double atomData13[13]; |
167 |
> |
int isDirectional; |
168 |
> |
char* atomTypeString; |
169 |
> |
char MPIatomTypeString[MINIBUFFERSIZE]; |
170 |
> |
|
171 |
> |
#else //is_mpi |
172 |
> |
int nAtoms = entry_plug->n_atoms; |
173 |
> |
#endif //is_mpi |
174 |
> |
|
175 |
|
double q[4]; |
176 |
|
DirectionalAtom* dAtom; |
76 |
– |
int nAtoms = entry_plug->n_atoms; |
177 |
|
Atom** atoms = entry_plug->atoms; |
178 |
< |
|
178 |
> |
double pos[3], vel[3]; |
179 |
|
|
180 |
|
#ifndef IS_MPI |
181 |
< |
|
181 |
> |
|
182 |
|
outFile << nAtoms << "\n"; |
83 |
– |
|
84 |
– |
outFile << currentTime << ";\t" |
85 |
– |
<< entry_plug->Hmat[0] << "\t" |
86 |
– |
<< entry_plug->Hmat[1] << "\t" |
87 |
– |
<< entry_plug->Hmat[2] << ";\t" |
183 |
|
|
184 |
< |
<< entry_plug->Hmat[3] << "\t" |
185 |
< |
<< entry_plug->Hmat[4] << "\t" |
186 |
< |
<< entry_plug->Hmat[5] << ";\t" |
184 |
> |
outFile << currentTime << ";\t" |
185 |
> |
<< entry_plug->Hmat[0][0] << "\t" |
186 |
> |
<< entry_plug->Hmat[1][0] << "\t" |
187 |
> |
<< entry_plug->Hmat[2][0] << ";\t" |
188 |
|
|
189 |
< |
<< entry_plug->Hmat[6] << "\t" |
190 |
< |
<< entry_plug->Hmat[7] << "\t" |
191 |
< |
<< entry_plug->Hmat[8] << ";\n"; |
192 |
< |
|
189 |
> |
<< entry_plug->Hmat[0][1] << "\t" |
190 |
> |
<< entry_plug->Hmat[1][1] << "\t" |
191 |
> |
<< entry_plug->Hmat[2][1] << ";\t" |
192 |
> |
|
193 |
> |
<< entry_plug->Hmat[0][2] << "\t" |
194 |
> |
<< entry_plug->Hmat[1][2] << "\t" |
195 |
> |
<< entry_plug->Hmat[2][2] << ";"; |
196 |
> |
//write out additional parameters, such as chi and eta |
197 |
> |
outFile << entry_plug->the_integrator->getAdditionalParameters(); |
198 |
> |
outFile << endl; |
199 |
> |
|
200 |
|
for( i=0; i<nAtoms; i++ ){ |
98 |
– |
|
201 |
|
|
202 |
+ |
atoms[i]->getPos(pos); |
203 |
+ |
atoms[i]->getVel(vel); |
204 |
+ |
|
205 |
|
sprintf( tempBuffer, |
206 |
|
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
207 |
|
atoms[i]->getType(), |
208 |
< |
atoms[i]->getX(), |
209 |
< |
atoms[i]->getY(), |
210 |
< |
atoms[i]->getZ(), |
211 |
< |
atoms[i]->get_vx(), |
212 |
< |
atoms[i]->get_vy(), |
213 |
< |
atoms[i]->get_vz()); |
208 |
> |
pos[0], |
209 |
> |
pos[1], |
210 |
> |
pos[2], |
211 |
> |
vel[0], |
212 |
> |
vel[1], |
213 |
> |
vel[2]); |
214 |
|
strcpy( writeLine, tempBuffer ); |
215 |
|
|
216 |
|
if( atoms[i]->isDirectional() ){ |
217 |
< |
|
217 |
> |
|
218 |
|
dAtom = (DirectionalAtom *)atoms[i]; |
219 |
|
dAtom->getQ( q ); |
220 |
< |
|
220 |
> |
|
221 |
|
sprintf( tempBuffer, |
222 |
|
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
223 |
|
q[0], |
231 |
|
} |
232 |
|
else |
233 |
|
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
234 |
< |
|
234 |
> |
|
235 |
|
outFile << writeLine; |
236 |
|
} |
132 |
– |
outFile.flush(); |
237 |
|
|
238 |
|
#else // is_mpi |
239 |
|
|
240 |
< |
// first thing first, suspend fatalities. |
241 |
< |
painCave.isEventLoop = 1; |
240 |
> |
/* code to find maximum tag value */ |
241 |
> |
|
242 |
> |
int *tagub, flag, MAXTAG; |
243 |
> |
MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
244 |
> |
if (flag) { |
245 |
> |
MAXTAG = *tagub; |
246 |
> |
} else { |
247 |
> |
MAXTAG = 32767; |
248 |
> |
} |
249 |
|
|
139 |
– |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
250 |
|
int haveError; |
251 |
|
|
252 |
|
MPI_Status istatus; |
253 |
|
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
254 |
< |
|
254 |
> |
|
255 |
|
// write out header and node 0's coordinates |
256 |
< |
|
256 |
> |
|
257 |
|
if( worldRank == 0 ){ |
258 |
+ |
|
259 |
+ |
// Node 0 needs a list of the magic potatoes for each processor; |
260 |
+ |
|
261 |
+ |
nProc = mpiSim->getNumberProcessors(); |
262 |
+ |
potatoes = new int[nProc]; |
263 |
+ |
|
264 |
+ |
for (i = 0; i < nProc; i++) |
265 |
+ |
potatoes[i] = 0; |
266 |
+ |
|
267 |
|
outFile << mpiSim->getTotAtoms() << "\n"; |
268 |
< |
|
269 |
< |
outFile << currentTime << "\t" |
270 |
< |
<< entry_plug->Hmat[0] << "\t" |
271 |
< |
<< entry_plug->Hmat[1] << "\t" |
272 |
< |
<< entry_plug->Hmat[2] << "\t" |
273 |
< |
|
274 |
< |
<< entry_plug->Hmat[3] << "\t" |
275 |
< |
<< entry_plug->Hmat[4] << "\t" |
276 |
< |
<< entry_plug->Hmat[5] << "\t" |
277 |
< |
|
278 |
< |
<< entry_plug->Hmat[6] << "\t" |
279 |
< |
<< entry_plug->Hmat[7] << "\t" |
280 |
< |
<< entry_plug->Hmat[8] << "\n"; |
281 |
< |
; |
268 |
> |
|
269 |
> |
outFile << currentTime << ";\t" |
270 |
> |
<< entry_plug->Hmat[0][0] << "\t" |
271 |
> |
<< entry_plug->Hmat[1][0] << "\t" |
272 |
> |
<< entry_plug->Hmat[2][0] << ";\t" |
273 |
> |
|
274 |
> |
<< entry_plug->Hmat[0][1] << "\t" |
275 |
> |
<< entry_plug->Hmat[1][1] << "\t" |
276 |
> |
<< entry_plug->Hmat[2][1] << ";\t" |
277 |
> |
|
278 |
> |
<< entry_plug->Hmat[0][2] << "\t" |
279 |
> |
<< entry_plug->Hmat[1][2] << "\t" |
280 |
> |
<< entry_plug->Hmat[2][2] << ";"; |
281 |
> |
|
282 |
> |
outFile << entry_plug->the_integrator->getAdditionalParameters(); |
283 |
> |
outFile << endl; |
284 |
|
outFile.flush(); |
285 |
+ |
|
286 |
+ |
currentIndex = 0; |
287 |
|
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
288 |
+ |
|
289 |
|
// Get the Node number which has this atom; |
290 |
|
|
291 |
< |
which_node = AtomToProcMap[i]; |
291 |
> |
which_node = AtomToProcMap[i]; |
292 |
|
|
293 |
< |
if (which_node == 0 ) { |
293 |
> |
if (which_node != 0) { |
294 |
> |
|
295 |
> |
if (potatoes[which_node] + 3 >= MAXTAG) { |
296 |
> |
// The potato was going to exceed the maximum value, |
297 |
> |
// so wrap this processor potato back to 0: |
298 |
> |
|
299 |
> |
potatoes[which_node] = 0; |
300 |
> |
MPI_Send(0, 1, MPI_INT, which_node, 0, MPI_COMM_WORLD); |
301 |
> |
|
302 |
> |
} |
303 |
> |
|
304 |
> |
myPotato = potatoes[which_node]; |
305 |
> |
|
306 |
> |
MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, |
307 |
> |
myPotato, MPI_COMM_WORLD, &istatus); |
308 |
> |
|
309 |
> |
atomTypeString = MPIatomTypeString; |
310 |
|
|
311 |
+ |
myPotato++; |
312 |
+ |
|
313 |
+ |
MPI_Recv(&isDirectional, 1, MPI_INT, which_node, |
314 |
+ |
myPotato, MPI_COMM_WORLD, &istatus); |
315 |
+ |
|
316 |
+ |
myPotato++; |
317 |
+ |
|
318 |
+ |
if (isDirectional) { |
319 |
+ |
MPI_Recv(atomData13, 13, MPI_DOUBLE, which_node, |
320 |
+ |
myPotato, MPI_COMM_WORLD, &istatus); |
321 |
+ |
} else { |
322 |
+ |
MPI_Recv(atomData6, 6, MPI_DOUBLE, which_node, |
323 |
+ |
myPotato, MPI_COMM_WORLD, &istatus); |
324 |
+ |
} |
325 |
+ |
|
326 |
+ |
myPotato++; |
327 |
+ |
potatoes[which_node] = myPotato; |
328 |
+ |
|
329 |
+ |
} else { |
330 |
+ |
|
331 |
|
haveError = 0; |
332 |
|
which_atom = i; |
333 |
< |
local_index=-1; |
334 |
< |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
335 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
336 |
< |
} |
337 |
< |
if (local_index != -1) { |
338 |
< |
//format the line |
339 |
< |
sprintf( tempBuffer, |
340 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
341 |
< |
atoms[local_index]->getType(), |
342 |
< |
atoms[local_index]->getX(), |
343 |
< |
atoms[local_index]->getY(), |
344 |
< |
atoms[local_index]->getZ(), |
345 |
< |
atoms[local_index]->get_vx(), |
346 |
< |
atoms[local_index]->get_vy(), |
347 |
< |
atoms[local_index]->get_vz()); // check here. |
348 |
< |
strcpy( writeLine, tempBuffer ); |
349 |
< |
|
333 |
> |
|
334 |
> |
local_index = indexArray[currentIndex].first; |
335 |
> |
|
336 |
> |
if (which_atom == indexArray[currentIndex].second) { |
337 |
> |
|
338 |
> |
atomTypeString = atoms[local_index]->getType(); |
339 |
> |
|
340 |
> |
atoms[local_index]->getPos(pos); |
341 |
> |
atoms[local_index]->getVel(vel); |
342 |
> |
|
343 |
> |
atomData6[0] = pos[0]; |
344 |
> |
atomData6[1] = pos[1]; |
345 |
> |
atomData6[2] = pos[2]; |
346 |
> |
|
347 |
> |
atomData6[3] = vel[0]; |
348 |
> |
atomData6[4] = vel[1]; |
349 |
> |
atomData6[5] = vel[2]; |
350 |
> |
|
351 |
> |
isDirectional = 0; |
352 |
> |
|
353 |
|
if( atoms[local_index]->isDirectional() ){ |
354 |
+ |
|
355 |
+ |
isDirectional = 1; |
356 |
|
|
357 |
|
dAtom = (DirectionalAtom *)atoms[local_index]; |
358 |
|
dAtom->getQ( q ); |
359 |
+ |
|
360 |
+ |
for (int j = 0; j < 6 ; j++) |
361 |
+ |
atomData13[j] = atomData6[j]; |
362 |
|
|
363 |
< |
sprintf( tempBuffer, |
364 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
365 |
< |
q[0], |
366 |
< |
q[1], |
367 |
< |
q[2], |
368 |
< |
q[3], |
369 |
< |
dAtom->getJx(), |
370 |
< |
dAtom->getJy(), |
371 |
< |
dAtom->getJz()); |
372 |
< |
strcat( writeLine, tempBuffer ); |
373 |
< |
|
206 |
< |
} |
207 |
< |
else |
208 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
209 |
< |
} |
210 |
< |
else { |
363 |
> |
atomData13[6] = q[0]; |
364 |
> |
atomData13[7] = q[1]; |
365 |
> |
atomData13[8] = q[2]; |
366 |
> |
atomData13[9] = q[3]; |
367 |
> |
|
368 |
> |
atomData13[10] = dAtom->getJx(); |
369 |
> |
atomData13[11] = dAtom->getJy(); |
370 |
> |
atomData13[12] = dAtom->getJz(); |
371 |
> |
} |
372 |
> |
|
373 |
> |
} else { |
374 |
|
sprintf(painCave.errMsg, |
375 |
|
"Atom %d not found on processor %d\n", |
376 |
|
i, worldRank ); |
377 |
|
haveError= 1; |
378 |
|
simError(); |
379 |
< |
} |
380 |
< |
|
381 |
< |
if(haveError) nodeZeroError(); |
382 |
< |
|
379 |
> |
} |
380 |
> |
|
381 |
> |
if(haveError) DieDieDie(); |
382 |
> |
|
383 |
> |
currentIndex ++; |
384 |
|
} |
385 |
< |
else { |
386 |
< |
myStatus = 1; |
387 |
< |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
224 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
225 |
< |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
226 |
< |
MPI_COMM_WORLD); |
227 |
< |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
228 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
229 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
230 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
385 |
> |
// If we've survived to here, format the line: |
386 |
> |
|
387 |
> |
if (!isDirectional) { |
388 |
|
|
389 |
< |
if(!myStatus) nodeZeroError(); |
389 |
> |
sprintf( writeLine, |
390 |
> |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
391 |
> |
atomTypeString, |
392 |
> |
atomData6[0], |
393 |
> |
atomData6[1], |
394 |
> |
atomData6[2], |
395 |
> |
atomData6[3], |
396 |
> |
atomData6[4], |
397 |
> |
atomData6[5]); |
398 |
|
|
399 |
+ |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
400 |
+ |
|
401 |
+ |
} else { |
402 |
+ |
|
403 |
+ |
sprintf( writeLine, |
404 |
+ |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
405 |
+ |
atomTypeString, |
406 |
+ |
atomData13[0], |
407 |
+ |
atomData13[1], |
408 |
+ |
atomData13[2], |
409 |
+ |
atomData13[3], |
410 |
+ |
atomData13[4], |
411 |
+ |
atomData13[5], |
412 |
+ |
atomData13[6], |
413 |
+ |
atomData13[7], |
414 |
+ |
atomData13[8], |
415 |
+ |
atomData13[9], |
416 |
+ |
atomData13[10], |
417 |
+ |
atomData13[11], |
418 |
+ |
atomData13[12]); |
419 |
+ |
|
420 |
|
} |
421 |
|
|
422 |
|
outFile << writeLine; |
237 |
– |
outFile.flush(); |
423 |
|
} |
424 |
|
|
240 |
– |
// kill everyone off: |
241 |
– |
myStatus = -1; |
242 |
– |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
243 |
– |
MPI_Send(&myStatus, 1, MPI_INT, j, |
244 |
– |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
245 |
– |
} |
425 |
|
|
426 |
+ |
outFile.flush(); |
427 |
+ |
sprintf( checkPointMsg, |
428 |
+ |
"Sucessfully took a dump.\n"); |
429 |
+ |
MPIcheckPoint(); |
430 |
+ |
delete[] potatoes; |
431 |
|
} else { |
432 |
+ |
|
433 |
+ |
// worldRank != 0, so I'm a remote node. |
434 |
+ |
|
435 |
+ |
// Set my magic potato to 0: |
436 |
+ |
|
437 |
+ |
myPotato = 0; |
438 |
+ |
currentIndex = 0; |
439 |
|
|
440 |
< |
done = 0; |
250 |
< |
while (!done) { |
440 |
> |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
441 |
|
|
442 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
253 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
254 |
< |
|
255 |
< |
if(!myStatus) anonymousNodeDie(); |
442 |
> |
// Am I the node which has this atom? |
443 |
|
|
444 |
< |
if(myStatus < 0) break; |
444 |
> |
if (AtomToProcMap[i] == worldRank) { |
445 |
|
|
446 |
< |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
260 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
261 |
< |
|
262 |
< |
myStatus = 1; |
263 |
< |
local_index=-1; |
264 |
< |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
265 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
266 |
< |
} |
267 |
< |
if (local_index != -1) { |
268 |
< |
//format the line |
269 |
< |
sprintf( tempBuffer, |
270 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
271 |
< |
atoms[local_index]->getType(), |
272 |
< |
atoms[local_index]->getX(), |
273 |
< |
atoms[local_index]->getY(), |
274 |
< |
atoms[local_index]->getZ(), |
275 |
< |
atoms[local_index]->get_vx(), |
276 |
< |
atoms[local_index]->get_vy(), |
277 |
< |
atoms[local_index]->get_vz()); // check here. |
278 |
< |
strcpy( writeLine, tempBuffer ); |
279 |
< |
|
280 |
< |
if( atoms[local_index]->isDirectional() ){ |
281 |
< |
|
282 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
283 |
< |
dAtom->getQ( q ); |
284 |
< |
|
285 |
< |
sprintf( tempBuffer, |
286 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
287 |
< |
q[0], |
288 |
< |
q[1], |
289 |
< |
q[2], |
290 |
< |
q[3], |
291 |
< |
dAtom->getJx(), |
292 |
< |
dAtom->getJy(), |
293 |
< |
dAtom->getJz()); |
294 |
< |
strcat( writeLine, tempBuffer ); |
295 |
< |
} |
296 |
< |
else{ |
297 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
298 |
< |
} |
299 |
< |
} |
300 |
< |
else { |
301 |
< |
sprintf(painCave.errMsg, |
302 |
< |
"Atom %d not found on processor %d\n", |
303 |
< |
which_atom, worldRank ); |
304 |
< |
myStatus = 0; |
305 |
< |
simError(); |
446 |
> |
if (myPotato + 3 >= MAXTAG) { |
447 |
|
|
448 |
< |
strcpy( writeLine, "Hello, I'm an error.\n"); |
449 |
< |
} |
448 |
> |
// The potato was going to exceed the maximum value, |
449 |
> |
// so wrap this processor potato back to 0 (and block until |
450 |
> |
// node 0 says we can go: |
451 |
|
|
452 |
< |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
453 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
454 |
< |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
455 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
456 |
< |
} |
457 |
< |
} |
458 |
< |
outFile.flush(); |
459 |
< |
sprintf( checkPointMsg, |
460 |
< |
"Sucessfully took a dump.\n"); |
319 |
< |
MPIcheckPoint(); |
452 |
> |
MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus); |
453 |
> |
|
454 |
> |
} |
455 |
> |
which_atom = i; |
456 |
> |
local_index = indexArray[currentIndex].first; |
457 |
> |
|
458 |
> |
if (which_atom == indexArray[currentIndex].second) { |
459 |
> |
|
460 |
> |
atomTypeString = atoms[local_index]->getType(); |
461 |
|
|
462 |
< |
// last thing last, enable fatalities. |
463 |
< |
painCave.isEventLoop = 0; |
462 |
> |
atoms[local_index]->getPos(pos); |
463 |
> |
atoms[local_index]->getVel(vel); |
464 |
|
|
465 |
< |
#endif // is_mpi |
466 |
< |
} |
465 |
> |
atomData6[0] = pos[0]; |
466 |
> |
atomData6[1] = pos[1]; |
467 |
> |
atomData6[2] = pos[2]; |
468 |
|
|
469 |
< |
void DumpWriter::writeFinal(double finalTime){ |
469 |
> |
atomData6[3] = vel[0]; |
470 |
> |
atomData6[4] = vel[1]; |
471 |
> |
atomData6[5] = vel[2]; |
472 |
> |
|
473 |
> |
isDirectional = 0; |
474 |
|
|
475 |
< |
char finalName[500]; |
330 |
< |
ofstream finalOut; |
475 |
> |
if( atoms[local_index]->isDirectional() ){ |
476 |
|
|
477 |
< |
const int BUFFERSIZE = 2000; |
478 |
< |
char tempBuffer[BUFFERSIZE]; |
479 |
< |
char writeLine[BUFFERSIZE]; |
477 |
> |
isDirectional = 1; |
478 |
> |
|
479 |
> |
dAtom = (DirectionalAtom *)atoms[local_index]; |
480 |
> |
dAtom->getQ( q ); |
481 |
> |
|
482 |
> |
for (int j = 0; j < 6 ; j++) |
483 |
> |
atomData13[j] = atomData6[j]; |
484 |
> |
|
485 |
> |
atomData13[6] = q[0]; |
486 |
> |
atomData13[7] = q[1]; |
487 |
> |
atomData13[8] = q[2]; |
488 |
> |
atomData13[9] = q[3]; |
489 |
|
|
490 |
< |
double q[4]; |
491 |
< |
DirectionalAtom* dAtom; |
492 |
< |
int nAtoms = entry_plug->n_atoms; |
493 |
< |
Atom** atoms = entry_plug->atoms; |
340 |
< |
int i, j, which_node, done, game_over, which_atom, local_index; |
341 |
< |
|
342 |
< |
|
343 |
< |
#ifdef IS_MPI |
344 |
< |
if(worldRank == 0 ){ |
345 |
< |
#endif // is_mpi |
346 |
< |
|
347 |
< |
strcpy( finalName, entry_plug->finalName ); |
348 |
< |
|
349 |
< |
finalOut.open( finalName, ios::out | ios::trunc ); |
350 |
< |
if( !finalOut ){ |
351 |
< |
sprintf( painCave.errMsg, |
352 |
< |
"Could not open \"%s\" for final dump output.\n", |
353 |
< |
finalName ); |
354 |
< |
painCave.isFatal = 1; |
355 |
< |
simError(); |
356 |
< |
} |
357 |
< |
|
358 |
< |
// finalOut.setf( ios::scientific ); |
359 |
< |
|
360 |
< |
#ifdef IS_MPI |
361 |
< |
} |
362 |
< |
|
363 |
< |
sprintf(checkPointMsg,"Opened file for final configuration\n"); |
364 |
< |
MPIcheckPoint(); |
365 |
< |
|
366 |
< |
#endif //is_mpi |
490 |
> |
atomData13[10] = dAtom->getJx(); |
491 |
> |
atomData13[11] = dAtom->getJy(); |
492 |
> |
atomData13[12] = dAtom->getJz(); |
493 |
> |
} |
494 |
|
|
495 |
< |
|
369 |
< |
#ifndef IS_MPI |
370 |
< |
|
371 |
< |
finalOut << nAtoms << "\n"; |
372 |
< |
|
373 |
< |
finalOut << finalTime << "\t" |
374 |
< |
<< entry_plug->Hmat[0] << "\t" |
375 |
< |
<< entry_plug->Hmat[1] << "\t" |
376 |
< |
<< entry_plug->Hmat[2] << "\t" |
377 |
< |
|
378 |
< |
<< entry_plug->Hmat[3] << "\t" |
379 |
< |
<< entry_plug->Hmat[4] << "\t" |
380 |
< |
<< entry_plug->Hmat[5] << "\t" |
381 |
< |
|
382 |
< |
<< entry_plug->Hmat[6] << "\t" |
383 |
< |
<< entry_plug->Hmat[7] << "\t" |
384 |
< |
<< entry_plug->Hmat[8] << "\n"; |
385 |
< |
|
386 |
< |
for( i=0; i<nAtoms; i++ ){ |
387 |
< |
|
388 |
< |
sprintf( tempBuffer, |
389 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
390 |
< |
atoms[i]->getType(), |
391 |
< |
atoms[i]->getX(), |
392 |
< |
atoms[i]->getY(), |
393 |
< |
atoms[i]->getZ(), |
394 |
< |
atoms[i]->get_vx(), |
395 |
< |
atoms[i]->get_vy(), |
396 |
< |
atoms[i]->get_vz()); |
397 |
< |
strcpy( writeLine, tempBuffer ); |
398 |
< |
|
399 |
< |
if( atoms[i]->isDirectional() ){ |
400 |
< |
|
401 |
< |
dAtom = (DirectionalAtom *)atoms[i]; |
402 |
< |
dAtom->getQ( q ); |
403 |
< |
|
404 |
< |
sprintf( tempBuffer, |
405 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
406 |
< |
q[0], |
407 |
< |
q[1], |
408 |
< |
q[2], |
409 |
< |
q[3], |
410 |
< |
dAtom->getJx(), |
411 |
< |
dAtom->getJy(), |
412 |
< |
dAtom->getJz()); |
413 |
< |
strcat( writeLine, tempBuffer ); |
414 |
< |
} |
415 |
< |
else |
416 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
417 |
< |
|
418 |
< |
finalOut << writeLine; |
419 |
< |
} |
420 |
< |
finalOut.flush(); |
421 |
< |
finalOut.close(); |
422 |
< |
|
423 |
< |
#else // is_mpi |
424 |
< |
|
425 |
< |
// first thing first, suspend fatalities. |
426 |
< |
painCave.isEventLoop = 1; |
427 |
< |
|
428 |
< |
int myStatus; // 1 = wakeup & success; 0 = error; -1 = AllDone |
429 |
< |
int haveError; |
430 |
< |
|
431 |
< |
MPI_Status istatus; |
432 |
< |
int *AtomToProcMap = mpiSim->getAtomToProcMap(); |
433 |
< |
|
434 |
< |
// write out header and node 0's coordinates |
435 |
< |
|
436 |
< |
haveError = 0; |
437 |
< |
if( worldRank == 0 ){ |
438 |
< |
finalOut << mpiSim->getTotAtoms() << "\n"; |
439 |
< |
|
440 |
< |
finalOut << finalTime << "\t" |
441 |
< |
<< entry_plug->Hmat[0] << "\t" |
442 |
< |
<< entry_plug->Hmat[1] << "\t" |
443 |
< |
<< entry_plug->Hmat[2] << "\t" |
444 |
< |
|
445 |
< |
<< entry_plug->Hmat[3] << "\t" |
446 |
< |
<< entry_plug->Hmat[4] << "\t" |
447 |
< |
<< entry_plug->Hmat[5] << "\t" |
448 |
< |
|
449 |
< |
<< entry_plug->Hmat[6] << "\t" |
450 |
< |
<< entry_plug->Hmat[7] << "\t" |
451 |
< |
<< entry_plug->Hmat[8] << "\n"; |
452 |
< |
|
453 |
< |
for (i = 0 ; i < mpiSim->getTotAtoms(); i++ ) { |
454 |
< |
// Get the Node number which has this molecule: |
455 |
< |
|
456 |
< |
which_node = AtomToProcMap[i]; |
457 |
< |
|
458 |
< |
if (which_node == mpiSim->getMyNode()) { |
459 |
< |
|
460 |
< |
which_atom = i; |
461 |
< |
local_index=-1; |
462 |
< |
for (j=0; (j<mpiSim->getMyNlocal()) && (local_index < 0); j++) { |
463 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
464 |
< |
} |
465 |
< |
if (local_index != -1) { |
466 |
< |
sprintf( tempBuffer, |
467 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
468 |
< |
atoms[local_index]->getType(), |
469 |
< |
atoms[local_index]->getX(), |
470 |
< |
atoms[local_index]->getY(), |
471 |
< |
atoms[local_index]->getZ(), |
472 |
< |
atoms[local_index]->get_vx(), |
473 |
< |
atoms[local_index]->get_vy(), |
474 |
< |
atoms[local_index]->get_vz()); |
475 |
< |
strcpy( writeLine, tempBuffer ); |
476 |
< |
|
477 |
< |
if( atoms[local_index]->isDirectional() ){ |
478 |
< |
|
479 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
480 |
< |
dAtom->getQ( q ); |
481 |
< |
|
482 |
< |
sprintf( tempBuffer, |
483 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
484 |
< |
q[0], |
485 |
< |
q[1], |
486 |
< |
q[2], |
487 |
< |
q[3], |
488 |
< |
dAtom->getJx(), |
489 |
< |
dAtom->getJy(), |
490 |
< |
dAtom->getJz()); |
491 |
< |
strcat( writeLine, tempBuffer ); |
492 |
< |
} |
493 |
< |
else |
494 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
495 |
< |
} |
496 |
< |
else { |
495 |
> |
} else { |
496 |
|
sprintf(painCave.errMsg, |
497 |
|
"Atom %d not found on processor %d\n", |
498 |
|
i, worldRank ); |
499 |
|
haveError= 1; |
500 |
|
simError(); |
501 |
< |
} |
501 |
> |
} |
502 |
|
|
503 |
< |
if(haveError) nodeZeroError(); |
504 |
< |
|
505 |
< |
} |
506 |
< |
else { |
503 |
> |
strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
504 |
> |
|
505 |
> |
// null terminate the string before sending (just in case): |
506 |
> |
MPIatomTypeString[MINIBUFFERSIZE-1] = '\0'; |
507 |
> |
|
508 |
> |
MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
509 |
> |
myPotato, MPI_COMM_WORLD); |
510 |
|
|
511 |
< |
myStatus = 1; |
510 |
< |
MPI_Send(&myStatus, 1, MPI_INT, which_node, |
511 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
512 |
< |
MPI_Send(&i, 1, MPI_INT, which_node, TAKE_THIS_TAG_INT, |
513 |
< |
MPI_COMM_WORLD); |
514 |
< |
MPI_Recv(writeLine, BUFFERSIZE, MPI_CHAR, which_node, |
515 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD, &istatus); |
516 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, which_node, |
517 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
518 |
< |
|
519 |
< |
if(!myStatus) nodeZeroError(); |
520 |
< |
} |
521 |
< |
|
522 |
< |
finalOut << writeLine; |
523 |
< |
} |
524 |
< |
|
525 |
< |
// kill everyone off: |
526 |
< |
myStatus = -1; |
527 |
< |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
528 |
< |
MPI_Send(&myStatus, 1, MPI_INT, j, |
529 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
530 |
< |
} |
511 |
> |
myPotato++; |
512 |
|
|
513 |
< |
} else { |
514 |
< |
|
515 |
< |
done = 0; |
516 |
< |
while (!done) { |
513 |
> |
MPI_Send(&isDirectional, 1, MPI_INT, 0, |
514 |
> |
myPotato, MPI_COMM_WORLD); |
515 |
> |
|
516 |
> |
myPotato++; |
517 |
> |
|
518 |
> |
if (isDirectional) { |
519 |
|
|
520 |
< |
MPI_Recv(&myStatus, 1, MPI_INT, 0, |
521 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
522 |
< |
|
523 |
< |
if(!myStatus) anonymousNodeDie(); |
541 |
< |
|
542 |
< |
if(myStatus < 0) break; |
543 |
< |
|
544 |
< |
MPI_Recv(&which_atom, 1, MPI_INT, 0, |
545 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD, &istatus); |
546 |
< |
|
547 |
< |
myStatus = 1; |
548 |
< |
local_index=-1; |
549 |
< |
for (j=0; j < mpiSim->getMyNlocal(); j++) { |
550 |
< |
if (atoms[j]->getGlobalIndex() == which_atom) local_index = j; |
551 |
< |
} |
552 |
< |
if (local_index != -1) { |
520 |
> |
MPI_Send(atomData13, 13, MPI_DOUBLE, 0, |
521 |
> |
myPotato, MPI_COMM_WORLD); |
522 |
> |
|
523 |
> |
} else { |
524 |
|
|
525 |
< |
//format the line |
526 |
< |
sprintf( tempBuffer, |
527 |
< |
"%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
557 |
< |
atoms[local_index]->getType(), |
558 |
< |
atoms[local_index]->getX(), |
559 |
< |
atoms[local_index]->getY(), |
560 |
< |
atoms[local_index]->getZ(), |
561 |
< |
atoms[local_index]->get_vx(), |
562 |
< |
atoms[local_index]->get_vy(), |
563 |
< |
atoms[local_index]->get_vz()); // check here. |
564 |
< |
strcpy( writeLine, tempBuffer ); |
565 |
< |
|
566 |
< |
if( atoms[local_index]->isDirectional() ){ |
567 |
< |
|
568 |
< |
dAtom = (DirectionalAtom *)atoms[local_index]; |
569 |
< |
dAtom->getQ( q ); |
570 |
< |
|
571 |
< |
sprintf( tempBuffer, |
572 |
< |
"%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
573 |
< |
q[0], |
574 |
< |
q[1], |
575 |
< |
q[2], |
576 |
< |
q[3], |
577 |
< |
dAtom->getJx(), |
578 |
< |
dAtom->getJy(), |
579 |
< |
dAtom->getJz()); |
580 |
< |
strcat( writeLine, tempBuffer ); |
581 |
< |
} |
582 |
< |
else{ |
583 |
< |
strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" ); |
584 |
< |
} |
585 |
< |
} |
586 |
< |
else { |
587 |
< |
sprintf(painCave.errMsg, |
588 |
< |
"Atom %d not found on processor %d\n", |
589 |
< |
which_atom, worldRank ); |
590 |
< |
myStatus = 0; |
591 |
< |
simError(); |
592 |
< |
|
593 |
< |
strcpy( writeLine, "Hello, I'm an error.\n"); |
594 |
< |
} |
525 |
> |
MPI_Send(atomData6, 6, MPI_DOUBLE, 0, |
526 |
> |
myPotato, MPI_COMM_WORLD); |
527 |
> |
} |
528 |
|
|
529 |
< |
MPI_Send(writeLine, BUFFERSIZE, MPI_CHAR, 0, |
530 |
< |
TAKE_THIS_TAG_CHAR, MPI_COMM_WORLD); |
531 |
< |
MPI_Send( &myStatus, 1, MPI_INT, 0, |
599 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
529 |
> |
myPotato++; |
530 |
> |
currentIndex++; |
531 |
> |
} |
532 |
|
} |
533 |
< |
} |
534 |
< |
finalOut.flush(); |
535 |
< |
sprintf( checkPointMsg, |
536 |
< |
"Sucessfully took a dump.\n"); |
537 |
< |
MPIcheckPoint(); |
533 |
> |
|
534 |
> |
sprintf( checkPointMsg, |
535 |
> |
"Sucessfully took a dump.\n"); |
536 |
> |
MPIcheckPoint(); |
537 |
> |
|
538 |
> |
} |
539 |
|
|
607 |
– |
if( worldRank == 0 ) finalOut.close(); |
540 |
|
#endif // is_mpi |
541 |
|
} |
542 |
|
|
611 |
– |
|
612 |
– |
|
543 |
|
#ifdef IS_MPI |
544 |
|
|
545 |
|
// a couple of functions to let us escape the write loop |
546 |
|
|
547 |
< |
void dWrite::nodeZeroError( void ){ |
618 |
< |
int j, myStatus; |
619 |
< |
|
620 |
< |
myStatus = 0; |
621 |
< |
for (j = 0; j < mpiSim->getNumberProcessors(); j++) { |
622 |
< |
MPI_Send( &myStatus, 1, MPI_INT, j, |
623 |
< |
TAKE_THIS_TAG_INT, MPI_COMM_WORLD); |
624 |
< |
} |
625 |
< |
|
547 |
> |
void dWrite::DieDieDie( void ){ |
548 |
|
|
549 |
|
MPI_Finalize(); |
550 |
|
exit (0); |
629 |
– |
|
551 |
|
} |
552 |
|
|
632 |
– |
void dWrite::anonymousNodeDie( void ){ |
633 |
– |
|
634 |
– |
MPI_Finalize(); |
635 |
– |
exit (0); |
636 |
– |
} |
637 |
– |
|
553 |
|
#endif //is_mpi |