ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-2.0/src/io/DumpWriter.cpp
(Generate patch)

Comparing trunk/OOPSE-2.0/src/io/DumpWriter.cpp (file contents):
Revision 2079 by tim, Thu Mar 3 14:40:20 2005 UTC vs.
Revision 2314 by tim, Tue Sep 20 21:22:38 2005 UTC

# 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 >
61 >    if (needCompression_) {
62 >        filename_ += ".gz";
63 >        eorFilename_ += ".gz";
64 >    }
65 >    
66   #ifdef IS_MPI
67  
68 <    if (worldRank == 0) {
68 >      if (worldRank == 0) {
69   #endif // is_mpi
70  
59        dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc);
71  
72 +        dumpFile_ = createOStream(filename_);
73 +
74          if (!dumpFile_) {
75 <            sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
76 <                    filename_.c_str());
77 <            painCave.isFatal = 1;
78 <            simError();
75 >          sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
76 >                  filename_.c_str());
77 >          painCave.isFatal = 1;
78 >          simError();
79          }
80  
81   #ifdef IS_MPI
82  
83 <    }
83 >      }
84  
85 <    sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
86 <    MPIcheckPoint();
85 >      sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
86 >      MPIcheckPoint();
87  
88   #endif // is_mpi
89  
90 < }
90 >    }
91  
92  
93 < DumpWriter::DumpWriter(SimInfo* info, const std::string& filename)
94 <                   : info_(info), filename_(filename){
93 >  DumpWriter::DumpWriter(SimInfo* info, const std::string& filename)
94 >    : info_(info), filename_(filename){
95 >
96 >    Globals* simParams = info->getSimParams();
97 >    eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor";    
98 >
99 >    needCompression_ = simParams->getCompressDumpFile();
100 >    if (needCompression_) {
101 >        filename_ += ".gz";
102 >        eorFilename_ += ".gz";
103 >    }
104 >    
105   #ifdef IS_MPI
106  
107 <    if (worldRank == 0) {
107 >      if (worldRank == 0) {
108   #endif // is_mpi
109  
87        eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor";
88        dumpFile_.open(filename_.c_str(), std::ios::out | std::ios::trunc);
110  
111 +        dumpFile_ = createOStream(filename_);
112 +
113          if (!dumpFile_) {
114 <            sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
115 <                    filename_.c_str());
116 <            painCave.isFatal = 1;
117 <            simError();
114 >          sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n",
115 >                  filename_.c_str());
116 >          painCave.isFatal = 1;
117 >          simError();
118          }
119  
120   #ifdef IS_MPI
121  
122 <    }
122 >      }
123  
124 <    sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
125 <    MPIcheckPoint();
124 >      sprintf(checkPointMsg, "Sucessfully opened output file for dumping.\n");
125 >      MPIcheckPoint();
126  
127   #endif // is_mpi
128  
129 < }
129 >    }
130  
131 < DumpWriter::~DumpWriter() {
131 >  DumpWriter::~DumpWriter() {
132  
133   #ifdef IS_MPI
134  
135      if (worldRank == 0) {
136   #endif // is_mpi
137  
138 <        dumpFile_.close();
138 >      delete dumpFile_;
139  
140   #ifdef IS_MPI
141  
# Line 120 | Line 143 | DumpWriter::~DumpWriter() {
143  
144   #endif // is_mpi
145  
146 < }
146 >  }
147  
148 < void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) {
148 >  void DumpWriter::writeCommentLine(std::ostream& os, Snapshot* s) {
149  
150      double currentTime;
151      Mat3x3d hmat;
# Line 137 | Line 160 | void DumpWriter::writeCommentLine(std::ostream& os, Sn
160      eta = s->getEta();
161      
162      os << currentTime << ";\t"
163 <         << hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t"
164 <         << hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t"
165 <         << hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t";
163 >       << hmat(0, 0) << "\t" << hmat(1, 0) << "\t" << hmat(2, 0) << ";\t"
164 >       << hmat(0, 1) << "\t" << hmat(1, 1) << "\t" << hmat(2, 1) << ";\t"
165 >       << hmat(0, 2) << "\t" << hmat(1, 2) << "\t" << hmat(2, 2) << ";\t";
166  
167      //write out additional parameters, such as chi and eta
168  
169      os << chi << "\t" << integralOfChiDt << "\t;";
170  
171      os << eta(0, 0) << "\t" << eta(1, 0) << "\t" << eta(2, 0) << ";\t"
172 <         << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t"
173 <         << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";";
172 >       << eta(0, 1) << "\t" << eta(1, 1) << "\t" << eta(2, 1) << ";\t"
173 >       << eta(0, 2) << "\t" << eta(1, 2) << "\t" << eta(2, 2) << ";";
174          
175      os << "\n";
176 < }
176 >  }
177  
178 < void DumpWriter::writeFrame(std::ostream& os) {
178 >  void DumpWriter::writeFrame(std::ostream& os) {
179      const int BUFFERSIZE = 2000;
180      const int MINIBUFFERSIZE = 100;
181  
# Line 181 | Line 204 | void DumpWriter::writeFrame(std::ostream& os) {
204  
205      for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
206  
207 <        for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
208 <            integrableObject = mol->nextIntegrableObject(ii)) {
207 >      for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
208 >           integrableObject = mol->nextIntegrableObject(ii)) {
209                  
210  
211 <            pos = integrableObject->getPos();
212 <            vel = integrableObject->getVel();
211 >        pos = integrableObject->getPos();
212 >        vel = integrableObject->getVel();
213  
214 <            sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
215 <                    integrableObject->getType().c_str(),
216 <                    pos[0], pos[1], pos[2],
217 <                    vel[0], vel[1], vel[2]);
214 >        sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
215 >                integrableObject->getType().c_str(),
216 >                pos[0], pos[1], pos[2],
217 >                vel[0], vel[1], vel[2]);
218  
219 <            strcpy(writeLine, tempBuffer);
197 <
198 <            if (integrableObject->isDirectional()) {
199 <                q = integrableObject->getQ();
200 <                ji = integrableObject->getJ();
219 >        strcpy(writeLine, tempBuffer);
220  
221 <                sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
222 <                        q[0], q[1], q[2], q[3],
223 <                        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 <            }
221 >        if (integrableObject->isDirectional()) {
222 >          q = integrableObject->getQ();
223 >          ji = integrableObject->getJ();
224  
225 <            os << writeLine;
225 >          sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",
226 >                  q[0], q[1], q[2], q[3],
227 >                  ji[0], ji[1], ji[2]);
228 >          strcat(writeLine, tempBuffer);
229 >        } else {
230 >          strcat(writeLine, "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
231 >        }
232  
233 <        }
233 >        os << writeLine;
234 >
235 >      }
236      }
237  
238      os.flush();
# Line 271 | Line 294 | void DumpWriter::writeFrame(std::ostream& os) {
294      MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag);
295  
296      if (flag) {
297 <        MAXTAG = *tagub;
297 >      MAXTAG = *tagub;
298      } else {
299 <        MAXTAG = 32767;
299 >      MAXTAG = 32767;
300      }
301  
302      if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file
303  
304 <        // Node 0 needs a list of the magic potatoes for each processor;
304 >      // Node 0 needs a list of the magic potatoes for each processor;
305  
306 <        MPI_Comm_size(MPI_COMM_WORLD, &nProc);
307 <        potatoes = new int[nProc];
306 >      MPI_Comm_size(MPI_COMM_WORLD, &nProc);
307 >      potatoes = new int[nProc];
308  
309 <        //write out the comment lines
310 <        for(int i = 0; i < nProc; i++) {
311 <            potatoes[i] = 0;
312 <        }
309 >      //write out the comment lines
310 >      for(int i = 0; i < nProc; i++) {
311 >        potatoes[i] = 0;
312 >      }
313  
314  
315 <        os << nTotObjects << "\n";
316 <        writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
315 >      os << nTotObjects << "\n";
316 >      writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot());
317  
318 <        for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
318 >      for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
319  
320 <            // Get the Node number which has this atom;
320 >        // Get the Node number which has this atom;
321  
322 <            which_node = info_->getMolToProc(i);
322 >        which_node = info_->getMolToProc(i);
323  
324 <            if (which_node != masterNode) { //current molecule is in slave node
325 <                if (potatoes[which_node] + 1 >= MAXTAG) {
326 <                    // The potato was going to exceed the maximum value,
327 <                    // so wrap this processor potato back to 0:        
324 >        if (which_node != masterNode) { //current molecule is in slave node
325 >          if (potatoes[which_node] + 1 >= MAXTAG) {
326 >            // The potato was going to exceed the maximum value,
327 >            // so wrap this processor potato back to 0:        
328  
329 <                    potatoes[which_node] = 0;
330 <                    MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0,
331 <                             MPI_COMM_WORLD);
332 <                }
329 >            potatoes[which_node] = 0;
330 >            MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0,
331 >                     MPI_COMM_WORLD);
332 >          }
333  
334 <                myPotato = potatoes[which_node];
334 >          myPotato = potatoes[which_node];
335  
336 <                //recieve the number of integrableObject in current molecule
337 <                MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato,
338 <                         MPI_COMM_WORLD, &istatus);
339 <                myPotato++;
336 >          //recieve the number of integrableObject in current molecule
337 >          MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato,
338 >                   MPI_COMM_WORLD, &istatus);
339 >          myPotato++;
340  
341 <                for(int l = 0; l < nCurObj; l++) {
342 <                    if (potatoes[which_node] + 2 >= MAXTAG) {
343 <                        // The potato was going to exceed the maximum value,
344 <                        // so wrap this processor potato back to 0:        
322 <
323 <                        potatoes[which_node] = 0;
324 <                        MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node,
325 <                                 0, MPI_COMM_WORLD);
326 <                    }
341 >          for(int l = 0; l < nCurObj; l++) {
342 >            if (potatoes[which_node] + 2 >= MAXTAG) {
343 >              // The potato was going to exceed the maximum value,
344 >              // so wrap this processor potato back to 0:        
345  
346 <                    MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR,
347 <                             which_node, myPotato, MPI_COMM_WORLD,
348 <                             &istatus);
346 >              potatoes[which_node] = 0;
347 >              MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node,
348 >                       0, MPI_COMM_WORLD);
349 >            }
350  
351 <                    myPotato++;
351 >            MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR,
352 >                     which_node, myPotato, MPI_COMM_WORLD,
353 >                     &istatus);
354  
355 <                    MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato,
335 <                             MPI_COMM_WORLD, &istatus);
336 <                    myPotato++;
355 >            myPotato++;
356  
357 <                    MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen);
357 >            MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato,
358 >                     MPI_COMM_WORLD, &istatus);
359 >            myPotato++;
360  
361 <                    if (msgLen == 13)
341 <                        isDirectional = 1;
342 <                    else
343 <                        isDirectional = 0;
361 >            MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen);
362  
363 <                    // If we've survived to here, format the line:
363 >            if (msgLen == 13)
364 >              isDirectional = 1;
365 >            else
366 >              isDirectional = 0;
367  
368 <                    if (!isDirectional) {
348 <                        sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
349 <                                MPIatomTypeString, atomData[0],
350 <                                atomData[1], atomData[2],
351 <                                atomData[3], atomData[4],
352 <                                atomData[5]);
368 >            // If we've survived to here, format the line:
369  
370 <                        strcat(writeLine,
371 <                               "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
372 <                    } else {
373 <                        sprintf(writeLine,
374 <                                "%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",
375 <                                MPIatomTypeString,
360 <                                atomData[0],
361 <                                atomData[1],
362 <                                atomData[2],
363 <                                atomData[3],
364 <                                atomData[4],
365 <                                atomData[5],
366 <                                atomData[6],
367 <                                atomData[7],
368 <                                atomData[8],
369 <                                atomData[9],
370 <                                atomData[10],
371 <                                atomData[11],
372 <                                atomData[12]);
373 <                    }
370 >            if (!isDirectional) {
371 >              sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
372 >                      MPIatomTypeString, atomData[0],
373 >                      atomData[1], atomData[2],
374 >                      atomData[3], atomData[4],
375 >                      atomData[5]);
376  
377 <                    os << writeLine;
377 >              strcat(writeLine,
378 >                     "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
379 >            } else {
380 >              sprintf(writeLine,
381 >                      "%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",
382 >                      MPIatomTypeString,
383 >                      atomData[0],
384 >                      atomData[1],
385 >                      atomData[2],
386 >                      atomData[3],
387 >                      atomData[4],
388 >                      atomData[5],
389 >                      atomData[6],
390 >                      atomData[7],
391 >                      atomData[8],
392 >                      atomData[9],
393 >                      atomData[10],
394 >                      atomData[11],
395 >                      atomData[12]);
396 >            }
397  
398 <                } // end for(int l =0)
398 >            os << writeLine;
399  
400 <                potatoes[which_node] = myPotato;
380 <            } else { //master node has current molecule
400 >          } // end for(int l =0)
401  
402 <                mol = info_->getMoleculeByGlobalIndex(i);
402 >          potatoes[which_node] = myPotato;
403 >        } else { //master node has current molecule
404  
405 <                if (mol == NULL) {
406 <                    sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank);
407 <                    painCave.isFatal = 1;
408 <                    simError();
409 <                }
405 >          mol = info_->getMoleculeByGlobalIndex(i);
406 >
407 >          if (mol == NULL) {
408 >            sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank);
409 >            painCave.isFatal = 1;
410 >            simError();
411 >          }
412                  
413 <                for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
414 <                    integrableObject = mol->nextIntegrableObject(ii)) {      
413 >          for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
414 >               integrableObject = mol->nextIntegrableObject(ii)) {      
415  
416 <                    pos = integrableObject->getPos();
417 <                    vel = integrableObject->getVel();
416 >            pos = integrableObject->getPos();
417 >            vel = integrableObject->getVel();
418  
419 <                    atomData[0] = pos[0];
420 <                    atomData[1] = pos[1];
421 <                    atomData[2] = pos[2];
419 >            atomData[0] = pos[0];
420 >            atomData[1] = pos[1];
421 >            atomData[2] = pos[2];
422  
423 <                    atomData[3] = vel[0];
424 <                    atomData[4] = vel[1];
425 <                    atomData[5] = vel[2];
423 >            atomData[3] = vel[0];
424 >            atomData[4] = vel[1];
425 >            atomData[5] = vel[2];
426  
427 <                    isDirectional = 0;
427 >            isDirectional = 0;
428  
429 <                    if (integrableObject->isDirectional()) {
430 <                        isDirectional = 1;
429 >            if (integrableObject->isDirectional()) {
430 >              isDirectional = 1;
431  
432 <                        q = integrableObject->getQ();
433 <                        ji = integrableObject->getJ();
432 >              q = integrableObject->getQ();
433 >              ji = integrableObject->getJ();
434  
435 <                        for(int j = 0; j < 6; j++) {
436 <                            atomData[j] = atomData[j];
437 <                        }
435 >              for(int j = 0; j < 6; j++) {
436 >                atomData[j] = atomData[j];
437 >              }
438  
439 <                        atomData[6] = q[0];
440 <                        atomData[7] = q[1];
441 <                        atomData[8] = q[2];
442 <                        atomData[9] = q[3];
439 >              atomData[6] = q[0];
440 >              atomData[7] = q[1];
441 >              atomData[8] = q[2];
442 >              atomData[9] = q[3];
443  
444 <                        atomData[10] = ji[0];
445 <                        atomData[11] = ji[1];
446 <                        atomData[12] = ji[2];
447 <                    }
444 >              atomData[10] = ji[0];
445 >              atomData[11] = ji[1];
446 >              atomData[12] = ji[2];
447 >            }
448  
449 <                    // If we've survived to here, format the line:
449 >            // If we've survived to here, format the line:
450  
451 <                    if (!isDirectional) {
452 <                        sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
453 <                                integrableObject->getType().c_str(), atomData[0],
454 <                                atomData[1], atomData[2],
455 <                                atomData[3], atomData[4],
456 <                                atomData[5]);
451 >            if (!isDirectional) {
452 >              sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t",
453 >                      integrableObject->getType().c_str(), atomData[0],
454 >                      atomData[1], atomData[2],
455 >                      atomData[3], atomData[4],
456 >                      atomData[5]);
457  
458 <                        strcat(writeLine,
459 <                               "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
460 <                    } else {
461 <                        sprintf(writeLine,
462 <                                "%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",
463 <                                integrableObject->getType().c_str(),
464 <                                atomData[0],
465 <                                atomData[1],
466 <                                atomData[2],
467 <                                atomData[3],
468 <                                atomData[4],
469 <                                atomData[5],
470 <                                atomData[6],
471 <                                atomData[7],
472 <                                atomData[8],
473 <                                atomData[9],
474 <                                atomData[10],
475 <                                atomData[11],
476 <                                atomData[12]);
477 <                    }
458 >              strcat(writeLine,
459 >                     "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n");
460 >            } else {
461 >              sprintf(writeLine,
462 >                      "%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",
463 >                      integrableObject->getType().c_str(),
464 >                      atomData[0],
465 >                      atomData[1],
466 >                      atomData[2],
467 >                      atomData[3],
468 >                      atomData[4],
469 >                      atomData[5],
470 >                      atomData[6],
471 >                      atomData[7],
472 >                      atomData[8],
473 >                      atomData[9],
474 >                      atomData[10],
475 >                      atomData[11],
476 >                      atomData[12]);
477 >            }
478  
479  
480 <                    os << writeLine;
480 >            os << writeLine;
481  
482 <                } //end for(iter = integrableObject.begin())
483 <            }
484 <        } //end for(i = 0; i < mpiSim->getNmol())
482 >          } //end for(iter = integrableObject.begin())
483 >        }
484 >      } //end for(i = 0; i < mpiSim->getNmol())
485  
486 <        os.flush();
486 >      os.flush();
487          
488 <        sprintf(checkPointMsg, "Sucessfully took a dump.\n");
489 <        MPIcheckPoint();
488 >      sprintf(checkPointMsg, "Sucessfully took a dump.\n");
489 >      MPIcheckPoint();
490  
491 <        delete [] potatoes;
491 >      delete [] potatoes;
492      } else {
493  
494 <        // worldRank != 0, so I'm a remote node.  
494 >      // worldRank != 0, so I'm a remote node.  
495  
496 <        // Set my magic potato to 0:
496 >      // Set my magic potato to 0:
497  
498 <        myPotato = 0;
498 >      myPotato = 0;
499  
500 <        for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
500 >      for(int i = 0; i < info_->getNGlobalMolecules(); i++) {
501  
502 <            // Am I the node which has this integrableObject?
503 <            int whichNode = info_->getMolToProc(i);
504 <            if (whichNode == worldRank) {
505 <                if (myPotato + 1 >= MAXTAG) {
502 >        // Am I the node which has this integrableObject?
503 >        int whichNode = info_->getMolToProc(i);
504 >        if (whichNode == worldRank) {
505 >          if (myPotato + 1 >= MAXTAG) {
506  
507 <                    // The potato was going to exceed the maximum value,
508 <                    // so wrap this processor potato back to 0 (and block until
509 <                    // node 0 says we can go:
507 >            // The potato was going to exceed the maximum value,
508 >            // so wrap this processor potato back to 0 (and block until
509 >            // node 0 says we can go:
510  
511 <                    MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
512 <                             &istatus);
513 <                }
511 >            MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
512 >                     &istatus);
513 >          }
514  
515 <                mol = info_->getMoleculeByGlobalIndex(i);
515 >          mol = info_->getMoleculeByGlobalIndex(i);
516  
517                  
518 <                nCurObj = mol->getNIntegrableObjects();
518 >          nCurObj = mol->getNIntegrableObjects();
519  
520 <                MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD);
521 <                myPotato++;
520 >          MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD);
521 >          myPotato++;
522  
523 <                for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
524 <                    integrableObject = mol->nextIntegrableObject(ii)) {
523 >          for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;
524 >               integrableObject = mol->nextIntegrableObject(ii)) {
525  
526 <                    if (myPotato + 2 >= MAXTAG) {
526 >            if (myPotato + 2 >= MAXTAG) {
527  
528 <                        // The potato was going to exceed the maximum value,
529 <                        // so wrap this processor potato back to 0 (and block until
530 <                        // node 0 says we can go:
528 >              // The potato was going to exceed the maximum value,
529 >              // so wrap this processor potato back to 0 (and block until
530 >              // node 0 says we can go:
531  
532 <                        MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
533 <                                 &istatus);
534 <                    }
532 >              MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD,
533 >                       &istatus);
534 >            }
535  
536 <                    pos = integrableObject->getPos();
537 <                    vel = integrableObject->getVel();
536 >            pos = integrableObject->getPos();
537 >            vel = integrableObject->getVel();
538  
539 <                    atomData[0] = pos[0];
540 <                    atomData[1] = pos[1];
541 <                    atomData[2] = pos[2];
539 >            atomData[0] = pos[0];
540 >            atomData[1] = pos[1];
541 >            atomData[2] = pos[2];
542  
543 <                    atomData[3] = vel[0];
544 <                    atomData[4] = vel[1];
545 <                    atomData[5] = vel[2];
543 >            atomData[3] = vel[0];
544 >            atomData[4] = vel[1];
545 >            atomData[5] = vel[2];
546  
547 <                    isDirectional = 0;
547 >            isDirectional = 0;
548  
549 <                    if (integrableObject->isDirectional()) {
550 <                        isDirectional = 1;
549 >            if (integrableObject->isDirectional()) {
550 >              isDirectional = 1;
551  
552 <                        q = integrableObject->getQ();
553 <                        ji = integrableObject->getJ();
552 >              q = integrableObject->getQ();
553 >              ji = integrableObject->getJ();
554  
555 <                        atomData[6] = q[0];
556 <                        atomData[7] = q[1];
557 <                        atomData[8] = q[2];
558 <                        atomData[9] = q[3];
555 >              atomData[6] = q[0];
556 >              atomData[7] = q[1];
557 >              atomData[8] = q[2];
558 >              atomData[9] = q[3];
559  
560 <                        atomData[10] = ji[0];
561 <                        atomData[11] = ji[1];
562 <                        atomData[12] = ji[2];
563 <                    }
560 >              atomData[10] = ji[0];
561 >              atomData[11] = ji[1];
562 >              atomData[12] = ji[2];
563 >            }
564  
565 <                    strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE);
565 >            strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE);
566  
567 <                    // null terminate the  std::string before sending (just in case):
568 <                    MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0';
567 >            // null terminate the  std::string before sending (just in case):
568 >            MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0';
569  
570 <                    MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
571 <                             myPotato, MPI_COMM_WORLD);
570 >            MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0,
571 >                     myPotato, MPI_COMM_WORLD);
572  
573 <                    myPotato++;
573 >            myPotato++;
574  
575 <                    if (isDirectional) {
576 <                        MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato,
577 <                                 MPI_COMM_WORLD);
578 <                    } else {
579 <                        MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato,
580 <                                 MPI_COMM_WORLD);
581 <                    }
575 >            if (isDirectional) {
576 >              MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato,
577 >                       MPI_COMM_WORLD);
578 >            } else {
579 >              MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato,
580 >                       MPI_COMM_WORLD);
581 >            }
582  
583 <                    myPotato++;
584 <                }
583 >            myPotato++;
584 >          }
585                      
586 <            }
586 >        }
587              
588 <        }
589 <        sprintf(checkPointMsg, "Sucessfully took a dump.\n");
590 <        MPIcheckPoint();
588 >      }
589 >      sprintf(checkPointMsg, "Sucessfully took a dump.\n");
590 >      MPIcheckPoint();
591      }
592  
593   #endif // is_mpi
594  
595 < }
595 >  }
596  
597 < void DumpWriter::writeDump() {
598 <    writeFrame(dumpFile_);
597 >  void DumpWriter::writeDump() {
598 >    writeFrame(*dumpFile_);
599 >  }
600  
601 < }
602 <
579 < void DumpWriter::writeEor() {
580 <    std::ofstream eorStream;
601 >  void DumpWriter::writeEor() {
602 >    std::ostream* eorStream;
603      
604   #ifdef IS_MPI
605      if (worldRank == 0) {
606   #endif // is_mpi
607  
608 <        eorStream.open(eorFilename_.c_str());
587 <        if (!eorStream.is_open()) {
588 <            sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n",
589 <                    eorFilename_.c_str());
590 <            painCave.isFatal = 1;
591 <            simError();
592 <        }
608 >      eorStream = createOStream(eorFilename_);
609  
610   #ifdef IS_MPI
611      }
612   #endif // is_mpi    
613  
614 <    writeFrame(eorStream);
599 < }
614 >    writeFrame(*eorStream);
615  
616 + #ifdef IS_MPI
617 +    if (worldRank == 0) {
618 + #endif // is_mpi
619 +    delete eorStream;
620  
621 < void DumpWriter::writeDumpAndEor() {
622 <    std::ofstream eorStream;
621 > #ifdef IS_MPI
622 >    }
623 > #endif // is_mpi  
624 >
625 >  }
626 >
627 >
628 >  void DumpWriter::writeDumpAndEor() {
629      std::vector<std::streambuf*> buffers;
630 +    std::ostream* eorStream;
631   #ifdef IS_MPI
632      if (worldRank == 0) {
633   #endif // is_mpi
634  
635 <        buffers.push_back(dumpFile_.rdbuf());
635 >      buffers.push_back(dumpFile_->rdbuf());
636  
637 <        eorStream.open(eorFilename_.c_str());
612 <        if (!eorStream.is_open()) {
613 <            sprintf(painCave.errMsg, "DumpWriter : Could not open \"%s\" for writing.\n",
614 <                    eorFilename_.c_str());
615 <            painCave.isFatal = 1;
616 <            simError();
617 <        }
637 >      eorStream = createOStream(eorFilename_);
638  
639 <        buffers.push_back(eorStream.rdbuf());
639 >      buffers.push_back(eorStream->rdbuf());
640          
641   #ifdef IS_MPI
642      }
# Line 626 | Line 646 | void DumpWriter::writeDumpAndEor() {
646      std::ostream os(&tbuf);
647  
648      writeFrame(os);
629    
630 }
649  
650 + #ifdef IS_MPI
651 +    if (worldRank == 0) {
652 + #endif // is_mpi
653 +    delete eorStream;
654  
655 + #ifdef IS_MPI
656 +    }
657 + #endif // is_mpi  
658 +    
659 +  }
660  
661 + std::ostream* DumpWriter::createOStream(const std::string& filename) {
662 +    std::ostream* newOStream;
663 +    if (needCompression_) {
664 +        newOStream = new ogzstream(filename.c_str());
665 +    } else {
666 +        newOStream = new std::ofstream(filename.c_str());
667 +    }
668 +    return newOStream;
669 + }
670 +
671   }//end namespace oopse

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines