Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default_init_allocator from http://stackoverflow.com/a/21028912… #3248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/adios2/engine/bp3/BP3Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void BP3Writer::WriteProfilingJSONFile()
transportTypes, transportProfilers) +
",\n");

const std::vector<char> profilingJSON(
const helper::adiosvec<char> profilingJSON(
m_BP3Serializer.AggregateProfilingJSON(lineJSON));

if (m_BP3Serializer.m_RankMPI == 0)
Expand Down
5 changes: 3 additions & 2 deletions source/adios2/engine/bp4/BP4Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ size_t BP4Reader::UpdateBuffer(const TimePoint &timeoutInstant,
{
const size_t maxIdxSize =
idxFileSize - m_MDIndexFileAlreadyReadSize;
std::vector<char> idxbuf(maxIdxSize);
helper::adiosvec<char> idxbuf(maxIdxSize);
m_MDIndexFileManager.ReadFile(idxbuf.data(), maxIdxSize,
m_MDIndexFileAlreadyReadSize);
size_t newIdxSize;
Expand Down Expand Up @@ -685,7 +685,8 @@ bool BP4Reader::CheckWriterActive()
size_t flag = 0;
if (m_BP4Deserializer.m_RankMPI == 0)
{
std::vector<char> header(m_BP4Deserializer.m_IndexHeaderSize, '\0');
helper::adiosvec<char> header(m_BP4Deserializer.m_IndexHeaderSize,
'\0');
m_MDIndexFileManager.ReadFile(
header.data(), m_BP4Deserializer.m_IndexHeaderSize, 0, 0);
bool active = m_BP4Deserializer.ReadActiveFlag(header);
Expand Down
2 changes: 1 addition & 1 deletion source/adios2/engine/bp4/BP4Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ void BP4Writer::WriteProfilingJSONFile()
transportTypes, transportProfilers) +
",\n");

const std::vector<char> profilingJSON(
const helper::adiosvec<char> profilingJSON(
m_BP4Serializer.AggregateProfilingJSON(lineJSON));

if (m_BP4Serializer.m_RankMPI == 0)
Expand Down
8 changes: 4 additions & 4 deletions source/adios2/engine/bp5/BP5Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ void BP5Reader::PerformGets()
double readTotal = 0.0;
double subfileTotal = 0.0;
size_t nReads = 0;
std::vector<char> buf(maxReadSize);
helper::adiosvec<char> buf(maxReadSize);

while (true)
{
Expand Down Expand Up @@ -393,7 +393,7 @@ void BP5Reader::PerformGets()
{
size_t maxOpenFiles = helper::SetWithinLimit(
(size_t)m_Parameters.MaxOpenFilesAtOnce, (size_t)1, MaxSizeT);
std::vector<char> buf(maxReadSize);
helper::adiosvec<char> buf(maxReadSize);
for (auto &Req : ReadRequests)
{
if (!Req.DestinationAddr)
Expand Down Expand Up @@ -1070,7 +1070,7 @@ size_t BP5Reader::ParseMetadataIndex(format::BufferSTL &bufferSTL,
return position;
}

bool BP5Reader::ReadActiveFlag(std::vector<char> &buffer)
bool BP5Reader::ReadActiveFlag(helper::adiosvec<char> &buffer)
{
if (buffer.size() < m_ActiveFlagPosition)
{
Expand All @@ -1094,7 +1094,7 @@ bool BP5Reader::CheckWriterActive()
auto fsize = m_MDIndexFileManager.GetFileSize(0);
if (fsize >= m_IndexHeaderSize)
{
std::vector<char> header(m_IndexHeaderSize, '\0');
helper::adiosvec<char> header(m_IndexHeaderSize, '\0');
m_MDIndexFileManager.ReadFile(header.data(), m_IndexHeaderSize, 0,
0);
bool active = ReadActiveFlag(header);
Expand Down
2 changes: 1 addition & 1 deletion source/adios2/engine/bp5/BP5Reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class BP5Reader : public BP5Engine, public Engine
const Seconds &pollSeconds,
const Seconds &timeoutSeconds);

bool ReadActiveFlag(std::vector<char> &buffer);
bool ReadActiveFlag(helper::adiosvec<char> &buffer);

/* Parse metadata.
*
Expand Down
19 changes: 11 additions & 8 deletions source/adios2/engine/bp5/BP5Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void BP5Writer::WriteMetadataFileIndex(uint64_t MetaDataPos,
bufsize += 1 + (4 + m_Comm.Size()) * sizeof(uint64_t);
}

std::vector<char> buf(bufsize);
helper::adiosvec<char> buf(bufsize);
size_t pos = 0;
uint64_t d;
unsigned char record;
Expand Down Expand Up @@ -524,14 +524,16 @@ void BP5Writer::EndStep()
WriteData(databuf);
m_Profiler.Stop("AWD");

std::vector<char> MetaBuffer = m_BP5Serializer.CopyMetadataToContiguous(
TSInfo.NewMetaMetaBlocks, TSInfo.MetaEncodeBuffer,
TSInfo.AttributeEncodeBuffer, m_ThisTimestepDataSize, m_StartDataPos);
helper::adiosvec<char> MetaBuffer =
m_BP5Serializer.CopyMetadataToContiguous(
TSInfo.NewMetaMetaBlocks, TSInfo.MetaEncodeBuffer,
TSInfo.AttributeEncodeBuffer, m_ThisTimestepDataSize,
m_StartDataPos);

size_t LocalSize = MetaBuffer.size();
std::vector<size_t> RecvCounts = m_Comm.GatherValues(LocalSize, 0);

std::vector<char> *RecvBuffer = new std::vector<char>;
helper::adiosvec<char> *RecvBuffer = new helper::adiosvec<char>;
if (m_Comm.Rank() == 0)
{
uint64_t TotalSize = 0;
Expand Down Expand Up @@ -1087,11 +1089,12 @@ void BP5Writer::InitTransports()
}

/*generate the header for the metadata index file*/
void BP5Writer::MakeHeader(std::vector<char> &buffer, size_t &position,
void BP5Writer::MakeHeader(helper::adiosvec<char> &buffer, size_t &position,
const std::string fileType, const bool isActive)
{
auto lf_CopyVersionChar = [](const std::string version,
std::vector<char> &buffer, size_t &position) {
helper::adiosvec<char> &buffer,
size_t &position) {
helper::CopyToBuffer(buffer, position, version.c_str());
};

Expand Down Expand Up @@ -1541,7 +1544,7 @@ void BP5Writer::FlushProfiler()
m_Profiler.GetRankProfilingJSON(transportTypes, transportProfilers) +
",\n");

const std::vector<char> profilingJSON(
const helper::adiosvec<char> profilingJSON(
m_Profiler.AggregateProfilingJSON(lineJSON));

if (m_RankMPI == 0)
Expand Down
2 changes: 1 addition & 1 deletion source/adios2/engine/bp5/BP5Writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class BP5Writer : public BP5Engine, public core::Engine

std::vector<std::vector<size_t>> FlushPosSizeInfo;

void MakeHeader(std::vector<char> &buffer, size_t &position,
void MakeHeader(helper::adiosvec<char> &buffer, size_t &position,
const std::string fileType, const bool isActive);

std::vector<uint64_t> m_WriterSubfileMap; // rank => subfile index
Expand Down
2 changes: 1 addition & 1 deletion source/adios2/engine/sst/SstReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ void SstReader::PerformGets()
else if (m_WriterMarshalMethod == SstMarshalBP)
{
std::vector<void *> sstReadHandlers;
std::vector<std::vector<char>> buffers;
std::vector<helper::adiosvec<char>> buffers;
size_t iter = 0;

if (m_BP3Deserializer->m_DeferredVariables.empty())
Expand Down
9 changes: 5 additions & 4 deletions source/adios2/engine/sst/SstReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ class SstReader : public Engine

private:
template <class T>
void ReadVariableBlocksRequests(Variable<T> &variable,
std::vector<void *> &sstReadHandlers,
std::vector<std::vector<char>> &buffers);
void
ReadVariableBlocksRequests(Variable<T> &variable,
std::vector<void *> &sstReadHandlers,
std::vector<helper::adiosvec<char>> &buffers);

template <class T>
void ReadVariableBlocksFill(Variable<T> &variable,
std::vector<std::vector<char>> &buffers,
std::vector<helper::adiosvec<char>> &buffers,
size_t &iter);

template <class T>
Expand Down
8 changes: 4 additions & 4 deletions source/adios2/engine/sst/SstReader.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace engine
template <class T>
void SstReader::ReadVariableBlocksRequests(
Variable<T> &variable, std::vector<void *> &sstReadHandlers,
std::vector<std::vector<char>> &buffers)
std::vector<helper::adiosvec<char>> &buffers)
{
PERFSTUBS_SCOPED_TIMER_FUNC();

Expand Down Expand Up @@ -122,9 +122,9 @@ void SstReader::ReadVariableBlocksRequests(
}

template <class T>
void SstReader::ReadVariableBlocksFill(Variable<T> &variable,
std::vector<std::vector<char>> &buffers,
size_t &iter)
void SstReader::ReadVariableBlocksFill(
Variable<T> &variable, std::vector<helper::adiosvec<char>> &buffers,
size_t &iter)
{
PERFSTUBS_SCOPED_TIMER_FUNC();

Expand Down
9 changes: 9 additions & 0 deletions source/adios2/helper/adiosComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef ADIOS2_HELPER_ADIOSCOMM_H_
#define ADIOS2_HELPER_ADIOSCOMM_H_

#include <adios2/helper/adiosType.h>
#include <memory>
#include <string>
#include <vector>
Expand Down Expand Up @@ -184,6 +185,10 @@ class Comm
template <class T>
void GathervVectors(const std::vector<T> &in, std::vector<T> &out,
size_t &position, int rankDestination = 0) const;

template <class T>
void GathervVectors(const helper::adiosvec<T> &in, helper::adiosvec<T> &out,
size_t &position, int rankDestination = 0) const;
/**
* Perform AllGather for source value
* @param source input
Expand All @@ -204,6 +209,10 @@ class Comm
void BroadcastVector(std::vector<T> &vector,
const int rankSource = 0) const;

template <class T>
void BroadcastVector(helper::adiosvec<T> &vector,
const int rankSource = 0) const;

std::string BroadcastFile(const std::string &fileName,
const std::string hint = "",
const int rankSource = 0) const;
Expand Down
59 changes: 59 additions & 0 deletions source/adios2/helper/adiosComm.inl
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,42 @@ void Comm::GathervVectors(const std::vector<T> &in, std::vector<T> &out,
position += gatheredSize;
}

template <class T>
void Comm::GathervVectors(const helper::adiosvec<T> &in,
helper::adiosvec<T> &out, size_t &position,
int rankDestination) const
{
const size_t inSize = in.size();
const std::vector<size_t> counts =
this->GatherValues(inSize, rankDestination);

size_t gatheredSize = 0;

int rank = this->Rank();

if (rank == rankDestination) // pre-allocate vector
{
gatheredSize = std::accumulate(counts.begin(), counts.end(), size_t(0));

const size_t newSize = position + gatheredSize;
try
{
out.reserve(newSize); // to avoid power of 2 growth
out.resize(newSize);
}
catch (...)
{
helper::ThrowNested<std::runtime_error>(
"Helper", "adiosComm", "GathervVectors",
"buffer overflow when resizing to " + std::to_string(newSize));
}
}

this->GathervArrays(in.data(), in.size(), counts.data(), counts.size(),
out.data() + position, rankDestination);
position += gatheredSize;
}

template <class T>
std::vector<T> Comm::AllGatherValues(const T source) const
{
Expand Down Expand Up @@ -170,6 +206,29 @@ void Comm::BroadcastVector(std::vector<T> &vector, const int rankSource) const
}
}

template <class T>
void Comm::BroadcastVector(helper::adiosvec<T> &vector,
const int rankSource) const
{
if (this->Size() == 1)
{
return;
}

// First Broadcast the size, then the contents
size_t inputSize = this->BroadcastValue(vector.size(), rankSource);

if (rankSource != this->Rank())
{
vector.resize(inputSize);
}

if (inputSize > 0)
{
this->Bcast(vector.data(), inputSize, rankSource);
}
}

template <typename TSend, typename TRecv>
void Comm::Allgather(const TSend *sendbuf, size_t sendcount, TRecv *recvbuf,
size_t recvcount, const std::string &hint) const
Expand Down
Loading