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