Newer
Older
/*
* SingleBP.h
*
* Created on: Dec 16, 2016
* Author: wfg
*/
* Constructor for Writer writes in BP format into a single heap capsule, manages several transports
* @param name unique name given to the engine
* @param accessMode
* @param mpiComm
* @param method
* @param debugMode
*/
Writer( ADIOS& adios, const std::string name, const std::string accessMode, MPI_Comm mpiComm,
const Method& method, const bool debugMode = false, const unsigned int cores = 1 );
void Write( Variable<char>& variable, const char* values );
void Write( Variable<unsigned char>& variable, const unsigned char* values );
void Write( Variable<short>& variable, const short* values );
void Write( Variable<unsigned short>& variable, const unsigned short* values );
void Write( Variable<int>& variable, const int* values );
void Write( Variable<unsigned int>& variable, const unsigned int* values );
void Write( Variable<long int>& variable, const long int* values );
void Write( Variable<unsigned long int>& variable, const unsigned long int* values );
void Write( Variable<long long int>& variable, const long long int* values );
void Write( Variable<unsigned long long int>& variable, const unsigned long long int* values ) ;
void Write( Variable<float>& variable, const float* values );
void Write( Variable<double>& variable, const double* values );
void Write( Variable<long double>& variable, const long double* values );
void Write( const std::string variableName, const char* values );
void Write( const std::string variableName, const unsigned char* values );
void Write( const std::string variableName, const short* values );
void Write( const std::string variableName, const unsigned short* values );
void Write( const std::string variableName, const int* values );
void Write( const std::string variableName, const unsigned int* values );
void Write( const std::string variableName, const long int* values );
void Write( const std::string variableName, const unsigned long int* values );
void Write( const std::string variableName, const long long int* values );
void Write( const std::string variableName, const unsigned long long int* values );
void Write( const std::string variableName, const float* values );
void Write( const std::string variableName, const double* values );
void Write( const std::string variableName, const long double* values );
Heap m_Buffer; ///< heap capsule
format::BP1Writer m_BP1Writer; ///< format object will provide the required BP functionality to be applied on m_Buffer and m_Transports
format::BP1MetadataSet m_MetadataSet; ///< metadata set accompanying the heap buffer data in bp format. Needed by m_BP1Writer
std::size_t m_MaxBufferSize;
float m_GrowthFactor = 1.5;
bool m_TransportFlush = false; ///< true: transport flush happened, buffer must be reset
/**
* Common function
* @param group
* @param variableName
* @param variable
*/
template< class T >
void WriteVariable( Variable<T>& variable, const T* values )
//set variable
variable.m_AppValues = values;
m_WrittenVariables.insert( variable.m_Name );
//precalculate new metadata and payload sizes
const std::size_t indexSize = m_BP1Writer.GetVariableIndexSize( variable );
const std::size_t payloadSize = variable.PayLoadSize();
//Buffer reallocation, expensive part
m_TransportFlush = CheckBuffersAllocation( variable.m_Name, indexSize, payloadSize );
//WRITE INDEX to data buffer and metadata structure (in memory)//
m_BP1Writer.WriteVariableIndex( variable, m_Buffer, m_MetadataSet );
if( m_TransportFlush == true ) //in batches
{
//write pg index
//flush to transports
//reset positions to zero, update absolute position
}
else //Write data to buffer
{
//EXPENSIVE part might want to use threads if large.
MemcpyThreads( m_Buffer.m_Data.data(), variable.m_AppValues, payloadSize, m_Cores );
//update indices
m_Buffer.m_DataPosition += payloadSize;
m_Buffer.m_DataAbsolutePosition += payloadSize;
}
}
/**
* Check if heap buffers for data and metadata need reallocation or maximum sizes have been reached.
* @param variableName name of the variable to be written
* @param indexSize precalculated index size
* @param payloadSize payload size from variable total size
* @return true: transport must be flush and buffers reset, false: buffer is sufficient
*/
bool CheckBuffersAllocation( const std::string variableName, const std::size_t indexSize, const std::size_t payloadSize );