# | 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 43 | Line 43 | |
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> | |
51 | #endif //is_mpi | |
52 | ||
53 | namespace oopse { | |
54 | ||
55 | < | DumpWriter::DumpWriter(SimInfo* info) |
56 | < | : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ |
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 | ||
72 | – | sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
73 | – | MPIcheckPoint(); |
74 | – | |
87 | #endif // is_mpi | |
88 | ||
89 | < | } |
89 | > | } |
90 | ||
91 | ||
92 | < | DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) |
93 | < | : info_(info), filename_(filename){ |
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 | < | eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; |
114 | < | dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc); |
113 | > | |
114 | > | dumpFile_ = createOStream(filename_); |
115 | ||
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 | < | } |
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 | < | sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n"); |
102 | < | MPIcheckPoint(); |
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 | < | } |
167 | > | |
168 | > | #endif // is_mpi |
169 | > | |
170 | > | } |
171 | ||
172 | < | DumpWriter::~DumpWriter() { |
172 | > | DumpWriter::~DumpWriter() { |
173 | ||
174 | #ifdef IS_MPI | |
175 | ||
176 | if (worldRank == 0) { | |
177 | #endif // is_mpi | |
178 | < | |
179 | < | dumpFile_.close(); |
180 | < | |
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", time); |
198 | > | os << buffer; |
199 | > | |
200 | Mat3x3d hmat; | |
129 | – | double chi; |
130 | – | double integralOfChiDt; |
131 | – | Mat3x3d eta; |
132 | – | |
133 | – | currentTime = s->getTime(); |
201 | hmat = s->getHmat(); | |
202 | < | chi = s->getChi(); |
203 | < | integralOfChiDt = s->getIntegralOfChiDt(); |
204 | < | eta = s->getEta(); |
205 | < | |
206 | < | 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"; |
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" |
150 | < | << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";"; |
151 | < | |
152 | < | os << "\n"; |
153 | < | } |
221 | > | os << " </FrameData>\n"; |
222 | > | } |
223 | ||
224 | < | void DumpWriter::writeFrame(std::ostream& os) { |
156 | < | const int BUFFERSIZE = 2000; |
157 | < | 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 | ||
162 | – | Quat4d q; |
163 | – | Vector3d ji; |
164 | – | Vector3d pos; |
165 | – | Vector3d vel; |
166 | – | |
230 | Molecule* mol; | |
231 | StuntDouble* integrableObject; | |
232 | SimInfo::MoleculeIterator mi; | |
233 | Molecule::IntegrableObjectIterator ii; | |
171 | – | |
172 | – | int nTotObjects; |
173 | – | nTotObjects = info_->getNGlobalIntegrableObjects(); |
234 | ||
235 | #ifndef IS_MPI | |
236 | + | os << " <Snapshot>\n"; |
237 | ||
238 | < | |
178 | < | os << nTotObjects << "\n"; |
179 | < | |
180 | < | writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
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", |
192 | < | integrableObject->getType().c_str(), |
193 | < | pos[0], pos[1], pos[2], |
194 | < | vel[0], vel[1], vel[2]); |
251 | > | os << " </Snapshot>\n"; |
252 | ||
196 | – | strcpy(writeLine, tempBuffer); |
197 | – | |
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 | – | } |
209 | – | |
210 | – | os << writeLine; |
211 | – | |
212 | – | } |
213 | – | } |
214 | – | |
253 | os.flush(); | |
254 | < | #else // is_mpi |
255 | < | /********************************************************************* |
256 | < | * Documentation? You want DOCUMENTATION? |
257 | < | * |
258 | < | * Why all the potatoes below? |
259 | < | * |
260 | < | * To make a long story short, the original version of DumpWriter |
261 | < | * worked in the most inefficient way possible. Node 0 would |
262 | < | * poke each of the node for an individual atom's formatted data |
263 | < | * as node 0 worked its way down the global index. This was particularly |
264 | < | * inefficient since the method blocked all processors at every atom |
227 | < | * (and did it twice!). |
228 | < | * |
229 | < | * An intermediate version of DumpWriter could be described from Node |
230 | < | * zero's perspective as follows: |
231 | < | * |
232 | < | * 1) Have 100 of your friends stand in a circle. |
233 | < | * 2) When you say go, have all of them start tossing potatoes at |
234 | < | * you (one at a time). |
235 | < | * 3) Catch the potatoes. |
236 | < | * |
237 | < | * It was an improvement, but MPI has buffers and caches that could |
238 | < | * best be described in this analogy as "potato nets", so there's no |
239 | < | * need to block the processors atom-by-atom. |
240 | < | * |
241 | < | * This new and improved DumpWriter works in an even more efficient |
242 | < | * way: |
243 | < | * |
244 | < | * 1) Have 100 of your friend stand in a circle. |
245 | < | * 2) When you say go, have them start tossing 5-pound bags of |
246 | < | * potatoes at you. |
247 | < | * 3) Once you've caught a friend's bag of potatoes, |
248 | < | * toss them a spud to let them know they can toss another bag. |
249 | < | * |
250 | < | * How's THAT for documentation? |
251 | < | * |
252 | < | *********************************************************************/ |
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 | < | int * potatoes; |
268 | < | int myPotato; |
269 | < | int nProc; |
270 | < | int which_node; |
271 | < | double atomData[13]; |
272 | < | int isDirectional; |
273 | < | const char * atomTypeString; |
274 | < | char MPIatomTypeString[MINIBUFFERSIZE]; |
275 | < | int msgLen; // the length of message actually recieved at master nodes |
264 | < | int haveError; |
265 | < | MPI_Status istatus; |
266 | < | int nCurObj; |
267 | < | |
268 | < | // code to find maximum tag value |
269 | < | int * tagub; |
270 | < | int flag; |
271 | < | int MAXTAG; |
272 | < | MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); |
267 | > | if (worldRank == masterNode) { |
268 | > | os << " <Snapshot>\n"; |
269 | > | writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
270 | > | os << buffer; |
271 | > | os << " <StuntDoubles>\n"; |
272 | > | |
273 | > | int nProc; |
274 | > | MPI_Comm_size(MPI_COMM_WORLD, &nProc); |
275 | > | for (int i = 1; i < nProc; ++i) { |
276 | ||
277 | < | if (flag) { |
278 | < | MAXTAG = *tagub; |
277 | > | // receive the length of the string buffer that was |
278 | > | // prepared by processor i |
279 | > | |
280 | > | int recvLength; |
281 | > | MPI_Recv(&recvLength, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &istatus); |
282 | > | char* recvBuffer = new char[recvLength]; |
283 | > | if (recvBuffer == NULL) { |
284 | > | |
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 << " </StuntDoubles>\n"; |
293 | > | |
294 | > | os << " </Snapshot>\n"; |
295 | > | os.flush(); |
296 | } else { | |
297 | < | MAXTAG = 32767; |
297 | > | int sendBufferLength = buffer.size(); |
298 | > | MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); |
299 | > | MPI_Send((void *)buffer.c_str(), sendBufferLength, MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); |
300 | } | |
301 | ||
302 | < | if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file |
302 | > | #endif // is_mpi |
303 | ||
304 | < | // Node 0 needs a list of the magic potatoes for each processor; |
304 | > | } |
305 | ||
306 | < | MPI_Comm_size(MPI_COMM_WORLD, &nProc); |
307 | < | potatoes = new int[nProc]; |
306 | > | std::string DumpWriter::prepareDumpLine(StuntDouble* integrableObject) { |
307 | > | |
308 | > | int index = integrableObject->getGlobalIntegrableObjectIndex(); |
309 | > | std::string type("pv"); |
310 | > | std::string line; |
311 | > | char tempBuffer[4096]; |
312 | ||
313 | < | //write out the comment lines |
314 | < | for(int i = 0; i < nProc; i++) { |
315 | < | potatoes[i] = 0; |
316 | < | } |
313 | > | Vector3d pos; |
314 | > | Vector3d vel; |
315 | > | pos = integrableObject->getPos(); |
316 | > | vel = integrableObject->getVel(); |
317 | > | sprintf(tempBuffer, "%18.10g\t%18.10g\t%18.10g\t%14.10g\t%14.10g\t%14.10g", |
318 | > | pos[0], pos[1], pos[2], |
319 | > | vel[0], vel[1], vel[2]); |
320 | > | line += tempBuffer; |
321 | ||
322 | + | if (integrableObject->isDirectional()) { |
323 | + | type += "qj"; |
324 | + | Quat4d q; |
325 | + | Vector3d ji; |
326 | + | q = integrableObject->getQ(); |
327 | + | ji = integrableObject->getJ(); |
328 | + | sprintf(tempBuffer, "\t%14.10g\t%14.10g\t%14.10g\t%14.10g\t%14.10g\t%14.10g\t%14.10g", |
329 | + | q[0], q[1], q[2], q[3], |
330 | + | ji[0], ji[1], ji[2]); |
331 | + | line += tempBuffer; |
332 | + | } |
333 | ||
334 | < | os << nTotObjects << "\n"; |
335 | < | writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); |
336 | < | |
337 | < | for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
338 | < | |
339 | < | // Get the Node number which has this atom; |
340 | < | |
341 | < | which_node = info_->getMolToProc(i); |
342 | < | |
343 | < | if (which_node != masterNode) { //current molecule is in slave node |
344 | < | if (potatoes[which_node] + 1 >= MAXTAG) { |
304 | < | // The potato was going to exceed the maximum value, |
305 | < | // so wrap this processor potato back to 0: |
306 | < | |
307 | < | potatoes[which_node] = 0; |
308 | < | MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, |
309 | < | MPI_COMM_WORLD); |
310 | < | } |
311 | < | |
312 | < | myPotato = potatoes[which_node]; |
313 | < | |
314 | < | //recieve the number of integrableObject in current molecule |
315 | < | MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato, |
316 | < | MPI_COMM_WORLD, &istatus); |
317 | < | myPotato++; |
318 | < | |
319 | < | for(int l = 0; l < nCurObj; l++) { |
320 | < | if (potatoes[which_node] + 2 >= MAXTAG) { |
321 | < | // The potato was going to exceed the maximum value, |
322 | < | // so wrap this processor potato back to 0: |
323 | < | |
324 | < | potatoes[which_node] = 0; |
325 | < | MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, |
326 | < | 0, MPI_COMM_WORLD); |
327 | < | } |
328 | < | |
329 | < | MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, |
330 | < | which_node, myPotato, MPI_COMM_WORLD, |
331 | < | &istatus); |
332 | < | |
333 | < | atomTypeString = MPIatomTypeString; |
334 | < | |
335 | < | myPotato++; |
336 | < | |
337 | < | MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, |
338 | < | MPI_COMM_WORLD, &istatus); |
339 | < | myPotato++; |
340 | < | |
341 | < | MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen); |
342 | < | |
343 | < | if (msgLen == 13) |
344 | < | isDirectional = 1; |
345 | < | else |
346 | < | isDirectional = 0; |
347 | < | |
348 | < | // If we've survived to here, format the line: |
349 | < | |
350 | < | if (!isDirectional) { |
351 | < | sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
352 | < | atomTypeString, atomData[0], |
353 | < | atomData[1], atomData[2], |
354 | < | atomData[3], atomData[4], |
355 | < | atomData[5]); |
356 | < | |
357 | < | strcat(writeLine, |
358 | < | "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
359 | < | } else { |
360 | < | sprintf(writeLine, |
361 | < | "%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", |
362 | < | atomTypeString, |
363 | < | atomData[0], |
364 | < | atomData[1], |
365 | < | atomData[2], |
366 | < | atomData[3], |
367 | < | atomData[4], |
368 | < | atomData[5], |
369 | < | atomData[6], |
370 | < | atomData[7], |
371 | < | atomData[8], |
372 | < | atomData[9], |
373 | < | atomData[10], |
374 | < | atomData[11], |
375 | < | atomData[12]); |
376 | < | } |
377 | < | |
378 | < | os << writeLine; |
379 | < | |
380 | < | } // end for(int l =0) |
381 | < | |
382 | < | potatoes[which_node] = myPotato; |
383 | < | } else { //master node has current molecule |
384 | < | |
385 | < | mol = info_->getMoleculeByGlobalIndex(i); |
386 | < | |
387 | < | if (mol == NULL) { |
388 | < | sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank); |
389 | < | painCave.isFatal = 1; |
390 | < | simError(); |
391 | < | } |
392 | < | |
393 | < | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
394 | < | integrableObject = mol->nextIntegrableObject(ii)) { |
395 | < | |
396 | < | atomTypeString = integrableObject->getType().c_str(); |
397 | < | |
398 | < | pos = integrableObject->getPos(); |
399 | < | vel = integrableObject->getVel(); |
400 | < | |
401 | < | atomData[0] = pos[0]; |
402 | < | atomData[1] = pos[1]; |
403 | < | atomData[2] = pos[2]; |
404 | < | |
405 | < | atomData[3] = vel[0]; |
406 | < | atomData[4] = vel[1]; |
407 | < | atomData[5] = vel[2]; |
408 | < | |
409 | < | isDirectional = 0; |
410 | < | |
411 | < | if (integrableObject->isDirectional()) { |
412 | < | isDirectional = 1; |
413 | < | |
414 | < | q = integrableObject->getQ(); |
415 | < | ji = integrableObject->getJ(); |
416 | < | |
417 | < | for(int j = 0; j < 6; j++) { |
418 | < | atomData[j] = atomData[j]; |
419 | < | } |
420 | < | |
421 | < | atomData[6] = q[0]; |
422 | < | atomData[7] = q[1]; |
423 | < | atomData[8] = q[2]; |
424 | < | atomData[9] = q[3]; |
425 | < | |
426 | < | atomData[10] = ji[0]; |
427 | < | atomData[11] = ji[1]; |
428 | < | atomData[12] = ji[2]; |
429 | < | } |
430 | < | |
431 | < | // If we've survived to here, format the line: |
432 | < | |
433 | < | if (!isDirectional) { |
434 | < | sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", |
435 | < | atomTypeString, atomData[0], |
436 | < | atomData[1], atomData[2], |
437 | < | atomData[3], atomData[4], |
438 | < | atomData[5]); |
439 | < | |
440 | < | strcat(writeLine, |
441 | < | "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); |
442 | < | } else { |
443 | < | sprintf(writeLine, |
444 | < | "%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", |
445 | < | atomTypeString, |
446 | < | atomData[0], |
447 | < | atomData[1], |
448 | < | atomData[2], |
449 | < | atomData[3], |
450 | < | atomData[4], |
451 | < | atomData[5], |
452 | < | atomData[6], |
453 | < | atomData[7], |
454 | < | atomData[8], |
455 | < | atomData[9], |
456 | < | atomData[10], |
457 | < | atomData[11], |
458 | < | atomData[12]); |
459 | < | } |
460 | < | |
461 | < | |
462 | < | os << writeLine; |
463 | < | |
464 | < | } //end for(iter = integrableObject.begin()) |
465 | < | } |
466 | < | } //end for(i = 0; i < mpiSim->getNmol()) |
467 | < | |
468 | < | os.flush(); |
469 | < | |
470 | < | sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
471 | < | MPIcheckPoint(); |
472 | < | |
473 | < | delete [] potatoes; |
474 | < | } else { |
475 | < | |
476 | < | // worldRank != 0, so I'm a remote node. |
477 | < | |
478 | < | // Set my magic potato to 0: |
479 | < | |
480 | < | myPotato = 0; |
481 | < | |
482 | < | for(int i = 0; i < info_->getNGlobalMolecules(); i++) { |
483 | < | |
484 | < | // Am I the node which has this integrableObject? |
485 | < | int whichNode = info_->getMolToProc(i); |
486 | < | if (whichNode == worldRank) { |
487 | < | if (myPotato + 1 >= MAXTAG) { |
488 | < | |
489 | < | // The potato was going to exceed the maximum value, |
490 | < | // so wrap this processor potato back to 0 (and block until |
491 | < | // node 0 says we can go: |
492 | < | |
493 | < | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
494 | < | &istatus); |
495 | < | } |
496 | < | |
497 | < | mol = info_->getMoleculeByGlobalIndex(i); |
498 | < | |
499 | < | |
500 | < | nCurObj = mol->getNIntegrableObjects(); |
501 | < | |
502 | < | MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD); |
503 | < | myPotato++; |
504 | < | |
505 | < | for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL; |
506 | < | integrableObject = mol->nextIntegrableObject(ii)) { |
507 | < | |
508 | < | if (myPotato + 2 >= MAXTAG) { |
509 | < | |
510 | < | // The potato was going to exceed the maximum value, |
511 | < | // so wrap this processor potato back to 0 (and block until |
512 | < | // node 0 says we can go: |
513 | < | |
514 | < | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, |
515 | < | &istatus); |
516 | < | } |
517 | < | |
518 | < | atomTypeString = integrableObject->getType().c_str(); |
519 | < | |
520 | < | pos = integrableObject->getPos(); |
521 | < | vel = integrableObject->getVel(); |
522 | < | |
523 | < | atomData[0] = pos[0]; |
524 | < | atomData[1] = pos[1]; |
525 | < | atomData[2] = pos[2]; |
526 | < | |
527 | < | atomData[3] = vel[0]; |
528 | < | atomData[4] = vel[1]; |
529 | < | atomData[5] = vel[2]; |
530 | < | |
531 | < | isDirectional = 0; |
532 | < | |
533 | < | if (integrableObject->isDirectional()) { |
534 | < | isDirectional = 1; |
535 | < | |
536 | < | q = integrableObject->getQ(); |
537 | < | ji = integrableObject->getJ(); |
538 | < | |
539 | < | atomData[6] = q[0]; |
540 | < | atomData[7] = q[1]; |
541 | < | atomData[8] = q[2]; |
542 | < | atomData[9] = q[3]; |
543 | < | |
544 | < | atomData[10] = ji[0]; |
545 | < | atomData[11] = ji[1]; |
546 | < | atomData[12] = ji[2]; |
547 | < | } |
548 | < | |
549 | < | strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); |
550 | < | |
551 | < | // null terminate the std::string before sending (just in case): |
552 | < | MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0'; |
553 | < | |
554 | < | MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, |
555 | < | myPotato, MPI_COMM_WORLD); |
556 | < | |
557 | < | myPotato++; |
558 | < | |
559 | < | if (isDirectional) { |
560 | < | MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato, |
561 | < | MPI_COMM_WORLD); |
562 | < | } else { |
563 | < | MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato, |
564 | < | MPI_COMM_WORLD); |
565 | < | } |
566 | < | |
567 | < | myPotato++; |
568 | < | } |
569 | < | |
570 | < | } |
571 | < | |
572 | < | } |
573 | < | sprintf(checkPointMsg, "Sucessfully took a dump.\n"); |
574 | < | MPIcheckPoint(); |
334 | > | if (needForceVector_) { |
335 | > | type += "ft"; |
336 | > | Vector3d frc; |
337 | > | Vector3d trq; |
338 | > | frc = integrableObject->getFrc(); |
339 | > | trq = integrableObject->getTrq(); |
340 | > | |
341 | > | sprintf(tempBuffer, "\t%14.10g\t%14.10g\t%14.10g\t%14.10g\t%14.10g\t%14.10g", |
342 | > | frc[0], frc[1], frc[2], |
343 | > | trq[0], trq[1], trq[2]); |
344 | > | line += tempBuffer; |
345 | } | |
346 | + | |
347 | + | sprintf(tempBuffer, "%d\t%s\t%s\n", index, type.c_str(), line.c_str()); |
348 | + | return std::string(tempBuffer); |
349 | + | } |
350 | ||
351 | < | #endif // is_mpi |
351 | > | void DumpWriter::writeDump() { |
352 | > | writeFrame(*dumpFile_); |
353 | > | } |
354 | ||
355 | < | } |
356 | < | |
581 | < | void DumpWriter::writeDump() { |
582 | < | writeFrame(dumpFile_); |
583 | < | |
584 | < | } |
585 | < | |
586 | < | void DumpWriter::writeEor() { |
587 | < | std::ofstream eorStream; |
355 | > | void DumpWriter::writeEor() { |
356 | > | std::ostream* eorStream; |
357 | ||
358 | #ifdef IS_MPI | |
359 | if (worldRank == 0) { | |
360 | #endif // is_mpi | |
361 | ||
362 | < | eorStream.open(eorFilename_.c_str()); |
594 | < | if (!eorStream.is_open()) { |
595 | < | sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n", |
596 | < | eorFilename_.c_str()); |
597 | < | painCave.isFatal = 1; |
598 | < | simError(); |
599 | < | } |
362 | > | eorStream = createOStream(eorFilename_); |
363 | ||
364 | #ifdef IS_MPI | |
365 | } | |
366 | #endif // is_mpi | |
367 | ||
368 | < | writeFrame(eorStream); |
606 | < | } |
368 | > | writeFrame(*eorStream); |
369 | ||
370 | + | #ifdef IS_MPI |
371 | + | if (worldRank == 0) { |
372 | + | #endif // is_mpi |
373 | + | writeClosing(*eorStream); |
374 | + | delete eorStream; |
375 | + | #ifdef IS_MPI |
376 | + | } |
377 | + | #endif // is_mpi |
378 | ||
379 | < | void DumpWriter::writeDumpAndEor() { |
380 | < | std::ofstream eorStream; |
379 | > | } |
380 | > | |
381 | > | |
382 | > | void DumpWriter::writeDumpAndEor() { |
383 | std::vector<std::streambuf*> buffers; | |
384 | + | std::ostream* eorStream; |
385 | #ifdef IS_MPI | |
386 | if (worldRank == 0) { | |
387 | #endif // is_mpi | |
388 | ||
389 | < | buffers.push_back(dumpFile_.rdbuf()); |
389 | > | buffers.push_back(dumpFile_->rdbuf()); |
390 | ||
391 | < | eorStream.open(eorFilename_.c_str()); |
619 | < | if (!eorStream.is_open()) { |
620 | < | sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n", |
621 | < | eorFilename_.c_str()); |
622 | < | painCave.isFatal = 1; |
623 | < | simError(); |
624 | < | } |
391 | > | eorStream = createOStream(eorFilename_); |
392 | ||
393 | < | buffers.push_back(eorStream.rdbuf()); |
393 | > | buffers.push_back(eorStream->rdbuf()); |
394 | ||
395 | #ifdef IS_MPI | |
396 | } | |
# | Line 633 | Line 400 | void DumpWriter::writeDumpAndEor() { | |
400 | std::ostream os(&tbuf); | |
401 | ||
402 | writeFrame(os); | |
403 | + | |
404 | + | #ifdef IS_MPI |
405 | + | if (worldRank == 0) { |
406 | + | #endif // is_mpi |
407 | + | writeClosing(*eorStream); |
408 | + | delete eorStream; |
409 | + | #ifdef IS_MPI |
410 | + | } |
411 | + | #endif // is_mpi |
412 | ||
413 | < | } |
413 | > | } |
414 | ||
415 | + | std::ostream* DumpWriter::createOStream(const std::string& filename) { |
416 | ||
417 | + | std::ostream* newOStream; |
418 | + | #ifdef HAVE_LIBZ |
419 | + | if (needCompression_) { |
420 | + | newOStream = new ogzstream(filename.c_str()); |
421 | + | } else { |
422 | + | newOStream = new std::ofstream(filename.c_str()); |
423 | + | } |
424 | + | #else |
425 | + | newOStream = new std::ofstream(filename.c_str()); |
426 | + | #endif |
427 | + | //write out MetaData first |
428 | + | (*newOStream) << "<OOPSE version=4>" << std::endl; |
429 | + | (*newOStream) << " <MetaData>" << std::endl; |
430 | + | (*newOStream) << info_->getRawMetaData(); |
431 | + | (*newOStream) << " </MetaData>" << std::endl; |
432 | + | return newOStream; |
433 | + | } |
434 | ||
435 | + | void DumpWriter::writeClosing(std::ostream& os) { |
436 | + | |
437 | + | os << "</OOPSE>\n"; |
438 | + | os.flush(); |
439 | + | } |
440 | + | |
441 | }//end namespace oopse |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |