1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
42 |
|
#include "io/DumpWriter.hpp" |
43 |
|
#include "primitives/Molecule.hpp" |
44 |
|
#include "utils/simError.h" |
45 |
< |
|
45 |
> |
#include "io/basic_teebuf.hpp" |
46 |
|
#ifdef IS_MPI |
47 |
|
#include <mpi.h> |
48 |
|
#endif //is_mpi |
49 |
|
|
50 |
|
namespace oopse { |
51 |
|
|
52 |
< |
DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) |
53 |
< |
: info_(info), filename_(filename){ |
52 |
> |
DumpWriter::DumpWriter(SimInfo* info) |
53 |
> |
: info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ |
54 |
|
#ifdef IS_MPI |
55 |
|
|
56 |
< |
if (worldRank == 0) { |
56 |
> |
if (worldRank == 0) { |
57 |
|
#endif // is_mpi |
58 |
|
|
59 |
|
dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); |
60 |
|
|
61 |
|
if (!dumpFile_) { |
62 |
< |
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
63 |
< |
filename_.c_str()); |
64 |
< |
painCave.isFatal = 1; |
65 |
< |
simError(); |
62 |
> |
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
63 |
> |
filename_.c_str()); |
64 |
> |
painCave.isFatal = 1; |
65 |
> |
simError(); |
66 |
|
} |
67 |
|
|
68 |
|
#ifdef IS_MPI |
69 |
|
|
70 |
+ |
} |
71 |
+ |
|
72 |
+ |
sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
73 |
+ |
MPIcheckPoint(); |
74 |
+ |
|
75 |
+ |
#endif // is_mpi |
76 |
+ |
|
77 |
|
} |
78 |
|
|
72 |
– |
sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
73 |
– |
MPIcheckPoint(); |
79 |
|
|
80 |
+ |
DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) |
81 |
+ |
: info_(info), filename_(filename){ |
82 |
+ |
#ifdef IS_MPI |
83 |
+ |
|
84 |
+ |
if (worldRank == 0) { |
85 |
|
#endif // is_mpi |
86 |
|
|
87 |
< |
} |
87 |
> |
eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
88 |
> |
dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); |
89 |
|
|
90 |
< |
DumpWriter::~DumpWriter() { |
90 |
> |
if (!dumpFile_) { |
91 |
> |
sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
92 |
> |
filename_.c_str()); |
93 |
> |
painCave.isFatal = 1; |
94 |
> |
simError(); |
95 |
> |
} |
96 |
|
|
97 |
|
#ifdef IS_MPI |
98 |
|
|
99 |
+ |
} |
100 |
+ |
|
101 |
+ |
sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
102 |
+ |
MPIcheckPoint(); |
103 |
+ |
|
104 |
+ |
#endif // is_mpi |
105 |
+ |
|
106 |
+ |
} |
107 |
+ |
|
108 |
+ |
DumpWriter::~DumpWriter() { |
109 |
+ |
|
110 |
+ |
#ifdef IS_MPI |
111 |
+ |
|
112 |
|
if (worldRank == 0) { |
113 |
|
#endif // is_mpi |
114 |
|
|
115 |
< |
dumpFile_.close(); |
115 |
> |
dumpFile_.close(); |
116 |
|
|
117 |
|
#ifdef IS_MPI |
118 |
|
|
120 |
|
|
121 |
|
#endif // is_mpi |
122 |
|
|
123 |
< |
} |
123 |
> |
} |
124 |
|
|
125 |
< |
void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) { |
125 |
> |
void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) { |
126 |
|
|
127 |
|
double currentTime; |
128 |
|
Mat3x3d hmat; |
137 |
|
eta = s->getEta(); |
138 |
|
|
139 |
|
os << currentTime << ";\t" |
140 |
< |
<< hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t" |
141 |
< |
<< hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t" |
142 |
< |
<< hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t"; |
140 |
> |
<< hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t" |
141 |
> |
<< hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t" |
142 |
> |
<< hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t"; |
143 |
|
|
144 |
|
//write out additional parameters, such as chi and eta |
145 |
|
|
146 |
|
os << chi << "\t" << integralOfChiDt << "\t;"; |
147 |
|
|
148 |
|
os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t" |
149 |
< |
<< eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t" |
150 |
< |
<< eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";"; |
149 |
> |
<< eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t" |
150 |
> |
<< eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";"; |
151 |
|
|
152 |
< |
os << std::endl; |
153 |
< |
} |
152 |
> |
os << "\n"; |
153 |
> |
} |
154 |
|
|
155 |
< |
void DumpWriter::writeFrame(std::ostream& os) { |
155 |
> |
void DumpWriter::writeFrame(std::ostream& os) { |
156 |
|
const int BUFFERSIZE = 2000; |
157 |
|
const int MINIBUFFERSIZE = 100; |
158 |
|
|
181 |
|
|
182 |
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
183 |
|
|
184 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
185 |
< |
integrableObject = mol->nextIntegrableObject(ii)) { |
184 |
> |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
185 |
> |
integrableObject = mol->nextIntegrableObject(ii)) { |
186 |
|
|
187 |
|
|
188 |
< |
pos = integrableObject->getPos(); |
189 |
< |
vel = integrableObject->getVel(); |
188 |
> |
pos = integrableObject->getPos(); |
189 |
> |
vel = integrableObject->getVel(); |
190 |
|
|
191 |
< |
sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
192 |
< |
integrableObject->getType().c_str(), |
193 |
< |
pos[0], pos[1], pos[2], |
194 |
< |
vel[0], vel[1], vel[2]); |
191 |
> |
sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
192 |
> |
integrableObject->getType().c_str(), |
193 |
> |
pos[0], pos[1], pos[2], |
194 |
> |
vel[0], vel[1], vel[2]); |
195 |
|
|
196 |
< |
strcpy(writeLine, tempBuffer); |
196 |
> |
strcpy(writeLine, tempBuffer); |
197 |
|
|
198 |
< |
if (integrableObject->isDirectional()) { |
199 |
< |
q = integrableObject->getQ(); |
200 |
< |
ji = integrableObject->getJ(); |
198 |
> |
if (integrableObject->isDirectional()) { |
199 |
> |
q = integrableObject->getQ(); |
200 |
> |
ji = integrableObject->getJ(); |
201 |
|
|
202 |
< |
sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
203 |
< |
q[0], q[1], q[2], q[3], |
204 |
< |
ji[0], ji[1], ji[2]); |
205 |
< |
strcat(writeLine, tempBuffer); |
206 |
< |
} else { |
207 |
< |
strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
208 |
< |
} |
180 |
< |
|
181 |
< |
os << writeLine; |
202 |
> |
sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
203 |
> |
q[0], q[1], q[2], q[3], |
204 |
> |
ji[0], ji[1], ji[2]); |
205 |
> |
strcat(writeLine, tempBuffer); |
206 |
> |
} else { |
207 |
> |
strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
208 |
> |
} |
209 |
|
|
210 |
< |
} |
210 |
> |
os << writeLine; |
211 |
> |
|
212 |
> |
} |
213 |
|
} |
214 |
|
|
215 |
|
os.flush(); |
258 |
|
int which_node; |
259 |
|
double atomData[13]; |
260 |
|
int isDirectional; |
232 |
– |
const char * atomTypeString; |
261 |
|
char MPIatomTypeString[MINIBUFFERSIZE]; |
262 |
|
int msgLen; // the length of message actually recieved at master nodes |
263 |
|
int haveError; |
271 |
|
MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
272 |
|
|
273 |
|
if (flag) { |
274 |
< |
MAXTAG = *tagub; |
274 |
> |
MAXTAG = *tagub; |
275 |
|
} else { |
276 |
< |
MAXTAG = 32767; |
276 |
> |
MAXTAG = 32767; |
277 |
|
} |
278 |
|
|
279 |
|
if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file |
280 |
|
|
281 |
< |
// Node 0 needs a list of the magic potatoes for each processor; |
281 |
> |
// Node 0 needs a list of the magic potatoes for each processor; |
282 |
|
|
283 |
< |
MPI_Comm_size(MPI_COMM_WORLD, &nProc); |
284 |
< |
potatoes = new int[nProc]; |
283 |
> |
MPI_Comm_size(MPI_COMM_WORLD, &nProc); |
284 |
> |
potatoes = new int[nProc]; |
285 |
|
|
286 |
< |
//write out the comment lines |
287 |
< |
for(int i = 0; i < nProc; i++) { |
288 |
< |
potatoes[i] = 0; |
289 |
< |
} |
286 |
> |
//write out the comment lines |
287 |
> |
for(int i = 0; i < nProc; i++) { |
288 |
> |
potatoes[i] = 0; |
289 |
> |
} |
290 |
|
|
291 |
|
|
292 |
< |
os << nTotObjects << "\n"; |
293 |
< |
writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
292 |
> |
os << nTotObjects << "\n"; |
293 |
> |
writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
294 |
|
|
295 |
< |
for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
295 |
> |
for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
296 |
|
|
297 |
< |
// Get the Node number which has this atom; |
297 |
> |
// Get the Node number which has this atom; |
298 |
|
|
299 |
< |
which_node = info_->getMolToProc(i); |
299 |
> |
which_node = info_->getMolToProc(i); |
300 |
|
|
301 |
< |
if (which_node != masterNode) { //current molecule is in slave node |
302 |
< |
if (potatoes[which_node] + 1 >= MAXTAG) { |
303 |
< |
// The potato was going to exceed the maximum value, |
304 |
< |
// so wrap this processor potato back to 0: |
301 |
> |
if (which_node != masterNode) { //current molecule is in slave node |
302 |
> |
if (potatoes[which_node] + 1 >= MAXTAG) { |
303 |
> |
// The potato was going to exceed the maximum value, |
304 |
> |
// so wrap this processor potato back to 0: |
305 |
|
|
306 |
< |
potatoes[which_node] = 0; |
307 |
< |
MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, |
308 |
< |
MPI_COMM_WORLD); |
309 |
< |
} |
306 |
> |
potatoes[which_node] = 0; |
307 |
> |
MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, |
308 |
> |
MPI_COMM_WORLD); |
309 |
> |
} |
310 |
|
|
311 |
< |
myPotato = potatoes[which_node]; |
311 |
> |
myPotato = potatoes[which_node]; |
312 |
|
|
313 |
< |
//recieve the number of integrableObject in current molecule |
314 |
< |
MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato, |
315 |
< |
MPI_COMM_WORLD, &istatus); |
316 |
< |
myPotato++; |
313 |
> |
//recieve the number of integrableObject in current molecule |
314 |
> |
MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato, |
315 |
> |
MPI_COMM_WORLD, &istatus); |
316 |
> |
myPotato++; |
317 |
|
|
318 |
< |
for(int l = 0; l < nCurObj; l++) { |
319 |
< |
if (potatoes[which_node] + 2 >= MAXTAG) { |
320 |
< |
// The potato was going to exceed the maximum value, |
321 |
< |
// so wrap this processor potato back to 0: |
318 |
> |
for(int l = 0; l < nCurObj; l++) { |
319 |
> |
if (potatoes[which_node] + 2 >= MAXTAG) { |
320 |
> |
// The potato was going to exceed the maximum value, |
321 |
> |
// so wrap this processor potato back to 0: |
322 |
|
|
323 |
< |
potatoes[which_node] = 0; |
324 |
< |
MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, |
325 |
< |
0, MPI_COMM_WORLD); |
326 |
< |
} |
323 |
> |
potatoes[which_node] = 0; |
324 |
> |
MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, |
325 |
> |
0, MPI_COMM_WORLD); |
326 |
> |
} |
327 |
|
|
328 |
< |
MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, |
329 |
< |
which_node, myPotato, MPI_COMM_WORLD, |
330 |
< |
&istatus); |
303 |
< |
|
304 |
< |
atomTypeString = MPIatomTypeString; |
328 |
> |
MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, |
329 |
> |
which_node, myPotato, MPI_COMM_WORLD, |
330 |
> |
&istatus); |
331 |
|
|
332 |
< |
myPotato++; |
332 |
> |
myPotato++; |
333 |
|
|
334 |
< |
MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, |
335 |
< |
MPI_COMM_WORLD, &istatus); |
336 |
< |
myPotato++; |
334 |
> |
MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, |
335 |
> |
MPI_COMM_WORLD, &istatus); |
336 |
> |
myPotato++; |
337 |
|
|
338 |
< |
MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen); |
338 |
> |
MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen); |
339 |
|
|
340 |
< |
if (msgLen == 13) |
341 |
< |
isDirectional = 1; |
342 |
< |
else |
343 |
< |
isDirectional = 0; |
340 |
> |
if (msgLen == 13) |
341 |
> |
isDirectional = 1; |
342 |
> |
else |
343 |
> |
isDirectional = 0; |
344 |
|
|
345 |
< |
// If we've survived to here, format the line: |
345 |
> |
// If we've survived to here, format the line: |
346 |
|
|
347 |
< |
if (!isDirectional) { |
348 |
< |
sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
349 |
< |
atomTypeString, atomData[0], |
350 |
< |
atomData[1], atomData[2], |
351 |
< |
atomData[3], atomData[4], |
352 |
< |
atomData[5]); |
347 |
> |
if (!isDirectional) { |
348 |
> |
sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
349 |
> |
MPIatomTypeString, atomData[0], |
350 |
> |
atomData[1], atomData[2], |
351 |
> |
atomData[3], atomData[4], |
352 |
> |
atomData[5]); |
353 |
|
|
354 |
< |
strcat(writeLine, |
355 |
< |
"0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
356 |
< |
} else { |
357 |
< |
sprintf(writeLine, |
358 |
< |
"%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", |
359 |
< |
atomTypeString, |
360 |
< |
atomData[0], |
361 |
< |
atomData[1], |
362 |
< |
atomData[2], |
363 |
< |
atomData[3], |
364 |
< |
atomData[4], |
365 |
< |
atomData[5], |
366 |
< |
atomData[6], |
367 |
< |
atomData[7], |
368 |
< |
atomData[8], |
369 |
< |
atomData[9], |
370 |
< |
atomData[10], |
371 |
< |
atomData[11], |
372 |
< |
atomData[12]); |
373 |
< |
} |
354 |
> |
strcat(writeLine, |
355 |
> |
"0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
356 |
> |
} else { |
357 |
> |
sprintf(writeLine, |
358 |
> |
"%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", |
359 |
> |
MPIatomTypeString, |
360 |
> |
atomData[0], |
361 |
> |
atomData[1], |
362 |
> |
atomData[2], |
363 |
> |
atomData[3], |
364 |
> |
atomData[4], |
365 |
> |
atomData[5], |
366 |
> |
atomData[6], |
367 |
> |
atomData[7], |
368 |
> |
atomData[8], |
369 |
> |
atomData[9], |
370 |
> |
atomData[10], |
371 |
> |
atomData[11], |
372 |
> |
atomData[12]); |
373 |
> |
} |
374 |
|
|
375 |
< |
os << writeLine; |
375 |
> |
os << writeLine; |
376 |
|
|
377 |
< |
} // end for(int l =0) |
377 |
> |
} // end for(int l =0) |
378 |
|
|
379 |
< |
potatoes[which_node] = myPotato; |
380 |
< |
} else { //master node has current molecule |
379 |
> |
potatoes[which_node] = myPotato; |
380 |
> |
} else { //master node has current molecule |
381 |
|
|
382 |
< |
mol = info_->getMoleculeByGlobalIndex(i); |
382 |
> |
mol = info_->getMoleculeByGlobalIndex(i); |
383 |
|
|
384 |
< |
if (mol == NULL) { |
385 |
< |
sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank); |
386 |
< |
painCave.isFatal = 1; |
387 |
< |
simError(); |
388 |
< |
} |
384 |
> |
if (mol == NULL) { |
385 |
> |
sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank); |
386 |
> |
painCave.isFatal = 1; |
387 |
> |
simError(); |
388 |
> |
} |
389 |
|
|
390 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
391 |
< |
integrableObject = mol->nextIntegrableObject(ii)) { |
366 |
< |
|
367 |
< |
atomTypeString = integrableObject->getType().c_str(); |
390 |
> |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
391 |
> |
integrableObject = mol->nextIntegrableObject(ii)) { |
392 |
|
|
393 |
< |
pos = integrableObject->getPos(); |
394 |
< |
vel = integrableObject->getVel(); |
393 |
> |
pos = integrableObject->getPos(); |
394 |
> |
vel = integrableObject->getVel(); |
395 |
|
|
396 |
< |
atomData[0] = pos[0]; |
397 |
< |
atomData[1] = pos[1]; |
398 |
< |
atomData[2] = pos[2]; |
396 |
> |
atomData[0] = pos[0]; |
397 |
> |
atomData[1] = pos[1]; |
398 |
> |
atomData[2] = pos[2]; |
399 |
|
|
400 |
< |
atomData[3] = vel[0]; |
401 |
< |
atomData[4] = vel[1]; |
402 |
< |
atomData[5] = vel[2]; |
400 |
> |
atomData[3] = vel[0]; |
401 |
> |
atomData[4] = vel[1]; |
402 |
> |
atomData[5] = vel[2]; |
403 |
|
|
404 |
< |
isDirectional = 0; |
404 |
> |
isDirectional = 0; |
405 |
|
|
406 |
< |
if (integrableObject->isDirectional()) { |
407 |
< |
isDirectional = 1; |
406 |
> |
if (integrableObject->isDirectional()) { |
407 |
> |
isDirectional = 1; |
408 |
|
|
409 |
< |
q = integrableObject->getQ(); |
410 |
< |
ji = integrableObject->getJ(); |
409 |
> |
q = integrableObject->getQ(); |
410 |
> |
ji = integrableObject->getJ(); |
411 |
|
|
412 |
< |
for(int j = 0; j < 6; j++) { |
413 |
< |
atomData[j] = atomData[j]; |
414 |
< |
} |
412 |
> |
for(int j = 0; j < 6; j++) { |
413 |
> |
atomData[j] = atomData[j]; |
414 |
> |
} |
415 |
|
|
416 |
< |
atomData[6] = q[0]; |
417 |
< |
atomData[7] = q[1]; |
418 |
< |
atomData[8] = q[2]; |
419 |
< |
atomData[9] = q[3]; |
416 |
> |
atomData[6] = q[0]; |
417 |
> |
atomData[7] = q[1]; |
418 |
> |
atomData[8] = q[2]; |
419 |
> |
atomData[9] = q[3]; |
420 |
|
|
421 |
< |
atomData[10] = ji[0]; |
422 |
< |
atomData[11] = ji[1]; |
423 |
< |
atomData[12] = ji[2]; |
424 |
< |
} |
421 |
> |
atomData[10] = ji[0]; |
422 |
> |
atomData[11] = ji[1]; |
423 |
> |
atomData[12] = ji[2]; |
424 |
> |
} |
425 |
|
|
426 |
< |
// If we've survived to here, format the line: |
426 |
> |
// If we've survived to here, format the line: |
427 |
|
|
428 |
< |
if (!isDirectional) { |
429 |
< |
sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
430 |
< |
atomTypeString, atomData[0], |
431 |
< |
atomData[1], atomData[2], |
432 |
< |
atomData[3], atomData[4], |
433 |
< |
atomData[5]); |
428 |
> |
if (!isDirectional) { |
429 |
> |
sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
430 |
> |
integrableObject->getType().c_str(), atomData[0], |
431 |
> |
atomData[1], atomData[2], |
432 |
> |
atomData[3], atomData[4], |
433 |
> |
atomData[5]); |
434 |
|
|
435 |
< |
strcat(writeLine, |
436 |
< |
"0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
437 |
< |
} else { |
438 |
< |
sprintf(writeLine, |
439 |
< |
"%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", |
440 |
< |
atomTypeString, |
441 |
< |
atomData[0], |
442 |
< |
atomData[1], |
443 |
< |
atomData[2], |
444 |
< |
atomData[3], |
445 |
< |
atomData[4], |
446 |
< |
atomData[5], |
447 |
< |
atomData[6], |
448 |
< |
atomData[7], |
449 |
< |
atomData[8], |
450 |
< |
atomData[9], |
451 |
< |
atomData[10], |
452 |
< |
atomData[11], |
453 |
< |
atomData[12]); |
454 |
< |
} |
435 |
> |
strcat(writeLine, |
436 |
> |
"0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
437 |
> |
} else { |
438 |
> |
sprintf(writeLine, |
439 |
> |
"%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", |
440 |
> |
integrableObject->getType().c_str(), |
441 |
> |
atomData[0], |
442 |
> |
atomData[1], |
443 |
> |
atomData[2], |
444 |
> |
atomData[3], |
445 |
> |
atomData[4], |
446 |
> |
atomData[5], |
447 |
> |
atomData[6], |
448 |
> |
atomData[7], |
449 |
> |
atomData[8], |
450 |
> |
atomData[9], |
451 |
> |
atomData[10], |
452 |
> |
atomData[11], |
453 |
> |
atomData[12]); |
454 |
> |
} |
455 |
|
|
456 |
|
|
457 |
< |
os << writeLine; |
457 |
> |
os << writeLine; |
458 |
|
|
459 |
< |
} //end for(iter = integrableObject.begin()) |
460 |
< |
} |
461 |
< |
} //end for(i = 0; i < mpiSim->getNmol()) |
459 |
> |
} //end for(iter = integrableObject.begin()) |
460 |
> |
} |
461 |
> |
} //end for(i = 0; i < mpiSim->getNmol()) |
462 |
|
|
463 |
< |
os.flush(); |
463 |
> |
os.flush(); |
464 |
|
|
465 |
< |
sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
466 |
< |
MPIcheckPoint(); |
465 |
> |
sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
466 |
> |
MPIcheckPoint(); |
467 |
|
|
468 |
< |
delete [] potatoes; |
468 |
> |
delete [] potatoes; |
469 |
|
} else { |
470 |
|
|
471 |
< |
// worldRank != 0, so I'm a remote node. |
471 |
> |
// worldRank != 0, so I'm a remote node. |
472 |
|
|
473 |
< |
// Set my magic potato to 0: |
473 |
> |
// Set my magic potato to 0: |
474 |
|
|
475 |
< |
myPotato = 0; |
475 |
> |
myPotato = 0; |
476 |
|
|
477 |
< |
for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
477 |
> |
for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
478 |
|
|
479 |
< |
// Am I the node which has this integrableObject? |
480 |
< |
int whichNode = info_->getMolToProc(i); |
481 |
< |
if (whichNode == worldRank) { |
482 |
< |
if (myPotato + 1 >= MAXTAG) { |
479 |
> |
// Am I the node which has this integrableObject? |
480 |
> |
int whichNode = info_->getMolToProc(i); |
481 |
> |
if (whichNode == worldRank) { |
482 |
> |
if (myPotato + 1 >= MAXTAG) { |
483 |
|
|
484 |
< |
// The potato was going to exceed the maximum value, |
485 |
< |
// so wrap this processor potato back to 0 (and block until |
486 |
< |
// node 0 says we can go: |
484 |
> |
// The potato was going to exceed the maximum value, |
485 |
> |
// so wrap this processor potato back to 0 (and block until |
486 |
> |
// node 0 says we can go: |
487 |
|
|
488 |
< |
MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
489 |
< |
&istatus); |
490 |
< |
} |
488 |
> |
MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
489 |
> |
&istatus); |
490 |
> |
} |
491 |
|
|
492 |
< |
mol = info_->getMoleculeByGlobalIndex(i); |
492 |
> |
mol = info_->getMoleculeByGlobalIndex(i); |
493 |
|
|
494 |
|
|
495 |
< |
nCurObj = mol->getNIntegrableObjects(); |
495 |
> |
nCurObj = mol->getNIntegrableObjects(); |
496 |
|
|
497 |
< |
MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD); |
498 |
< |
myPotato++; |
497 |
> |
MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD); |
498 |
> |
myPotato++; |
499 |
|
|
500 |
< |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
501 |
< |
integrableObject = mol->nextIntegrableObject(ii)) { |
500 |
> |
for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
501 |
> |
integrableObject = mol->nextIntegrableObject(ii)) { |
502 |
|
|
503 |
< |
if (myPotato + 2 >= MAXTAG) { |
503 |
> |
if (myPotato + 2 >= MAXTAG) { |
504 |
|
|
505 |
< |
// The potato was going to exceed the maximum value, |
506 |
< |
// so wrap this processor potato back to 0 (and block until |
507 |
< |
// node 0 says we can go: |
505 |
> |
// The potato was going to exceed the maximum value, |
506 |
> |
// so wrap this processor potato back to 0 (and block until |
507 |
> |
// node 0 says we can go: |
508 |
|
|
509 |
< |
MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
510 |
< |
&istatus); |
511 |
< |
} |
509 |
> |
MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
510 |
> |
&istatus); |
511 |
> |
} |
512 |
|
|
513 |
< |
atomTypeString = integrableObject->getType().c_str(); |
513 |
> |
pos = integrableObject->getPos(); |
514 |
> |
vel = integrableObject->getVel(); |
515 |
|
|
516 |
< |
pos = integrableObject->getPos(); |
517 |
< |
vel = integrableObject->getVel(); |
516 |
> |
atomData[0] = pos[0]; |
517 |
> |
atomData[1] = pos[1]; |
518 |
> |
atomData[2] = pos[2]; |
519 |
|
|
520 |
< |
atomData[0] = pos[0]; |
521 |
< |
atomData[1] = pos[1]; |
522 |
< |
atomData[2] = pos[2]; |
520 |
> |
atomData[3] = vel[0]; |
521 |
> |
atomData[4] = vel[1]; |
522 |
> |
atomData[5] = vel[2]; |
523 |
|
|
524 |
< |
atomData[3] = vel[0]; |
499 |
< |
atomData[4] = vel[1]; |
500 |
< |
atomData[5] = vel[2]; |
524 |
> |
isDirectional = 0; |
525 |
|
|
526 |
< |
isDirectional = 0; |
526 |
> |
if (integrableObject->isDirectional()) { |
527 |
> |
isDirectional = 1; |
528 |
|
|
529 |
< |
if (integrableObject->isDirectional()) { |
530 |
< |
isDirectional = 1; |
529 |
> |
q = integrableObject->getQ(); |
530 |
> |
ji = integrableObject->getJ(); |
531 |
|
|
532 |
< |
q = integrableObject->getQ(); |
533 |
< |
ji = integrableObject->getJ(); |
532 |
> |
atomData[6] = q[0]; |
533 |
> |
atomData[7] = q[1]; |
534 |
> |
atomData[8] = q[2]; |
535 |
> |
atomData[9] = q[3]; |
536 |
|
|
537 |
< |
atomData[6] = q[0]; |
538 |
< |
atomData[7] = q[1]; |
539 |
< |
atomData[8] = q[2]; |
540 |
< |
atomData[9] = q[3]; |
537 |
> |
atomData[10] = ji[0]; |
538 |
> |
atomData[11] = ji[1]; |
539 |
> |
atomData[12] = ji[2]; |
540 |
> |
} |
541 |
|
|
542 |
< |
atomData[10] = ji[0]; |
516 |
< |
atomData[11] = ji[1]; |
517 |
< |
atomData[12] = ji[2]; |
518 |
< |
} |
542 |
> |
strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE); |
543 |
|
|
544 |
< |
strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
544 |
> |
// null terminate the std::string before sending (just in case): |
545 |
> |
MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0'; |
546 |
|
|
547 |
< |
// null terminate the std::string before sending (just in case): |
548 |
< |
MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0'; |
547 |
> |
MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
548 |
> |
myPotato, MPI_COMM_WORLD); |
549 |
|
|
550 |
< |
MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
526 |
< |
myPotato, MPI_COMM_WORLD); |
550 |
> |
myPotato++; |
551 |
|
|
552 |
< |
myPotato++; |
552 |
> |
if (isDirectional) { |
553 |
> |
MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato, |
554 |
> |
MPI_COMM_WORLD); |
555 |
> |
} else { |
556 |
> |
MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato, |
557 |
> |
MPI_COMM_WORLD); |
558 |
> |
} |
559 |
|
|
560 |
< |
if (isDirectional) { |
561 |
< |
MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato, |
532 |
< |
MPI_COMM_WORLD); |
533 |
< |
} else { |
534 |
< |
MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato, |
535 |
< |
MPI_COMM_WORLD); |
536 |
< |
} |
537 |
< |
|
538 |
< |
myPotato++; |
539 |
< |
} |
560 |
> |
myPotato++; |
561 |
> |
} |
562 |
|
|
563 |
< |
} |
563 |
> |
} |
564 |
|
|
565 |
< |
} |
566 |
< |
sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
567 |
< |
MPIcheckPoint(); |
565 |
> |
} |
566 |
> |
sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
567 |
> |
MPIcheckPoint(); |
568 |
|
} |
569 |
|
|
570 |
|
#endif // is_mpi |
571 |
|
|
572 |
< |
} |
572 |
> |
} |
573 |
|
|
574 |
+ |
void DumpWriter::writeDump() { |
575 |
+ |
writeFrame(dumpFile_); |
576 |
+ |
|
577 |
+ |
} |
578 |
+ |
|
579 |
+ |
void DumpWriter::writeEor() { |
580 |
+ |
std::ofstream eorStream; |
581 |
+ |
|
582 |
+ |
#ifdef IS_MPI |
583 |
+ |
if (worldRank == 0) { |
584 |
+ |
#endif // is_mpi |
585 |
+ |
|
586 |
+ |
eorStream.open(eorFilename_.c_str()); |
587 |
+ |
if (!eorStream.is_open()) { |
588 |
+ |
sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n", |
589 |
+ |
eorFilename_.c_str()); |
590 |
+ |
painCave.isFatal = 1; |
591 |
+ |
simError(); |
592 |
+ |
} |
593 |
+ |
|
594 |
+ |
#ifdef IS_MPI |
595 |
+ |
} |
596 |
+ |
#endif // is_mpi |
597 |
+ |
|
598 |
+ |
writeFrame(eorStream); |
599 |
+ |
} |
600 |
+ |
|
601 |
+ |
|
602 |
+ |
void DumpWriter::writeDumpAndEor() { |
603 |
+ |
std::ofstream eorStream; |
604 |
+ |
std::vector<std::streambuf*> buffers; |
605 |
+ |
#ifdef IS_MPI |
606 |
+ |
if (worldRank == 0) { |
607 |
+ |
#endif // is_mpi |
608 |
+ |
|
609 |
+ |
buffers.push_back(dumpFile_.rdbuf()); |
610 |
+ |
|
611 |
+ |
eorStream.open(eorFilename_.c_str()); |
612 |
+ |
if (!eorStream.is_open()) { |
613 |
+ |
sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n", |
614 |
+ |
eorFilename_.c_str()); |
615 |
+ |
painCave.isFatal = 1; |
616 |
+ |
simError(); |
617 |
+ |
} |
618 |
+ |
|
619 |
+ |
buffers.push_back(eorStream.rdbuf()); |
620 |
+ |
|
621 |
+ |
#ifdef IS_MPI |
622 |
+ |
} |
623 |
+ |
#endif // is_mpi |
624 |
+ |
|
625 |
+ |
TeeBuf tbuf(buffers.begin(), buffers.end()); |
626 |
+ |
std::ostream os(&tbuf); |
627 |
+ |
|
628 |
+ |
writeFrame(os); |
629 |
+ |
|
630 |
+ |
} |
631 |
+ |
|
632 |
+ |
|
633 |
+ |
|
634 |
|
}//end namespace oopse |