ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/io/DumpWriter.cpp
(Generate patch)

Comparing trunk/src/io/DumpWriter.cpp (file contents):
Revision 221 by chrisfen, Tue Nov 23 22:48:31 2004 UTC vs.
Revision 1024 by tim, Wed Aug 30 18:42:29 2006 UTC

# Line 1 | Line 1
1 < #define _LARGEFILE_SOURCE64
2 < #define _FILE_OFFSET_BITS 64
1 > /*
2 > * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved.
3 > *
4 > * The University of Notre Dame grants you ("Licensee") a
5 > * non-exclusive, royalty free, license to use, modify and
6 > * redistribute this software in source and binary code form, provided
7 > * that the following conditions are met:
8 > *
9 > * 1. Acknowledgement of the program authors must be made in any
10 > *    publication of scientific results based in part on use of the
11 > *    program.  An acceptable form of acknowledgement is citation of
12 > *    the article in which the program was described (Matthew
13 > *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 > *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 > *    Parallel Simulation Engine for Molecular Dynamics,"
16 > *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 > *
18 > * 2. Redistributions of source code must retain the above copyright
19 > *    notice, this list of conditions and the following disclaimer.
20 > *
21 > * 3. Redistributions in binary form must reproduce the above copyright
22 > *    notice, this list of conditions and the following disclaimer in the
23 > *    documentation and/or other materials provided with the
24 > *    distribution.
25 > *
26 > * This software is provided "AS IS," without a warranty of any
27 > * kind. All express or implied conditions, representations and
28 > * warranties, including any implied warranty of merchantability,
29 > * fitness for a particular purpose or non-infringement, are hereby
30 > * excluded.  The University of Notre Dame and its licensors shall not
31 > * be liable for any damages suffered by licensee as a result of
32 > * using, modifying or distributing the software or its
33 > * derivatives. In no event will the University of Notre Dame or its
34 > * licensors be liable for any lost revenue, profit or data, or for
35 > * direct, indirect, special, consequential, incidental or punitive
36 > * damages, however caused and regardless of the theory of liability,
37 > * arising out of the use of or inability to use software, even if the
38 > * University of Notre Dame has been advised of the possibility of
39 > * such damages.
40 > */
41 >
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  
4 #include <string.h>
5 #include <iostream>
6 #include <fstream>
7 #include <algorithm>
8 #include <utility>
9
49   #ifdef IS_MPI
50   #include <mpi.h>
12 #include "brains/mpiSimulation.hpp"
13
14 namespace dWrite{
15  void DieDieDie( void );
16 }
17
18 using namespace dWrite;
51   #endif //is_mpi
52  
53 < #include "io/ReadWrite.hpp"
22 < #include "utils/simError.h"
53 > namespace oopse {
54  
55 < DumpWriter::DumpWriter( SimInfo* the_entry_plug ){
55 >  DumpWriter::DumpWriter(SimInfo* info)
56 >    : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){
57  
58 <  entry_plug = the_entry_plug;
59 <
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 <  if(worldRank == 0 ){
70 >
71 >    if (worldRank == 0) {
72   #endif // is_mpi
73 +        
74 +      dumpFile_ = createOStream(filename_);
75  
76 <    dumpFile.open(entry_plug->sampleName.c_str(), ios::out | 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  
83 <    if( !dumpFile ){
83 > #ifdef IS_MPI
84  
36      sprintf( painCave.errMsg,
37               "Could not open \"%s\" for dump output.\n",
38               entry_plug->sampleName.c_str());
39      painCave.isFatal = 1;
40      simError();
85      }
86  
87 < #ifdef IS_MPI
87 > #endif // is_mpi
88 >
89    }
90  
46  //sort the local atoms by global index
47  sortByGlobalIndex();
48  
49  sprintf( checkPointMsg,
50           "Sucessfully opened output file for dumping.\n");
51  MPIcheckPoint();
52 #endif // is_mpi
53 }
91  
92 < DumpWriter::~DumpWriter( ){
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 <  if(worldRank == 0 ){
109 >
110 >    if (worldRank == 0) {
111   #endif // is_mpi
112  
113 <    dumpFile.close();
113 >      
114 >      dumpFile_ = createOStream(filename_);
115  
116 < #ifdef IS_MPI
117 <  }
118 < #endif // is_mpi
119 < }
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 < /**
71 < * A hook function to load balancing
72 < */
125 >    }
126  
127 < void DumpWriter::update(){
75 <  sortByGlobalIndex();          
76 < }
77 <  
78 < /**
79 < * Auxiliary sorting function
80 < */
81 <
82 < bool indexSortingCriterion(const pair<int, int>& p1, const pair<int, int>& p2){
83 <  return p1.second < p2.second;
84 < }
127 > #endif // is_mpi
128  
129 < /**
87 < * Sorting the local index by global index
88 < */
89 <
90 < void DumpWriter::sortByGlobalIndex(){
91 <  Molecule* mols = entry_plug->molecules;  
92 <  indexArray.clear();
129 >  }
130    
131 <  for(int i = 0; i < entry_plug->n_mol;i++)
132 <    indexArray.push_back(make_pair(i, mols[i].getGlobalIndex()));
133 <  
134 <  sort(indexArray.begin(), indexArray.end(), indexSortingCriterion);    
135 < }
136 <
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 < void DumpWriter::writeDump(double currentTime){
167 >    
168 > #endif // is_mpi
169 >    
170 >  }
171  
172 <  ofstream finalOut;
105 <  vector<ofstream*> fileStreams;
172 >  DumpWriter::~DumpWriter() {
173  
174   #ifdef IS_MPI
175 <  if(worldRank == 0 ){
176 < #endif    
177 <    finalOut.open( entry_plug->finalName.c_str(), ios::out | ios::trunc );
178 <    if( !finalOut ){
179 <      sprintf( painCave.errMsg,
180 <               "Could not open \"%s\" for final dump output.\n",
181 <               entry_plug->finalName.c_str() );
115 <      painCave.isFatal = 1;
116 <      simError();
117 <    }
175 >
176 >    if (worldRank == 0) {
177 > #endif // is_mpi
178 >      if (createDumpFile_){
179 >        writeClosing(*dumpFile_);
180 >        delete dumpFile_;
181 >      }
182   #ifdef IS_MPI
183 <  }
183 >
184 >    }
185 >
186   #endif // is_mpi
187  
188 <  fileStreams.push_back(&finalOut);
123 <  fileStreams.push_back(&dumpFile);
188 >  }
189  
190 <  writeFrame(fileStreams, currentTime);
190 >  void DumpWriter::writeFrameProperties(std::ostream& os, Snapshot* s) {
191  
192 < #ifdef IS_MPI
128 <  finalOut.close();
129 < #endif
130 <        
131 < }
192 >    char buffer[1024];
193  
194 < void DumpWriter::writeFinal(double currentTime){
194 >    os << "    <FrameData>\n";
195  
196 <  ofstream finalOut;
197 <  vector<ofstream*> fileStreams;
196 >    RealType currentTime = s->getTime();
197 >    sprintf(buffer, "        Time: %.10g\n", time);
198 >    os << buffer;
199  
200 < #ifdef IS_MPI
201 <  if(worldRank == 0 ){
202 < #endif // is_mpi
200 >    Mat3x3d hmat;
201 >    hmat = s->getHmat();
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 <    finalOut.open( entry_plug->finalName.c_str(), ios::out | ios::trunc );
208 >    RealType chi = s->getChi();
209 >    RealType integralOfChiDt = s->getIntegralOfChiDt();
210 >    sprintf(buffer, "  Thermostat: %.10g , %.10g\n", chi, integralOfChiDt);
211 >    os << buffer;
212  
213 <    if( !finalOut ){
214 <      sprintf( painCave.errMsg,
215 <               "Could not open \"%s\" for final dump output.\n",
216 <               entry_plug->finalName.c_str() );
217 <      painCave.isFatal = 1;
218 <      simError();
219 <    }
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 < #ifdef IS_MPI
221 >    os << "    </FrameData>\n";
222    }
154 #endif // is_mpi
155  
156  fileStreams.push_back(&finalOut);  
157  writeFrame(fileStreams, currentTime);
223  
224 +  void DumpWriter::writeFrame(std::ostream& os) {
225 +
226   #ifdef IS_MPI
227 <  finalOut.close();
227 >    MPI_Status istatus;
228   #endif
162  
163 }
229  
230 < void DumpWriter::writeFrame( vector<ofstream*>& outFile, double currentTime ){
230 >    Molecule* mol;
231 >    StuntDouble* integrableObject;
232 >    SimInfo::MoleculeIterator mi;
233 >    Molecule::IntegrableObjectIterator ii;
234  
167  const int BUFFERSIZE = 2000;
168  const int MINIBUFFERSIZE = 100;
169
170  char tempBuffer[BUFFERSIZE];  
171  char writeLine[BUFFERSIZE];
172
173  int i;
174  unsigned int k;
175
176 #ifdef IS_MPI
177  
178  /*********************************************************************
179   * Documentation?  You want DOCUMENTATION?
180   *
181   * Why all the potatoes below?  
182   *
183   * To make a long story short, the original version of DumpWriter
184   * worked in the most inefficient way possible.  Node 0 would
185   * poke each of the node for an individual atom's formatted data
186   * as node 0 worked its way down the global index. This was particularly
187   * inefficient since the method blocked all processors at every atom
188   * (and did it twice!).
189   *
190   * An intermediate version of DumpWriter could be described from Node
191   * zero's perspective as follows:
192   *
193   *  1) Have 100 of your friends stand in a circle.
194   *  2) When you say go, have all of them start tossing potatoes at
195   *     you (one at a time).
196   *  3) Catch the potatoes.
197   *
198   * It was an improvement, but MPI has buffers and caches that could
199   * best be described in this analogy as "potato nets", so there's no
200   * need to block the processors atom-by-atom.
201   *
202   * This new and improved DumpWriter works in an even more efficient
203   * way:
204   *
205   *  1) Have 100 of your friend stand in a circle.
206   *  2) When you say go, have them start tossing 5-pound bags of
207   *     potatoes at you.
208   *  3) Once you've caught a friend's bag of potatoes,
209   *     toss them a spud to let them know they can toss another bag.
210   *
211   * How's THAT for documentation?
212   *
213   *********************************************************************/
214
215  int *potatoes;
216  int myPotato;
217
218  int nProc;
219  int j, which_node, done, which_atom, local_index, currentIndex;
220  double atomData[13];
221  int isDirectional;
222  char* atomTypeString;
223  char MPIatomTypeString[MINIBUFFERSIZE];
224  int nObjects;
225  int msgLen; // the length of message actually recieved at master nodes
226 #endif //is_mpi
227
228  double q[4], ji[3];
229  DirectionalAtom* dAtom;
230  double pos[3], vel[3];
231  int nTotObjects;
232  StuntDouble* sd;
233  char* molName;
234  vector<StuntDouble*> integrableObjects;
235  vector<StuntDouble*>::iterator iter;
236  nTotObjects = entry_plug->getTotIntegrableObjects();
235   #ifndef IS_MPI
236 <  
239 <  for(k = 0; k < outFile.size(); k++){
240 <    *outFile[k] << nTotObjects << "\n";
236 >    os << "  <Snapshot>\n";
237  
238 <    *outFile[k] << currentTime << ";\t"
243 <               << entry_plug->Hmat[0][0] << "\t"
244 <                     << entry_plug->Hmat[1][0] << "\t"
245 <                     << entry_plug->Hmat[2][0] << ";\t"
246 <              
247 <               << entry_plug->Hmat[0][1] << "\t"
248 <                     << entry_plug->Hmat[1][1] << "\t"
249 <                     << entry_plug->Hmat[2][1] << ";\t"
238 >    writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot());
239  
240 <                     << entry_plug->Hmat[0][2] << "\t"
241 <                     << entry_plug->Hmat[1][2] << "\t"
253 <                     << entry_plug->Hmat[2][2] << ";";
240 >    os << "    <StuntDoubles>\n";
241 >    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
242  
243 <    //write out additional parameters, such as chi and eta
244 <    *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl;
245 <  }
258 <  
259 <  for( i=0; i< entry_plug->n_mol; i++ ){
243 >      for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
244 >           integrableObject = mol->nextIntegrableObject(ii)) {  
245 >        os << prepareDumpLine(integrableObject);
246  
247 <    integrableObjects = entry_plug->molecules[i].getIntegrableObjects();
248 <    molName = (entry_plug->compStamps[entry_plug->molecules[i].getStampID()])->getID();
249 <    
264 <    for( iter = integrableObjects.begin();iter !=  integrableObjects.end(); ++iter){
265 <      sd = *iter;
266 <      sd->getPos(pos);
267 <      sd->getVel(vel);
247 >      }
248 >    }    
249 >    os << "    </StuntDoubles>\n";
250  
251 <      sprintf( tempBuffer,
270 <             "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
271 <             sd->getType(),
272 <             pos[0],
273 <             pos[1],
274 <             pos[2],
275 <             vel[0],
276 <             vel[1],
277 <             vel[2]);
278 <      strcpy( writeLine, tempBuffer );
251 >    os << "  </Snapshot>\n";
252  
253 <      if( sd->isDirectional() ){
254 <
255 <        sd->getQ( q );
256 <        sd->getJ( ji );
257 <
258 <        sprintf( tempBuffer,
259 <               "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
260 <               q[0],
261 <               q[1],
289 <               q[2],
290 <               q[3],
291 <                 ji[0],
292 <                 ji[1],
293 <                 ji[2]);
294 <        strcat( 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        }
296      else
297        strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
298    
299      for(k = 0; k < outFile.size(); k++)
300        *outFile[k] << writeLine;      
263      }
264      
265 <  }
265 >    const int masterNode = 0;
266  
267 < #else // is_mpi
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 <  /* code to find maximum tag value */
278 <  
309 <  int *tagub, flag, MAXTAG;
310 <  MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag);
311 <  if (flag) {
312 <    MAXTAG = *tagub;
313 <  } else {
314 <    MAXTAG = 32767;
315 <  }  
277 >        // receive the length of the string buffer that was
278 >        // prepared by processor i
279  
280 <  int haveError;
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 >      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 <  MPI_Status istatus;
320 <  int nCurObj;
321 <  int *MolToProcMap = mpiSim->getMolToProcMap();
302 > #endif // is_mpi
303  
304 <  // write out header and node 0's coordinates
304 >  }
305  
306 <  if( worldRank == 0 ){
307 <
308 <    // Node 0 needs a list of the magic potatoes for each processor;
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 <    nProc = mpiSim->getNProcessors();
314 <    potatoes = new int[nProc];
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 <    //write out the comment lines
323 <    for (i = 0; i < nProc; i++)
324 <      potatoes[i] = 0;
325 <    
326 <    for(k = 0; k < outFile.size(); k++){
327 <      *outFile[k] << nTotObjects << "\n";
328 <      
329 <      *outFile[k] << currentTime << ";\t"
330 <                  << entry_plug->Hmat[0][0] << "\t"
331 <                  << entry_plug->Hmat[1][0] << "\t"
342 <                  << entry_plug->Hmat[2][0] << ";\t"
343 <        
344 <                  << entry_plug->Hmat[0][1] << "\t"
345 <                  << entry_plug->Hmat[1][1] << "\t"
346 <                  << entry_plug->Hmat[2][1] << ";\t"
347 <        
348 <                  << entry_plug->Hmat[0][2] << "\t"
349 <                  << entry_plug->Hmat[1][2] << "\t"
350 <                  << entry_plug->Hmat[2][2] << ";";
351 <      
352 <      *outFile[k] << entry_plug->the_integrator->getAdditionalParameters()
353 <                  << endl;
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      }
355    
356    currentIndex = 0;
357    
358    for (i = 0 ; i < mpiSim->getNMolGlobal(); i++ ) {
359      
360      // Get the Node number which has this atom;
361      
362      which_node = MolToProcMap[i];
363      
364      if (which_node != 0) {
365        
366        if (potatoes[which_node] + 1 >= MAXTAG) {
367          // The potato was going to exceed the maximum value,
368          // so wrap this processor potato back to 0:        
333  
334 <          potatoes[which_node] = 0;          
335 <          MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0,
336 <                   MPI_COMM_WORLD);
337 <          
338 <        }
339 <
340 <        myPotato = potatoes[which_node];        
341 <
342 <        //recieve the number of integrableObject in current molecule
343 <        MPI_Recv(&nCurObj, 1, MPI_INT, which_node,
344 <                 myPotato, MPI_COMM_WORLD, &istatus);
345 <        myPotato++;
382 <        
383 <        for(int l = 0; l < nCurObj; l++){
384 <
385 <          if (potatoes[which_node] + 2 >= MAXTAG) {
386 <            // The potato was going to exceed the maximum value,
387 <            // so wrap this processor potato back to 0:        
388 <
389 <            potatoes[which_node] = 0;          
390 <            MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, MPI_COMM_WORLD);
391 <            
392 <          }
393 <
394 <          MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node,
395 <          myPotato, MPI_COMM_WORLD, &istatus);
396 <
397 <          atomTypeString = MPIatomTypeString;
398 <
399 <          myPotato++;
400 <
401 <          MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, MPI_COMM_WORLD, &istatus);
402 <          myPotato++;
403 <
404 <          MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen);
405 <
406 <          if(msgLen  == 13)
407 <            isDirectional = 1;
408 <          else
409 <            isDirectional = 0;
410 <          
411 <          // If we've survived to here, format the line:
412 <            
413 <          if (!isDirectional) {
414 <        
415 <            sprintf( writeLine,
416 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
417 <                 atomTypeString,
418 <                 atomData[0],
419 <                 atomData[1],
420 <                 atomData[2],
421 <                 atomData[3],
422 <                 atomData[4],
423 <                 atomData[5]);
424 <        
425 <           strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
426 <        
427 <          }
428 <          else {
429 <        
430 <                sprintf( writeLine,
431 <                         "%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",
432 <                         atomTypeString,
433 <                         atomData[0],
434 <                         atomData[1],
435 <                         atomData[2],
436 <                         atomData[3],
437 <                         atomData[4],
438 <                         atomData[5],
439 <                         atomData[6],
440 <                         atomData[7],
441 <                         atomData[8],
442 <                         atomData[9],
443 <                         atomData[10],
444 <                         atomData[11],
445 <                         atomData[12]);
446 <            
447 <          }
448 <          
449 <          for(k = 0; k < outFile.size(); k++)
450 <            *outFile[k] << writeLine;            
451 <
452 <        }// end for(int l =0)
453 <        potatoes[which_node] = myPotato;
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 <      }
348 <      else {
349 <        
458 <        haveError = 0;
459 <        
460 <            local_index = indexArray[currentIndex].first;        
461 <            
462 <            integrableObjects = (entry_plug->molecules[local_index]).getIntegrableObjects();
347 >    sprintf(tempBuffer, "%d\t%s\t%s\n", index, type.c_str(), line.c_str());
348 >    return std::string(tempBuffer);
349 >  }
350  
351 <        for(iter= integrableObjects.begin(); iter != integrableObjects.end(); ++iter){    
352 <                sd = *iter;
353 <            atomTypeString = sd->getType();
467 <            
468 <            sd->getPos(pos);
469 <            sd->getVel(vel);          
470 <          
471 <            atomData[0] = pos[0];
472 <            atomData[1] = pos[1];
473 <            atomData[2] = pos[2];
351 >  void DumpWriter::writeDump() {
352 >    writeFrame(*dumpFile_);
353 >  }
354  
355 <            atomData[3] = vel[0];
356 <            atomData[4] = vel[1];
477 <            atomData[5] = vel[2];
478 <              
479 <            isDirectional = 0;
480 <
481 <            if( sd->isDirectional() ){
482 <
483 <              isDirectional = 1;
484 <                
485 <              sd->getQ( q );
486 <              sd->getJ( ji );
487 <
488 <              for (int j = 0; j < 6 ; j++)
489 <                atomData[j] = atomData[j];            
490 <              
491 <              atomData[6] = q[0];
492 <              atomData[7] = q[1];
493 <              atomData[8] = q[2];
494 <              atomData[9] = q[3];
495 <              
496 <              atomData[10] = ji[0];
497 <              atomData[11] = ji[1];
498 <              atomData[12] = ji[2];
499 <            }
500 <            
501 <            // If we've survived to here, format the line:
502 <            
503 <            if (!isDirectional) {
504 <        
505 <              sprintf( writeLine,
506 <                 "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
507 <                 atomTypeString,
508 <                 atomData[0],
509 <                 atomData[1],
510 <                 atomData[2],
511 <                 atomData[3],
512 <                 atomData[4],
513 <                 atomData[5]);
514 <        
515 <             strcat( writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n" );
516 <        
517 <            }
518 <            else {
519 <        
520 <                sprintf( writeLine,
521 <                         "%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",
522 <                         atomTypeString,
523 <                         atomData[0],
524 <                         atomData[1],
525 <                         atomData[2],
526 <                         atomData[3],
527 <                         atomData[4],
528 <                         atomData[5],
529 <                         atomData[6],
530 <                         atomData[7],
531 <                         atomData[8],
532 <                         atomData[9],
533 <                         atomData[10],
534 <                         atomData[11],
535 <                         atomData[12]);
536 <              
537 <            }
538 <            
539 <            for(k = 0; k < outFile.size(); k++)
540 <              *outFile[k] << writeLine;
541 <            
542 <            
543 <        }//end for(iter = integrableObject.begin())
544 <        
545 <      currentIndex++;
546 <      }
547 <
548 <    }//end for(i = 0; i < mpiSim->getNmol())
355 >  void DumpWriter::writeEor() {
356 >    std::ostream* eorStream;
357      
358 <    for(k = 0; k < outFile.size(); k++)
359 <      outFile[k]->flush();
360 <    
553 <    sprintf( checkPointMsg,
554 <             "Sucessfully took a dump.\n");
555 <    
556 <    MPIcheckPoint();        
557 <    
558 <    delete[] potatoes;
559 <    
560 <  } else {
358 > #ifdef IS_MPI
359 >    if (worldRank == 0) {
360 > #endif // is_mpi
361  
362 <    // worldRank != 0, so I'm a remote node.  
362 >      eorStream = createOStream(eorFilename_);
363  
364 <    // Set my magic potato to 0:
364 > #ifdef IS_MPI
365 >    }
366 > #endif // is_mpi    
367  
368 <    myPotato = 0;
567 <    currentIndex = 0;
568 <    
569 <    for (i = 0 ; i < mpiSim->getNMolGlobal(); i++ ) {
570 <      
571 <      // Am I the node which has this integrableObject?
572 <      
573 <      if (MolToProcMap[i] == worldRank) {
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 <        if (myPotato + 1 >= MAXTAG) {
577 <          
578 <          // The potato was going to exceed the maximum value,
579 <          // so wrap this processor potato back to 0 (and block until
580 <          // node 0 says we can go:
581 <          
582 <          MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus);
583 <          
584 <        }
379 >  }
380  
586          local_index = indexArray[currentIndex].first;        
587          integrableObjects = entry_plug->molecules[local_index].getIntegrableObjects();
588          
589          nCurObj = integrableObjects.size();
590                      
591          MPI_Send(&nCurObj, 1, MPI_INT, 0,
592                   myPotato, MPI_COMM_WORLD);
593          myPotato++;
381  
382 <          for( iter = integrableObjects.begin(); iter  != integrableObjects.end(); iter++){
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 <            if (myPotato + 2 >= MAXTAG) {
598 <          
599 <              // The potato was going to exceed the maximum value,
600 <              // so wrap this processor potato back to 0 (and block until
601 <              // node 0 says we can go:
602 <          
603 <              MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus);
604 <              
605 <            }
606 <            
607 <            sd = *iter;
608 <            
609 <            atomTypeString = sd->getType();
389 >      buffers.push_back(dumpFile_->rdbuf());
390  
391 <            sd->getPos(pos);
612 <            sd->getVel(vel);
391 >      eorStream = createOStream(eorFilename_);
392  
393 <            atomData[0] = pos[0];
394 <            atomData[1] = pos[1];
395 <            atomData[2] = pos[2];
393 >      buffers.push_back(eorStream->rdbuf());
394 >        
395 > #ifdef IS_MPI
396 >    }
397 > #endif // is_mpi    
398  
399 <            atomData[3] = vel[0];
400 <            atomData[4] = vel[1];
620 <            atomData[5] = vel[2];
621 <              
622 <            isDirectional = 0;
399 >    TeeBuf tbuf(buffers.begin(), buffers.end());
400 >    std::ostream os(&tbuf);
401  
402 <            if( sd->isDirectional() ){
402 >    writeFrame(os);
403  
404 <                isDirectional = 1;
405 <                
406 <                sd->getQ( q );
407 <                sd->getJ( ji );
408 <                
409 <                
410 <                atomData[6] = q[0];
411 <                atomData[7] = q[1];
634 <                atomData[8] = q[2];
635 <                atomData[9] = q[3];
636 <      
637 <                atomData[10] = ji[0];
638 <                atomData[11] = ji[1];
639 <                atomData[12] = ji[2];
640 <              }
641 <
642 <            
643 <            strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE);
644 <
645 <            // null terminate the string before sending (just in case):
646 <            MPIatomTypeString[MINIBUFFERSIZE-1] = '\0';
647 <
648 <            MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
649 <                             myPotato, MPI_COMM_WORLD);
650 <            
651 <            myPotato++;
652 <            
653 <            if (isDirectional) {
654 <
655 <              MPI_Send(atomData, 13, MPI_DOUBLE, 0,
656 <                       myPotato, MPI_COMM_WORLD);
657 <              
658 <            } else {
659 <
660 <              MPI_Send(atomData, 6, MPI_DOUBLE, 0,
661 <                       myPotato, MPI_COMM_WORLD);
662 <            }
663 <
664 <            myPotato++;  
665 <
666 <          }
667 <
668 <          currentIndex++;    
669 <          
670 <        }
671 <      
672 <      }
673 <
674 <    sprintf( checkPointMsg,
675 <             "Successfully took a dump.\n");
676 <    MPIcheckPoint();                
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    }
679  
680 #endif // is_mpi
681 }
414  
415 < #ifdef IS_MPI
415 >  std::ostream* DumpWriter::createOStream(const std::string& filename) {
416  
417 < // a couple of functions to let us escape the write loop
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 dWrite::DieDieDie( void ){
435 >  void DumpWriter::writeClosing(std::ostream& os) {
436  
437 <  MPI_Finalize();
438 <  exit (0);
439 < }
437 >    os << "</OOPSE>\n";
438 >    os.flush();
439 >  }
440  
441 < #endif //is_mpi
441 > }//end namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines