Skip to content
Snippets Groups Projects
Commit cc287d98 authored by William F Godoy's avatar William F Godoy
Browse files

Fixed bug in Read, need to add tests

parent fa61cc8c
No related branches found
No related tags found
1 merge request!294Bp1read : Initial Reading Capabilities and latest API
......@@ -2,17 +2,17 @@
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* helloBPReaderHeatMap.cpp : Writes a regular heat map in a regular 2D mesh,
* helloBPReaderHeatMap.cpp : Writes a heat map in a regular 2D mesh,
* values grow from 0 in increments of 1
*
* temperature[gNx, gNy]
* where: gNx = MPI_size_x * Nx and gNy = MPI_size_y * Ny
* temperature[gNx, Ny]
* where: gNx = MPI_size_x * Nx
*
* 0 1 2 ... gNy-1
* gNy gNy+1 gNy+2 ... 2*gNy-1
* 0 1 2 ... Ny-1
* Ny Ny+1 Ny+2 ... 2*Ny-1
* ...
* ...
* (gNx-1)*gNy ... gNx*gNy-1
* (gNx-1)*Ny ... gNx*Ny-1
*
*
* Created on: Nov 1, 2017
......@@ -40,8 +40,8 @@ int main(int argc, char *argv[])
constexpr std::size_t Ny = 10;
const adios2::Dims count{Nx, Ny};
const adios2::Dims start{rank * Nx, rank * Ny};
const adios2::Dims shape{size * Nx, size * Ny};
const adios2::Dims start{rank * Nx, 0};
const adios2::Dims shape{size * Nx, Ny};
// populate local temperature values
std::vector<unsigned int> temperatures(Nx * Ny);
......@@ -51,8 +51,7 @@ int main(int argc, char *argv[])
for (unsigned int j = 0; j < Ny; ++j)
{
const unsigned int jGlobal = start[1] + j;
const unsigned int value = iGlobal * shape[1] + jGlobal;
const unsigned int value = iGlobal * shape[1] + j;
temperatures[i * Ny + j] = value;
}
}
......@@ -88,12 +87,15 @@ int main(int argc, char *argv[])
// this just discovers in the metadata file that the variable exists
adios2::Variable<unsigned int> *inTemperature =
getHeatMap.InquireVariable<unsigned int>("temperature");
inTemperature->SetSelection({{2, 2}, {4, 4}});
// now read the variable
if (inTemperature != nullptr)
{
std::vector<unsigned int> inTemperatures(16);
inTemperature->SetSelection({{2, 2}, {6, 1}});
size_t elementsSize = inTemperature->GetElementsSize();
std::vector<unsigned int> inTemperatures(elementsSize);
std::cout << "Pre-allocated " << elementsSize << " elements, "
<< elementsSize * sizeof(unsigned int) << " bytes\n";
bpReader.GetSync(*inTemperature, inTemperatures.data());
std::cout << "Incoming temperature map:\n";
......@@ -101,7 +103,7 @@ int main(int argc, char *argv[])
for (auto i = 0; i < inTemperatures.size(); ++i)
{
std::cout << inTemperatures[i] << " ";
if ((i + 1) % 4 == 0)
if ((i + 1) % inTemperature->m_Count.back() == 0)
{
std::cout << "\n";
}
......
......@@ -137,8 +137,8 @@ void VariableBase::SetStepSelection(const std::pair<size_t, size_t> &boxSteps)
", in call to Setting Step Selection\n");
}
m_StepStart = boxSteps.first;
m_StepCount = boxSteps.second;
m_StepsStart = boxSteps.first;
m_StepsCount = boxSteps.second;
}
// transforms related functions
......@@ -185,6 +185,11 @@ void VariableBase::CheckDimensions(const std::string hint) const
// TODO need to think more exceptions here
}
size_t VariableBase::GetElementsSize() const
{
return GetTotalSize(m_Count) * m_StepsCount;
}
// PRIVATE
void VariableBase::InitShapeType()
{
......
......@@ -68,8 +68,8 @@ public:
size_t m_AvailableStepsStart = 1;
size_t m_AvailableStepsCount = 0;
size_t m_StepStart = 1;
size_t m_StepCount = 1;
size_t m_StepsStart = 1;
size_t m_StepsCount = 1;
/** Index Metadata Position in a serial metadata buffer */
size_t m_IndexStart;
......@@ -143,6 +143,13 @@ public:
* @param hint extra debugging info for the exception */
void CheckDimensions(const std::string hint) const;
/**
* Returns the minimum required allocation for the current selection
* @return memory size to be allocated by a pointer/vector to read this
* variable
*/
size_t GetElementsSize() const;
protected:
const bool m_DebugMode = false;
......
......@@ -153,7 +153,7 @@ void BPFileReader::ReadVariables(
m_BP3Deserializer.ClipContiguousMemory(
variableName, m_IO, contiguousMemory,
blockInfo.IntersectionBox);
blockInfo.BlockBox, blockInfo.IntersectionBox);
} // end block
} // end step
} // end subfile
......
......@@ -26,9 +26,11 @@ namespace adios2
struct SubFileInfo
{
/** from characteristics, first = Start point, second =
End point of block of data */
Box<Dims> BlockBox;
Box<Dims> IntersectionBox; ///< first = Start point, second = End point
Box<size_t> Seeks; ///< first = Start seek, second = End seek
std::vector<char> ContiguousData; /// TODO: check if needed
};
/**
......
......@@ -38,7 +38,8 @@ void BP3Deserializer::ParseMetadata(IO &io)
void BP3Deserializer::ClipContiguousMemory(
const std::string &variableName, IO &io,
const std::vector<char> &contiguousMemory, const Box<Dims> &intersectionBox)
const std::vector<char> &contiguousMemory, const Box<Dims> &blockBox,
const Box<Dims> &intersectionBox) const
{
// get variable pointer and set data in it with local dimensions
const std::string type(io.InquireVariableType(variableName));
......@@ -52,7 +53,7 @@ void BP3Deserializer::ClipContiguousMemory(
Variable<T> *variable = io.InquireVariable<T>(variableName); \
if (variable != nullptr) \
{ \
ClipContiguousMemoryCommon(*variable, contiguousMemory, \
ClipContiguousMemoryCommon(*variable, contiguousMemory, blockBox, \
intersectionBox); \
} \
}
......
......@@ -56,7 +56,8 @@ public:
void ClipContiguousMemory(const std::string &variableName, IO &io,
const std::vector<char> &contiguousMemory,
const Box<Dims> &intersectionBox);
const Box<Dims> &blockBox,
const Box<Dims> &intersectionBox) const;
private:
std::map<std::string, SubFileInfoMap> m_DeferredVariables;
......@@ -87,13 +88,13 @@ private:
template <class T>
void ClipContiguousMemoryCommon(Variable<T> &variable,
const std::vector<char> &contiguousMemory,
const Box<Dims> &intersectionBox);
const Box<Dims> &blockBox,
const Box<Dims> &intersectionBox) const;
template <class T>
void
ClipContiguousMemoryCommonRowZero(Variable<T> &variable,
const std::vector<char> &contiguousMemory,
const Box<Dims> &intersectionBox);
void ClipContiguousMemoryCommonRowZero(
Variable<T> &variable, const std::vector<char> &contiguousMemory,
const Box<Dims> &blockBox, const Box<Dims> &intersectionBox) const;
};
#define declare_template_instantiation(T) \
......
......@@ -134,9 +134,9 @@ BP3Deserializer::GetSubFileInfo(const Variable<T> &variable) const
const auto &buffer = m_Metadata.m_Buffer;
const size_t stepStart = variable.m_StepStart;
const size_t stepStart = variable.m_StepsStart;
const size_t stepEnd =
stepStart + variable.m_StepCount; // inclusive or exclusive?
stepStart + variable.m_StepsCount; // inclusive or exclusive?
// selection = [start, end[
const Box<Dims> selectionBox =
......@@ -158,12 +158,11 @@ BP3Deserializer::GetSubFileInfo(const Variable<T> &variable) const
const Characteristics<T> blockCharacteristics =
ReadElementIndexCharacteristics<T>(buffer, blockPosition);
const Box<Dims> blockBox = StartEndBox(blockCharacteristics.Start,
blockCharacteristics.Count);
// check if they intersect
SubFileInfo info;
info.IntersectionBox = IntersectionBox(selectionBox, blockBox);
info.BlockBox = StartEndBox(blockCharacteristics.Start,
blockCharacteristics.Count);
info.IntersectionBox = IntersectionBox(selectionBox, info.BlockBox);
if (info.IntersectionBox.first.empty() ||
info.IntersectionBox.second.empty())
......@@ -171,14 +170,15 @@ BP3Deserializer::GetSubFileInfo(const Variable<T> &variable) const
continue;
}
// if they intersect get info Seeks (first: start, second: count)
info.Seeks.first = blockCharacteristics.Statistics.PayloadOffset +
LinearIndex(blockBox, info.IntersectionBox.first,
m_IsRowMajor, m_IsZeroIndex) *
sizeof(T);
info.Seeks.first =
blockCharacteristics.Statistics.PayloadOffset +
LinearIndex(info.BlockBox, info.IntersectionBox.first,
m_IsRowMajor, m_IsZeroIndex) *
sizeof(T);
info.Seeks.second =
blockCharacteristics.Statistics.PayloadOffset +
(LinearIndex(blockBox, info.IntersectionBox.second,
(LinearIndex(info.BlockBox, info.IntersectionBox.second,
m_IsRowMajor, m_IsZeroIndex) +
1) *
sizeof(T);
......@@ -186,7 +186,7 @@ BP3Deserializer::GetSubFileInfo(const Variable<T> &variable) const
const size_t fileIndex = static_cast<const size_t>(
blockCharacteristics.Statistics.FileIndex);
infoMap[fileIndex][step].push_back(info);
infoMap[fileIndex][step].push_back(std::move(info));
}
}
......@@ -196,7 +196,7 @@ BP3Deserializer::GetSubFileInfo(const Variable<T> &variable) const
template <class T>
void BP3Deserializer::ClipContiguousMemoryCommon(
Variable<T> &variable, const std::vector<char> &contiguousMemory,
const Box<Dims> &intersectionBox)
const Box<Dims> &blockBox, const Box<Dims> &intersectionBox) const
{
const Dims &start = intersectionBox.first;
if (start.size() == 1) // 1D copy memory
......@@ -214,7 +214,7 @@ void BP3Deserializer::ClipContiguousMemoryCommon(
if (m_IsRowMajor && m_IsZeroIndex)
{
ClipContiguousMemoryCommonRowZero(variable, contiguousMemory,
ClipContiguousMemoryCommonRowZero(variable, contiguousMemory, blockBox,
intersectionBox);
}
}
......@@ -222,7 +222,7 @@ void BP3Deserializer::ClipContiguousMemoryCommon(
template <class T>
void BP3Deserializer::ClipContiguousMemoryCommonRowZero(
Variable<T> &variable, const std::vector<char> &contiguousMemory,
const Box<Dims> &intersectionBox)
const Box<Dims> &blockBox, const Box<Dims> &intersectionBox) const
{
const Dims &start = intersectionBox.first;
const Dims &end = intersectionBox.second;
......@@ -236,13 +236,15 @@ void BP3Deserializer::ClipContiguousMemoryCommonRowZero(
const size_t dimensions = start.size();
bool run = true;
const size_t intersectionStart =
LinearIndex(blockBox, intersectionBox.first, true, true) * sizeof(T);
while (run)
{
// here copy current linear memory between currentPoint and end
const size_t contiguousStart =
LinearIndex(intersectionBox, currentPoint, true, true) *
sizeof(T); // TODO: FIX THIS, must be absolute box, not intersection
// box
LinearIndex(blockBox, currentPoint, true, true) * sizeof(T) -
intersectionStart;
const size_t variableStart =
LinearIndex(selectionBox, currentPoint, true, true) * sizeof(T);
......@@ -260,7 +262,7 @@ void BP3Deserializer::ClipContiguousMemoryCommonRowZero(
while (true)
{
++currentPoint[p];
if (currentPoint[p] > end[p]) // TODO: fix end condition
if (currentPoint[p] > end[p]) // TODO: check end condition
{
if (p == 0)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment