PetaVision  Alpha
CheckpointEntryDataStore.cpp
1 /*
2  * CheckpointEntryDataStore.cpp
3  *
4  * Created on Sep 27, 2016
5  * Author: Pete Schultz
6  */
7 
8 #include "CheckpointEntryDataStore.hpp"
9 #include "structures/Buffer.hpp"
10 #include "utils/BufferUtilsMPI.hpp"
11 #include "utils/BufferUtilsPvp.hpp"
12 #include "utils/PVAssert.hpp"
13 
14 namespace PV {
15 
16 // Constructors defined in .hpp file.
17 // Write and remove methods inherited from CheckpointEntryPvp.
18 
19 void CheckpointEntryDataStore::read(std::string const &checkpointDirectory, double *simTimePtr)
20  const {
21  CheckpointEntryPvp::read(checkpointDirectory, simTimePtr);
22  for (int bufferId = 0; bufferId < mDataStore->getNumBuffers(); bufferId++) {
23  for (int levelId = 0; levelId < mDataStore->getNumLevels(); levelId++) {
24  mDataStore->markActiveIndicesOutOfSync(bufferId, levelId);
25  }
26  }
27 }
28 
29 int CheckpointEntryDataStore::getNumFrames() const {
30  int const numBuffers = getDataStore()->getNumBuffers();
31  int const numLevels = getDataStore()->getNumLevels();
32  int const mpiBatchDim = getMPIBlock()->getBatchDimension();
33 
34  return numLevels * numBuffers * mpiBatchDim;
35 }
36 
37 float *CheckpointEntryDataStore::calcBatchElementStart(int frame) const {
38  int const numBuffers = getDataStore()->getNumBuffers();
39  int const numLevels = getDataStore()->getNumLevels();
40  int const level = frame % numLevels;
41  int const buffer = (frame / numLevels) % numBuffers; // Integer division
42  return getDataStore()->buffer(buffer, level);
43 }
44 
45 int CheckpointEntryDataStore::calcMPIBatchIndex(int frame) const {
46  return frame / (getDataStore()->getNumLevels() * getDataStore()->getNumBuffers());
47 }
48 
49 void CheckpointEntryDataStore::setLastUpdateTimes(std::vector<double> const &timestamps) const {
50  int const numBuffers = getDataStore()->getNumBuffers();
51  int const numLevels = getDataStore()->getNumLevels();
52  int const mpiBatchIndex = getMPIBlock()->getBatchIndex();
53  double const *updateTimesBatchElement = &timestamps[numBuffers * numLevels * mpiBatchIndex];
54  for (int b = 0; b < numBuffers; b++) {
55  for (int l = 0; l < numLevels; l++) {
56  getDataStore()->setLastUpdateTime(b, l, updateTimesBatchElement[b * numLevels + l]);
57  }
58  }
59 }
60 
61 } // end namespace PV
int getBatchDimension() const
Definition: MPIBlock.hpp:135
int getBatchIndex() const
Definition: MPIBlock.hpp:171