Skip to content

Commit

Permalink
Merge pull request #2516 from franzpoeschel/fix-bp4-serializer-buffer…
Browse files Browse the repository at this point in the history
…-shrinking

Do not shrink serialization buffer upon EndStep – Fix Performance Bug
  • Loading branch information
pnorbert authored Nov 19, 2020
2 parents 0f4eabf + cda50f3 commit 301b4e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
17 changes: 14 additions & 3 deletions source/adios2/toolkit/format/bp/bp4/BP4Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,13 +372,24 @@ void BP4Serializer::SerializeDataBuffer(core::IO &io) noexcept
if (attributesSizeInData)
{
attributesSizeInData += 12; // count + length + end ID
m_Data.Resize(position + attributesSizeInData + 4,
"when writing Attributes in rank=0\n");
// Take care not to shrink the buffer size in this.
// Otherwise, growing the buffer again later on is expensive
// - not because of reallocation, but because of (re)initialization
// with zeros by BufferSTL::Resize.
const size_t minSize = position + attributesSizeInData + 4;
if (m_Data.m_Buffer.size() < minSize)
{
m_Data.Resize(minSize, "when writing Attributes in rank=0\n");
}
PutAttributes(io);
}
else
{
m_Data.Resize(position + 12 + 4, "for empty Attributes\n");
const size_t minSize = position + 12 + 4;
if (m_Data.m_Buffer.size() < minSize)
{
m_Data.Resize(minSize, "for empty Attributes\n");
}
// Attribute index header for zero attributes: 0, 0LL
// Resize() already takes care of this
position += 12;
Expand Down
3 changes: 2 additions & 1 deletion testing/adios2/engine/bp/TestBPBufferSize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ TEST_F(BPBufferSizeTest, SyncDeferredIdenticalUsage)
* size
* */
const size_t TotalDataSize = Nx * sizeof(double) * 3;
const size_t MaxExtra = 16777216; /* 16MB extra allowed in buffer */
const size_t MaxExtra =
18 * 1024 * 1024; /* 18MB extra allowed in buffer */
for (size_t step = 0; step < NSteps; ++step)
{
EXPECT_LT(bufsize_sync_beginstep[step], TotalDataSize + MaxExtra);
Expand Down

0 comments on commit 301b4e2

Please sign in to comment.