Skip to content

Commit

Permalink
Don't force initialization for buffers whose contents we will immedia…
Browse files Browse the repository at this point in the history
…tely destroy (ornladios#4031)

* BufferMalloc
  • Loading branch information
eisenhauer authored and vicentebolea committed Feb 21, 2024
1 parent 1e63aaa commit 271b809
Show file tree
Hide file tree
Showing 10 changed files with 420 additions and 254 deletions.
1 change: 1 addition & 0 deletions source/adios2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ add_library(adios2_core
toolkit/format/buffer/chunk/ChunkV.cpp
toolkit/format/buffer/ffs/BufferFFS.cpp
toolkit/format/buffer/heap/BufferSTL.cpp
toolkit/format/buffer/heap/BufferMalloc.cpp
toolkit/format/buffer/malloc/MallocV.cpp

toolkit/format/bp/BPBase.cpp toolkit/format/bp/BPBase.tcc
Expand Down
23 changes: 14 additions & 9 deletions source/adios2/engine/bp5/BP5Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void BP5Reader::InstallMetadataForTimestep(size_t Step)
{
// variable metadata for timestep
size_t ThisMDSize =
helper::ReadValue<uint64_t>(m_Metadata.m_Buffer, Position, m_Minifooter.IsLittleEndian);
char *ThisMD = m_Metadata.m_Buffer.data() + MDPosition;
helper::ReadValue<uint64_t>(m_Metadata.Data(), Position, m_Minifooter.IsLittleEndian);
char *ThisMD = m_Metadata.Data() + MDPosition;
if (m_OpenMode == Mode::ReadRandomAccess)
{
m_BP5Deserializer->InstallMetaData(ThisMD, ThisMDSize, WriterRank, Step);
Expand All @@ -86,8 +86,8 @@ void BP5Reader::InstallMetadataForTimestep(size_t Step)
{
// attribute metadata for timestep
size_t ThisADSize =
helper::ReadValue<uint64_t>(m_Metadata.m_Buffer, Position, m_Minifooter.IsLittleEndian);
char *ThisAD = m_Metadata.m_Buffer.data() + MDPosition;
helper::ReadValue<uint64_t>(m_Metadata.Data(), Position, m_Minifooter.IsLittleEndian);
char *ThisAD = m_Metadata.Data() + MDPosition;
if (ThisADSize > 0)
m_BP5Deserializer->InstallAttributeData(ThisAD, ThisADSize);
MDPosition += ThisADSize;
Expand Down Expand Up @@ -820,8 +820,7 @@ void BP5Reader::UpdateBuffer(const TimePoint &timeoutInstant, const Seconds &pol
for (auto p : m_FilteredMetadataInfo)
{
m_JSONProfiler.AddBytes("metadataread", p.second);
m_MDFileManager.ReadFile(m_Metadata.m_Buffer.data() + mempos, p.second,
p.first);
m_MDFileManager.ReadFile(m_Metadata.Data() + mempos, p.second, p.first);
mempos += p.second;
}
m_MDFileAlreadyReadSize = expectedMinFileSize;
Expand Down Expand Up @@ -863,14 +862,20 @@ void BP5Reader::UpdateBuffer(const TimePoint &timeoutInstant, const Seconds &pol
}
}

// broadcast buffer to all ranks from zero
m_Comm.BroadcastVector(m_Metadata.m_Buffer);

// broadcast metadata index buffer to all ranks from zero
m_Comm.BroadcastVector(m_MetaMetadata.m_Buffer);

InstallMetaMetaData(m_MetaMetadata);

size_t inputSize = m_Comm.BroadcastValue(m_Metadata.Size(), 0);

if (m_Comm.Rank() != 0)
{
m_Metadata.Resize(inputSize, "metadata broadcast");
}

m_Comm.Bcast(m_Metadata.Data(), inputSize, 0);

if (m_OpenMode == Mode::ReadRandomAccess)
{
for (size_t Step = 0; Step < m_MetadataIndexTable.size(); Step++)
Expand Down
5 changes: 2 additions & 3 deletions source/adios2/engine/bp5/BP5Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*
* BP5Reader.h
*
* Created on: Aug 1, 2018
* Author: Lipeng Wan [email protected]
*/

#ifndef ADIOS2_ENGINE_BP5_BP5READER_H_
Expand All @@ -18,6 +16,7 @@
#include "adios2/helper/adiosComm.h"
#include "adios2/helper/adiosRangeFilter.h"
#include "adios2/toolkit/format/bp5/BP5Deserializer.h"
#include "adios2/toolkit/format/buffer/heap/BufferMalloc.h"
#include "adios2/toolkit/remote/Remote.h"
#include "adios2/toolkit/transportman/TransportMan.h"

Expand Down Expand Up @@ -225,7 +224,7 @@ class BP5Reader : public BP5Engine, public Engine

format::BufferSTL m_MetadataIndex;
format::BufferSTL m_MetaMetadata;
format::BufferSTL m_Metadata;
format::BufferMalloc m_Metadata;

void InstallMetaMetaData(format::BufferSTL MetaMetadata);
void InstallMetadataForTimestep(size_t Step);
Expand Down
9 changes: 5 additions & 4 deletions source/adios2/helper/adiosMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* adiosMemory.h : Memory copy operations functions using std::copy std::insert
* and std::memcpy
*
* Created on: May 17, 2017
* Author: William F Godoy [email protected]
*/

#ifndef ADIOS2_HELPER_ADIOSMEMORY_H_
Expand Down Expand Up @@ -83,7 +81,7 @@ void CopyToBufferThreads(std::vector<char> &buffer, size_t &position, const T *s
const size_t elements = 1, const unsigned int threads = 1) noexcept;

template <class T>
void ReverseCopyFromBuffer(const std::vector<char> &buffer, size_t &position, T *destination,
void ReverseCopyFromBuffer(const char *buffer, size_t &position, T *destination,
const size_t elements = 1) noexcept;

/**
Expand All @@ -95,7 +93,7 @@ void ReverseCopyFromBuffer(const std::vector<char> &buffer, size_t &position, T
* @param elements number of elements of destination type
*/
template <class T>
void CopyFromBuffer(const std::vector<char> &buffer, size_t &position, T *destination,
void CopyFromBuffer(const char *buffer, size_t &position, T *destination,
const size_t elements = 1) noexcept;

/**
Expand All @@ -110,6 +108,9 @@ template <class T>
T ReadValue(const std::vector<char> &buffer, size_t &position,
const bool isLittleEndian = true) noexcept;

template <class T>
T ReadValue(const char *buffer, size_t &position, const bool isLittleEndian = true) noexcept;

/** Read in 'nElems' elements from buffer into output array
* output must be pre-allocated.
*/
Expand Down
Loading

0 comments on commit 271b809

Please sign in to comment.