Newer
Older
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* BP1Base.cpp
*
* Created on: Feb 7, 2017
* Author: William F Godoy godoywf@ornl.gov
*/
#include "BP1Base.h"
#include "BP1Base.tcc"
#include "adios2/helper/adiosFunctions.h" //CreateDirectory, StringToTimeUnit
namespace adios
{
namespace format
{
BP1Base::BP1Base(MPI_Comm mpiComm, const bool debugMode)
: m_HeapBuffer(debugMode), m_BP1Aggregator(mpiComm, debugMode),
m_DebugMode(debugMode)
{
}
void BP1Base::InitParameters(const Params ¶meters)
{
// flags for defaults that require constructors
bool useDefaultInitialBufferSize = true;
bool useDefaultProfileUnits = true;
for (const auto &pair : parameters)
{
const std::string key(pair.first);
const std::string value(pair.second);
{
InitParameterProfile(value);
}
{
InitParameterProfileUnits(value);
useDefaultProfileUnits = false;
}
else if (key == "BufferGrowthFactor")
{
InitParameterBufferGrowth(value);
}
else if (key == "InitialBufferSize")
{
InitParameterInitBufferSize(value);
useDefaultInitialBufferSize = false;
{
InitParameterMaxBufferSize(value);
}
{
InitParameterVerbose(value);
}
}
// default timer for buffering
if (m_Profiler.IsActive && useDefaultProfileUnits)
{
m_Profiler.Timers.emplace(
"buffering",
profiling::Timer("buffering", DefaultTimeUnitEnum, m_DebugMode));
if (useDefaultInitialBufferSize)
m_HeapBuffer.ResizeData(DefaultInitialBufferSize);
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
}
}
std::vector<std::string>
BP1Base::GetBPBaseNames(const std::vector<std::string> &names) const noexcept
{
std::vector<std::string> bpBaseNames;
bpBaseNames.reserve(names.size());
for (const auto &name : names)
{
bpBaseNames.push_back(GetBPBaseName(name));
}
return bpBaseNames;
}
std::string BP1Base::GetBPBaseName(const std::string &name) const noexcept
{
return AddExtension(name, ".bp");
}
std::vector<std::string>
BP1Base::GetBPNames(const std::vector<std::string> &names) const noexcept
{
std::vector<std::string> bpNames;
bpNames.reserve(names.size());
for (const auto &name : names)
{
bpNames.push_back(GetBPName(name));
}
return bpNames;
}
std::string BP1Base::GetBPName(const std::string &name) const noexcept
{
const std::string baseName = AddExtension(name, ".bp");
// opens a file transport under name.bp/name.bp.rank
const std::string bpName(baseName + "/" + baseName + "." +
std::to_string(m_BP1Aggregator.m_RankMPI));
return bpName;
}
// PROTECTED
void BP1Base::InitParameterProfile(const std::string value)
{
if (value == "off" || value == "Off")
{
m_Profiler.IsActive = false;
}
else if (value == "on" || value == "On")
{
m_Profiler.IsActive = true; // default
}
else
{
{
throw std::invalid_argument("ERROR: IO SetParameters profile "
"invalid value, valid: "
"profile=on or "
"profile=off, in call to Open\n");
}
}
}
void BP1Base::InitParameterProfileUnits(const std::string value)
{
TimeUnit timeUnit = StringToTimeUnit(value, m_DebugMode);
if (m_Profiler.Timers.count("buffering") == 1)
{
m_Profiler.Timers.erase("buffering");
}
m_Profiler.Timers.emplace(
"buffering", profiling::Timer("buffering", timeUnit, m_DebugMode));
}
void BP1Base::InitParameterBufferGrowth(const std::string value)
{
{
bool success = true;
try
{
m_GrowthFactor = std::stof(value);
}
catch (std::exception &e)
{
success = false;
}
{
throw std::invalid_argument(
"ERROR: IO SetParameter buffer_growth value "
"can't be less or equal than 1 (default = 1.5), or couldn't "
"convert number, in call to Open\n");
}
}
else
{
m_GrowthFactor = std::stof(value);
}
}
void BP1Base::InitParameterInitBufferSize(const std::string value)
{
const std::string errorMessage(
"ERROR: couldn't convert value of init_buffer_size IO "
"SetParameter, valid syntax: InitialBufferSize=10Gb, "
"InitialBufferSize=1000Mb, InitialBufferSize=16Kb (minimum default), "
{
if (value.size() < 2)
{
throw std::invalid_argument(errorMessage);
}
}
const std::string number(value.substr(0, value.size() - 2));
const std::string units(value.substr(value.size() - 2));
const size_t factor = BytesFactor(units, m_DebugMode);
size_t bufferSize = DefaultInitialBufferSize; // from ADIOSTypes.h
{
bool success = true;
try
{
bufferSize = static_cast<size_t>(std::stoul(number) * factor);
}
catch (std::exception &e)
{
success = false;
}
if (!success || bufferSize < DefaultInitialBufferSize) // 16384b
{
throw std::invalid_argument(errorMessage);
}
}
else
{
bufferSize = static_cast<size_t>(std::stoul(number) * factor);
}
m_HeapBuffer.ResizeData(bufferSize);
}
void BP1Base::InitParameterMaxBufferSize(const std::string value)
{
const std::string errorMessage(
"ERROR: couldn't convert value of max_buffer_size IO "
"SetParameter, valid syntax: MaxBufferSize=10Gb, "
"MaxBufferSize=1000Mb, MaxBufferSize=16Kb (minimum default), "
{
if (value.size() < 2)
{
throw std::invalid_argument(errorMessage);
}
}
const std::string number(value.substr(0, value.size() - 2));
const std::string units(value.substr(value.size() - 2));
const size_t factor = BytesFactor(units, m_DebugMode);
{
bool success = true;
try
{
m_MaxBufferSize = static_cast<size_t>(std::stoul(number) * factor);
}
catch (std::exception &e)
{
success = false;
}
if (!success || m_MaxBufferSize < 16 * 1024) // 16384b
{
throw std::invalid_argument(errorMessage);
}
}
else
{
m_MaxBufferSize = static_cast<size_t>(std::stoul(number) * factor);
}
}
void BP1Base::InitParameterVerbose(const std::string value)
{
}
catch (std::exception &e)
{
success = false;
}
if (!success || verbosity < 0 || verbosity > 5)
"ERROR: value in Verbose=value in IO SetParameters must be "
"an integer in the range [0,5], in call to Open\n");
}
}
else
{
m_Verbosity = static_cast<unsigned int>(verbosity);
}
std::vector<uint8_t>
BP1Base::GetTransportIDs(const std::vector<std::string> &transportsTypes) const
noexcept
{
auto lf_GetTransportID = [](const std::string method) -> uint8_t {
int id = METHOD_UNKNOWN;
else if (method == "File_fstream")
{
id = METHOD_FILE;
}
return static_cast<uint8_t>(id);
};
std::vector<uint8_t> transportsIDs;
transportsIDs.reserve(transportsTypes.size());
for (const auto transportType : transportsTypes)
{
transportsIDs.push_back(lf_GetTransportID(transportType));
}
return transportsIDs;
}
size_t BP1Base::GetProcessGroupIndexSize(const std::string name,
const std::string timeStepName,
const size_t transportsSize) const
noexcept
{
// pgIndex + list of methods (transports)
size_t pgSize =
(name.length() + timeStepName.length() + 23) + (3 + transportsSize);
return pgSize;
}
#define declare_template_instantiation(T) \
template BP1Base::ResizeResult BP1Base::ResizeBuffer( \
const Variable<T> &variable);
ADIOS2_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
} // end namespace format
} // end namespace adios