Newer
Older
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* BPFileReader.cpp
*
* Created on: Feb 27, 2017
#include "BPFileReader.h"
#include "BPFileReader.tcc"
#include "adios2/helper/adiosFunctions.h" // MPI BroadcastVector
BPFileReader::BPFileReader(IO &io, const std::string &name, const Mode openMode,
MPI_Comm mpiComm)
: Engine("BPFileReader", io, name, openMode, mpiComm),
m_BP3Deserializer(mpiComm, m_DebugMode), m_FileManager(mpiComm, m_DebugMode),
m_SubFileManager(mpiComm, m_DebugMode)
void BPFileReader::PerformGets()
{
const auto variablesSubFileInfo =
m_BP3Deserializer.PerformGetsVariablesSubFileInfo(m_IO);
}
void BPFileReader::Close(const int /*transportIndex*/) {}
// PRIVATE
void BPFileReader::Init()
{
if (m_OpenMode != Mode::Read)
"ERROR: BPFileReader only supports OpenMode::Read from" +
m_Name + " " + m_EndMessage);
void BPFileReader::InitTransports()
if (m_IO.m_TransportsParameters.empty())
{
Params defaultTransportParameters;
defaultTransportParameters["transport"] = "File";
m_IO.m_TransportsParameters.push_back(defaultTransportParameters);
}
if (m_BP3Deserializer.m_RankMPI == 0)
m_BP3Deserializer.GetBPMetadataFileName(m_Name));
const bool profile = m_BP3Deserializer.m_Profiler.IsActive;
m_FileManager.OpenFiles({}, {metadataFile}, adios2::Mode::Read,
m_IO.m_TransportsParameters, profile);
if (m_BP3Deserializer.m_RankMPI == 0)
{
const size_t fileSize = m_FileManager.GetFileSize(0);
m_BP3Deserializer.m_Metadata.Resize(
fileSize,
"allocating metadata buffer, in call to BPFileReader Open");
m_FileManager.ReadFile(m_BP3Deserializer.m_Metadata.m_Buffer.data(),
// broadcast buffer to all ranks from zero
m_BP3Deserializer.m_Metadata.m_Buffer =
BroadcastVector(m_BP3Deserializer.m_Metadata.m_Buffer, m_MPIComm);
// fills IO with Variables and Attributes
m_BP3Deserializer.ParseMetadata(m_IO);
#define declare_type(T) \
void BPFileReader::DoGetSync(Variable<T> &variable, T *data) \
{ \
GetSyncCommon(variable, data); \
} \
void BPFileReader::DoGetDeferred(Variable<T> &variable, T *data) \
{ \
GetDeferredCommon(variable, data); \
} \
void BPFileReader::DoGetDeferred(Variable<T> &variable, T &data) \
{ \
GetDeferredCommon(variable, &data); \
}
ADIOS2_FOREACH_TYPE_1ARG(declare_type)
#undef declare_type
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
void BPFileReader::ReadVariables(
IO &io, const std::map<std::string, SubFileInfoMap> &variablesSubFileInfo)
{
const bool &profile = m_BP3Deserializer.m_Profiler.IsActive;
// sequentially request bytes from transport manager
// threaded here?
for (const auto &variableNamePair : variablesSubFileInfo) // variable name
{
const std::string variableName(variableNamePair.first);
unsigned int subFileTransportIndex = 0;
// or threaded here?
for (const auto &subFileIndexPair : variableNamePair.second)
{
const unsigned int subFileIndex = subFileIndexPair.first;
const std::string subFile(
m_BP3Deserializer.GetBPSubFileName(m_Name, subFileIndex));
m_SubFileManager.OpenFiles({}, {subFile}, adios2::Mode::Read,
std::vector<Params>(), profile);
for (const auto &stepPair : subFileIndexPair.second) // step
{
const size_t step = stepPair.first;
for (const auto &blockInfo : stepPair.second)
{
const auto &seek = blockInfo.Seeks;
const size_t blockStart = seek.first;
const size_t blockSize = seek.second - seek.first;
std::vector<char> contiguousData(blockSize);
m_SubFileManager.ReadFile(contiguousData.data(), blockStart,
blockSize, subFileTransportIndex);
// will go to BP3Deserializer along with contiguous data
// Variable Data
// blockInfo.IntersectionBox;
} // end block
} // end step
++subFileTransportIndex;
} // end subfile
} // end variable
m_SubFileManager.CloseFiles();
}
} // end namespace adios2