--- trunk/src/brains/BlockSnapshotManager.cpp 2011/07/25 17:30:53 1596 +++ trunk/src/brains/BlockSnapshotManager.cpp 2014/01/24 14:17:42 1966 @@ -35,13 +35,14 @@ * * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). - * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). - * [4] Vardeman & Gezelter, in progress (2009). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). + * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). + * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). */ #include #include "brains/BlockSnapshotManager.hpp" -// #include "utils/residentMem.h" -// #include "utils/physmem.h" +//#include "utils/residentMem.h" +//#include "utils/physmem.h" #include "utils/Algorithm.hpp" #include "brains/SimInfo.hpp" #include "io/DumpReader.hpp" @@ -49,33 +50,40 @@ namespace OpenMD { namespace OpenMD { BlockSnapshotManager::BlockSnapshotManager(SimInfo* info, const std::string& filename, - int storageLayout, - long long int memSize, + int storageLayout, + long long int memSize, int blockCapacity) - : SnapshotManager(storageLayout), info_(info), memSize_(memSize), + : SnapshotManager(storageLayout), info_(info), memSize_(memSize), blockCapacity_(blockCapacity), activeBlocks_(blockCapacity_, -1), activeRefCount_(blockCapacity_, 0) { nAtoms_ = info->getNGlobalAtoms(); nRigidBodies_ = info->getNGlobalRigidBodies(); + nCutoffGroups_ = info->getNCutoffGroups(); // eliminate suspect calls to figure out free memory: // RealType physMem = physmem_total(); // RealType rssMem = residentMem(); // RealType avaliablePhysMem = physMem - rssMem; - + int bytesPerStuntDouble = DataStorage::getBytesPerStuntDouble(storageLayout); + int bytesPerCutoffGroup = DataStorage::getBytesPerStuntDouble(DataStorage::dslPosition); - int bytesPerFrame = (nRigidBodies_ + nAtoms_) * bytesPerStuntDouble; + int bytesPerFrameData = Snapshot::getFrameDataSize(); + int bytesPerFrame = (nRigidBodies_ + nAtoms_) * bytesPerStuntDouble + + nCutoffGroups_ * bytesPerCutoffGroup + + bytesPerFrameData; // total number of frames that can fit in memory - //RealType frameCapacity = avaliablePhysMem / bytesPerFrame; - RealType frameCapacity = memSize_ / bytesPerFrame; + RealType frameCapacity = (RealType) memSize_ / (RealType) bytesPerFrame; // number of frames in each block given the need to hold multiple blocks // in memory at the same time: nSnapshotPerBlock_ = int(frameCapacity) / blockCapacity_; + if (nSnapshotPerBlock_ <= 0) { + std::cerr << "not enough memory to hold two configs!" << std::endl; + } reader_ = new DumpReader(info, filename); nframes_ = reader_->getNFrames(); int nblocks = nframes_ / nSnapshotPerBlock_; @@ -91,20 +99,33 @@ namespace OpenMD { snapshots_.insert(snapshots_.begin(), nframes_, static_cast(NULL)); - std::cout << "-----------------------------------------------------"< 0) { + } else if ( hasZeroRefBlock() ) { //if already reach the block capacity, need to unload a block with 0 reference int zeroRefBlock = getFirstZeroRefBlock(); assert(zeroRefBlock != -1); @@ -175,6 +196,10 @@ namespace OpenMD { //in case, unloadBlock called multiple times activeRefCount_[i - activeBlocks_.begin()] = 0; } + + if (activeRefCount_[i-activeBlocks_.begin()] == 0) { + internalUnload(block); + } unloadSuccess = true; } else { @@ -198,6 +223,7 @@ namespace OpenMD { } void BlockSnapshotManager::internalUnload(int block) { + std::cerr << "called internal unload for block "<< block << "\n"; for (int i = blocks_[block].first; i < blocks_[block].second; ++i) { delete snapshots_[i]; snapshots_[i] = NULL; @@ -225,17 +251,14 @@ namespace OpenMD { } Snapshot* BlockSnapshotManager::loadFrame(int frame){ - Snapshot* snapshot = new Snapshot(nAtoms_, nRigidBodies_, getStorageLayout()); + Snapshot* snapshot = new Snapshot(nAtoms_, nRigidBodies_, nCutoffGroups_, + getStorageLayout()); snapshot->setID(frame); + snapshot->clearDerivedProperties(); - /** @todo fixed me */ - Snapshot* oldSnapshot = currentSnapshot_; currentSnapshot_ = snapshot; reader_->readFrame(frame); - // What was this for? It doesn't make sense! - //currentSnapshot_ = oldSnapshot; - return snapshot; }