| 1 | < | #define _LARGEFILE_SOURCE64 | 
| 2 | < | #define _FILE_OFFSET_BITS 64 | 
| 1 | > | /* | 
| 2 | > | * Copyright (c) 2009 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. Redistributions of source code must retain the above copyright | 
| 10 | > | *    notice, this list of conditions and the following disclaimer. | 
| 11 | > | * | 
| 12 | > | * 2. Redistributions in binary form must reproduce the above copyright | 
| 13 | > | *    notice, this list of conditions and the following disclaimer in the | 
| 14 | > | *    documentation and/or other materials provided with the | 
| 15 | > | *    distribution. | 
| 16 | > | * | 
| 17 | > | * This software is provided "AS IS," without a warranty of any | 
| 18 | > | * kind. All express or implied conditions, representations and | 
| 19 | > | * warranties, including any implied warranty of merchantability, | 
| 20 | > | * fitness for a particular purpose or non-infringement, are hereby | 
| 21 | > | * excluded.  The University of Notre Dame and its licensors shall not | 
| 22 | > | * be liable for any damages suffered by licensee as a result of | 
| 23 | > | * using, modifying or distributing the software or its | 
| 24 | > | * derivatives. In no event will the University of Notre Dame or its | 
| 25 | > | * licensors be liable for any lost revenue, profit or data, or for | 
| 26 | > | * direct, indirect, special, consequential, incidental or punitive | 
| 27 | > | * damages, however caused and regardless of the theory of liability, | 
| 28 | > | * arising out of the use of or inability to use software, even if the | 
| 29 | > | * University of Notre Dame has been advised of the possibility of | 
| 30 | > | * such damages. | 
| 31 | > | * | 
| 32 | > | * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your | 
| 33 | > | * research, please cite the appropriate papers when you publish your | 
| 34 | > | * work.  Good starting points are: | 
| 35 | > | * | 
| 36 | > | * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). | 
| 37 | > | * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). | 
| 38 | > | * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). | 
| 39 | > | * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010). | 
| 40 | > | * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). | 
| 41 | > | */ | 
| 42 |  |  | 
| 43 | < | #include <string.h> | 
| 5 | < | #include <iostream> | 
| 6 | < | #include <fstream> | 
| 7 | < | #include <algorithm> | 
| 8 | < | #include <utility> | 
| 43 | > | #include "config.h" | 
| 44 |  |  | 
| 45 |  | #ifdef IS_MPI | 
| 46 |  | #include <mpi.h> | 
| 47 | < | #include "brains/mpiSimulation.hpp" | 
| 47 | > | #endif | 
| 48 | > |  | 
| 49 | > | #include "io/DumpWriter.hpp" | 
| 50 | > | #include "primitives/Molecule.hpp" | 
| 51 | > | #include "utils/simError.h" | 
| 52 | > | #include "io/basic_teebuf.hpp" | 
| 53 | > | #ifdef HAVE_ZLIB | 
| 54 | > | #include "io/gzstream.hpp" | 
| 55 | > | #endif | 
| 56 | > | #include "io/Globals.hpp" | 
| 57 |  |  | 
| 58 | < | namespace dWrite{ | 
| 59 | < | void DieDieDie( void ); | 
| 60 | < | } | 
| 58 | > | #ifdef _MSC_VER | 
| 59 | > | #define isnan(x) _isnan((x)) | 
| 60 | > | #define isinf(x) (!_finite(x) && !_isnan(x)) | 
| 61 | > | #endif | 
| 62 |  |  | 
| 63 | < | using namespace dWrite; | 
| 64 | < | #endif //is_mpi | 
| 63 | > | using namespace std; | 
| 64 | > | namespace OpenMD { | 
| 65 |  |  | 
| 66 | < | #include "io/ReadWrite.hpp" | 
| 67 | < | #include "utils/simError.h" | 
| 66 | > | DumpWriter::DumpWriter(SimInfo* info) | 
| 67 | > | : info_(info), filename_(info->getDumpFileName()), eorFilename_(info->getFinalConfigFileName()){ | 
| 68 |  |  | 
| 69 | < | DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ | 
| 69 | > | Globals* simParams = info->getSimParams(); | 
| 70 | > | needCompression_   = simParams->getCompressDumpFile(); | 
| 71 | > | needForceVector_   = simParams->getOutputForceVector(); | 
| 72 | > | needParticlePot_   = simParams->getOutputParticlePotential(); | 
| 73 | > | needFlucQ_         = simParams->getOutputFluctuatingCharges(); | 
| 74 | > | needElectricField_ = simParams->getOutputElectricField(); | 
| 75 |  |  | 
| 76 | < | entry_plug = the_entry_plug; | 
| 76 | > | if (needParticlePot_ || needFlucQ_ || needElectricField_) { | 
| 77 | > | doSiteData_ = true; | 
| 78 | > | } else { | 
| 79 | > | doSiteData_ = false; | 
| 80 | > | } | 
| 81 |  |  | 
| 82 | + | createDumpFile_ = true; | 
| 83 | + | #ifdef HAVE_LIBZ | 
| 84 | + | if (needCompression_) { | 
| 85 | + | filename_ += ".gz"; | 
| 86 | + | eorFilename_ += ".gz"; | 
| 87 | + | } | 
| 88 | + | #endif | 
| 89 | + |  | 
| 90 |  | #ifdef IS_MPI | 
| 91 | < | if(worldRank == 0 ){ | 
| 91 | > |  | 
| 92 | > | if (worldRank == 0) { | 
| 93 |  | #endif // is_mpi | 
| 94 | + |  | 
| 95 | + | dumpFile_ = createOStream(filename_); | 
| 96 |  |  | 
| 97 | < | dumpFile.open(entry_plug->sampleName.c_str(), ios::out | ios::trunc ); | 
| 97 | > | if (!dumpFile_) { | 
| 98 | > | sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", | 
| 99 | > | filename_.c_str()); | 
| 100 | > | painCave.isFatal = 1; | 
| 101 | > | simError(); | 
| 102 | > | } | 
| 103 |  |  | 
| 104 | < | if( !dumpFile ){ | 
| 104 | > | #ifdef IS_MPI | 
| 105 |  |  | 
| 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(); | 
| 106 |  | } | 
| 107 |  |  | 
| 108 | < | #ifdef IS_MPI | 
| 108 | > | #endif // is_mpi | 
| 109 | > |  | 
| 110 |  | } | 
| 111 |  |  | 
| 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 | – | } | 
| 112 |  |  | 
| 113 | < | DumpWriter::~DumpWriter( ){ | 
| 113 | > | DumpWriter::DumpWriter(SimInfo* info, const std::string& filename) | 
| 114 | > | : info_(info), filename_(filename){ | 
| 115 |  |  | 
| 116 | < | #ifdef IS_MPI | 
| 117 | < | if(worldRank == 0 ){ | 
| 59 | < | #endif // is_mpi | 
| 116 | > | Globals* simParams = info->getSimParams(); | 
| 117 | > | eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; | 
| 118 |  |  | 
| 119 | < | dumpFile.close(); | 
| 119 | > | needCompression_   = simParams->getCompressDumpFile(); | 
| 120 | > | needForceVector_   = simParams->getOutputForceVector(); | 
| 121 | > | needParticlePot_   = simParams->getOutputParticlePotential(); | 
| 122 | > | needFlucQ_         = simParams->getOutputFluctuatingCharges(); | 
| 123 | > | needElectricField_ = simParams->getOutputElectricField(); | 
| 124 |  |  | 
| 125 | + | if (needParticlePot_ || needFlucQ_ || needElectricField_) { | 
| 126 | + | doSiteData_ = true; | 
| 127 | + | } else { | 
| 128 | + | doSiteData_ = false; | 
| 129 | + | } | 
| 130 | + |  | 
| 131 | + | createDumpFile_ = true; | 
| 132 | + | #ifdef HAVE_LIBZ | 
| 133 | + | if (needCompression_) { | 
| 134 | + | filename_ += ".gz"; | 
| 135 | + | eorFilename_ += ".gz"; | 
| 136 | + | } | 
| 137 | + | #endif | 
| 138 | + |  | 
| 139 |  | #ifdef IS_MPI | 
| 140 | < | } | 
| 140 | > |  | 
| 141 | > | if (worldRank == 0) { | 
| 142 |  | #endif // is_mpi | 
| 66 | – | } | 
| 143 |  |  | 
| 144 | + |  | 
| 145 | + | dumpFile_ = createOStream(filename_); | 
| 146 | + |  | 
| 147 | + | if (!dumpFile_) { | 
| 148 | + | sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", | 
| 149 | + | filename_.c_str()); | 
| 150 | + | painCave.isFatal = 1; | 
| 151 | + | simError(); | 
| 152 | + | } | 
| 153 | + |  | 
| 154 |  | #ifdef IS_MPI | 
| 155 |  |  | 
| 156 | < | /** | 
| 71 | < | * A hook function to load balancing | 
| 72 | < | */ | 
| 156 | > | } | 
| 157 |  |  | 
| 158 | < | 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 | < | } | 
| 158 | > | #endif // is_mpi | 
| 159 |  |  | 
| 160 | < | /** | 
| 87 | < | * Sorting the local index by global index | 
| 88 | < | */ | 
| 89 | < |  | 
| 90 | < | void DumpWriter::sortByGlobalIndex(){ | 
| 91 | < | Molecule* mols = entry_plug->molecules; | 
| 92 | < | indexArray.clear(); | 
| 160 | > | } | 
| 161 |  |  | 
| 162 | < | for(int i = 0; i < entry_plug->n_mol;i++) | 
| 163 | < | indexArray.push_back(make_pair(i, mols[i].getGlobalIndex())); | 
| 164 | < |  | 
| 165 | < | sort(indexArray.begin(), indexArray.end(), indexSortingCriterion); | 
| 166 | < | } | 
| 162 | > | DumpWriter::DumpWriter(SimInfo* info, const std::string& filename, bool writeDumpFile) | 
| 163 | > | : info_(info), filename_(filename){ | 
| 164 | > |  | 
| 165 | > | Globals* simParams = info->getSimParams(); | 
| 166 | > | eorFilename_ = filename_.substr(0, filename_.rfind(".")) + ".eor"; | 
| 167 | > |  | 
| 168 | > | needCompression_   = simParams->getCompressDumpFile(); | 
| 169 | > | needForceVector_   = simParams->getOutputForceVector(); | 
| 170 | > | needParticlePot_   = simParams->getOutputParticlePotential(); | 
| 171 | > | needFlucQ_         = simParams->getOutputFluctuatingCharges(); | 
| 172 | > | needElectricField_ = simParams->getOutputElectricField(); | 
| 173 |  |  | 
| 174 | < | #endif | 
| 174 | > | if (needParticlePot_ || needFlucQ_ || needElectricField_) { | 
| 175 | > | doSiteData_ = true; | 
| 176 | > | } else { | 
| 177 | > | doSiteData_ = false; | 
| 178 | > | } | 
| 179 |  |  | 
| 180 | < | void DumpWriter::writeDump(double currentTime){ | 
| 181 | < |  | 
| 182 | < | ofstream finalOut; | 
| 183 | < | vector<ofstream*> fileStreams; | 
| 106 | < |  | 
| 107 | < | #ifdef IS_MPI | 
| 108 | < | if(worldRank == 0 ){ | 
| 109 | < | #endif | 
| 110 | < | finalOut.open( entry_plug->finalName.c_str(), ios::out | ios::trunc ); | 
| 111 | < | if( !finalOut ){ | 
| 112 | < | sprintf( painCave.errMsg, | 
| 113 | < | "Could not open \"%s\" for final dump output.\n", | 
| 114 | < | entry_plug->finalName.c_str() ); | 
| 115 | < | painCave.isFatal = 1; | 
| 116 | < | simError(); | 
| 180 | > | #ifdef HAVE_LIBZ | 
| 181 | > | if (needCompression_) { | 
| 182 | > | filename_ += ".gz"; | 
| 183 | > | eorFilename_ += ".gz"; | 
| 184 |  | } | 
| 185 | + | #endif | 
| 186 | + |  | 
| 187 |  | #ifdef IS_MPI | 
| 188 | < | } | 
| 188 | > |  | 
| 189 | > | if (worldRank == 0) { | 
| 190 |  | #endif // is_mpi | 
| 191 | + |  | 
| 192 | + | createDumpFile_ = writeDumpFile; | 
| 193 | + | if (createDumpFile_) { | 
| 194 | + | dumpFile_ = createOStream(filename_); | 
| 195 | + |  | 
| 196 | + | if (!dumpFile_) { | 
| 197 | + | sprintf(painCave.errMsg, "Could not open \"%s\" for dump output.\n", | 
| 198 | + | filename_.c_str()); | 
| 199 | + | painCave.isFatal = 1; | 
| 200 | + | simError(); | 
| 201 | + | } | 
| 202 | + | } | 
| 203 | + | #ifdef IS_MPI | 
| 204 | + |  | 
| 205 | + | } | 
| 206 |  |  | 
| 207 | < | fileStreams.push_back(&finalOut); | 
| 208 | < | fileStreams.push_back(&dumpFile); | 
| 207 | > |  | 
| 208 | > | #endif // is_mpi | 
| 209 | > |  | 
| 210 | > | } | 
| 211 |  |  | 
| 212 | < | writeFrame(fileStreams, currentTime); | 
| 212 | > | DumpWriter::~DumpWriter() { | 
| 213 |  |  | 
| 214 |  | #ifdef IS_MPI | 
| 128 | – | finalOut.close(); | 
| 129 | – | #endif | 
| 130 | – |  | 
| 131 | – | } | 
| 215 |  |  | 
| 216 | < | void DumpWriter::writeFinal(double currentTime){ | 
| 216 | > | if (worldRank == 0) { | 
| 217 | > | #endif // is_mpi | 
| 218 | > | if (createDumpFile_){ | 
| 219 | > | writeClosing(*dumpFile_); | 
| 220 | > | delete dumpFile_; | 
| 221 | > | } | 
| 222 | > | #ifdef IS_MPI | 
| 223 |  |  | 
| 224 | < | ofstream finalOut; | 
| 136 | < | vector<ofstream*> fileStreams; | 
| 224 | > | } | 
| 225 |  |  | 
| 138 | – | #ifdef IS_MPI | 
| 139 | – | if(worldRank == 0 ){ | 
| 226 |  | #endif // is_mpi | 
| 227 |  |  | 
| 228 | < | finalOut.open( entry_plug->finalName.c_str(), ios::out | ios::trunc ); | 
| 228 | > | } | 
| 229 |  |  | 
| 230 | < | if( !finalOut ){ | 
| 230 | > | void DumpWriter::writeFrameProperties(std::ostream& os, Snapshot* s) { | 
| 231 | > |  | 
| 232 | > | char buffer[1024]; | 
| 233 | > |  | 
| 234 | > | os << "    <FrameData>\n"; | 
| 235 | > |  | 
| 236 | > | RealType currentTime = s->getTime(); | 
| 237 | > |  | 
| 238 | > | if (isinf(currentTime) || isnan(currentTime)) { | 
| 239 |  | sprintf( painCave.errMsg, | 
| 240 | < | "Could not open \"%s\" for final dump output.\n", | 
| 147 | < | entry_plug->finalName.c_str() ); | 
| 240 | > | "DumpWriter detected a numerical error writing the time"); | 
| 241 |  | painCave.isFatal = 1; | 
| 242 |  | simError(); | 
| 243 |  | } | 
| 244 | + |  | 
| 245 | + | sprintf(buffer, "        Time: %.10g\n", currentTime); | 
| 246 | + | os << buffer; | 
| 247 |  |  | 
| 248 | < | #ifdef IS_MPI | 
| 249 | < | } | 
| 154 | < | #endif // is_mpi | 
| 155 | < |  | 
| 156 | < | fileStreams.push_back(&finalOut); | 
| 157 | < | writeFrame(fileStreams, currentTime); | 
| 248 | > | Mat3x3d hmat; | 
| 249 | > | hmat = s->getHmat(); | 
| 250 |  |  | 
| 251 | < | #ifdef IS_MPI | 
| 252 | < | finalOut.close(); | 
| 253 | < | #endif | 
| 254 | < |  | 
| 255 | < | } | 
| 251 | > | for (unsigned int i = 0; i < 3; i++) { | 
| 252 | > | for (unsigned int j = 0; j < 3; j++) { | 
| 253 | > | if (isinf(hmat(i,j)) || isnan(hmat(i,j))) { | 
| 254 | > | sprintf( painCave.errMsg, | 
| 255 | > | "DumpWriter detected a numerical error writing the box"); | 
| 256 | > | painCave.isFatal = 1; | 
| 257 | > | simError(); | 
| 258 | > | } | 
| 259 | > | } | 
| 260 | > | } | 
| 261 | > |  | 
| 262 | > | sprintf(buffer, "        Hmat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n", | 
| 263 | > | hmat(0, 0), hmat(1, 0), hmat(2, 0), | 
| 264 | > | hmat(0, 1), hmat(1, 1), hmat(2, 1), | 
| 265 | > | hmat(0, 2), hmat(1, 2), hmat(2, 2)); | 
| 266 | > | os << buffer; | 
| 267 |  |  | 
| 268 | < | void DumpWriter::writeFrame( vector<ofstream*>& outFile, double currentTime ){ | 
| 268 | > | pair<RealType, RealType> thermostat = s->getThermostat(); | 
| 269 |  |  | 
| 270 | < | const int BUFFERSIZE = 2000; | 
| 271 | < | const int MINIBUFFERSIZE = 100; | 
| 270 | > | if (isinf(thermostat.first)  || isnan(thermostat.first) || | 
| 271 | > | isinf(thermostat.second) || isnan(thermostat.second)) { | 
| 272 | > | sprintf( painCave.errMsg, | 
| 273 | > | "DumpWriter detected a numerical error writing the thermostat"); | 
| 274 | > | painCave.isFatal = 1; | 
| 275 | > | simError(); | 
| 276 | > | } | 
| 277 | > | sprintf(buffer, "  Thermostat: %.10g , %.10g\n", thermostat.first, | 
| 278 | > | thermostat.second); | 
| 279 | > | os << buffer; | 
| 280 |  |  | 
| 281 | < | char tempBuffer[BUFFERSIZE]; | 
| 282 | < | char writeLine[BUFFERSIZE]; | 
| 281 | > | Mat3x3d eta; | 
| 282 | > | eta = s->getBarostat(); | 
| 283 |  |  | 
| 284 | < | int i; | 
| 285 | < | unsigned int k; | 
| 284 | > | for (unsigned int i = 0; i < 3; i++) { | 
| 285 | > | for (unsigned int j = 0; j < 3; j++) { | 
| 286 | > | if (isinf(eta(i,j)) || isnan(eta(i,j))) { | 
| 287 | > | sprintf( painCave.errMsg, | 
| 288 | > | "DumpWriter detected a numerical error writing the barostat"); | 
| 289 | > | painCave.isFatal = 1; | 
| 290 | > | simError(); | 
| 291 | > | } | 
| 292 | > | } | 
| 293 | > | } | 
| 294 | > |  | 
| 295 | > | sprintf(buffer, "    Barostat: {{ %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }, { %.10g, %.10g, %.10g }}\n", | 
| 296 | > | eta(0, 0), eta(1, 0), eta(2, 0), | 
| 297 | > | eta(0, 1), eta(1, 1), eta(2, 1), | 
| 298 | > | eta(0, 2), eta(1, 2), eta(2, 2)); | 
| 299 | > | os << buffer; | 
| 300 |  |  | 
| 301 | < | #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(); | 
| 237 | < | #ifndef IS_MPI | 
| 238 | < |  | 
| 239 | < | for(k = 0; k < outFile.size(); k++){ | 
| 240 | < | *outFile[k] << nTotObjects << "\n"; | 
| 241 | < |  | 
| 242 | < | *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" | 
| 250 | < |  | 
| 251 | < | << entry_plug->Hmat[0][2] << "\t" | 
| 252 | < | << entry_plug->Hmat[1][2] << "\t" | 
| 253 | < | << entry_plug->Hmat[2][2] << ";"; | 
| 254 | < |  | 
| 255 | < | //write out additional parameters, such as chi and eta | 
| 256 | < | *outFile[k] << entry_plug->the_integrator->getAdditionalParameters() << endl; | 
| 301 | > | os << "    </FrameData>\n"; | 
| 302 |  | } | 
| 258 | – |  | 
| 259 | – | for( i=0; i< entry_plug->n_mol; i++ ){ | 
| 303 |  |  | 
| 304 | < | integrableObjects = entry_plug->molecules[i].getIntegrableObjects(); | 
| 262 | < | molName = (entry_plug->compStamps[entry_plug->molecules[i].getStampID()])->getID(); | 
| 263 | < |  | 
| 264 | < | for( iter = integrableObjects.begin();iter !=  integrableObjects.end(); ++iter){ | 
| 265 | < | sd = *iter; | 
| 266 | < | sd->getPos(pos); | 
| 267 | < | sd->getVel(vel); | 
| 304 | > | void DumpWriter::writeFrame(std::ostream& os) { | 
| 305 |  |  | 
| 306 | < | sprintf( tempBuffer, | 
| 307 | < | "%s\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t", | 
| 308 | < | sd->getType(), | 
| 272 | < | pos[0], | 
| 273 | < | pos[1], | 
| 274 | < | pos[2], | 
| 275 | < | vel[0], | 
| 276 | < | vel[1], | 
| 277 | < | vel[2]); | 
| 278 | < | strcpy( writeLine, tempBuffer ); | 
| 306 | > | #ifdef IS_MPI | 
| 307 | > | MPI_Status istatus; | 
| 308 | > | #endif | 
| 309 |  |  | 
| 310 | < | if( sd->isDirectional() ){ | 
| 310 | > | Molecule* mol; | 
| 311 | > | StuntDouble* sd; | 
| 312 | > | SimInfo::MoleculeIterator mi; | 
| 313 | > | Molecule::IntegrableObjectIterator ii; | 
| 314 | > | RigidBody::AtomIterator ai; | 
| 315 |  |  | 
| 316 | < | sd->getQ( q ); | 
| 317 | < | sd->getJ( ji ); | 
| 316 | > | #ifndef IS_MPI | 
| 317 | > | os << "  <Snapshot>\n"; | 
| 318 | > |  | 
| 319 | > | writeFrameProperties(os, info_->getSnapshotManager()->getCurrentSnapshot()); | 
| 320 |  |  | 
| 321 | < | sprintf( tempBuffer, | 
| 322 | < | "%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", | 
| 323 | < | q[0], | 
| 324 | < | q[1], | 
| 325 | < | q[2], | 
| 326 | < | q[3], | 
| 327 | < | ji[0], | 
| 328 | < | ji[1], | 
| 293 | < | ji[2]); | 
| 294 | < | strcat( writeLine, tempBuffer ); | 
| 321 | > | os << "    <StuntDoubles>\n"; | 
| 322 | > | for (mol = info_->beginMolecule(mi); mol != NULL; | 
| 323 | > | mol = info_->nextMolecule(mi)) { | 
| 324 | > |  | 
| 325 | > | for (sd = mol->beginIntegrableObject(ii); sd != NULL; | 
| 326 | > | sd = mol->nextIntegrableObject(ii)) { | 
| 327 | > | os << prepareDumpLine(sd); | 
| 328 | > |  | 
| 329 |  | } | 
| 330 | < | else | 
| 331 | < | 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; | 
| 301 | < | } | 
| 302 | < |  | 
| 303 | < | } | 
| 330 | > | } | 
| 331 | > | os << "    </StuntDoubles>\n"; | 
| 332 |  |  | 
| 333 | < | #else // is_mpi | 
| 333 | > | if (doSiteData_) { | 
| 334 | > | os << "    <SiteData>\n"; | 
| 335 | > | for (mol = info_->beginMolecule(mi); mol != NULL; | 
| 336 | > | mol = info_->nextMolecule(mi)) { | 
| 337 | > |  | 
| 338 | > | for (sd = mol->beginIntegrableObject(ii); sd != NULL; | 
| 339 | > | sd = mol->nextIntegrableObject(ii)) { | 
| 340 |  |  | 
| 341 | < | /* code to find maximum tag value */ | 
| 342 | < |  | 
| 343 | < | 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 | < | } | 
| 341 | > | int ioIndex = sd->getGlobalIntegrableObjectIndex(); | 
| 342 | > | // do one for the IO itself | 
| 343 | > | os << prepareSiteLine(sd, ioIndex, 0); | 
| 344 |  |  | 
| 345 | < | int haveError; | 
| 345 | > | if (sd->isRigidBody()) { | 
| 346 | > |  | 
| 347 | > | RigidBody* rb = static_cast<RigidBody*>(sd); | 
| 348 | > | int siteIndex = 0; | 
| 349 | > | for (Atom* atom = rb->beginAtom(ai); atom != NULL; | 
| 350 | > | atom = rb->nextAtom(ai)) { | 
| 351 | > | os << prepareSiteLine(atom, ioIndex, siteIndex); | 
| 352 | > | siteIndex++; | 
| 353 | > | } | 
| 354 | > | } | 
| 355 | > | } | 
| 356 | > | } | 
| 357 | > | os << "    </SiteData>\n"; | 
| 358 | > | } | 
| 359 | > | os << "  </Snapshot>\n"; | 
| 360 |  |  | 
| 361 | < | MPI_Status istatus; | 
| 362 | < | int nCurObj; | 
| 321 | < | int *MolToProcMap = mpiSim->getMolToProcMap(); | 
| 361 | > | os.flush(); | 
| 362 | > | #else | 
| 363 |  |  | 
| 364 | < | // write out header and node 0's coordinates | 
| 364 | > | const int masterNode = 0; | 
| 365 | > | int worldRank; | 
| 366 | > | int nProc; | 
| 367 |  |  | 
| 368 | < | if( worldRank == 0 ){ | 
| 368 | > | MPI_Comm_size( MPI_COMM_WORLD, &nProc); | 
| 369 | > | MPI_Comm_rank( MPI_COMM_WORLD, &worldRank); | 
| 370 |  |  | 
| 327 | – | // Node 0 needs a list of the magic potatoes for each processor; | 
| 371 |  |  | 
| 372 | < | nProc = mpiSim->getNProcessors(); | 
| 373 | < | potatoes = new int[nProc]; | 
| 372 | > | if (worldRank == masterNode) { | 
| 373 | > | os << "  <Snapshot>\n"; | 
| 374 | > | writeFrameProperties(os, | 
| 375 | > | info_->getSnapshotManager()->getCurrentSnapshot()); | 
| 376 | > | os << "    <StuntDoubles>\n"; | 
| 377 | > | } | 
| 378 |  |  | 
| 379 | < | //write out the comment lines | 
| 380 | < | for (i = 0; i < nProc; i++) | 
| 381 | < | potatoes[i] = 0; | 
| 382 | < |  | 
| 383 | < | for(k = 0; k < outFile.size(); k++){ | 
| 384 | < | *outFile[k] << nTotObjects << "\n"; | 
| 385 | < |  | 
| 386 | < | *outFile[k] << currentTime << ";\t" | 
| 340 | < | << entry_plug->Hmat[0][0] << "\t" | 
| 341 | < | << 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; | 
| 379 | > | //every node prepares the dump lines for integrable objects belong to itself | 
| 380 | > | std::string buffer; | 
| 381 | > | for (mol = info_->beginMolecule(mi); mol != NULL; | 
| 382 | > | mol = info_->nextMolecule(mi)) { | 
| 383 | > | for (sd = mol->beginIntegrableObject(ii); sd != NULL; | 
| 384 | > | sd = mol->nextIntegrableObject(ii)) { | 
| 385 | > | buffer += prepareDumpLine(sd); | 
| 386 | > | } | 
| 387 |  | } | 
| 388 |  |  | 
| 389 | < | currentIndex = 0; | 
| 390 | < |  | 
| 358 | < | for (i = 0 ; i < mpiSim->getNMolGlobal(); i++ ) { | 
| 389 | > | if (worldRank == masterNode) { | 
| 390 | > | os << buffer; | 
| 391 |  |  | 
| 392 | < | // Get the Node number which has this atom; | 
| 393 | < |  | 
| 394 | < | 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: | 
| 392 | > | for (int i = 1; i < nProc; ++i) { | 
| 393 | > | // tell processor i to start sending us data: | 
| 394 | > | MPI_Bcast(&i, 1, MPI_INT, masterNode, MPI_COMM_WORLD); | 
| 395 |  |  | 
| 396 | < | potatoes[which_node] = 0; | 
| 397 | < | MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, | 
| 398 | < | MPI_COMM_WORLD); | 
| 399 | < |  | 
| 400 | < | } | 
| 396 | > | // receive the length of the string buffer that was | 
| 397 | > | // prepared by processor i: | 
| 398 | > | int recvLength; | 
| 399 | > | MPI_Recv(&recvLength, 1, MPI_INT, i, MPI_ANY_TAG, MPI_COMM_WORLD, | 
| 400 | > | &istatus); | 
| 401 |  |  | 
| 402 | < | myPotato = potatoes[which_node]; | 
| 403 | < |  | 
| 404 | < | //recieve the number of integrableObject in current molecule | 
| 405 | < | MPI_Recv(&nCurObj, 1, MPI_INT, which_node, | 
| 406 | < | myPotato, MPI_COMM_WORLD, &istatus); | 
| 407 | < | myPotato++; | 
| 408 | < |  | 
| 409 | < | for(int l = 0; l < nCurObj; l++){ | 
| 410 | < |  | 
| 411 | < | if (potatoes[which_node] + 2 >= MAXTAG) { | 
| 412 | < | // The potato was going to exceed the maximum value, | 
| 413 | < | // so wrap this processor potato back to 0: | 
| 414 | < |  | 
| 415 | < | potatoes[which_node] = 0; | 
| 416 | < | MPI_Send(&potatoes[which_node], 1, MPI_INT, which_node, 0, MPI_COMM_WORLD); | 
| 417 | < |  | 
| 418 | < | } | 
| 419 | < |  | 
| 420 | < | MPI_Recv(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, which_node, | 
| 421 | < | myPotato, MPI_COMM_WORLD, &istatus); | 
| 422 | < |  | 
| 423 | < | atomTypeString = MPIatomTypeString; | 
| 424 | < |  | 
| 425 | < | myPotato++; | 
| 426 | < |  | 
| 427 | < | 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; | 
| 402 | > | // create a buffer to receive the data | 
| 403 | > | char* recvBuffer = new char[recvLength]; | 
| 404 | > | if (recvBuffer == NULL) { | 
| 405 | > | } else { | 
| 406 | > | // receive the data: | 
| 407 | > | MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, | 
| 408 | > | MPI_ANY_TAG, MPI_COMM_WORLD, &istatus); | 
| 409 | > | // send it to the file: | 
| 410 | > | os << recvBuffer; | 
| 411 | > | // get rid of the receive buffer: | 
| 412 | > | delete [] recvBuffer; | 
| 413 | > | } | 
| 414 | > | } | 
| 415 | > | } else { | 
| 416 | > | int sendBufferLength = buffer.size() + 1; | 
| 417 | > | int myturn = 0; | 
| 418 | > | for (int i = 1; i < nProc; ++i){ | 
| 419 | > | // wait for the master node to call our number: | 
| 420 | > | MPI_Bcast(&myturn, 1, MPI_INT, masterNode, MPI_COMM_WORLD); | 
| 421 | > | if (myturn == worldRank){ | 
| 422 | > | // send the length of our buffer: | 
| 423 | > | MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); | 
| 424 | > |  | 
| 425 | > | // send our buffer: | 
| 426 | > | MPI_Send((void *)buffer.c_str(), sendBufferLength, | 
| 427 | > | MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); | 
| 428 |  |  | 
| 429 | < | }// end for(int l =0) | 
| 453 | < | potatoes[which_node] = myPotato; | 
| 454 | < |  | 
| 429 | > | } | 
| 430 |  | } | 
| 431 | < | else { | 
| 432 | < |  | 
| 433 | < | haveError = 0; | 
| 434 | < |  | 
| 435 | < | local_index = indexArray[currentIndex].first; | 
| 461 | < |  | 
| 462 | < | integrableObjects = (entry_plug->molecules[local_index]).getIntegrableObjects(); | 
| 431 | > | } | 
| 432 | > |  | 
| 433 | > | if (worldRank == masterNode) { | 
| 434 | > | os << "    </StuntDoubles>\n"; | 
| 435 | > | } | 
| 436 |  |  | 
| 437 | < | for(iter= integrableObjects.begin(); iter != integrableObjects.end(); ++iter){ | 
| 438 | < | sd = *iter; | 
| 439 | < | atomTypeString = sd->getType(); | 
| 440 | < |  | 
| 441 | < | sd->getPos(pos); | 
| 442 | < | sd->getVel(vel); | 
| 443 | < |  | 
| 444 | < | atomData[0] = pos[0]; | 
| 445 | < | atomData[1] = pos[1]; | 
| 446 | < | atomData[2] = pos[2]; | 
| 437 | > | if (doSiteData_) { | 
| 438 | > | if (worldRank == masterNode) { | 
| 439 | > | os << "    <SiteData>\n"; | 
| 440 | > | } | 
| 441 | > | buffer.clear(); | 
| 442 | > | for (mol = info_->beginMolecule(mi); mol != NULL; | 
| 443 | > | mol = info_->nextMolecule(mi)) { | 
| 444 | > |  | 
| 445 | > | for (sd = mol->beginIntegrableObject(ii); sd != NULL; | 
| 446 | > | sd = mol->nextIntegrableObject(ii)) { | 
| 447 | > |  | 
| 448 | > | int ioIndex = sd->getGlobalIntegrableObjectIndex(); | 
| 449 | > | // do one for the IO itself | 
| 450 | > | buffer += prepareSiteLine(sd, ioIndex, 0); | 
| 451 |  |  | 
| 452 | < | atomData[3] = vel[0]; | 
| 476 | < | 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 | < | } | 
| 452 | > | if (sd->isRigidBody()) { | 
| 453 |  |  | 
| 454 | < | // If we've survived to here, format the line: | 
| 455 | < |  | 
| 456 | < | if (!isDirectional) { | 
| 457 | < |  | 
| 458 | < | sprintf( writeLine, | 
| 459 | < | "%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 | < |  | 
| 454 | > | RigidBody* rb = static_cast<RigidBody*>(sd); | 
| 455 | > | int siteIndex = 0; | 
| 456 | > | for (Atom* atom = rb->beginAtom(ai); atom != NULL; | 
| 457 | > | atom = rb->nextAtom(ai)) { | 
| 458 | > | buffer += prepareSiteLine(atom, ioIndex, siteIndex); | 
| 459 | > | siteIndex++; | 
| 460 |  | } | 
| 461 | < |  | 
| 462 | < | for(k = 0; k < outFile.size(); k++) | 
| 540 | < | *outFile[k] << writeLine; | 
| 541 | < |  | 
| 542 | < |  | 
| 543 | < | }//end for(iter = integrableObject.begin()) | 
| 544 | < |  | 
| 545 | < | currentIndex++; | 
| 461 | > | } | 
| 462 | > | } | 
| 463 |  | } | 
| 464 |  |  | 
| 465 | < | }//end for(i = 0; i < mpiSim->getNmol()) | 
| 465 | > | if (worldRank == masterNode) { | 
| 466 | > | os << buffer; | 
| 467 | > |  | 
| 468 | > | for (int i = 1; i < nProc; ++i) { | 
| 469 | > |  | 
| 470 | > | // tell processor i to start sending us data: | 
| 471 | > | MPI_Bcast(&i, 1, MPI_INT, masterNode, MPI_COMM_WORLD); | 
| 472 | > |  | 
| 473 | > | // receive the length of the string buffer that was | 
| 474 | > | // prepared by processor i: | 
| 475 | > | int recvLength; | 
| 476 | > | MPI_Recv(&recvLength, 1, MPI_INT, i, MPI_ANY_TAG, MPI_COMM_WORLD, | 
| 477 | > | &istatus); | 
| 478 | > |  | 
| 479 | > | // create a buffer to receive the data | 
| 480 | > | char* recvBuffer = new char[recvLength]; | 
| 481 | > | if (recvBuffer == NULL) { | 
| 482 | > | } else { | 
| 483 | > | // receive the data: | 
| 484 | > | MPI_Recv(recvBuffer, recvLength, MPI_CHAR, i, | 
| 485 | > | MPI_ANY_TAG, MPI_COMM_WORLD, &istatus); | 
| 486 | > | // send it to the file: | 
| 487 | > | os << recvBuffer; | 
| 488 | > | // get rid of the receive buffer: | 
| 489 | > | delete [] recvBuffer; | 
| 490 | > | } | 
| 491 | > | } | 
| 492 | > | } else { | 
| 493 | > | int sendBufferLength = buffer.size() + 1; | 
| 494 | > | int myturn = 0; | 
| 495 | > | for (int i = 1; i < nProc; ++i){ | 
| 496 | > | // wait for the master node to call our number: | 
| 497 | > | MPI_Bcast(&myturn, 1, MPI_INT, masterNode, MPI_COMM_WORLD); | 
| 498 | > | if (myturn == worldRank){ | 
| 499 | > | // send the length of our buffer: | 
| 500 | > | MPI_Send(&sendBufferLength, 1, MPI_INT, masterNode, 0, MPI_COMM_WORLD); | 
| 501 | > | // send our buffer: | 
| 502 | > | MPI_Send((void *)buffer.c_str(), sendBufferLength, | 
| 503 | > | MPI_CHAR, masterNode, 0, MPI_COMM_WORLD); | 
| 504 | > | } | 
| 505 | > | } | 
| 506 | > | } | 
| 507 | > |  | 
| 508 | > | if (worldRank == masterNode) { | 
| 509 | > | os << "    </SiteData>\n"; | 
| 510 | > | } | 
| 511 | > | } | 
| 512 |  |  | 
| 513 | < | for(k = 0; k < outFile.size(); k++) | 
| 514 | < | outFile[k]->flush(); | 
| 513 | > | if (worldRank == masterNode) { | 
| 514 | > | os << "  </Snapshot>\n"; | 
| 515 | > | os.flush(); | 
| 516 | > | } | 
| 517 |  |  | 
| 518 | < | sprintf( checkPointMsg, | 
| 554 | < | "Sucessfully took a dump.\n"); | 
| 518 | > | #endif // is_mpi | 
| 519 |  |  | 
| 520 | < | MPIcheckPoint(); | 
| 557 | < |  | 
| 558 | < | delete[] potatoes; | 
| 559 | < |  | 
| 560 | < | } else { | 
| 520 | > | } | 
| 521 |  |  | 
| 522 | < | // worldRank != 0, so I'm a remote node. | 
| 522 | > | std::string DumpWriter::prepareDumpLine(StuntDouble* sd) { | 
| 523 | > |  | 
| 524 | > | int index = sd->getGlobalIntegrableObjectIndex(); | 
| 525 | > | std::string type("pv"); | 
| 526 | > | std::string line; | 
| 527 | > | char tempBuffer[4096]; | 
| 528 |  |  | 
| 529 | < | // Set my magic potato to 0: | 
| 529 | > | Vector3d pos; | 
| 530 | > | Vector3d vel; | 
| 531 | > | pos = sd->getPos(); | 
| 532 |  |  | 
| 533 | < | myPotato = 0; | 
| 534 | < | currentIndex = 0; | 
| 535 | < |  | 
| 536 | < | for (i = 0 ; i < mpiSim->getNMolGlobal(); i++ ) { | 
| 537 | < |  | 
| 538 | < | // Am I the node which has this integrableObject? | 
| 539 | < |  | 
| 540 | < | if (MolToProcMap[i] == worldRank) { | 
| 533 | > | if (isinf(pos[0]) || isnan(pos[0]) || | 
| 534 | > | isinf(pos[1]) || isnan(pos[1]) || | 
| 535 | > | isinf(pos[2]) || isnan(pos[2]) ) { | 
| 536 | > | sprintf( painCave.errMsg, | 
| 537 | > | "DumpWriter detected a numerical error writing the position" | 
| 538 | > | " for object %d", index); | 
| 539 | > | painCave.isFatal = 1; | 
| 540 | > | simError(); | 
| 541 | > | } | 
| 542 |  |  | 
| 543 | + | vel = sd->getVel(); | 
| 544 |  |  | 
| 545 | < | if (myPotato + 1 >= MAXTAG) { | 
| 546 | < |  | 
| 547 | < | // The potato was going to exceed the maximum value, | 
| 548 | < | // so wrap this processor potato back to 0 (and block until | 
| 549 | < | // node 0 says we can go: | 
| 550 | < |  | 
| 551 | < | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus); | 
| 552 | < |  | 
| 553 | < | } | 
| 545 | > | if (isinf(vel[0]) || isnan(vel[0]) || | 
| 546 | > | isinf(vel[1]) || isnan(vel[1]) || | 
| 547 | > | isinf(vel[2]) || isnan(vel[2]) ) { | 
| 548 | > | sprintf( painCave.errMsg, | 
| 549 | > | "DumpWriter detected a numerical error writing the velocity" | 
| 550 | > | " for object %d", index); | 
| 551 | > | painCave.isFatal = 1; | 
| 552 | > | simError(); | 
| 553 | > | } | 
| 554 |  |  | 
| 555 | < | local_index = indexArray[currentIndex].first; | 
| 556 | < | integrableObjects = entry_plug->molecules[local_index].getIntegrableObjects(); | 
| 557 | < |  | 
| 558 | < | nCurObj = integrableObjects.size(); | 
| 590 | < |  | 
| 591 | < | MPI_Send(&nCurObj, 1, MPI_INT, 0, | 
| 592 | < | myPotato, MPI_COMM_WORLD); | 
| 593 | < | myPotato++; | 
| 555 | > | sprintf(tempBuffer, "%18.10g %18.10g %18.10g %13e %13e %13e", | 
| 556 | > | pos[0], pos[1], pos[2], | 
| 557 | > | vel[0], vel[1], vel[2]); | 
| 558 | > | line += tempBuffer; | 
| 559 |  |  | 
| 560 | < | for( iter = integrableObjects.begin(); iter  != integrableObjects.end(); iter++){ | 
| 560 | > | if (sd->isDirectional()) { | 
| 561 | > | type += "qj"; | 
| 562 | > | Quat4d q; | 
| 563 | > | Vector3d ji; | 
| 564 | > | q = sd->getQ(); | 
| 565 |  |  | 
| 566 | < | if (myPotato + 2 >= MAXTAG) { | 
| 567 | < |  | 
| 568 | < | // The potato was going to exceed the maximum value, | 
| 569 | < | // so wrap this processor potato back to 0 (and block until | 
| 570 | < | // node 0 says we can go: | 
| 571 | < |  | 
| 572 | < | MPI_Recv(&myPotato, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &istatus); | 
| 573 | < |  | 
| 574 | < | } | 
| 575 | < |  | 
| 607 | < | sd = *iter; | 
| 608 | < |  | 
| 609 | < | atomTypeString = sd->getType(); | 
| 566 | > | if (isinf(q[0]) || isnan(q[0]) || | 
| 567 | > | isinf(q[1]) || isnan(q[1]) || | 
| 568 | > | isinf(q[2]) || isnan(q[2]) || | 
| 569 | > | isinf(q[3]) || isnan(q[3]) ) { | 
| 570 | > | sprintf( painCave.errMsg, | 
| 571 | > | "DumpWriter detected a numerical error writing the quaternion" | 
| 572 | > | " for object %d", index); | 
| 573 | > | painCave.isFatal = 1; | 
| 574 | > | simError(); | 
| 575 | > | } | 
| 576 |  |  | 
| 577 | < | sd->getPos(pos); | 
| 578 | < | sd->getVel(vel); | 
| 577 | > | ji = sd->getJ(); | 
| 578 | > |  | 
| 579 | > | if (isinf(ji[0]) || isnan(ji[0]) || | 
| 580 | > | isinf(ji[1]) || isnan(ji[1]) || | 
| 581 | > | isinf(ji[2]) || isnan(ji[2]) ) { | 
| 582 | > | sprintf( painCave.errMsg, | 
| 583 | > | "DumpWriter detected a numerical error writing the angular" | 
| 584 | > | " momentum for object %d", index); | 
| 585 | > | painCave.isFatal = 1; | 
| 586 | > | simError(); | 
| 587 | > | } | 
| 588 |  |  | 
| 589 | < | atomData[0] = pos[0]; | 
| 590 | < | atomData[1] = pos[1]; | 
| 591 | < | atomData[2] = pos[2]; | 
| 589 | > | sprintf(tempBuffer, " %13e %13e %13e %13e %13e %13e %13e", | 
| 590 | > | q[0], q[1], q[2], q[3], | 
| 591 | > | ji[0], ji[1], ji[2]); | 
| 592 | > | line += tempBuffer; | 
| 593 | > | } | 
| 594 |  |  | 
| 595 | < | atomData[3] = vel[0]; | 
| 596 | < | atomData[4] = vel[1]; | 
| 597 | < | atomData[5] = vel[2]; | 
| 598 | < |  | 
| 599 | < | isDirectional = 0; | 
| 600 | < |  | 
| 601 | < | if( sd->isDirectional() ){ | 
| 602 | < |  | 
| 603 | < | isDirectional = 1; | 
| 604 | < |  | 
| 605 | < | sd->getQ( q ); | 
| 606 | < | sd->getJ( ji ); | 
| 607 | < |  | 
| 608 | < |  | 
| 609 | < | atomData[6] = q[0]; | 
| 633 | < | atomData[7] = q[1]; | 
| 634 | < | atomData[8] = q[2]; | 
| 635 | < | atomData[9] = q[3]; | 
| 595 | > | if (needForceVector_) { | 
| 596 | > | type += "f"; | 
| 597 | > | Vector3d frc = sd->getFrc(); | 
| 598 | > | if (isinf(frc[0]) || isnan(frc[0]) || | 
| 599 | > | isinf(frc[1]) || isnan(frc[1]) || | 
| 600 | > | isinf(frc[2]) || isnan(frc[2]) ) { | 
| 601 | > | sprintf( painCave.errMsg, | 
| 602 | > | "DumpWriter detected a numerical error writing the force" | 
| 603 | > | " for object %d", index); | 
| 604 | > | painCave.isFatal = 1; | 
| 605 | > | simError(); | 
| 606 | > | } | 
| 607 | > | sprintf(tempBuffer, " %13e %13e %13e", | 
| 608 | > | frc[0], frc[1], frc[2]); | 
| 609 | > | line += tempBuffer; | 
| 610 |  |  | 
| 611 | < | atomData[10] = ji[0]; | 
| 612 | < | atomData[11] = ji[1]; | 
| 613 | < | atomData[12] = ji[2]; | 
| 614 | < | } | 
| 611 | > | if (sd->isDirectional()) { | 
| 612 | > | type += "t"; | 
| 613 | > | Vector3d trq = sd->getTrq(); | 
| 614 | > | if (isinf(trq[0]) || isnan(trq[0]) || | 
| 615 | > | isinf(trq[1]) || isnan(trq[1]) || | 
| 616 | > | isinf(trq[2]) || isnan(trq[2]) ) { | 
| 617 | > | sprintf( painCave.errMsg, | 
| 618 | > | "DumpWriter detected a numerical error writing the torque" | 
| 619 | > | " for object %d", index); | 
| 620 | > | painCave.isFatal = 1; | 
| 621 | > | simError(); | 
| 622 | > | } | 
| 623 | > | sprintf(tempBuffer, " %13e %13e %13e", | 
| 624 | > | trq[0], trq[1], trq[2]); | 
| 625 | > | line += tempBuffer; | 
| 626 | > | } | 
| 627 | > | } | 
| 628 |  |  | 
| 629 | < |  | 
| 630 | < | strncpy(MPIatomTypeString, atomTypeString, MINIBUFFERSIZE); | 
| 629 | > | sprintf(tempBuffer, "%10d %7s %s\n", index, type.c_str(), line.c_str()); | 
| 630 | > | return std::string(tempBuffer); | 
| 631 | > | } | 
| 632 |  |  | 
| 633 | < | // null terminate the string before sending (just in case): | 
| 634 | < | MPIatomTypeString[MINIBUFFERSIZE-1] = '\0'; | 
| 633 | > | std::string DumpWriter::prepareSiteLine(StuntDouble* sd, int ioIndex, int siteIndex) { | 
| 634 | > | int storageLayout = info_->getSnapshotManager()->getStorageLayout(); | 
| 635 |  |  | 
| 636 | < | MPI_Send(MPIatomTypeString, MINIBUFFERSIZE, MPI_CHAR, 0, | 
| 637 | < | myPotato, MPI_COMM_WORLD); | 
| 638 | < |  | 
| 639 | < | myPotato++; | 
| 652 | < |  | 
| 653 | < | if (isDirectional) { | 
| 636 | > | std::string id; | 
| 637 | > | std::string type; | 
| 638 | > | std::string line; | 
| 639 | > | char tempBuffer[4096]; | 
| 640 |  |  | 
| 641 | < | MPI_Send(atomData, 13, MPI_DOUBLE, 0, | 
| 642 | < | myPotato, MPI_COMM_WORLD); | 
| 641 | > | if (sd->isRigidBody()) { | 
| 642 | > | sprintf(tempBuffer, "%10d           ", ioIndex); | 
| 643 | > | id = std::string(tempBuffer); | 
| 644 | > | } else { | 
| 645 | > | sprintf(tempBuffer, "%10d %10d", ioIndex, siteIndex); | 
| 646 | > | id = std::string(tempBuffer); | 
| 647 | > | } | 
| 648 |  |  | 
| 649 | < | } else { | 
| 649 | > | if (needFlucQ_) { | 
| 650 | > | if (storageLayout & DataStorage::dslFlucQPosition) { | 
| 651 | > | type += "c"; | 
| 652 | > | RealType fqPos = sd->getFlucQPos(); | 
| 653 | > | if (isinf(fqPos) || isnan(fqPos) ) { | 
| 654 | > | sprintf( painCave.errMsg, | 
| 655 | > | "DumpWriter detected a numerical error writing the" | 
| 656 | > | " fluctuating charge for object %s", id.c_str()); | 
| 657 | > | painCave.isFatal = 1; | 
| 658 | > | simError(); | 
| 659 | > | } | 
| 660 | > | sprintf(tempBuffer, " %13e ", fqPos); | 
| 661 | > | line += tempBuffer; | 
| 662 | > | } | 
| 663 |  |  | 
| 664 | < | MPI_Send(atomData, 6, MPI_DOUBLE, 0, | 
| 665 | < | myPotato, MPI_COMM_WORLD); | 
| 666 | < | } | 
| 664 | > | if (storageLayout & DataStorage::dslFlucQVelocity) { | 
| 665 | > | type += "w"; | 
| 666 | > | RealType fqVel = sd->getFlucQVel(); | 
| 667 | > | if (isinf(fqVel) || isnan(fqVel) ) { | 
| 668 | > | sprintf( painCave.errMsg, | 
| 669 | > | "DumpWriter detected a numerical error writing the" | 
| 670 | > | " fluctuating charge velocity for object %s", id.c_str()); | 
| 671 | > | painCave.isFatal = 1; | 
| 672 | > | simError(); | 
| 673 | > | } | 
| 674 | > | sprintf(tempBuffer, " %13e ", fqVel); | 
| 675 | > | line += tempBuffer; | 
| 676 | > | } | 
| 677 |  |  | 
| 678 | < | myPotato++; | 
| 679 | < |  | 
| 678 | > | if (needForceVector_) { | 
| 679 | > | if (storageLayout & DataStorage::dslFlucQForce) { | 
| 680 | > | type += "g"; | 
| 681 | > | RealType fqFrc = sd->getFlucQFrc(); | 
| 682 | > | if (isinf(fqFrc) || isnan(fqFrc) ) { | 
| 683 | > | sprintf( painCave.errMsg, | 
| 684 | > | "DumpWriter detected a numerical error writing the" | 
| 685 | > | " fluctuating charge force for object %s", id.c_str()); | 
| 686 | > | painCave.isFatal = 1; | 
| 687 | > | simError(); | 
| 688 |  | } | 
| 689 | + | sprintf(tempBuffer, " %13e ", fqFrc); | 
| 690 | + | line += tempBuffer; | 
| 691 | + | } | 
| 692 | + | } | 
| 693 | + | } | 
| 694 | + |  | 
| 695 | + | if (needElectricField_) { | 
| 696 | + | if (storageLayout & DataStorage::dslElectricField) { | 
| 697 | + | type += "e"; | 
| 698 | + | Vector3d eField= sd->getElectricField(); | 
| 699 | + | if (isinf(eField[0]) || isnan(eField[0]) || | 
| 700 | + | isinf(eField[1]) || isnan(eField[1]) || | 
| 701 | + | isinf(eField[2]) || isnan(eField[2]) ) { | 
| 702 | + | sprintf( painCave.errMsg, | 
| 703 | + | "DumpWriter detected a numerical error writing the electric" | 
| 704 | + | " field for object %s", id.c_str()); | 
| 705 | + | painCave.isFatal = 1; | 
| 706 | + | simError(); | 
| 707 | + | } | 
| 708 | + | sprintf(tempBuffer, " %13e %13e %13e", | 
| 709 | + | eField[0], eField[1], eField[2]); | 
| 710 | + | line += tempBuffer; | 
| 711 | + | } | 
| 712 | + | } | 
| 713 |  |  | 
| 714 | < | currentIndex++; | 
| 715 | < |  | 
| 714 | > |  | 
| 715 | > | if (needParticlePot_) { | 
| 716 | > | if (storageLayout & DataStorage::dslParticlePot) { | 
| 717 | > | type += "u"; | 
| 718 | > | RealType particlePot = sd->getParticlePot(); | 
| 719 | > | if (isinf(particlePot) || isnan(particlePot)) { | 
| 720 | > | sprintf( painCave.errMsg, | 
| 721 | > | "DumpWriter detected a numerical error writing the particle " | 
| 722 | > | " potential for object %s", id.c_str()); | 
| 723 | > | painCave.isFatal = 1; | 
| 724 | > | simError(); | 
| 725 |  | } | 
| 726 | < |  | 
| 726 | > | sprintf(tempBuffer, " %13e", particlePot); | 
| 727 | > | line += tempBuffer; | 
| 728 |  | } | 
| 729 | + | } | 
| 730 | + |  | 
| 731 | + | sprintf(tempBuffer, "%s %7s %s\n", id.c_str(), type.c_str(), line.c_str()); | 
| 732 | + | return std::string(tempBuffer); | 
| 733 | + | } | 
| 734 |  |  | 
| 735 | < | sprintf( checkPointMsg, | 
| 736 | < | "Successfully took a dump.\n"); | 
| 737 | < | MPIcheckPoint(); | 
| 735 | > | void DumpWriter::writeDump() { | 
| 736 | > | writeFrame(*dumpFile_); | 
| 737 | > | } | 
| 738 | > |  | 
| 739 | > | void DumpWriter::writeEor() { | 
| 740 | > |  | 
| 741 | > | std::ostream* eorStream = NULL; | 
| 742 | > |  | 
| 743 | > | #ifdef IS_MPI | 
| 744 | > | if (worldRank == 0) { | 
| 745 | > | #endif // is_mpi | 
| 746 | > |  | 
| 747 | > | eorStream = createOStream(eorFilename_); | 
| 748 | > |  | 
| 749 | > | #ifdef IS_MPI | 
| 750 | > | } | 
| 751 | > | #endif | 
| 752 |  |  | 
| 753 | + | writeFrame(*eorStream); | 
| 754 | + |  | 
| 755 | + | #ifdef IS_MPI | 
| 756 | + | if (worldRank == 0) { | 
| 757 | + | #endif | 
| 758 | + |  | 
| 759 | + | writeClosing(*eorStream); | 
| 760 | + | delete eorStream; | 
| 761 | + |  | 
| 762 | + | #ifdef IS_MPI | 
| 763 | + | } | 
| 764 | + | #endif // is_mpi | 
| 765 | + |  | 
| 766 |  | } | 
| 767 | < |  | 
| 767 | > |  | 
| 768 | > |  | 
| 769 | > | void DumpWriter::writeDumpAndEor() { | 
| 770 | > | std::vector<std::streambuf*> buffers; | 
| 771 | > | std::ostream* eorStream; | 
| 772 | > | #ifdef IS_MPI | 
| 773 | > | if (worldRank == 0) { | 
| 774 |  | #endif // is_mpi | 
| 775 | < | } | 
| 775 | > | buffers.push_back(dumpFile_->rdbuf()); | 
| 776 | > | eorStream = createOStream(eorFilename_); | 
| 777 | > | buffers.push_back(eorStream->rdbuf()); | 
| 778 | > | #ifdef IS_MPI | 
| 779 | > | } | 
| 780 | > | #endif // is_mpi | 
| 781 |  |  | 
| 782 | + | TeeBuf tbuf(buffers.begin(), buffers.end()); | 
| 783 | + | std::ostream os(&tbuf); | 
| 784 | + | writeFrame(os); | 
| 785 | + |  | 
| 786 |  | #ifdef IS_MPI | 
| 787 | + | if (worldRank == 0) { | 
| 788 | + | #endif // is_mpi | 
| 789 | + | writeClosing(*eorStream); | 
| 790 | + | delete eorStream; | 
| 791 | + | #ifdef IS_MPI | 
| 792 | + | } | 
| 793 | + | #endif // is_mpi | 
| 794 | + | } | 
| 795 |  |  | 
| 796 | < | // a couple of functions to let us escape the write loop | 
| 796 | > | std::ostream* DumpWriter::createOStream(const std::string& filename) { | 
| 797 |  |  | 
| 798 | < | void dWrite::DieDieDie( void ){ | 
| 798 | > | std::ostream* newOStream; | 
| 799 | > | #ifdef HAVE_ZLIB | 
| 800 | > | if (needCompression_) { | 
| 801 | > | newOStream = new ogzstream(filename.c_str()); | 
| 802 | > | } else { | 
| 803 | > | newOStream = new std::ofstream(filename.c_str()); | 
| 804 | > | } | 
| 805 | > | #else | 
| 806 | > | newOStream = new std::ofstream(filename.c_str()); | 
| 807 | > | #endif | 
| 808 | > | //write out MetaData first | 
| 809 | > | (*newOStream) << "<OpenMD version=2>" << std::endl; | 
| 810 | > | (*newOStream) << "  <MetaData>" << std::endl; | 
| 811 | > | (*newOStream) << info_->getRawMetaData(); | 
| 812 | > | (*newOStream) << "  </MetaData>" << std::endl; | 
| 813 | > | return newOStream; | 
| 814 | > | } | 
| 815 |  |  | 
| 816 | < | MPI_Finalize(); | 
| 690 | < | exit (0); | 
| 691 | < | } | 
| 816 | > | void DumpWriter::writeClosing(std::ostream& os) { | 
| 817 |  |  | 
| 818 | < | #endif //is_mpi | 
| 818 | > | os << "</OpenMD>\n"; | 
| 819 | > | os.flush(); | 
| 820 | > | } | 
| 821 | > |  | 
| 822 | > | }//end namespace OpenMD |