Skip to content
Snippets Groups Projects
Commit f3b5c539 authored by William F Godoy's avatar William F Godoy
Browse files

BP1Writer Template macro for overloaded primitive and complex types

Moved more template functions in BP1Writer.h to BP1Writer.cpp
Added Macros in ADIOSMacros.h for handling overloaded template functions


To do:
Extend 1 arg template to 2 arg for template function in BP1Writer.tcc
parent 1a201071
No related branches found
No related tags found
1 merge request!54Move BP1Writer templates out of header
...@@ -39,4 +39,24 @@ ...@@ -39,4 +39,24 @@
MACRO(std::complex<double>) \ MACRO(std::complex<double>) \
MACRO(std::complex<long double>) MACRO(std::complex<long double>)
#define ADIOS_FOREACH_PRIMITIVE_TYPE_1ARG(MACRO) \
MACRO(char) \
MACRO(unsigned char) \
MACRO(short) \
MACRO(unsigned short) \
MACRO(int) \
MACRO(unsigned int) \
MACRO(long int) \
MACRO(unsigned long int) \
MACRO(long long int) \
MACRO(unsigned long long int) \
MACRO(float) \
MACRO(double) \
MACRO(long double)
#define ADIOS_FOREACH_COMPLEX_TYPE_1ARG(MACRO) \
MACRO(float) \
MACRO(double) \
MACRO(long double)
#endif // ADIOSMACROS_H #endif // ADIOSMACROS_H
...@@ -250,8 +250,7 @@ private: ...@@ -250,8 +250,7 @@ private:
/** /**
* Returns corresponding index of type BP1Index, if doesn't exists creates a * Returns corresponding index of type BP1Index, if doesn't exists creates a
* new one. * new one. Used for variables and attributes
* Used for variables and attributes
* @param name variable or attribute name to look for index * @param name variable or attribute name to look for index
* @param indices look up hash table of indices * @param indices look up hash table of indices
* @param isNew true: index is newly created, false: index already exists in * @param isNew true: index is newly created, false: index already exists in
...@@ -281,12 +280,51 @@ private: ...@@ -281,12 +280,51 @@ private:
}; };
#define declare_template_instantiation(T) \ #define declare_template_instantiation(T) \
extern template void BP1Writer::WriteVariableMetadata( \ 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 Variable<T> &variable, capsule::STLVector &heap, \
BP1MetadataSet &metadataSet) const noexcept; 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) ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef 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 // 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( \
......
...@@ -15,74 +15,6 @@ namespace adios ...@@ -15,74 +15,6 @@ namespace adios
namespace format namespace format
{ {
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, class U> template <class T, class U>
void BP1Writer::WriteVariableMetadataCommon(const Variable<T> &variable, void BP1Writer::WriteVariableMetadataCommon(const Variable<T> &variable,
...@@ -254,88 +186,5 @@ void BP1Writer::WriteVariableCharacteristics(const Variable<T> &variable, ...@@ -254,88 +186,5 @@ void BP1Writer::WriteVariableCharacteristics(const Variable<T> &variable,
&characteristicsLength); // length &characteristicsLength); // length
} }
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
// //here we can make decisions for
// 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)
{
if (valuesSize >= 10000000) // ten million? this needs actual results
// //here we can make decisions for
// based on valuesSize
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;
}
} // end namespace format } // end namespace format
} // end namespace } // end namespace
...@@ -418,49 +418,48 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet, ...@@ -418,49 +418,48 @@ void BP1Writer::FlattenMetadata(BP1MetadataSet &metadataSet,
} }
// TEMPLATES // TEMPLATES
// template <class T> template <class T>
// std::size_t BP1Writer::GetVariableIndexSize(const Variable<T> &variable) std::size_t BP1Writer::GetVariableIndexSize(const Variable<T> &variable) const
// const noexcept
// noexcept {
//{ // size_t indexSize = varEntryLength + memberID + lengthGroupName +
// // size_t indexSize = varEntryLength + memberID + lengthGroupName + // groupName + lengthVariableName + lengthOfPath + path + datatype
// // groupName + lengthVariableName + lengthOfPath + path + datatype std::size_t indexSize = 23; // without characteristics
// std::size_t indexSize = 23; // without characteristics indexSize += variable.m_Name.size();
// indexSize += variable.m_Name.size();
// // characteristics 3 and 4, check variable number of dimensions
// // characteristics 3 and 4, check variable number of dimensions const std::size_t dimensions =
// const std::size_t dimensions = variable.DimensionsSize(); // commas in CSV + 1
// variable.DimensionsSize(); // commas in CSV + 1 indexSize += 28 * dimensions; // 28 bytes per dimension
// indexSize += 28 * dimensions; // 28 bytes per dimension indexSize += 1; // id
// indexSize += 1; // id
// // characteristics, offset + payload offset in data
// // characteristics, offset + payload offset in data indexSize += 2 * (1 + 8);
// indexSize += 2 * (1 + 8); // characteristic 0, if scalar add value, for now only allowing string
// // characteristic 0, if scalar add value, for now only allowing string if (dimensions == 1)
// if (dimensions == 1) {
// { indexSize += sizeof(T);
// indexSize += sizeof(T); indexSize += 1; // id
// indexSize += 1; // id // must have an if here
// // must have an if here indexSize += 2 + variable.m_Name.size();
// indexSize += 2 + variable.m_Name.size(); indexSize += 1; // id
// indexSize += 1; // id }
// }
// // characteristic statistics
// // characteristic statistics if (m_Verbosity == 0) // default, only min and max
// if (m_Verbosity == 0) // default, only min and max {
// { indexSize += 2 * (sizeof(T) + 1);
// indexSize += 2 * (sizeof(T) + 1); indexSize += 1 + 1; // id
// indexSize += 1 + 1; // id }
// }
// return indexSize + 12; // extra 12 bytes in case of attributes
// return indexSize + 12; // extra 12 bytes in case of attributes // need to add transform characteristics
// // need to add transform characteristics }
//} #define declare_template_instantiation(T) \
//#define declare_template_instantiation(T) \ template std::size_t BP1Writer::GetVariableIndexSize( \
// 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)
// ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation) #undef declare_template_instantiation
//#undef declare_template_instantiation
template <class T> template <class T>
void BP1Writer::WriteVariableMetadata(const Variable<T> &variable, void BP1Writer::WriteVariableMetadata(const Variable<T> &variable,
...@@ -475,154 +474,152 @@ void BP1Writer::WriteVariableMetadata(const Variable<T> &variable, ...@@ -475,154 +474,152 @@ void BP1Writer::WriteVariableMetadata(const Variable<T> &variable,
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)
#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) ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
#undef declare_template_instantiation #undef declare_template_instantiation
// template <class T> // PRIVATE TEMPLATES BELOW
// void BP1Writer::WriteVariableMetadata(const Variable<std::complex<T>> template <class T>
// &variable, BP1Writer::Stats<T> BP1Writer::GetStats(const Variable<T> &variable) const
// capsule::STLVector &heap, noexcept
// BP1MetadataSet &metadataSet) const {
// noexcept Stats<T> stats;
//{ const std::size_t valuesSize = variable.TotalSize();
// Stats<T> stats = GetStats(variable);
// WriteVariableMetadataCommon(variable, stats, heap, metadataSet); if (m_Verbosity == 0)
//} {
//#define declare_template_instantiation(T) \ if (valuesSize >= 10000000) // ten million? this needs actual results
// template void BP1Writer::WriteVariableMetadata( \ // //we can make decisions for threads
// const Variable<std::complex<T>> &variable, capsule::STLVector &heap, \ // based on valuesSize
// BP1MetadataSet &metadataSet) const noexcept; GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max,
// ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation) m_Threads); // here we can add cores from constructor
//#undef declare_template_instantiation else
// GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max);
// template <class T> }
// void BP1Writer::WriteVariablePayload(const Variable<T> &variable, return stats;
// capsule::STLVector &heap, }
// const unsigned int nthreads) const #define declare_template_instantiation(T) \
// noexcept template BP1Writer::Stats<T> BP1Writer::GetStats( \
//{ const Variable<T> &variable) const noexcept;
// // EXPENSIVE part, might want to use threads if large, serial for now ADIOS_FOREACH_PRIMITIVE_TYPE_1ARG(declare_template_instantiation)
// InsertToBuffer(heap.m_Data, variable.m_AppValues, variable.TotalSize()); #undef declare_template_instantiation
// heap.m_DataAbsolutePosition += variable.PayLoadSize();
//} template <class T>
//#define declare_template_instantiation(T) \ BP1Writer::Stats<T>
// template void BP1Writer::WriteVariablePayload( \ BP1Writer::GetStats(const Variable<std::complex<T>> &variable) const noexcept
// const Variable<T> &variable, capsule::STLVector &heap, \ {
// const unsigned int nthreads) const noexcept; Stats<T> stats;
// ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation) const std::size_t valuesSize = variable.TotalSize();
//#undef declare_template_instantiation
// if (m_Verbosity == 0)
//// PRIVATE {
// template <class T> // ten million? this needs actual results
// BP1Writer::Stats<T> BP1Writer::GetStats(const Variable<T> &variable) const // to make decisions for threads usage
// noexcept if (valuesSize >= 10000000)
//{ {
// Stats<T> stats; GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max,
// const std::size_t valuesSize = variable.TotalSize(); m_Threads);
// }
// if (m_Verbosity == 0) else
// { {
// if (valuesSize >= 10000000) // ten million? this needs actual results GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max);
// // //here we can make decisions for }
// threads }
// // based on valuesSize return stats;
// GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max, }
// m_Threads); // here we can add cores from constructor #define declare_template_instantiation(T) \
// else template BP1Writer::Stats<T> BP1Writer::GetStats( \
// GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max); const Variable<std::complex<T>> &variable) const noexcept;
// } ADIOS_FOREACH_COMPLEX_TYPE_1ARG(declare_template_instantiation)
// return stats; #undef declare_template_instantiation
//}
//#define declare_template_instantiation(T) \ template <class T>
// template BP1Writer::Stats<T> BP1Writer::GetStats( \ void BP1Writer::WriteBoundsRecord(const bool isScalar, const Stats<T> &stats,
// const Variable<T> &variable) const noexcept; std::vector<char> &buffer,
// ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation) std::uint8_t &characteristicsCounter,
//#undef declare_template_instantiation const bool addLength) const noexcept
// {
// template <class T> if (isScalar == true)
// BP1Writer::Stats<T> {
// BP1Writer::GetStats(const Variable<std::complex<T>> &variable) const noexcept WriteCharacteristicRecord(characteristic_value, stats.Min, buffer,
//{ characteristicsCounter,
// Stats<T> stats; addLength); // stats.min = stats.max = value
// const std::size_t valuesSize = variable.TotalSize(); return;
// }
// if (m_Verbosity == 0)
// { if (m_Verbosity == 0) // default verbose
// if (valuesSize >= 10000000) // ten million? this needs actual results {
// // //here we can make decisions for WriteCharacteristicRecord(characteristic_min, stats.Min, buffer,
// threads characteristicsCounter, addLength);
// // based on valuesSize WriteCharacteristicRecord(characteristic_max, stats.Max, buffer,
// GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max, characteristicsCounter, addLength);
// m_Threads); }
// else }
// GetMinMax(variable.m_AppValues, valuesSize, stats.Min, stats.Max); #define declare_template_instantiation(T) \
// } template void BP1Writer::WriteBoundsRecord( \
// return stats; const bool isScalar, const Stats<T> &stats, std::vector<char> &buffer, \
//} std::uint8_t &characteristicsCounter, const bool addLength) \
//#define declare_template_instantiation(T) \ const noexcept;
// template BP1Writer::Stats<T> BP1Writer::GetStats( \ ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
// const Variable<std::complex<T>> &variable) const noexcept; #undef declare_template_instantiation
// ADIOS_FOREACH_TYPE_1ARG(declare_template_instantiation)
//#undef declare_template_instantiation template <class T>
// void BP1Writer::WriteCharacteristicRecord(const std::uint8_t characteristicID,
// template <class T> const T &value,
// void BP1Writer::WriteBoundsRecord(const bool isScalar, const Stats<T> &stats, std::vector<char> &buffer,
// std::vector<char> &buffer, std::uint8_t &characteristicsCounter,
// std::uint8_t &characteristicsCounter, const bool addLength) const noexcept
// const bool addLength) const noexcept {
//{ const std::uint8_t id = characteristicID;
// if (isScalar == true) InsertToBuffer(buffer, &id);
// {
// WriteCharacteristicRecord(characteristic_value, stats.Min, buffer, if (addLength == true)
// characteristicsCounter, {
// addLength); // stats.min = stats.max = value const std::uint16_t lengthOfCharacteristic = sizeof(T); // id
// return; InsertToBuffer(buffer, &lengthOfCharacteristic);
// } }
//
// if (m_Verbosity == 0) // default verbose InsertToBuffer(buffer, &value);
// { ++characteristicsCounter;
// WriteCharacteristicRecord(characteristic_min, stats.Min, buffer, }
// characteristicsCounter, addLength); #define define_template_instantiation(T) \
// WriteCharacteristicRecord(characteristic_max, stats.Max, buffer, template void BP1Writer::WriteCharacteristicRecord( \
// characteristicsCounter, addLength); const std::uint8_t characteristicID, const T &value, \
// } std::vector<char> &buffer, std::uint8_t &characteristicsCounter, \
//} const bool addLength) const noexcept;
//#define declare_template_instantiation(T) \ ADIOS_FOREACH_TYPE_1ARG(define_template_instantiation)
// template void BP1Writer::WriteBoundsRecord( \ #undef define_template_instatiation
// 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