| 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 | 
| 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", currentTime); | 
| 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 | 
< | 
 | 
| 237 | 
< | 
 | 
| 238 | 
< | 
    os << nTotObjects << "\n"; | 
| 179 | 
< | 
         | 
| 180 | 
< | 
    writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); | 
| 236 | 
> | 
    os << "  <Snapshot>\n"; | 
| 237 | 
> | 
  | 
| 238 | 
> | 
    writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); | 
| 239 | 
  | 
 | 
| 240 | 
+ | 
    os << "    <StuntDoubles>\n"; | 
| 241 | 
  | 
    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 242 | 
  | 
 | 
| 243 | 
< | 
        for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;  | 
| 244 | 
< | 
            integrableObject = mol->nextIntegrableObject(ii)) {  | 
| 245 | 
< | 
                 | 
| 243 | 
> | 
       | 
| 244 | 
> | 
      for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;   | 
| 245 | 
> | 
           integrableObject = mol->nextIntegrableObject(ii)) {   | 
| 246 | 
> | 
          os << prepareDumpLine(integrableObject); | 
| 247 | 
> | 
           | 
| 248 | 
> | 
      } | 
| 249 | 
> | 
    }     | 
| 250 | 
> | 
    os << "    </StuntDoubles>\n"; | 
| 251 | 
> | 
     | 
| 252 | 
> | 
    os << "  </Snapshot>\n"; | 
| 253 | 
  | 
 | 
| 254 | 
< | 
            pos = integrableObject->getPos(); | 
| 255 | 
< | 
            vel = integrableObject->getVel(); | 
| 254 | 
> | 
    os.flush(); | 
| 255 | 
> | 
#else | 
| 256 | 
> | 
    //every node prepares the dump lines for integrable objects belong to itself | 
| 257 | 
> | 
    std::string buffer; | 
| 258 | 
> | 
    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { | 
| 259 | 
  | 
 | 
| 191 | 
– | 
            sprintf(tempBuffer, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", | 
| 192 | 
– | 
                    integrableObject->getType().c_str(),  | 
| 193 | 
– | 
                    pos[0], pos[1], pos[2], | 
| 194 | 
– | 
                    vel[0], vel[1], vel[2]); | 
| 260 | 
  | 
 | 
| 261 | 
< | 
            strcpy(writeLine, tempBuffer); | 
| 261 | 
> | 
      for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;  | 
| 262 | 
> | 
           integrableObject = mol->nextIntegrableObject(ii)) {   | 
| 263 | 
> | 
          buffer += prepareDumpLine(integrableObject); | 
| 264 | 
> | 
      } | 
| 265 | 
> | 
    } | 
| 266 | 
> | 
     | 
| 267 | 
> | 
    const int masterNode = 0; | 
| 268 | 
  | 
 | 
| 269 | 
< | 
            if (integrableObject->isDirectional()) { | 
| 270 | 
< | 
                q = integrableObject->getQ(); | 
| 271 | 
< | 
                ji = integrableObject->getJ(); | 
| 269 | 
> | 
    if (worldRank == masterNode) {       | 
| 270 | 
> | 
      os << "  <Snapshot>\n";    | 
| 271 | 
> | 
      writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); | 
| 272 | 
> | 
      os << "    <StuntDoubles>\n"; | 
| 273 | 
> | 
         | 
| 274 | 
> | 
      os << buffer; | 
| 275 | 
  | 
 | 
| 276 | 
< | 
                sprintf(tempBuffer, "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n",  | 
| 277 | 
< | 
                        q[0], q[1], q[2], q[3], | 
| 278 | 
< | 
                        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 | 
< | 
            } | 
| 276 | 
> | 
      int nProc; | 
| 277 | 
> | 
      MPI_Comm_size(MPI_COMM_WORLD, &nProc); | 
| 278 | 
> | 
      for (int i = 1; i < nProc; ++i) { | 
| 279 | 
  | 
 | 
| 280 | 
< | 
            os << writeLine; | 
| 280 | 
> | 
        // receive the length of the string buffer that was | 
| 281 | 
> | 
        // prepared by processor i | 
| 282 | 
  | 
 | 
| 283 | 
+ | 
        int recvLength; | 
| 284 | 
+ | 
        MPI_Recv(&recvLength, 1, MPI_INT, i, 0, MPI_COMM_WORLD, &istatus); | 
| 285 | 
+ | 
        char* recvBuffer = new char[recvLength]; | 
| 286 | 
+ | 
        if (recvBuffer == NULL) { | 
| 287 | 
+ | 
        } else { | 
| 288 | 
+ | 
          MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, 0, MPI_COMM_WORLD, &istatus); | 
| 289 | 
+ | 
          os << recvBuffer; | 
| 290 | 
+ | 
          delete recvBuffer; | 
| 291 | 
  | 
        } | 
| 292 | 
< | 
    } | 
| 293 | 
< | 
 | 
| 294 | 
< | 
    os.flush(); | 
| 295 | 
< | 
#else // is_mpi | 
| 296 | 
< | 
    /********************************************************************* | 
| 218 | 
< | 
     * Documentation?  You want DOCUMENTATION? | 
| 219 | 
< | 
     *  | 
| 220 | 
< | 
     * Why all the potatoes below?   | 
| 221 | 
< | 
     * | 
| 222 | 
< | 
     * To make a long story short, the original version of DumpWriter | 
| 223 | 
< | 
     * worked in the most inefficient way possible.  Node 0 would  | 
| 224 | 
< | 
     * poke each of the node for an individual atom's formatted data  | 
| 225 | 
< | 
     * as node 0 worked its way down the global index. This was particularly  | 
| 226 | 
< | 
     * 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 | 
< | 
     *********************************************************************/ | 
| 253 | 
< | 
    const int masterNode = 0; | 
| 254 | 
< | 
 | 
| 255 | 
< | 
    int * potatoes; | 
| 256 | 
< | 
    int myPotato; | 
| 257 | 
< | 
    int nProc; | 
| 258 | 
< | 
    int which_node; | 
| 259 | 
< | 
    double atomData[13]; | 
| 260 | 
< | 
    int isDirectional; | 
| 261 | 
< | 
    char MPIatomTypeString[MINIBUFFERSIZE]; | 
| 262 | 
< | 
    int msgLen; // the length of message actually recieved at master nodes | 
| 263 | 
< | 
    int haveError; | 
| 264 | 
< | 
    MPI_Status istatus; | 
| 265 | 
< | 
    int nCurObj; | 
| 266 | 
< | 
     | 
| 267 | 
< | 
    // code to find maximum tag value | 
| 268 | 
< | 
    int * tagub; | 
| 269 | 
< | 
    int flag; | 
| 270 | 
< | 
    int MAXTAG; | 
| 271 | 
< | 
    MPI_Attr_get(MPI_COMM_WORLD, MPI_TAG_UB, &tagub, &flag); | 
| 272 | 
< | 
 | 
| 273 | 
< | 
    if (flag) { | 
| 274 | 
< | 
        MAXTAG = *tagub; | 
| 292 | 
> | 
      }  | 
| 293 | 
> | 
      os << "    </StuntDoubles>\n"; | 
| 294 | 
> | 
       | 
| 295 | 
> | 
      os << "  </Snapshot>\n"; | 
| 296 | 
> | 
      os.flush(); | 
| 297 | 
  | 
    } else { | 
| 298 | 
< | 
        MAXTAG = 32767; | 
| 298 | 
> | 
      int sendBufferLength = buffer.size() + 1; | 
| 299 | 
> | 
      MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); | 
| 300 | 
> | 
      MPI_Send((void *)buffer.c_str(), sendBufferLength, MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); | 
| 301 | 
  | 
    } | 
| 302 | 
  | 
 | 
| 303 | 
< | 
    if (worldRank == masterNode) { //master node (node 0) is responsible for writing the dump file | 
| 303 | 
> | 
#endif // is_mpi | 
| 304 | 
  | 
 | 
| 305 | 
< | 
        // Node 0 needs a list of the magic potatoes for each processor; | 
| 305 | 
> | 
  } | 
| 306 | 
  | 
 | 
| 307 | 
< | 
        MPI_Comm_size(MPI_COMM_WORLD, &nProc); | 
| 308 | 
< | 
        potatoes = new int[nProc]; | 
| 307 | 
> | 
  std::string DumpWriter::prepareDumpLine(StuntDouble* integrableObject) { | 
| 308 | 
> | 
         | 
| 309 | 
> | 
    int index = integrableObject->getGlobalIntegrableObjectIndex(); | 
| 310 | 
> | 
    std::string type("pv"); | 
| 311 | 
> | 
    std::string line; | 
| 312 | 
> | 
    char tempBuffer[4096]; | 
| 313 | 
  | 
 | 
| 314 | 
< | 
        //write out the comment lines | 
| 315 | 
< | 
        for(int i = 0; i < nProc; i++) { | 
| 316 | 
< | 
            potatoes[i] = 0; | 
| 317 | 
< | 
        } | 
| 314 | 
> | 
    Vector3d pos; | 
| 315 | 
> | 
    Vector3d vel; | 
| 316 | 
> | 
    pos = integrableObject->getPos(); | 
| 317 | 
> | 
    vel = integrableObject->getVel();            | 
| 318 | 
> | 
    sprintf(tempBuffer, "%18.10g %18.10g %18.10g %13e %13e %13e",  | 
| 319 | 
> | 
            pos[0], pos[1], pos[2], | 
| 320 | 
> | 
            vel[0], vel[1], vel[2]);                     | 
| 321 | 
> | 
    line += tempBuffer; | 
| 322 | 
  | 
 | 
| 323 | 
+ | 
    if (integrableObject->isDirectional()) { | 
| 324 | 
+ | 
      type += "qj"; | 
| 325 | 
+ | 
      Quat4d q; | 
| 326 | 
+ | 
      Vector3d ji; | 
| 327 | 
+ | 
      q = integrableObject->getQ(); | 
| 328 | 
+ | 
      ji = integrableObject->getJ(); | 
| 329 | 
+ | 
      sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e %13e", | 
| 330 | 
+ | 
              q[0], q[1], q[2], q[3], | 
| 331 | 
+ | 
              ji[0], ji[1], ji[2]); | 
| 332 | 
+ | 
      line += tempBuffer; | 
| 333 | 
+ | 
    } | 
| 334 | 
  | 
 | 
| 335 | 
< | 
        os << nTotObjects << "\n"; | 
| 336 | 
< | 
        writeCommentLine(os, info_->getSnapshotManager()->getCurrentSnapshot()); | 
| 337 | 
< | 
 | 
| 338 | 
< | 
        for(int i = 0; i < info_->getNGlobalMolecules(); i++) { | 
| 339 | 
< | 
 | 
| 340 | 
< | 
            // Get the Node number which has this atom; | 
| 341 | 
< | 
 | 
| 342 | 
< | 
            which_node = info_->getMolToProc(i); | 
| 343 | 
< | 
 | 
| 344 | 
< | 
            if (which_node != masterNode) { //current molecule is in slave node | 
| 345 | 
< | 
                if (potatoes[which_node] + 1 >= MAXTAG) { | 
| 303 | 
< | 
                    // The potato was going to exceed the maximum value,  | 
| 304 | 
< | 
                    // so wrap this processor potato back to 0:          | 
| 305 | 
< | 
 | 
| 306 | 
< | 
                    potatoes[which_node] = 0; | 
| 307 | 
< | 
                    MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, | 
| 308 | 
< | 
                             MPI_COMM_WORLD); | 
| 309 | 
< | 
                } | 
| 310 | 
< | 
 | 
| 311 | 
< | 
                myPotato = potatoes[which_node]; | 
| 312 | 
< | 
 | 
| 313 | 
< | 
                //recieve the number of integrableObject in current molecule | 
| 314 | 
< | 
                MPI_Recv(&nCurObj, 1, MPI_INT, which_node, myPotato, | 
| 315 | 
< | 
                         MPI_COMM_WORLD, &istatus); | 
| 316 | 
< | 
                myPotato++; | 
| 317 | 
< | 
 | 
| 318 | 
< | 
                for(int l = 0; l < nCurObj; l++) { | 
| 319 | 
< | 
                    if (potatoes[which_node] + 2 >= MAXTAG) { | 
| 320 | 
< | 
                        // The potato was going to exceed the maximum value,  | 
| 321 | 
< | 
                        // so wrap this processor potato back to 0:          | 
| 322 | 
< | 
 | 
| 323 | 
< | 
                        potatoes[which_node] = 0; | 
| 324 | 
< | 
                        MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, | 
| 325 | 
< | 
                                 0, MPI_COMM_WORLD); | 
| 326 | 
< | 
                    } | 
| 327 | 
< | 
 | 
| 328 | 
< | 
                    MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, | 
| 329 | 
< | 
                             which_node, myPotato, MPI_COMM_WORLD, | 
| 330 | 
< | 
                             &istatus); | 
