Skip to content
Snippets Groups Projects
Commit c5b13d0d authored by William F Godoy's avatar William F Godoy Committed by Atkins, Charles Vernon
Browse files

Moving templates implementations to tcc

Changed BP1Writer.h by BPWriter.tcc in unique "public" header BP1.h
parent f3b5c539
No related branches found
No related tags found
1 merge request!54Move BP1Writer templates out of header
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "utilities/format/bp1/BP1Aggregator.h" #include "utilities/format/bp1/BP1Aggregator.h"
#include "utilities/format/bp1/BP1Structs.h" #include "utilities/format/bp1/BP1Structs.h"
#include "utilities/format/bp1/BP1Writer.h" //#include "utilities/format/bp1/BP1Writer.h"
#include "utilities/format/bp1/BP1Writer.tcc"
#endif /* BP1_H_ */ #endif /* BP1_H_ */
...@@ -279,76 +279,14 @@ private: ...@@ -279,76 +279,14 @@ private:
capsule::STLVector &buffer) const noexcept; capsule::STLVector &buffer) const noexcept;
}; };
#define declare_template_instantiation(T) \
extern template std::size_t BP1Writer::GetVariableIndexSize( \
const Variable<T> &variable) const noexcept; \
\
extern template void BP1Writer::WriteVariablePayload( \
const Variable<T> &variable, capsule::STLVector &heap, \
const unsigned int nthreads) const noexcept; \
\
extern template void BP1Writer::WriteBoundsRecord( \
const bool isScalar, const Stats<T> &stats, std::vector<char> &buffer, \
std::uint8_t &characteristicsCounter, const bool addLength) \
const noexcept; \
\
extern template void BP1Writer::WriteCharacteristicRecord( \
const std::uint8_t characteristicID, const T &value, \
std::vector<char> &buffer, std::uint8_t &characteristicsCounter, \
const bool addLength) const noexcept;
ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
// SEPARATE PRIMITIVE FROM COMPLEX OVERLOADS
// PRIMITIVE
#define declare_template_instantiation(T) \
extern template void BP1Writer::WriteVariableMetadata( \
const Variable<T> &variable, capsule::STLVector &heap, \
BP1MetadataSet &metadataSet) const noexcept; \
\
extern template BP1Writer::Stats<T> BP1Writer::GetStats( \
const Variable<T> &variable) const noexcept;
ADIOS_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
// COMPLEX
#define declare_template_instantiation(T) \
extern template void BP1Writer::WriteVariableMetadata( \
const Variable<std::complex<T>> &variable, capsule::STLVector &heap, \
BP1MetadataSet &metadataSet) const noexcept; \
\
extern template BP1Writer::Stats<T> BP1Writer::GetStats( \
const Variable<std::complex<T>> &variable) const noexcept;
ADIOS_FOREACH_COMPLEX_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
// Explicit declaration of the template methods
//#define declare_template_instantiation(T) \ //#define declare_template_instantiation(T) \
//// extern template std::size_t BP1Writer::GetVariableIndexSize( \ // extern template std::size_t BP1Writer::GetVariableIndexSize( \
//// const Variable<T> &variable) const noexcept; // const Variable<T> &variable) const noexcept; \
// ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
//#undef declare_template_instantiation
// extern template void BP1Writer::WriteVariableMetadata( \
// const Variable<T> &variable, capsule::STLVector &heap, \
// BP1MetadataSet &metadataSet) const noexcept; \
// \
// extern template void BP1Writer::WriteVariableMetadata( \
// const Variable<std::complex<T>> &variable, capsule::STLVector &heap, \
// BP1MetadataSet &metadataSet) const noexcept; \
// \ // \
// extern template void BP1Writer::WriteVariablePayload( \ // extern template void BP1Writer::WriteVariablePayload( \
// const Variable<T> &variable, capsule::STLVector &heap, \ // const Variable<T> &variable, capsule::STLVector &heap, \
// const unsigned int nthreads) const noexcept; \ // const unsigned int nthreads) const noexcept; \
// \ // \
// extern template Stats<T> BP1Writer::GetStats(const Variable<T> &variable) \
// const noexcept; \
// \
// extern template Stats<T> BP1Writer::GetStats( \
// const Variable<std::complex<T>> &variable) const noexcept; \
// \
// extern template void BP1Writer::WriteBoundsRecord( \ // extern template void BP1Writer::WriteBoundsRecord( \
// const bool isScalar, const Stats<T> &stats, std::vector<char> &buffer, \ // const bool isScalar, const Stats<T> &stats, std::vector<char> &buffer, \
// std::uint8_t &characteristicsCounter, const bool addLength) \ // std::uint8_t &characteristicsCounter, const bool addLength) \
...@@ -358,10 +296,38 @@ ADIOS_FOREACH_COMPLEX_TYPE_1ARG(declare_template_instantiation) ...@@ -358,10 +296,38 @@ ADIOS_FOREACH_COMPLEX_TYPE_1ARG(declare_template_instantiation)
// const std::uint8_t characteristicID, const T &value, \ // const std::uint8_t characteristicID, const T &value, \
// std::vector<char> &buffer, std::uint8_t &characteristicsCounter, \ // std::vector<char> &buffer, std::uint8_t &characteristicsCounter, \
// const bool addLength) const noexcept; // const bool addLength) const noexcept;
//
// ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
//#undef declare_template_instantiation
//
//// SEPARATE PRIMITIVE FROM COMPLEX OVERLOADS
//// PRIMITIVE
//#define declare_template_instantiation(T) \
// extern template void BP1Writer::WriteVariableMetadata( \
// const Variable<T> &variable, capsule::STLVector &heap, \
// BP1MetadataSet &metadataSet) const noexcept; \
// \
// extern template BP1Writer::Stats<T> BP1Writer::GetStats( \
// const Variable<T> &variable) const noexcept;
//
// ADIOS_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
//#undef declare_template_instantiation
//
//// COMPLEX
//#define declare_template_instantiation(T) \
// extern template void BP1Writer::WriteVariableMetadata( \
// const Variable<std::complex<T>> &variable, capsule::STLVector &heap, \
// BP1MetadataSet &metadataSet) const noexcept; \
// \
// extern template BP1Writer::Stats<T> BP1Writer::GetStats( \
// const Variable<std::complex<T>> &variable) const noexcept;
//
// ADIOS_FOREACH_COMPLEX_TYPE_1ARG(declare_template_instantiation)
//#undef declare_template_instantiation
} // end namespace format } // end namespace format
} // end namespace adios } // end namespace adios
#include "utilities/format/bp1/BP1Writer.tcc" //#include "utilities/format/bp1/BP1Writer.tcc"
#endif /* BP1WRITER_H_ */ #endif /* BP1WRITER_H_ */
...@@ -8,14 +8,170 @@ ...@@ -8,14 +8,170 @@
* Author: wfg * Author: wfg
*/ */
#include "BP1Writer.h" #include "utilities/format/bp1/BP1Writer.h"
namespace adios namespace adios
{ {
namespace format namespace format
{ {
// PUBLIC
template <class T>
std::size_t BP1Writer::GetVariableIndexSize(const Variable<T> &variable) const
noexcept
{
// size_t indexSize = varEntryLength + memberID + lengthGroupName +
// groupName + lengthVariableName + lengthOfPath + path + datatype
std::size_t indexSize = 23; // without characteristics
indexSize += variable.m_Name.size();
// characteristics 3 and 4, check variable number of dimensions
const std::size_t dimensions =
variable.DimensionsSize(); // commas in CSV + 1
indexSize += 28 * dimensions; // 28 bytes per dimension
indexSize += 1; // id
// characteristics, offset + payload offset in data
indexSize += 2 * (1 + 8);
// characteristic 0, if scalar add value, for now only allowing string
if (dimensions == 1)
{
indexSize += sizeof(T);
indexSize += 1; // id
// must have an if here
indexSize += 2 + variable.m_Name.size();
indexSize += 1; // id
}
// characteristic statistics
if (m_Verbosity == 0) // default, only min and max
{
indexSize += 2 * (sizeof(T) + 1);
indexSize += 1 + 1; // id
}
return indexSize + 12; // extra 12 bytes in case of attributes
// need to add transform characteristics
}
template <class T>
void BP1Writer::WriteVariableMetadata(const Variable<T> &variable,
capsule::STLVector &heap,
BP1MetadataSet &metadataSet) const
noexcept
{
Stats<T> stats = GetStats(variable);
WriteVariableMetadataCommon(variable, stats, heap, metadataSet);
}
template <class T>
void BP1Writer::WriteVariableMetadata(const Variable<std::complex<T>> &variable,
capsule::STLVector &heap,
BP1MetadataSet &metadataSet) const
noexcept
{
Stats<T> stats = GetStats(variable);
WriteVariableMetadataCommon(variable, stats, heap, metadataSet);
}
template <class T>
void BP1Writer::WriteVariablePayload(const Variable<T> &variable,
capsule::STLVector &heap,
const unsigned int nthreads) const noexcept
{
// EXPENSIVE part, might want to use threads if large, serial for now
InsertToBuffer(heap.m_Data, variable.m_AppValues, variable.TotalSize());
heap.m_DataAbsolutePosition += variable.PayLoadSize();
}
// PRIVATE // PRIVATE
template <class T>
BP1Writer::Stats<T> BP1Writer::GetStats(const Variable<T> &variable) const
noexcept
{
Stats<T> stats;
const std::size_t valuesSize = variable.TotalSize();
if (m_Verbosity == 0)
{
if (valuesSize >= 10000000) // ten million? this needs actual results
// //we can make decisions for threads
// based on valuesSize
GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max,
m_Threads); // here we can add cores from constructor
else
GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max);
}
return stats;
}
template <class T>
BP1Writer::Stats<T>
BP1Writer::GetStats(const Variable<std::complex<T>> &variable) const noexcept
{
Stats<T> stats;
const std::size_t valuesSize = variable.TotalSize();
if (m_Verbosity == 0)
{
// ten million? this needs actual results
// to make decisions for threads usage
if (valuesSize >= 10000000)
{
GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max,
m_Threads);
}
else
{
GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max);
}
}
return stats;
}
template <class T>
void BP1Writer::WriteBoundsRecord(const bool isScalar, const Stats<T> &stats,
std::vector<char> &buffer,
std::uint8_t &characteristicsCounter,
const bool addLength) const noexcept
{
if (isScalar == true)
{
WriteCharacteristicRecord(characteristic_value, stats.Min, buffer,
characteristicsCounter,
addLength); // stats.min = stats.max = value
return;
}
if (m_Verbosity == 0) // default verbose
{
WriteCharacteristicRecord(characteristic_min, stats.Min, buffer,
characteristicsCounter, addLength);
WriteCharacteristicRecord(characteristic_max, stats.Max, buffer,
characteristicsCounter, addLength);
}
}
template <class T>
void BP1Writer::WriteCharacteristicRecord(const std::uint8_t characteristicID,
const T &value,
std::vector<char> &buffer,
std::uint8_t &characteristicsCounter,
const bool addLength) const noexcept
{
const std::uint8_t id = characteristicID;
InsertToBuffer(buffer, &id);
if (addLength == true)
{
const std::uint16_t lengthOfCharacteristic = sizeof(T); // id
InsertToBuffer(buffer, &lengthOfCharacteristic);
}
InsertToBuffer(buffer, &value);
++characteristicsCounter;
}
template <class T, class U> template <class T, class U>
void BP1Writer::WriteVariableMetadataCommon(const Variable<T> &variable, void BP1Writer::WriteVariableMetadataCommon(const Variable<T> &variable,
Stats<U> &stats, Stats<U> &stats,
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
#include <vector> #include <vector>
/// \endcond /// \endcond
#include "utilities/format/bp1/BP1Writer.h" //#include "utilities/format/bp1/BP1Writer.h"
#include "utilities/format/bp1/BP1Writer.tcc"
namespace adios namespace adios
{ {
...@@ -417,209 +418,5 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet, ...@@ -417,209 +418,5 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet,
metadataSet.Log.TotalBytes.push_back(heap.m_DataAbsolutePosition); metadataSet.Log.TotalBytes.push_back(heap.m_DataAbsolutePosition);
} }
// TEMPLATES
template <class T>
std::size_t BP1Writer::GetVariableIndexSize(const Variable<T> &variable) const
noexcept
{
// size_t indexSize = varEntryLength + memberID + lengthGroupName +
// groupName + lengthVariableName + lengthOfPath + path + datatype
std::size_t indexSize = 23; // without characteristics
indexSize += variable.m_Name.size();
// characteristics 3 and 4, check variable number of dimensions
const std::size_t dimensions =
variable.DimensionsSize(); // commas in CSV + 1
indexSize += 28 * dimensions; // 28 bytes per dimension
indexSize += 1; // id
// characteristics, offset + payload offset in data
indexSize += 2 * (1 + 8);
// characteristic 0, if scalar add value, for now only allowing string
if (dimensions == 1)
{
indexSize += sizeof(T);
indexSize += 1; // id
// must have an if here
indexSize += 2 + variable.m_Name.size();
indexSize += 1; // id
}
// characteristic statistics
if (m_Verbosity == 0) // default, only min and max
{
indexSize += 2 * (sizeof(T) + 1);
indexSize += 1 + 1; // id
}
return indexSize + 12; // extra 12 bytes in case of attributes
// need to add transform characteristics
}
#define declare_template_instantiation(T) \
template std::size_t BP1Writer::GetVariableIndexSize( \
const Variable<T> &variable) const noexcept;
ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
template <class T>
void BP1Writer::WriteVariableMetadata(const Variable<T> &variable,
capsule::STLVector &heap,
BP1MetadataSet &metadataSet) const
noexcept
{
Stats<T> stats = GetStats(variable);
WriteVariableMetadataCommon(variable, stats, heap, metadataSet);
}
#define declare_template_instantiation(T) \
template void BP1Writer::WriteVariableMetadata( \
const Variable<T> &variable, capsule::STLVector &heap, \
BP1MetadataSet &metadataSet) const noexcept;
ADIOS_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
template <class T>
void BP1Writer::WriteVariableMetadata(const Variable<std::complex<T>> &variable,
capsule::STLVector &heap,
BP1MetadataSet &metadataSet) const
noexcept
{
Stats<T> stats = GetStats(variable);
WriteVariableMetadataCommon(variable, stats, heap, metadataSet);
}
#define declare_template_instantiation(T) \
template void BP1Writer::WriteVariableMetadata( \
const Variable<std::complex<T>> &variable, capsule::STLVector &heap, \
BP1MetadataSet &metadataSet) const noexcept;
ADIOS_FOREACH_COMPLEX_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
template <class T>
void BP1Writer::WriteVariablePayload(const Variable<T> &variable,
capsule::STLVector &heap,
const unsigned int nthreads) const noexcept
{
// EXPENSIVE part, might want to use threads if large, serial for now
InsertToBuffer(heap.m_Data, variable.m_AppValues, variable.TotalSize());
heap.m_DataAbsolutePosition += variable.PayLoadSize();
}
#define declare_template_instantiation(T) \
template void BP1Writer::WriteVariablePayload( \
const Variable<T> &variable, capsule::STLVector &heap, \
const unsigned int nthreads) const noexcept;
ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
// PRIVATE TEMPLATES BELOW
template <class T>
BP1Writer::Stats<T> BP1Writer::GetStats(const Variable<T> &variable) const
noexcept
{
Stats<T> stats;
const std::size_t valuesSize = variable.TotalSize();
if (m_Verbosity == 0)
{
if (valuesSize >= 10000000) // ten million? this needs actual results
// //we can make decisions for threads
// based on valuesSize
GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max,
m_Threads); // here we can add cores from constructor
else
GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max);
}
return stats;
}
#define declare_template_instantiation(T) \
template BP1Writer::Stats<T> BP1Writer::GetStats( \
const Variable<T> &variable) const noexcept;
ADIOS_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
template <class T>
BP1Writer::Stats<T>
BP1Writer::GetStats(const Variable<std::complex<T>> &variable) const noexcept
{
Stats<T> stats;
const std::size_t valuesSize = variable.TotalSize();
if (m_Verbosity == 0)
{
// ten million? this needs actual results
// to make decisions for threads usage
if (valuesSize >= 10000000)
{
GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max,
m_Threads);
}
else
{
GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max);
}
}
return stats;
}
#define declare_template_instantiation(T) \
template BP1Writer::Stats<T> BP1Writer::GetStats( \
const Variable<std::complex<T>> &variable) const noexcept;
ADIOS_FOREACH_COMPLEX_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
template <class T>
void BP1Writer::WriteBoundsRecord(const bool isScalar, const Stats<T> &stats,
std::vector<char> &buffer,
std::uint8_t &characteristicsCounter,
const bool addLength) const noexcept
{
if (isScalar == true)
{
WriteCharacteristicRecord(characteristic_value, stats.Min, buffer,
characteristicsCounter,
addLength); // stats.min = stats.max = value
return;
}
if (m_Verbosity == 0) // default verbose
{
WriteCharacteristicRecord(characteristic_min, stats.Min, buffer,
characteristicsCounter, addLength);
WriteCharacteristicRecord(characteristic_max, stats.Max, buffer,
characteristicsCounter, addLength);
}
}
#define declare_template_instantiation(T) \
template void BP1Writer::WriteBoundsRecord( \
const bool isScalar, const Stats<T> &stats, std::vector<char> &buffer, \
std::uint8_t &characteristicsCounter, const bool addLength) \
const noexcept;
ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
template <class T>
void BP1Writer::WriteCharacteristicRecord(const std::uint8_t characteristicID,
const T &value,
std::vector<char> &buffer,
std::uint8_t &characteristicsCounter,
const bool addLength) const noexcept
{
const std::uint8_t id = characteristicID;
InsertToBuffer(buffer, &id);
if (addLength == true)
{
const std::uint16_t lengthOfCharacteristic = sizeof(T); // id
InsertToBuffer(buffer, &lengthOfCharacteristic);
}
InsertToBuffer(buffer, &value);
++characteristicsCounter;
}
#define define_template_instantiation(T) \
template void BP1Writer::WriteCharacteristicRecord( \
const std::uint8_t characteristicID, const T &value, \
std::vector<char> &buffer, std::uint8_t &characteristicsCounter, \
const bool addLength) const noexcept;
ADIOS_FOREACH_TYPE_1ARG(define_template_instantiation)
#undef define_template_instatiation
} // end namespace format } // end namespace format
} // end namespace adios } // end namespace adios
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment