Skip to content

Commit

Permalink
Merge pull request #1035 from pnorbert/fix_attributes
Browse files Browse the repository at this point in the history
Serialize new attributes in non-first steps in BP3Serializer.
  • Loading branch information
pnorbert committed Dec 4, 2018
2 parents 97a0ee0 + 550e560 commit bae9c99
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 18 deletions.
1 change: 0 additions & 1 deletion source/adios2/engine/insitumpi/InSituMPIReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ StepStatus InSituMPIReader::BeginStep(const StepMode mode,

// Parse metadata into Variables and Attributes maps
m_IO.RemoveAllVariables();
m_IO.RemoveAllAttributes();
m_BP3Deserializer.ParseMetadata(m_BP3Deserializer.m_Metadata, m_IO);

if (m_Verbosity == 5)
Expand Down
8 changes: 6 additions & 2 deletions source/adios2/toolkit/format/bp3/BP3Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
/// \endcond

Expand Down Expand Up @@ -87,8 +88,6 @@ class BP3Base
/** @brief key: attribute name, value: bp metadata attribute index */
std::unordered_map<std::string, SerialElementIndex> AttributesIndices;

bool AreAttributesWritten = false;

/** Fixed size for mini footer, adding 28 bytes for ADIOS version */
const unsigned int MiniFooterSize = 28 + 28;

Expand Down Expand Up @@ -176,6 +175,11 @@ class BP3Base
/** tracks the overall size of deferred variables */
size_t m_DeferredVariablesDataSize = 0;

/** attributes are serialized only once, this set contains the names of ones
* already serialized.
*/
std::unordered_set<std::string> m_SerializedAttributes;

/**
* Unique constructor
* @param mpiComm for m_BP1Aggregator
Expand Down
29 changes: 23 additions & 6 deletions source/adios2/toolkit/format/bp3/BP3Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ void BP3Serializer::PutAttributes(core::IO &io)
const std::string name(attributePair.first);
const std::string type(attributePair.second.first);

// each attribute is only written to output once
// so filter out the ones already written
auto it = m_SerializedAttributes.find(name);
if (it != m_SerializedAttributes.end())
{
continue;
}

if (type == "unknown")
{
}
Expand Down Expand Up @@ -635,20 +643,21 @@ void BP3Serializer::SerializeDataBuffer(core::IO &io) noexcept
helper::CopyToBuffer(buffer, m_MetadataSet.DataPGVarsCountPosition,
&varsLength);

// attributes are only written once

if (!m_MetadataSet.AreAttributesWritten)
// each attribute is only written to output once
size_t attributesSizeInData = GetAttributesSizeInData(io);
if (attributesSizeInData)
{
const size_t attributesSizeInData = GetAttributesSizeInData(io);
attributesSizeInData += 12; // count + length
m_Data.Resize(position + attributesSizeInData,
"when writing Attributes in rank=0\n");

PutAttributes(io);
m_MetadataSet.AreAttributesWritten = true;
}
else
{
m_Data.Resize(position + 12, "for empty Attributes\n");
// Attribute index header for zero attributes: 0, 0LL
// Resize() already takes care of this
position += 12;
absolutePosition += 12;
}
Expand Down Expand Up @@ -1614,14 +1623,22 @@ uint32_t BP3Serializer::GetFileIndex() const noexcept

size_t BP3Serializer::GetAttributesSizeInData(core::IO &io) const noexcept
{
size_t attributesSizeInData = 12; // count + length
size_t attributesSizeInData = 0;

auto &attributes = io.GetAttributesDataMap();

for (const auto &attribute : attributes)
{
const std::string type = attribute.second.first;

// each attribute is only written to output once
// so filter out the ones already written
auto it = m_SerializedAttributes.find(attribute.first);
if (it != m_SerializedAttributes.end())
{
continue;
}

if (type == "compound")
{
}
Expand Down
3 changes: 2 additions & 1 deletion source/adios2/toolkit/format/bp3/BP3Serializer.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,9 @@ void BP3Serializer::PutAttributeInIndex(const core::Attribute<T> &attribute,
helper::CopyToBuffer(buffer, backPosition,
&characteristicsLength); // length

// Finish characteristic count length
// Remember this attribute and its serialized piece
m_MetadataSet.AttributesIndices.emplace(attribute.m_Name, index);
m_SerializedAttributes.emplace(attribute.m_Name);
}

template <>
Expand Down
16 changes: 8 additions & 8 deletions testing/adios2/engine/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ endif()
# 2nd arg: 1 for serialized execution, 0 for concurrent execution of Writer/Reader
# 3rd arg: engine parameters

#gtest_add_tests(TARGET TestEngineCommon ${extra_test_args}
# EXTRA_ARGS "BPFile" "1"
# TEST_SUFFIX _BPFile)
gtest_add_tests(TARGET TestEngineCommon ${extra_test_args}
EXTRA_ARGS "BPFile" "1"
TEST_SUFFIX _BPFile)

if(ADIOS2_HAVE_HDF5)
gtest_add_tests(TARGET TestEngineCommon ${extra_test_args}
Expand All @@ -38,11 +38,11 @@ gtest_add_tests(TARGET TestEngineCommon ${extra_test_args}
TEST_SUFFIX _SST_BP)
endif()

#if(ADIOS2_HAVE_MPI)
#gtest_add_tests(TARGET TestEngineCommon ${extra_test_args}
# EXTRA_ARGS "InSituMPI" "0"
# TEST_SUFFIX _InSituMPI)
#endif()
if(ADIOS2_HAVE_MPI)
gtest_add_tests(TARGET TestEngineCommon ${extra_test_args}
EXTRA_ARGS "InSituMPI" "0"
TEST_SUFFIX _InSituMPI)
endif()

#if(ADIOS2_HAVE_DataMan)
#gtest_add_tests(TARGET TestEngineCommon ${extra_test_args}
Expand Down

0 comments on commit bae9c99

Please sign in to comment.