| 331 | 
< | 
 | 
| 332 | 
< | 
                    myPotato++; | 
| 333 | 
< | 
 | 
| 334 | 
< | 
                    MPI_Recv(atomData, 13, MPI_DOUBLE, which_node, myPotato, | 
| 335 | 
< | 
                             MPI_COMM_WORLD, &istatus); | 
| 336 | 
< | 
                    myPotato++; | 
| 337 | 
< | 
 | 
| 338 | 
< | 
                    MPI_Get_count(&istatus, MPI_DOUBLE, &msgLen); | 
| 339 | 
< | 
 | 
| 340 | 
< | 
                    if (msgLen == 13) | 
| 341 | 
< | 
                        isDirectional = 1; | 
| 342 | 
< | 
                    else | 
| 343 | 
< | 
                        isDirectional = 0; | 
| 344 | 
< | 
 | 
| 345 | 
< | 
                    // If we've survived to here, format the line: | 
| 346 | 
< | 
 | 
| 347 | 
< | 
                    if (!isDirectional) { | 
| 348 | 
< | 
                        sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", | 
| 349 | 
< | 
                                MPIatomTypeString, atomData[0], | 
| 350 | 
< | 
                                atomData[1], atomData[2], | 
| 351 | 
< | 
                                atomData[3], atomData[4], | 
| 352 | 
< | 
                                atomData[5]); | 
| 353 | 
< | 
 | 
| 354 | 
< | 
                        strcat(writeLine, | 
| 355 | 
< | 
                               "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); | 
| 356 | 
< | 
                    } else { | 
| 357 | 
< | 
                        sprintf(writeLine, | 
| 358 | 
< | 
                                "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", | 
| 359 | 
< | 
                                MPIatomTypeString, | 
| 360 | 
< | 
                                atomData[0], | 
| 361 | 
< | 
                                atomData[1], | 
| 362 | 
< | 
                                atomData[2], | 
| 363 | 
< | 
                                atomData[3], | 
| 364 | 
< | 
                                atomData[4], | 
| 365 | 
< | 
                                atomData[5], | 
| 366 | 
< | 
                                atomData[6], | 
| 367 | 
< | 
                                atomData[7], | 
| 368 | 
< | 
                                atomData[8], | 
| 369 | 
< | 
                                atomData[9], | 
| 370 | 
< | 
                                atomData[10], | 
| 371 | 
< | 
                                atomData[11], | 
| 372 | 
< | 
                                atomData[12]); | 
| 373 | 
< | 
                    } | 
| 374 | 
< | 
 | 
| 375 | 
< | 
                    os << writeLine; | 
| 376 | 
< | 
 | 
| 377 | 
< | 
                } // end for(int l =0) | 
| 378 | 
< | 
 | 
| 379 | 
< | 
                potatoes[which_node] = myPotato; | 
| 380 | 
< | 
            } else { //master node has current molecule | 
| 381 | 
< | 
 | 
| 382 | 
< | 
                mol = info_->getMoleculeByGlobalIndex(i); | 
| 383 | 
< | 
 | 
| 384 | 
< | 
                if (mol == NULL) { | 
| 385 | 
< | 
                    sprintf(painCave.errMsg, "Molecule not found on node %d!", worldRank); | 
| 386 | 
< | 
                    painCave.isFatal = 1; | 
| 387 | 
< | 
                    simError(); | 
| 388 | 
< | 
                } | 
| 389 | 
< | 
                 | 
| 390 | 
< | 
                for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;  | 
| 391 | 
< | 
                    integrableObject = mol->nextIntegrableObject(ii)) {       | 
| 392 | 
< | 
 | 
| 393 | 
< | 
                    pos = integrableObject->getPos(); | 
| 394 | 
< | 
                    vel = integrableObject->getVel(); | 
| 395 | 
< | 
 | 
| 396 | 
< | 
                    atomData[0] = pos[0]; | 
| 397 | 
< | 
                    atomData[1] = pos[1]; | 
| 398 | 
< | 
                    atomData[2] = pos[2]; | 
| 399 | 
< | 
 | 
| 400 | 
< | 
                    atomData[3] = vel[0]; | 
| 401 | 
< | 
                    atomData[4] = vel[1]; | 
| 402 | 
< | 
                    atomData[5] = vel[2]; | 
| 403 | 
< | 
 | 
| 404 | 
< | 
                    isDirectional = 0; | 
| 405 | 
< | 
 | 
| 406 | 
< | 
                    if (integrableObject->isDirectional()) { | 
| 407 | 
< | 
                        isDirectional = 1; | 
| 408 | 
< | 
 | 
| 409 | 
< | 
                        q = integrableObject->getQ(); | 
| 410 | 
< | 
                        ji = integrableObject->getJ(); | 
| 411 | 
< | 
 | 
| 412 | 
< | 
                        for(int j = 0; j < 6; j++) { | 
| 413 | 
< | 
                            atomData[j] = atomData[j]; | 
| 414 | 
< | 
                        } | 
| 415 | 
< | 
 | 
| 416 | 
< | 
                        atomData[6] = q[0]; | 
| 417 | 
< | 
                        atomData[7] = q[1]; | 
| 418 | 
< | 
                        atomData[8] = q[2]; | 
| 419 | 
< | 
                        atomData[9] = q[3]; | 
| 420 | 
< | 
 | 
| 421 | 
< | 
                        atomData[10] = ji[0]; | 
| 422 | 
< | 
                        atomData[11] = ji[1]; | 
| 423 | 
< | 
                        atomData[12] = ji[2]; | 
| 424 | 
< | 
                    } | 
| 425 | 
< | 
 | 
| 426 | 
< | 
                    // If we've survived to here, format the line: | 
| 427 | 
< | 
 | 
| 428 | 
< | 
                    if (!isDirectional) { | 
| 429 | 
< | 
                        sprintf(writeLine, "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", | 
| 430 | 
< | 
                                integrableObject->getType().c_str(), atomData[0], | 
| 431 | 
< | 
                                atomData[1], atomData[2], | 
| 432 | 
< | 
                                atomData[3], atomData[4], | 
| 433 | 
< | 
                                atomData[5]); | 
| 434 | 
< | 
 | 
| 435 | 
< | 
                        strcat(writeLine, | 
| 436 | 
< | 
                               "0.0\t0.0\t0.0\t0.0\t0.0\t0.0\t0.0\n"); | 
| 437 | 
< | 
                    } else { | 
| 438 | 
< | 
                        sprintf(writeLine, | 
| 439 | 
< | 
                                "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", | 
| 440 | 
< | 
                                integrableObject->getType().c_str(), | 
| 441 | 
< | 
                                atomData[0], | 
| 442 | 
< | 
                                atomData[1], | 
| 443 | 
< | 
                                atomData[2], | 
| 444 | 
< | 
                                atomData[3], | 
| 445 | 
< | 
                                atomData[4], | 
| 446 | 
< | 
                                atomData[5], | 
| 447 | 
< | 
                                atomData[6], | 
| 448 | 
< | 
                                atomData[7], | 
| 449 | 
< | 
                                atomData[8], | 
| 450 | 
< | 
                                atomData[9], | 
| 451 | 
< | 
                                atomData[10], | 
| 452 | 
< | 
                                atomData[11], | 
| 453 | 
< | 
                                atomData[12]); | 
| 454 | 
< | 
                    } | 
| 455 | 
< | 
 | 
| 456 | 
< | 
 | 
| 457 | 
< | 
                    os << writeLine; | 
| 458 | 
< | 
 | 
| 459 | 
< | 
                } //end for(iter = integrableObject.begin()) | 
| 460 | 
< | 
            } | 
| 461 | 
< | 
        } //end for(i = 0; i < mpiSim->getNmol()) | 
| 462 | 
< | 
 | 
| 463 | 
< | 
        os.flush(); | 
| 464 | 
< | 
         | 
| 465 | 
< | 
        sprintf(checkPointMsg, "Sucessfully took a dump.\n"); | 
| 466 | 
< | 
        MPIcheckPoint(); | 
| 467 | 
< | 
 | 
| 468 | 
< | 
        delete [] potatoes; | 
| 469 | 
< | 
    } else { | 
| 470 | 
< | 
 | 
| 471 | 
< | 
        // worldRank != 0, so I'm a remote node.   | 
| 472 | 
< | 
 | 
| 473 | 
< | 
        // Set my magic potato to 0: | 
| 474 | 
< | 
 | 
| 475 | 
< | 
        myPotato = 0; | 
| 476 | 
< | 
 | 
| 477 | 
< | 
        for(int i = 0; i < info_->getNGlobalMolecules(); i++) { | 
| 478 | 
< | 
 | 
| 479 | 
< | 
            // Am I the node which has this integrableObject? | 
| 480 | 
< | 
            int whichNode = info_->getMolToProc(i); | 
| 481 | 
< | 
            if (whichNode == worldRank) { | 
| 482 | 
< | 
                if (myPotato + 1 >= MAXTAG) { | 
| 483 | 
< | 
 | 
| 484 | 
< | 
                    // The potato was going to exceed the maximum value,  | 
| 485 | 
< | 
                    // so wrap this processor potato back to 0 (and block until | 
| 486 | 
< | 
                    // node 0 says we can go: | 
| 487 | 
< | 
 | 
| 488 | 
< | 
                    MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, | 
| 489 | 
< | 
                             &istatus); | 
| 490 | 
< | 
                } | 
| 491 | 
< | 
 | 
| 492 | 
< | 
                mol = info_->getMoleculeByGlobalIndex(i); | 
| 493 | 
< | 
 | 
| 494 | 
< | 
                 | 
| 495 | 
< | 
                nCurObj = mol->getNIntegrableObjects(); | 
| 496 | 
< | 
 | 
| 497 | 
< | 
                MPI_Send(&nCurObj, 1, MPI_INT, 0, myPotato, MPI_COMM_WORLD); | 
| 498 | 
< | 
                myPotato++; | 
| 499 | 
< | 
 | 
| 500 | 
< | 
                for (integrableObject = mol->beginIntegrableObject(ii); integrableObject != NULL;  | 
| 501 | 
< | 
                    integrableObject = mol->nextIntegrableObject(ii)) { | 
| 502 | 
< | 
 | 
| 503 | 
< | 
                    if (myPotato + 2 >= MAXTAG) { | 
| 504 | 
< | 
 | 
| 505 | 
< | 
                        // The potato was going to exceed the maximum value,  | 
| 506 | 
< | 
                        // so wrap this processor potato back to 0 (and block until | 
| 507 | 
< | 
                        // node 0 says we can go: | 
| 508 | 
< | 
 | 
| 509 | 
< | 
                        MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, | 
| 510 | 
< | 
                                 &istatus); | 
| 511 | 
< | 
                    } | 
| 512 | 
< | 
 | 
| 513 | 
< | 
                    pos = integrableObject->getPos(); | 
| 514 | 
< | 
                    vel = integrableObject->getVel(); | 
| 515 | 
< | 
 | 
| 516 | 
< | 
                    atomData[0] = pos[0]; | 
| 517 | 
< | 
                    atomData[1] = pos[1]; | 
| 518 | 
< | 
                    atomData[2] = pos[2]; | 
| 519 | 
< | 
 | 
| 520 | 
< | 
                    atomData[3] = vel[0]; | 
| 521 | 
< | 
                    atomData[4] = vel[1]; | 
| 522 | 
< | 
                    atomData[5] = vel[2]; | 
| 523 | 
< | 
 | 
| 524 | 
< | 
                    isDirectional = 0; | 
| 525 | 
< | 
 | 
| 526 | 
< | 
                    if (integrableObject->isDirectional()) { | 
| 527 | 
< | 
                        isDirectional = 1; | 
| 528 | 
< | 
 | 
| 529 | 
< | 
                        q = integrableObject->getQ(); | 
| 530 | 
< | 
                        ji = integrableObject->getJ(); | 
| 531 | 
< | 
 | 
| 532 | 
< | 
                        atomData[6] = q[0]; | 
| 533 | 
< | 
                        atomData[7] = q[1]; | 
| 534 | 
< | 
                        atomData[8] = q[2]; | 
| 535 | 
< | 
                        atomData[9] = q[3]; | 
| 536 | 
< | 
 | 
| 537 | 
< | 
                        atomData[10] = ji[0]; | 
| 538 | 
< | 
                        atomData[11] = ji[1]; | 
| 539 | 
< | 
                        atomData[12] = ji[2]; | 
| 540 | 
< | 
                    } | 
| 541 | 
< | 
 | 
| 542 | 
< | 
                    strncpy(MPIatomTypeString, integrableObject->getType().c_str(), MINIBUFFERSIZE); | 
| 543 | 
< | 
 | 
| 544 | 
< | 
                    // null terminate the  std::string before sending (just in case): | 
| 545 | 
< | 
                    MPIatomTypeString[MINIBUFFERSIZE - 1] = '\0'; | 
| 546 | 
< | 
 | 
| 547 | 
< | 
                    MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, | 
| 548 | 
< | 
                             myPotato, MPI_COMM_WORLD); | 
| 549 | 
< | 
 | 
| 550 | 
< | 
                    myPotato++; | 
| 551 | 
< | 
 | 
| 552 | 
< | 
                    if (isDirectional) { | 
| 553 | 
< | 
                        MPI_Send(atomData, 13, MPI_DOUBLE, 0, myPotato, | 
| 554 | 
< | 
                                 MPI_COMM_WORLD); | 
| 555 | 
< | 
                    } else { | 
| 556 | 
< | 
                        MPI_Send(atomData, 6, MPI_DOUBLE, 0, myPotato, | 
| 557 | 
< | 
                                 MPI_COMM_WORLD); | 
| 558 | 
< | 
                    } | 
| 559 | 
< | 
 | 
| 560 | 
< | 
                    myPotato++; | 
| 561 | 
< | 
                } | 
| 562 | 
< | 
                     | 
| 563 | 
< | 
            } | 
| 564 | 
< | 
             | 
| 565 | 
< | 
        } | 
| 566 | 
< | 
        sprintf(checkPointMsg, "Sucessfully took a dump.\n"); | 
| 567 | 
< | 
        MPIcheckPoint(); | 
| 335 | 
> | 
    if (needForceVector_) { | 
| 336 | 
> | 
      type += "ft"; | 
| 337 | 
> | 
      Vector3d frc; | 
| 338 | 
> | 
      Vector3d trq; | 
| 339 | 
> | 
      frc = integrableObject->getFrc(); | 
| 340 | 
> | 
      trq = integrableObject->getTrq(); | 
| 341 | 
> | 
               | 
| 342 | 
> | 
      sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e", | 
| 343 | 
> | 
              frc[0], frc[1], frc[2], | 
| 344 | 
> | 
              trq[0], trq[1], trq[2]); | 
| 345 | 
> | 
      line += tempBuffer; | 
| 346 | 
  | 
    } | 
| 347 | 
+ | 
         | 
| 348 | 
+ | 
    sprintf(tempBuffer, "%10d %7s %s\n", index, type.c_str(), line.c_str()); | 
| 349 | 
+ | 
    return std::string(tempBuffer); | 
| 350 | 
+ | 
  } | 
| 351 | 
  | 
 | 
| 352 | 
< | 
#endif // is_mpi | 
| 352 | 
> | 
  void DumpWriter::writeDump() { | 
| 353 | 
> | 
    writeFrame(*dumpFile_); | 
| 354 | 
> | 
  } | 
| 355 | 
  | 
 | 
| 356 | 
< | 
} | 
| 357 | 
< | 
 | 
| 574 | 
< | 
void DumpWriter::writeDump() { | 
| 575 | 
< | 
    writeFrame(dumpFile_); | 
| 576 | 
< | 
 | 
| 577 | 
< | 
} | 
| 578 | 
< | 
 | 
| 579 | 
< | 
void DumpWriter::writeEor() { | 
| 580 | 
< | 
    std::ofstream eorStream; | 
| 356 | 
> | 
  void DumpWriter::writeEor() { | 
| 357 | 
> | 
    std::ostream* eorStream; | 
| 358 | 
  | 
     | 
| 359 | 
  | 
#ifdef IS_MPI | 
| 360 | 
  | 
    if (worldRank == 0) { | 
| 361 | 
  | 
#endif // is_mpi | 
| 362 | 
  | 
 | 
| 363 | 
< | 
        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 | 
< | 
        } | 
| 363 | 
> | 
      eorStream = createOStream(eorFilename_); | 
| 364 | 
  | 
 | 
| 365 | 
  | 
#ifdef IS_MPI | 
| 366 | 
  | 
    } | 
| 367 | 
  | 
#endif // is_mpi     | 
| 368 | 
  | 
 | 
| 369 | 
< | 
    writeFrame(eorStream); | 
| 599 | 
< | 
} | 
| 369 | 
> | 
    writeFrame(*eorStream); | 
| 370 | 
  | 
 | 
| 371 | 
+ | 
#ifdef IS_MPI | 
| 372 | 
+ | 
    if (worldRank == 0) { | 
| 373 | 
+ | 
#endif // is_mpi | 
| 374 | 
+ | 
      writeClosing(*eorStream); | 
| 375 | 
+ | 
      delete eorStream; | 
| 376 | 
+ | 
#ifdef IS_MPI | 
| 377 | 
+ | 
    } | 
| 378 | 
+ | 
#endif // is_mpi   | 
| 379 | 
  | 
 | 
| 380 | 
< | 
void DumpWriter::writeDumpAndEor() { | 
| 381 | 
< | 
    std::ofstream eorStream; | 
| 380 | 
> | 
  } | 
| 381 | 
> | 
 | 
| 382 | 
> | 
 | 
| 383 | 
> | 
  void DumpWriter::writeDumpAndEor() { | 
| 384 | 
  | 
    std::vector<std::streambuf*> buffers; | 
| 385 | 
+ | 
    std::ostream* eorStream; | 
| 386 | 
  | 
#ifdef IS_MPI | 
| 387 | 
  | 
    if (worldRank == 0) { | 
| 388 | 
  | 
#endif // is_mpi | 
| 389 | 
  | 
 | 
| 390 | 
< | 
        buffers.push_back(dumpFile_.rdbuf()); | 
| 390 | 
> | 
      buffers.push_back(dumpFile_->rdbuf()); | 
| 391 | 
  | 
 | 
| 392 | 
< | 
        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 | 
< | 
        } | 
| 392 | 
> | 
      eorStream = createOStream(eorFilename_); | 
| 393 | 
  | 
 | 
| 394 | 
< | 
        buffers.push_back(eorStream.rdbuf()); | 
| 394 | 
> | 
      buffers.push_back(eorStream->rdbuf()); | 
| 395 | 
  | 
         | 
| 396 | 
  | 
#ifdef IS_MPI | 
| 397 | 
  | 
    } | 
| 401 | 
  | 
    std::ostream os(&tbuf); | 
| 402 | 
  | 
 | 
| 403 | 
  | 
    writeFrame(os); | 
| 404 | 
+ | 
 | 
| 405 | 
+ | 
#ifdef IS_MPI | 
| 406 | 
+ | 
    if (worldRank == 0) { | 
| 407 | 
+ | 
#endif // is_mpi | 
| 408 | 
+ | 
      writeClosing(*eorStream); | 
| 409 | 
+ | 
      delete eorStream; | 
| 410 | 
+ | 
#ifdef IS_MPI | 
| 411 | 
+ | 
    } | 
| 412 | 
+ | 
#endif // is_mpi   | 
| 413 | 
  | 
     | 
| 414 | 
< | 
} | 
| 414 | 
> | 
  } | 
| 415 | 
  | 
 | 
| 416 | 
+ | 
  std::ostream* DumpWriter::createOStream(const std::string& filename) { | 
| 417 | 
  | 
 | 
| 418 | 
+ | 
    std::ostream* newOStream; | 
| 419 | 
+ | 
#ifdef HAVE_LIBZ  | 
| 420 | 
+ | 
    if (needCompression_) { | 
| 421 | 
+ | 
      newOStream = new ogzstream(filename.c_str()); | 
| 422 | 
+ | 
    } else { | 
| 423 | 
+ | 
      newOStream = new std::ofstream(filename.c_str()); | 
| 424 | 
+ | 
    } | 
| 425 | 
+ | 
#else | 
| 426 | 
+ | 
    newOStream = new std::ofstream(filename.c_str()); | 
| 427 | 
+ | 
#endif | 
| 428 | 
+ | 
    //write out MetaData first | 
| 429 | 
+ | 
    (*newOStream) << "<OOPSE version=4>" << std::endl; | 
| 430 | 
+ | 
    (*newOStream) << "  <MetaData>" << std::endl; | 
| 431 | 
+ | 
    (*newOStream) << info_->getRawMetaData(); | 
| 432 | 
+ | 
    (*newOStream) << "  </MetaData>" << std::endl; | 
| 433 | 
+ | 
    return newOStream; | 
| 434 | 
+ | 
  } | 
| 435 | 
  | 
 | 
| 436 | 
+ | 
  void DumpWriter::writeClosing(std::ostream& os) { | 
| 437 | 
+ | 
 | 
| 438 | 
+ | 
    os << "</OOPSE>\n"; | 
| 439 | 
+ | 
    os.flush(); | 
| 440 | 
+ | 
  } | 
| 441 | 
+ | 
 | 
| 442 | 
  | 
}//end namespace oopse |