Skip to content
Snippets Groups Projects
Commit c6f435ff authored by Atkins, Charles Vernon's avatar Atkins, Charles Vernon
Browse files

Use type traits to consolidate primitive and complex template methods

parent cb02ae1e
No related branches found
No related tags found
1 merge request!60Use type traits to consolidate primitive and complex template methods
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
/// \endcond /// \endcond
#include "ADIOSMacros.h" #include "ADIOSMacros.h"
#include "ADIOSTypes.h"
#include "utilities/format/bp1/BP1Base.h" #include "utilities/format/bp1/BP1Base.h"
#include "utilities/format/bp1/BP1Structs.h" #include "utilities/format/bp1/BP1Structs.h"
...@@ -83,7 +84,7 @@ public: ...@@ -83,7 +84,7 @@ public:
noexcept; noexcept;
/** /**
* Version for primitive types (except std::complex<T>) * Write metadata for a given variable
* @param variable * @param variable
* @param heap * @param heap
* @param metadataSet * @param metadataSet
...@@ -93,17 +94,6 @@ public: ...@@ -93,17 +94,6 @@ public:
capsule::STLVector &heap, capsule::STLVector &heap,
BP1MetadataSet &metadataSet) const noexcept; BP1MetadataSet &metadataSet) const noexcept;
/**
* Overloaded version for std::complex<T> variables
* @param variable
* @param heap
* @param metadataSet
*/
template <class T>
void WriteVariableMetadata(const Variable<std::complex<T>> &variable,
capsule::STLVector &heap,
BP1MetadataSet &metadataSet) const noexcept;
/** /**
* Expensive part this is only for heap buffers need to adapt to vector of * Expensive part this is only for heap buffers need to adapt to vector of
* capsules * capsules
...@@ -150,36 +140,23 @@ public: ...@@ -150,36 +140,23 @@ public:
noexcept; noexcept;
private: private:
/** template <class T>
* Common function called from WriterVariableMetadata for primitive and void WriteVariableMetadataInData(
* complex types const Variable<T> &variable,
* @param variable const Stats<typename TypeInfo<T>::ValueType> &stats,
* @param stats capsule::STLVector &heap) const noexcept;
* @param heap
* @param metadataSet
*/
template <class T, class U>
void WriteVariableMetadataCommon(const Variable<T> &variable,
Stats<U> &stats, capsule::STLVector &heap,
BP1MetadataSet &metadataSet) const
noexcept;
template <class T, class U>
void WriteVariableMetadataInData(const Variable<T> &variable,
const Stats<U> &stats,
capsule::STLVector &heap) const noexcept;
template <class T, class U> template <class T>
void WriteVariableMetadataInIndex(const Variable<T> &variable, void WriteVariableMetadataInIndex(
const Stats<U> &stats, const bool isNew, const Variable<T> &variable,
BP1Index &index) const noexcept; const Stats<typename TypeInfo<T>::ValueType> &stats, const bool isNew,
BP1Index &index) const noexcept;
template <class T, class U> template <class T>
void WriteVariableCharacteristics(const Variable<T> &variable, void WriteVariableCharacteristics(
const Stats<U> &stats, const Variable<T> &variable,
std::vector<char> &buffer, const Stats<typename TypeInfo<T>::ValueType> &stats,
const bool addLength = false) const std::vector<char> &buffer, const bool addLength = false) const noexcept;
noexcept;
/** /**
* Writes from &buffer[position]: [2 * Writes from &buffer[position]: [2
...@@ -212,20 +189,13 @@ private: ...@@ -212,20 +189,13 @@ private:
const bool addType = false) const noexcept; const bool addType = false) const noexcept;
/** /**
* GetStats for primitive types except std::complex<T> types * Get variable statistics
* @param variable
* @return stats
*/
template <class T>
Stats<T> GetStats(const Variable<T> &variable) const noexcept;
/**
* GetStats for std::complex<T> types
* @param variable * @param variable
* @return stats * @return stats
*/ */
template <class T> template <class T>
Stats<T> GetStats(const Variable<std::complex<T>> &variable) const noexcept; Stats<typename TypeInfo<T>::ValueType>
GetStats(const Variable<T> &variable) const noexcept;
template <class T> template <class T>
void WriteBoundsRecord(const bool isScalar, const Stats<T> &stats, void WriteBoundsRecord(const bool isScalar, const Stats<T> &stats,
...@@ -282,28 +252,13 @@ private: ...@@ -282,28 +252,13 @@ private:
#define declare_template_instantiation(T) \ #define declare_template_instantiation(T) \
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; \
\
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( \ extern template void BP1Writer::WriteVariableMetadata( \
const Variable<T> &variable, capsule::STLVector &heap, \ const Variable<T> &variable, capsule::STLVector &heap, \
BP1MetadataSet &metadataSet) const noexcept; BP1MetadataSet &metadataSet) const noexcept;
ADIOS_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation) ADIOS_FOREACH_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;
ADIOS_FOREACH_COMPLEX_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation #undef declare_template_instantiation
} // end namespace format } // end namespace format
......
...@@ -424,28 +424,13 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet, ...@@ -424,28 +424,13 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet,
#define declare_template_instantiation(T) \ #define declare_template_instantiation(T) \
template void BP1Writer::WriteVariablePayload( \ 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; \
\
ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
// SEPARATE PRIMITIVE FROM COMPLEX OVERLOADS
// PRIMITIVE
#define declare_template_instantiation(T) \
template void BP1Writer::WriteVariableMetadata( \ template void BP1Writer::WriteVariableMetadata( \
const Variable<T> &variable, capsule::STLVector &heap, \ const Variable<T> &variable, capsule::STLVector &heap, \
BP1MetadataSet &metadataSet) const noexcept; BP1MetadataSet &metadataSet) const noexcept;
ADIOS_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation) ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation
// COMPLEX
#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 #undef declare_template_instantiation
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
...@@ -62,18 +62,24 @@ void BP1Writer::WriteVariableMetadata(const Variable<T> &variable, ...@@ -62,18 +62,24 @@ void BP1Writer::WriteVariableMetadata(const Variable<T> &variable,
BP1MetadataSet &metadataSet) const BP1MetadataSet &metadataSet) const
noexcept noexcept
{ {
Stats<T> stats = GetStats(variable); Stats<typename TypeInfo<T>::ValueType> stats = GetStats(variable);
WriteVariableMetadataCommon(variable, stats, heap, metadataSet);
}
template <class T> stats.TimeIndex = metadataSet.TimeStep;
void BP1Writer::WriteVariableMetadata(const Variable<std::complex<T>> &variable, // Get new Index or point to existing index
capsule::STLVector &heap, bool isNew = true; // flag to check if variable is new
BP1MetadataSet &metadataSet) const BP1Index &varIndex =
noexcept GetBP1Index(variable.m_Name, metadataSet.VarsIndices, isNew);
{ stats.MemberID = varIndex.MemberID;
Stats<T> stats = GetStats(variable);
WriteVariableMetadataCommon(variable, stats, heap, metadataSet); // write metadata header in data and extract offsets
stats.Offset = heap.m_DataAbsolutePosition;
WriteVariableMetadataInData(variable, stats, heap);
stats.PayloadOffset = heap.m_DataAbsolutePosition;
// write to metadata index
WriteVariableMetadataInIndex(variable, stats, isNew, varIndex);
++metadataSet.DataPGVarsCount;
} }
template <class T> template <class T>
...@@ -88,10 +94,10 @@ void BP1Writer::WriteVariablePayload(const Variable<T> &variable, ...@@ -88,10 +94,10 @@ void BP1Writer::WriteVariablePayload(const Variable<T> &variable,
// PRIVATE // PRIVATE
template <class T> template <class T>
BP1Writer::Stats<T> BP1Writer::GetStats(const Variable<T> &variable) const BP1Writer::Stats<typename TypeInfo<T>::ValueType>
noexcept BP1Writer::GetStats(const Variable<T> &variable) const noexcept
{ {
Stats<T> stats; Stats<typename TypeInfo<T>::ValueType> stats;
const std::size_t valuesSize = variable.TotalSize(); const std::size_t valuesSize = variable.TotalSize();
if (m_Verbosity == 0) if (m_Verbosity == 0)
...@@ -107,30 +113,6 @@ BP1Writer::Stats<T> BP1Writer::GetStats(const Variable<T> &variable) const ...@@ -107,30 +113,6 @@ BP1Writer::Stats<T> BP1Writer::GetStats(const Variable<T> &variable) const
return stats; 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> template <class T>
void BP1Writer::WriteBoundsRecord(const bool isScalar, const Stats<T> &stats, void BP1Writer::WriteBoundsRecord(const bool isScalar, const Stats<T> &stats,
std::vector<char> &buffer, std::vector<char> &buffer,
...@@ -174,36 +156,11 @@ void BP1Writer::WriteCharacteristicRecord(const std::uint8_t characteristicID, ...@@ -174,36 +156,11 @@ void BP1Writer::WriteCharacteristicRecord(const std::uint8_t characteristicID,
++characteristicsCounter; ++characteristicsCounter;
} }
template <class T, class U> template <class T>
void BP1Writer::WriteVariableMetadataCommon(const Variable<T> &variable, void BP1Writer::WriteVariableMetadataInData(
Stats<U> &stats, const Variable<T> &variable,
capsule::STLVector &heap, const Stats<typename TypeInfo<T>::ValueType> &stats,
BP1MetadataSet &metadataSet) const capsule::STLVector &heap) const noexcept
noexcept
{
stats.TimeIndex = metadataSet.TimeStep;
// Get new Index or point to existing index
bool isNew = true; // flag to check if variable is new
BP1Index &varIndex =
GetBP1Index(variable.m_Name, metadataSet.VarsIndices, isNew);
stats.MemberID = varIndex.MemberID;
// write metadata header in data and extract offsets
stats.Offset = heap.m_DataAbsolutePosition;
WriteVariableMetadataInData(variable, stats, heap);
stats.PayloadOffset = heap.m_DataAbsolutePosition;
// write to metadata index
WriteVariableMetadataInIndex(variable, stats, isNew, varIndex);
++metadataSet.DataPGVarsCount;
}
template <class T, class U>
void BP1Writer::WriteVariableMetadataInData(const Variable<T> &variable,
const Stats<U> &stats,
capsule::STLVector &heap) const
noexcept
{ {
auto &buffer = heap.m_Data; auto &buffer = heap.m_Data;
...@@ -246,11 +203,11 @@ void BP1Writer::WriteVariableMetadataInData(const Variable<T> &variable, ...@@ -246,11 +203,11 @@ void BP1Writer::WriteVariableMetadataInData(const Variable<T> &variable,
// used as payload position // used as payload position
} }
template <class T, class U> template <class T>
void BP1Writer::WriteVariableMetadataInIndex(const Variable<T> &variable, void BP1Writer::WriteVariableMetadataInIndex(
const Stats<U> &stats, const Variable<T> &variable,
const bool isNew, const Stats<typename TypeInfo<T>::ValueType> &stats, const bool isNew,
BP1Index &index) const noexcept BP1Index &index) const noexcept
{ {
auto &buffer = index.Buffer; auto &buffer = index.Buffer;
...@@ -282,12 +239,11 @@ void BP1Writer::WriteVariableMetadataInIndex(const Variable<T> &variable, ...@@ -282,12 +239,11 @@ void BP1Writer::WriteVariableMetadataInIndex(const Variable<T> &variable,
WriteVariableCharacteristics(variable, stats, buffer); WriteVariableCharacteristics(variable, stats, buffer);
} }
template <class T, class U> template <class T>
void BP1Writer::WriteVariableCharacteristics(const Variable<T> &variable, void BP1Writer::WriteVariableCharacteristics(
const Stats<U> &stats, const Variable<T> &variable,
std::vector<char> &buffer, const Stats<typename TypeInfo<T>::ValueType> &stats,
const bool addLength) const std::vector<char> &buffer, const bool addLength) const noexcept
noexcept
{ {
const std::size_t characteristicsCountPosition = const std::size_t characteristicsCountPosition =
buffer.size(); // very important to track as writer is going back to buffer.size(); // very important to track as writer is going back to
......
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