--- trunk/src/brains/BlockSnapshotManager.cpp 2013/06/16 15:15:42 1879 +++ trunk/src/brains/BlockSnapshotManager.cpp 2015/03/07 21:41:51 2071 @@ -53,8 +53,9 @@ namespace OpenMD { int storageLayout, long long int memSize, int blockCapacity) - : SnapshotManager(storageLayout), info_(info), memSize_(memSize), - blockCapacity_(blockCapacity), activeBlocks_(blockCapacity_, -1), + : SnapshotManager(storageLayout), info_(info), + blockCapacity_(blockCapacity), memSize_(memSize), + activeBlocks_(blockCapacity_, -1), activeRefCount_(blockCapacity_, 0) { nAtoms_ = info->getNGlobalAtoms(); @@ -67,8 +68,13 @@ namespace OpenMD { // RealType avaliablePhysMem = physMem - rssMem; int bytesPerStuntDouble = DataStorage::getBytesPerStuntDouble(storageLayout); - int bytesPerFrame = (nRigidBodies_ + nAtoms_) * bytesPerStuntDouble; + int bytesPerCutoffGroup = DataStorage::getBytesPerStuntDouble(DataStorage::dslPosition); + 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 = (RealType) memSize_ / (RealType) bytesPerFrame; @@ -76,6 +82,9 @@ namespace OpenMD { // 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 +100,33 @@ namespace OpenMD { snapshots_.insert(snapshots_.begin(), nframes_, static_cast(NULL)); - std::cout << "-----------------------------------------------------"<::iterator i = findActiveBlock(block); - bool loadSuccess; + bool loadSuccess(false); if (i != activeBlocks_.end()) { - //if block is already in memory, just increast the reference count + // If the block is already in memory, just increase the + // reference count: ++activeRefCount_[i - activeBlocks_.begin()]; loadSuccess = true; } else if (getNActiveBlocks() < blockCapacity_){ - //if number of active blocks is less than the block capacity, just load it + // If the number of active blocks is less than the block + // capacity, just load the block: internalLoad(block); loadSuccess = true; } else if ( hasZeroRefBlock() ) { - //if already reach the block capacity, need to unload a block with 0 reference + // If we have already reached the block capacity, we need to + // unload a block with 0 references: int zeroRefBlock = getFirstZeroRefBlock(); assert(zeroRefBlock != -1); internalUnload(zeroRefBlock); internalLoad(block); } else { - //reach the capacity and all blocks in memory are not zero reference + // We have reached capacity and all blocks in memory are have + // non-zero references: loadSuccess = false; - } - + } return loadSuccess; } @@ -175,6 +200,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 +227,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;