# | Line 1 | Line 1 | |
---|---|---|
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 | |
# | Line 42 | Line 42 | |
42 | #include "io/DumpWriter.hpp" | |
43 | #include "primitives/Molecule.hpp" | |
44 | #include "utils/simError.h" | |
45 | + | #include "io/basic_teebuf.hpp" |
46 | + | #include "io/gzstream.hpp" |
47 | + | #include "io/Globals.hpp" |
48 | ||
49 | #ifdef IS_MPI | |
50 | #include <mpi.h> | |
# | Line 49 | Line 52 | namespace oopse { | |
52 | ||
53 | namespace oopse { | |
54 | ||
55 | < | DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) |
56 | < | : info_(info), filename_(filename){ |
55 | > | DumpWriter::DumpWriter(SimInfo* info) |
56 | > | : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ |
57 | > | |
58 | > | Globals* simParams = info->getSimParams(); |
59 | > | needCompression_ = simParams->getCompressDumpFile(); |
60 | > | needForceVector_ = simParams->getOutputForceVector(); |
61 | > | createDumpFile_ = true; |
62 | > | #ifdef HAVE_LIBZ |
63 | > | if (needCompression_) { |
64 | > | filename_ += ".gz"; |
65 | > | eorFilename_ += ".gz"; |
66 | > | } |
67 | > | #endif |
68 | > | |
69 | #ifdef IS_MPI | |
70 | ||
71 | if (worldRank == 0) { | |
72 | #endif // is_mpi | |
73 | + | |
74 | + | dumpFile_ = createOStream(filename_); |
75 | ||
76 | < | dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); |
76 | > | if (!dumpFile_) { |
77 | > | sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
78 | > | filename_.c_str()); |
79 | > | painCave.isFatal = 1; |
80 | > | simError(); |
81 | > | } |
82 | ||
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(); |
66 | – | } |
67 | – | |
83 | #ifdef IS_MPI | |
84 | ||
85 | } | |
86 | ||
87 | < | sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
73 | < | MPIcheckPoint(); |
87 | > | #endif // is_mpi |
88 | ||
89 | + | } |
90 | + | |
91 | + | |
92 | + | DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) |
93 | + | : info_(info), filename_(filename){ |
94 | + | |
95 | + | Globals* simParams = info->getSimParams(); |
96 | + | eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
97 | + | |
98 | + | needCompression_ = simParams->getCompressDumpFile(); |
99 | + | needForceVector_ = simParams->getOutputForceVector(); |
100 | + | createDumpFile_ = true; |
101 | + | #ifdef HAVE_LIBZ |
102 | + | if (needCompression_) { |
103 | + | filename_ += ".gz"; |
104 | + | eorFilename_ += ".gz"; |
105 | + | } |
106 | + | #endif |
107 | + | |
108 | + | #ifdef IS_MPI |
109 | + | |
110 | + | if (worldRank == 0) { |
111 | #endif // is_mpi | |
112 | ||
113 | < | } |
113 | > | |
114 | > | dumpFile_ = createOStream(filename_); |
115 | ||
116 | < | DumpWriter::~DumpWriter() { |
116 | > | if (!dumpFile_) { |
117 | > | sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
118 | > | filename_.c_str()); |
119 | > | painCave.isFatal = 1; |
120 | > | simError(); |
121 | > | } |
122 | ||
123 | #ifdef IS_MPI | |
124 | ||
125 | + | } |
126 | + | |
127 | + | #endif // is_mpi |
128 | + | |
129 | + | } |
130 | + | |
131 | + | DumpWriter::DumpWriter(SimInfo* info, const std::string& filename, bool writeDumpFile) |
132 | + | : info_(info), filename_(filename){ |
133 | + | |
134 | + | Globals* simParams = info->getSimParams(); |
135 | + | eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
136 | + | |
137 | + | needCompression_ = simParams->getCompressDumpFile(); |
138 | + | needForceVector_ = simParams->getOutputForceVector(); |
139 | + | |
140 | + | #ifdef HAVE_LIBZ |
141 | + | if (needCompression_) { |
142 | + | filename_ += ".gz"; |
143 | + | eorFilename_ += ".gz"; |
144 | + | } |
145 | + | #endif |
146 | + | |
147 | + | #ifdef IS_MPI |
148 | + | |
149 | if (worldRank == 0) { | |
150 | #endif // is_mpi | |
151 | + | |
152 | + | createDumpFile_ = writeDumpFile; |
153 | + | if (createDumpFile_) { |
154 | + | dumpFile_ = createOStream(filename_); |
155 | + | |
156 | + | if (!dumpFile_) { |
157 | + | sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", |
158 | + | filename_.c_str()); |
159 | + | painCave.isFatal = 1; |
160 | + | simError(); |
161 | + | } |
162 | + | } |
163 | + | #ifdef IS_MPI |
164 | + | |
165 | + | } |
166 | ||
167 | < | dumpFile_.close(); |
167 | > | |
168 | > | #endif // is_mpi |
169 | > | |
170 | > | } |
171 | ||
172 | + | DumpWriter::~DumpWriter() { |
173 | + | |
174 | #ifdef IS_MPI | |
175 | ||
176 | + | if (worldRank == 0) { |
177 | + | #endif // is_mpi |
178 | + | if (createDumpFile_){ |
179 | + | writeClosing(*dumpFile_); |
180 | + | delete dumpFile_; |
181 | + | } |
182 | + | #ifdef IS_MPI |
183 | + | |
184 | } | |
185 | ||
186 | #endif // is_mpi | |
187 | ||
188 | < | } |
188 | > | } |
189 | ||
190 | < | void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) { |
190 | > | void DumpWriter::writeFrameProperties(std::ostream& os, Snapshot* s) { |
191 | ||
192 | < | double currentTime; |
192 | > | char buffer[1024]; |
193 | > | |
194 | > | os << " <FrameData>\n"; |
195 | > | |
196 | > | RealType currentTime = s->getTime(); |
197 | > | sprintf(buffer, " Time: %.10g\n", currentTime); |
198 | > | os << buffer; |
199 | > | |
200 | Mat3x3d hmat; | |
100 | – | double chi; |
101 | – | double integralOfChiDt; |
102 | – | Mat3x3d eta; |
103 | – | |
104 | – | currentTime = s->getTime(); |
201 | hmat = s->getHmat(); | |
202 | < | chi = s->getChi(); |
203 | < | integralOfChiDt = s->getIntegralOfChiDt(); |
204 | < | eta = s->getEta(); |
205 | < | |
206 | < | os << currentTime << ";\t" |
111 | < | << hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t" |
112 | < | << hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t" |
113 | < | << hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t"; |
202 | > | sprintf(buffer, " Hmat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n", |
203 | > | hmat(0, 0), hmat(1, 0), hmat(2, 0), |
204 | > | hmat(0, 1), hmat(1, 1), hmat(2, 1), |
205 | > | hmat(0, 2), hmat(1, 2), hmat(2, 2)); |
206 | > | os << buffer; |
207 | ||
208 | < | //write out additional parameters, such as chi and eta |
208 | > | RealType chi = s->getChi(); |
209 | > | RealType integralOfChiDt = s->getIntegralOfChiDt(); |
210 | > | sprintf(buffer, " Thermostat: %.10g , %.10g\n", chi, integralOfChiDt); |
211 | > | os << buffer; |
212 | ||
213 | < | os << chi << "\t" << integralOfChiDt << "\t;"; |
213 | > | Mat3x3d eta; |
214 | > | eta = s->getEta(); |
215 | > | sprintf(buffer, " Barostat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n", |
216 | > | eta(0, 0), eta(1, 0), eta(2, 0), |
217 | > | eta(0, 1), eta(1, 1), eta(2, 1), |
218 | > | eta(0, 2), eta(1, 2), eta(2, 2)); |
219 | > | os << buffer; |
220 | ||
221 | < | os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t" |
222 | < | << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t" |
121 | < | << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";"; |
122 | < | |
123 | < | os << std::endl; |
124 | < | } |
221 | > | os << " </FrameData>\n"; |
222 | > | } |
223 | ||
224 | < | void DumpWriter::writeFrame(std::ostream& os) { |
127 | < | const int BUFFERSIZE = 2000; |
128 | < | const int MINIBUFFERSIZE = 100; |
224 | > | void DumpWriter::writeFrame(std::ostream& os) { |
225 | ||
226 | < | char tempBuffer[BUFFERSIZE]; |
227 | < | char writeLine[BUFFERSIZE]; |
226 | > | #ifdef IS_MPI |
227 | > | MPI_Status istatus; |
228 | > | #endif |
229 | ||
133 | – | Quat4d q; |
134 | – | Vector3d ji; |
135 | – | Vector3d pos; |
136 | – | Vector3d vel; |
137 | – | |
230 | Molecule* mol; | |
231 | StuntDouble* integrableObject; | |
232 | SimInfo::MoleculeIterator mi; | |
233 | Molecule::IntegrableObjectIterator ii; | |
142 | – | |
143 | – | int nTotObjects; |
144 | – | nTotObjects = info_->getNGlobalIntegrableObjects(); |
234 | ||
235 | #ifndef IS_MPI | |
236 | < | |
237 | < | |
238 | < | os << nTotObjects << "\n"; |
150 | < | |
151 | < | writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
236 | > | os << " <Snapshot>\n"; |
237 | > | |
238 | > | writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
239 | ||
240 | + | os << " <StuntDoubles>\n"; |
241 | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | |
242 | ||
243 | < | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
244 | < | integrableObject = mol->nextIntegrableObject(ii)) { |
245 | < | |
243 | > | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
244 | > | integrableObject = mol->nextIntegrableObject(ii)) { |
245 | > | os << prepareDumpLine(integrableObject); |
246 | ||
247 | < | pos = integrableObject->getPos(); |
248 | < | vel = integrableObject->getVel(); |
247 | > | } |
248 | > | } |
249 | > | os << " </StuntDoubles>\n"; |
250 | ||
251 | < | sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
163 | < | integrableObject->getType().c_str(), |
164 | < | pos[0], pos[1], pos[2], |
165 | < | vel[0], vel[1], vel[2]); |
251 | > | os << " </Snapshot>\n"; |
252 | ||
253 | < | strcpy(writeLine, tempBuffer); |
253 | > | os.flush(); |
254 | > | #else |
255 | > | //every node prepares the dump lines for integrable objects belong to itself |
256 | > | std::string buffer; |
257 | > | for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
258 | > | |
259 | > | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
260 | > | integrableObject = mol->nextIntegrableObject(ii)) { |
261 | > | buffer += prepareDumpLine(integrableObject); |
262 | > | } |
263 | > | } |
264 | > | |
265 | > | const int masterNode = 0; |
266 | ||
267 | < | if (integrableObject->isDirectional()) { |
268 | < | q = integrableObject->getQ(); |
269 | < | ji = integrableObject->getJ(); |
267 | > | if (worldRank == masterNode) { |
268 | > | os << " <Snapshot>\n"; |
269 | > | writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
270 | > | os << " <StuntDoubles>\n"; |
271 | > | |
272 | > | os << buffer; |
273 | ||
274 | < | sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", |
275 | < | q[0], q[1], q[2], q[3], |
276 | < | ji[0], ji[1], ji[2]); |
176 | < | strcat(writeLine, tempBuffer); |
177 | < | } else { |
178 | < | strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
179 | < | } |
274 | > | int nProc; |
275 | > | MPI_Comm_size(MPI_COMM_WORLD, &nProc); |
276 | > | for (int i = 1; i < nProc; ++i) { |
277 | ||
278 | < | os << writeLine; |
278 | > | // receive the length of the string buffer that was |
279 | > | // prepared by processor i |
280 | ||
281 | + | int recvLength; |
282 | + | MPI_Recv(&recvLength, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &istatus); |
283 | + | char* recvBuffer = new char[recvLength]; |
284 | + | if (recvBuffer == NULL) { |
285 | + | } else { |
286 | + | MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, 0, MPI_COMM_WORLD, &istatus); |
287 | + | os << recvBuffer; |
288 | + | delete recvBuffer; |
289 | } | |
290 | < | } |
291 | < | |
292 | < | os.flush(); |
293 | < | #else // is_mpi |
294 | < | /********************************************************************* |
189 | < | * Documentation? You want DOCUMENTATION? |
190 | < | * |
191 | < | * Why all the potatoes below? |
192 | < | * |
193 | < | * To make a long story short, the original version of DumpWriter |
194 | < | * worked in the most inefficient way possible. Node 0 would |
195 | < | * poke each of the node for an individual atom's formatted data |
196 | < | * as node 0 worked its way down the global index. This was particularly |
197 | < | * inefficient since the method blocked all processors at every atom |
198 | < | * (and did it twice!). |
199 | < | * |
200 | < | * An intermediate version of DumpWriter could be described from Node |
201 | < | * zero's perspective as follows: |
202 | < | * |
203 | < | * 1) Have 100 of your friends stand in a circle. |
204 | < | * 2) When you say go, have all of them start tossing potatoes at |
205 | < | * you (one at a time). |
206 | < | * 3) Catch the potatoes. |
207 | < | * |
208 | < | * It was an improvement, but MPI has buffers and caches that could |
209 | < | * best be described in this analogy as "potato nets", so there's no |
210 | < | * need to block the processors atom-by-atom. |
211 | < | * |
212 | < | * This new and improved DumpWriter works in an even more efficient |
213 | < | * way: |
214 | < | * |
215 | < | * 1) Have 100 of your friend stand in a circle. |
216 | < | * 2) When you say go, have them start tossing 5-pound bags of |
217 | < | * potatoes at you. |
218 | < | * 3) Once you've caught a friend's bag of potatoes, |
219 | < | * toss them a spud to let them know they can toss another bag. |
220 | < | * |
221 | < | * How's THAT for documentation? |
222 | < | * |
223 | < | *********************************************************************/ |
224 | < | const int masterNode = 0; |
225 | < | |
226 | < | int * potatoes; |
227 | < | int myPotato; |
228 | < | int nProc; |
229 | < | int which_node; |
230 | < | double atomData[13]; |
231 | < | int isDirectional; |
232 | < | const char * atomTypeString; |
233 | < | char MPIatomTypeString[MINIBUFFERSIZE]; |
234 | < | int msgLen; // the length of message actually recieved at master nodes |
235 | < | int haveError; |
236 | < | MPI_Status istatus; |
237 | < | int nCurObj; |
238 | < | |
239 | < | // code to find maximum tag value |
240 | < | int * tagub; |
241 | < | int flag; |
242 | < | int MAXTAG; |
243 | < | MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
244 | < | |
245 | < | if (flag) { |
246 | < | MAXTAG = *tagub; |
290 | > | } |
291 | > | os << " </StuntDoubles>\n"; |
292 | > | |
293 | > | os << " </Snapshot>\n"; |
294 | > | os.flush(); |
295 | } else { | |
296 | < | MAXTAG = 32767; |
296 | > | int sendBufferLength = buffer.size() + 1; |
297 | > | MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); |
298 | > | MPI_Send((void *)buffer.c_str(), sendBufferLength, MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); |
299 | } | |
300 | ||
301 | < | if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file |
301 | > | #endif // is_mpi |
302 | ||
303 | < | // Node 0 needs a list of the magic potatoes for each processor; |
303 | > | } |
304 | ||
305 | < | MPI_Comm_size(MPI_COMM_WORLD, &nProc); |
306 | < | potatoes = new int[nProc]; |
305 | > | std::string DumpWriter::prepareDumpLine(StuntDouble* integrableObject) { |
306 | > | |
307 | > | int index = integrableObject->getGlobalIntegrableObjectIndex(); |
308 | > | std::string type("pv"); |
309 | > | std::string line; |
310 | > | char tempBuffer[4096]; |
311 | ||
312 | < | //write out the comment lines |
313 | < | for(int i = 0; i < nProc; i++) { |
314 | < | potatoes[i] = 0; |
315 | < | } |
312 | > | Vector3d pos; |
313 | > | Vector3d vel; |
314 | > | pos = integrableObject->getPos(); |
315 | > | vel = integrableObject->getVel(); |
316 | > | sprintf(tempBuffer, "%18.10g %18.10g %18.10g %13e %13e %13e", |
317 | > | pos[0], pos[1], pos[2], |
318 | > | vel[0], vel[1], vel[2]); |
319 | > | line += tempBuffer; |
320 | ||
321 | < | |
322 | < | os << nTotObjects << "\n"; |
323 | < | writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
324 | < | |
325 | < | for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
326 | < | |
327 | < | // Get the Node number which has this atom; |
328 | < | |
329 | < | which_node = info_->getMolToProc(i); |
330 | < | |
331 | < | if (which_node != masterNode) { //current molecule is in slave node |
274 | < | if (potatoes[which_node] + 1 >= MAXTAG) { |
275 | < | // The potato was going to exceed the maximum value, |
276 | < | // so wrap this processor potato back to 0: |
277 | < | |
278 | < | potatoes[which_node] = 0; |
279 | < | MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, |
280 | < | MPI_COMM_WORLD); |
281 | < | } |
282 | < | |
283 | < | myPotato = potatoes[which_node]; |
321 | > | if (integrableObject->isDirectional()) { |
322 | > | type += "qj"; |
323 | > | Quat4d q; |
324 | > | Vector3d ji; |
325 | > | q = integrableObject->getQ(); |
326 | > | ji = integrableObject->getJ(); |
327 | > | sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e %13e", |
328 | > | q[0], q[1], q[2], q[3], |
329 | > | ji[0], ji[1], ji[2]); |
330 | > | line += tempBuffer; |
331 | > | } |
332 | ||
333 | < | //recieve the number of integrableObject in current molecule |
334 | < | MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato, |
335 | < | MPI_COMM_WORLD, &istatus); |
336 | < | myPotato++; |
333 | > | if (needForceVector_) { |
334 | > | type += "ft"; |
335 | > | Vector3d frc; |
336 | > | Vector3d trq; |
337 | > | frc = integrableObject->getFrc(); |
338 | > | trq = integrableObject->getTrq(); |
339 | > | |
340 | > | sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e", |
341 | > | frc[0], frc[1], frc[2], |
342 | > | trq[0], trq[1], trq[2]); |
343 | > | line += tempBuffer; |
344 | > | } |
345 | > | |
346 | > | sprintf(tempBuffer, "%10d %7s %s\n", index, type.c_str(), line.c_str()); |
347 | > | return std::string(tempBuffer); |
348 | > | } |
349 | ||
350 | < | for(int l = 0; l < nCurObj; l++) { |
351 | < | if (potatoes[which_node] + 2 >= MAXTAG) { |
352 | < | // The potato was going to exceed the maximum value, |
293 | < | // so wrap this processor potato back to 0: |
350 | > | void DumpWriter::writeDump() { |
351 | > | writeFrame(*dumpFile_); |
352 | > | } |
353 | ||
354 | < | potatoes[which_node] = 0; |
355 | < | MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, |
356 | < | 0, MPI_COMM_WORLD); |
357 | < | } |
354 | > | void DumpWriter::writeEor() { |
355 | > | std::ostream* eorStream; |
356 | > | |
357 | > | #ifdef IS_MPI |
358 | > | if (worldRank == 0) { |
359 | > | #endif // is_mpi |
360 | ||
361 | < | MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, |
301 | < | which_node, myPotato, MPI_COMM_WORLD, |
302 | < | &istatus); |
361 | > | eorStream = createOStream(eorFilename_); |
362 | ||
363 | < | atomTypeString = MPIatomTypeString; |
363 | > | #ifdef IS_MPI |
364 | > | } |
365 | > | #endif // is_mpi |
366 | ||
367 | < | myPotato++; |
367 | > | writeFrame(*eorStream); |
368 | ||
369 | < | MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, |
370 | < | MPI_COMM_WORLD, &istatus); |
371 | < | myPotato++; |
369 | > | #ifdef IS_MPI |
370 | > | if (worldRank == 0) { |
371 | > | #endif // is_mpi |
372 | > | writeClosing(*eorStream); |
373 | > | delete eorStream; |
374 | > | #ifdef IS_MPI |
375 | > | } |
376 | > | #endif // is_mpi |
377 | ||
378 | < | MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen); |
378 | > | } |
379 | ||
314 | – | if (msgLen == 13) |
315 | – | isDirectional = 1; |
316 | – | else |
317 | – | isDirectional = 0; |
380 | ||
381 | < | // If we've survived to here, format the line: |
381 | > | void DumpWriter::writeDumpAndEor() { |
382 | > | std::vector<std::streambuf*> buffers; |
383 | > | std::ostream* eorStream; |
384 | > | #ifdef IS_MPI |
385 | > | if (worldRank == 0) { |
386 | > | #endif // is_mpi |
387 | ||
388 | < | if (!isDirectional) { |
322 | < | sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
323 | < | atomTypeString, atomData[0], |
324 | < | atomData[1], atomData[2], |
325 | < | atomData[3], atomData[4], |
326 | < | atomData[5]); |
388 | > | buffers.push_back(dumpFile_->rdbuf()); |
389 | ||
390 | < | strcat(writeLine, |
329 | < | "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
330 | < | } else { |
331 | < | sprintf(writeLine, |
332 | < | "%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", |
333 | < | atomTypeString, |
334 | < | atomData[0], |
335 | < | atomData[1], |
336 | < | atomData[2], |
337 | < | atomData[3], |
338 | < | atomData[4], |
339 | < | atomData[5], |
340 | < | atomData[6], |
341 | < | atomData[7], |
342 | < | atomData[8], |
343 | < | atomData[9], |
344 | < | atomData[10], |
345 | < | atomData[11], |
346 | < | atomData[12]); |
347 | < | } |
390 | > | eorStream = createOStream(eorFilename_); |
391 | ||
392 | < | os << writeLine; |
350 | < | |
351 | < | } // end for(int l =0) |
352 | < | |
353 | < | potatoes[which_node] = myPotato; |
354 | < | } else { //master node has current molecule |
355 | < | |
356 | < | mol = info_->getMoleculeByGlobalIndex(i); |
357 | < | |
358 | < | if (mol == NULL) { |
359 | < | sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank); |
360 | < | painCave.isFatal = 1; |
361 | < | simError(); |
362 | < | } |
363 | < | |
364 | < | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
365 | < | integrableObject = mol->nextIntegrableObject(ii)) { |
366 | < | |
367 | < | atomTypeString = integrableObject->getType().c_str(); |
368 | < | |
369 | < | pos = integrableObject->getPos(); |
370 | < | vel = integrableObject->getVel(); |
371 | < | |
372 | < | atomData[0] = pos[0]; |
373 | < | atomData[1] = pos[1]; |
374 | < | atomData[2] = pos[2]; |
375 | < | |
376 | < | atomData[3] = vel[0]; |
377 | < | atomData[4] = vel[1]; |
378 | < | atomData[5] = vel[2]; |
379 | < | |
380 | < | isDirectional = 0; |
381 | < | |
382 | < | if (integrableObject->isDirectional()) { |
383 | < | isDirectional = 1; |
384 | < | |
385 | < | q = integrableObject->getQ(); |
386 | < | ji = integrableObject->getJ(); |
387 | < | |
388 | < | for(int j = 0; j < 6; j++) { |
389 | < | atomData[j] = atomData[j]; |
390 | < | } |
391 | < | |
392 | < | atomData[6] = q[0]; |
393 | < | atomData[7] = q[1]; |
394 | < | atomData[8] = q[2]; |
395 | < | atomData[9] = q[3]; |
396 | < | |
397 | < | atomData[10] = ji[0]; |
398 | < | atomData[11] = ji[1]; |
399 | < | atomData[12] = ji[2]; |
400 | < | } |
401 | < | |
402 | < | // If we've survived to here, format the line: |
403 | < | |
404 | < | if (!isDirectional) { |
405 | < | sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
406 | < | atomTypeString, atomData[0], |
407 | < | atomData[1], atomData[2], |
408 | < | atomData[3], atomData[4], |
409 | < | atomData[5]); |
410 | < | |
411 | < | strcat(writeLine, |
412 | < | "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
413 | < | } else { |
414 | < | sprintf(writeLine, |
415 | < | "%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", |
416 | < | atomTypeString, |
417 | < | atomData[0], |
418 | < | atomData[1], |
419 | < | atomData[2], |
420 | < | atomData[3], |
421 | < | atomData[4], |
422 | < | atomData[5], |
423 | < | atomData[6], |
424 | < | atomData[7], |
425 | < | atomData[8], |
426 | < | atomData[9], |
427 | < | atomData[10], |
428 | < | atomData[11], |
429 | < | atomData[12]); |
430 | < | } |
431 | < | |
432 | < | |
433 | < | os << writeLine; |
434 | < | |
435 | < | } //end for(iter = integrableObject.begin()) |
436 | < | } |
437 | < | } //end for(i = 0; i < mpiSim->getNmol()) |
438 | < | |
439 | < | os.flush(); |
392 | > | buffers.push_back(eorStream->rdbuf()); |
393 | ||
394 | < | sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
395 | < | MPIcheckPoint(); |
394 | > | #ifdef IS_MPI |
395 | > | } |
396 | > | #endif // is_mpi |
397 | ||
398 | < | delete [] potatoes; |
399 | < | } else { |
398 | > | TeeBuf tbuf(buffers.begin(), buffers.end()); |
399 | > | std::ostream os(&tbuf); |
400 | ||
401 | < | // worldRank != 0, so I'm a remote node. |
401 | > | writeFrame(os); |
402 | ||
403 | < | // Set my magic potato to 0: |
403 | > | #ifdef IS_MPI |
404 | > | if (worldRank == 0) { |
405 | > | #endif // is_mpi |
406 | > | writeClosing(*eorStream); |
407 | > | delete eorStream; |
408 | > | #ifdef IS_MPI |
409 | > | } |
410 | > | #endif // is_mpi |
411 | > | |
412 | > | } |
413 | ||
414 | < | myPotato = 0; |
414 | > | std::ostream* DumpWriter::createOStream(const std::string& filename) { |
415 | ||
416 | < | for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
417 | < | |
418 | < | // Am I the node which has this integrableObject? |
419 | < | int whichNode = info_->getMolToProc(i); |
420 | < | if (whichNode == worldRank) { |
421 | < | if (myPotato + 1 >= MAXTAG) { |
459 | < | |
460 | < | // The potato was going to exceed the maximum value, |
461 | < | // so wrap this processor potato back to 0 (and block until |
462 | < | // node 0 says we can go: |
463 | < | |
464 | < | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
465 | < | &istatus); |
466 | < | } |
467 | < | |
468 | < | mol = info_->getMoleculeByGlobalIndex(i); |
469 | < | |
470 | < | |
471 | < | nCurObj = mol->getNIntegrableObjects(); |
472 | < | |
473 | < | MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD); |
474 | < | myPotato++; |
475 | < | |
476 | < | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
477 | < | integrableObject = mol->nextIntegrableObject(ii)) { |
478 | < | |
479 | < | if (myPotato + 2 >= MAXTAG) { |
480 | < | |
481 | < | // The potato was going to exceed the maximum value, |
482 | < | // so wrap this processor potato back to 0 (and block until |
483 | < | // node 0 says we can go: |
484 | < | |
485 | < | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
486 | < | &istatus); |
487 | < | } |
488 | < | |
489 | < | atomTypeString = integrableObject->getType().c_str(); |
490 | < | |
491 | < | pos = integrableObject->getPos(); |
492 | < | vel = integrableObject->getVel(); |
493 | < | |
494 | < | atomData[0] = pos[0]; |
495 | < | atomData[1] = pos[1]; |
496 | < | atomData[2] = pos[2]; |
497 | < | |
498 | < | atomData[3] = vel[0]; |
499 | < | atomData[4] = vel[1]; |
500 | < | atomData[5] = vel[2]; |
501 | < | |
502 | < | isDirectional = 0; |
503 | < | |
504 | < | if (integrableObject->isDirectional()) { |
505 | < | isDirectional = 1; |
506 | < | |
507 | < | q = integrableObject->getQ(); |
508 | < | ji = integrableObject->getJ(); |
509 | < | |
510 | < | atomData[6] = q[0]; |
511 | < | atomData[7] = q[1]; |
512 | < | atomData[8] = q[2]; |
513 | < | atomData[9] = q[3]; |
514 | < | |
515 | < | atomData[10] = ji[0]; |
516 | < | atomData[11] = ji[1]; |
517 | < | atomData[12] = ji[2]; |
518 | < | } |
519 | < | |
520 | < | strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
521 | < | |
522 | < | // null terminate the std::string before sending (just in case): |
523 | < | MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0'; |
524 | < | |
525 | < | MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
526 | < | myPotato, MPI_COMM_WORLD); |
527 | < | |
528 | < | myPotato++; |
529 | < | |
530 | < | if (isDirectional) { |
531 | < | 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 | < | } |
540 | < | |
541 | < | } |
542 | < | |
543 | < | } |
544 | < | sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
545 | < | MPIcheckPoint(); |
416 | > | std::ostream* newOStream; |
417 | > | #ifdef HAVE_LIBZ |
418 | > | if (needCompression_) { |
419 | > | newOStream = new ogzstream(filename.c_str()); |
420 | > | } else { |
421 | > | newOStream = new std::ofstream(filename.c_str()); |
422 | } | |
423 | + | #else |
424 | + | newOStream = new std::ofstream(filename.c_str()); |
425 | + | #endif |
426 | + | //write out MetaData first |
427 | + | (*newOStream) << "<OOPSE version=4>" << std::endl; |
428 | + | (*newOStream) << " <MetaData>" << std::endl; |
429 | + | (*newOStream) << info_->getRawMetaData(); |
430 | + | (*newOStream) << " </MetaData>" << std::endl; |
431 | + | return newOStream; |
432 | + | } |
433 | ||
434 | < | #endif // is_mpi |
434 | > | void DumpWriter::writeClosing(std::ostream& os) { |
435 | ||
436 | < | } |
436 | > | os << "</OOPSE>\n"; |
437 | > | os.flush(); |
438 | > | } |
439 | ||
440 | }//end namespace oopse |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |