Skip to content
Snippets Groups Projects
Commit 94554982 authored by Nils Kohl's avatar Nils Kohl :full_moon_with_face:
Browse files

Implemented std::array support for send and recv buffer shift operators (also extended buffer test)

parent 9e36486b
Branches
Tags
No related merge requests found
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <boost/integer.hpp> #include <boost/integer.hpp>
#include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid.hpp>
#include <array>
#include <deque> #include <deque>
#include <limits> #include <limits>
#include <list> #include <list>
...@@ -82,6 +83,51 @@ struct BufferSizeTrait< std::pair<T1,T2> > { ...@@ -82,6 +83,51 @@ struct BufferSizeTrait< std::pair<T1,T2> > {
// ----------------------------- Standard Container Support ----------------------------------------------------------- // ----------------------------- Standard Container Support -----------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------------------------------------------
template< typename T, // Element type of SendBuffer
typename G, // Growth policy of SendBuffer
typename Cont > // Container
void sendNonResizableContainer( GenericSendBuffer<T,G> & buf, const Cont & container )
{
buf.addDebugMarker( "ar" );
for( const auto & it : container )
buf << it;
}
template< typename T, // Element type of RecvBuffer
typename Cont > // Container
void recvNonResizableContainer( GenericRecvBuffer<T> & buf, Cont & container )
{
buf.readDebugMarker( "ar" );
for( auto & it : container )
buf >> it;
}
template< typename T, // Element type of SendBuffer
typename G, // Growth policy of SendBuffer
typename CT, // Element type
std::size_t N > // Array size
GenericSendBuffer<T,G>& operator<<( GenericSendBuffer<T,G> & buf, const std::array<CT, N> & array )
{
sendNonResizableContainer(buf, array);
return buf;
}
template< typename T, // Element type of RecvBuffer
typename CT, // Element type
std::size_t N > // Array size
GenericRecvBuffer<T>& operator>>( GenericRecvBuffer<T> & buf, std::array<CT, N> & array )
{
recvNonResizableContainer(buf, array);
return buf;
}
template<typename T, std::size_t N>
struct BufferSizeTrait< std::array< T, N > > {
static const bool constantSize = true;
static const uint_t size = N * sizeof(T) + BUFFER_DEBUG_OVERHEAD;
};
template< typename T, // Element type of SendBuffer template< typename T, // Element type of SendBuffer
typename G, // Growth policy of SendBuffer typename G, // Growth policy of SendBuffer
typename Cont> // Container typename Cont> // Container
......
...@@ -122,6 +122,16 @@ void initBoostArray( boost::array< T, N > & array ) ...@@ -122,6 +122,16 @@ void initBoostArray( boost::array< T, N > & array )
*it = dist( rng ); *it = dist( rng );
} }
template<typename T, std::size_t N>
void initStdArray( std::array< T, N > & array )
{
static std::mt19937 rng;
std::uniform_int_distribution<T> dist;
for( auto it = array.begin(); it != array.end(); ++it )
*it = dist( rng );
}
/// Simulates one send and receive operation /// Simulates one send and receive operation
/// data is put into send buffer and copied to RecvBuffer /// data is put into send buffer and copied to RecvBuffer
...@@ -153,6 +163,7 @@ void bufferTest() ...@@ -153,6 +163,7 @@ void bufferTest()
std::multimap<unsigned int, walberla::int64_t> stdMultiMap, stdMultiMapEmpty; std::multimap<unsigned int, walberla::int64_t> stdMultiMap, stdMultiMapEmpty;
boost::array< unsigned int, 19 > boostArray; boost::array< unsigned int, 19 > boostArray;
std::array < unsigned int, 19 > stdArray;
initVecBool(boolStdVec); initVecBool(boolStdVec);
initIntegerContainer(stdVec); initIntegerContainer(stdVec);
...@@ -163,6 +174,7 @@ void bufferTest() ...@@ -163,6 +174,7 @@ void bufferTest()
initIntegerMap(stdMap); initIntegerMap(stdMap);
initIntegerMap(stdMultiMap); initIntegerMap(stdMultiMap);
initBoostArray(boostArray); initBoostArray(boostArray);
initStdArray(stdArray);
// Create send buffer and put two values in it // Create send buffer and put two values in it
GenericSendBuffer<T> sb; GenericSendBuffer<T> sb;
...@@ -178,7 +190,7 @@ void bufferTest() ...@@ -178,7 +190,7 @@ void bufferTest()
sb << stdMultiSet << stdMultiSetEmpty; sb << stdMultiSet << stdMultiSetEmpty;
sb << stdMap << stdMapEmpty; sb << stdMap << stdMapEmpty;
sb << stdMultiMap << stdMultiMapEmpty; sb << stdMultiMap << stdMultiMapEmpty;
sb << boostArray; sb << boostArray << stdArray;
// Copying // Copying
//RecvBuffer<T> rb; //RecvBuffer<T> rb;
...@@ -209,6 +221,7 @@ void bufferTest() ...@@ -209,6 +221,7 @@ void bufferTest()
std::multimap<unsigned int, walberla::int64_t> recvStdMultiMap, recvStdMultiMapEmpty; std::multimap<unsigned int, walberla::int64_t> recvStdMultiMap, recvStdMultiMapEmpty;
boost::array<unsigned int, 19> recvBoostArray; boost::array<unsigned int, 19> recvBoostArray;
std::array <unsigned int, 19> recvStdArray;
rb >> recvD >> recvI; rb >> recvD >> recvI;
rb >> recvVec >> recvMat; rb >> recvVec >> recvMat;
...@@ -222,7 +235,7 @@ void bufferTest() ...@@ -222,7 +235,7 @@ void bufferTest()
rb >> recvStdMultiSet >> recvStdMultiSetEmpty; rb >> recvStdMultiSet >> recvStdMultiSetEmpty;
rb >> recvStdMap >> recvStdMapEmpty; rb >> recvStdMap >> recvStdMapEmpty;
rb >> recvStdMultiMap >> recvStdMultiMapEmpty; rb >> recvStdMultiMap >> recvStdMultiMapEmpty;
rb >> recvBoostArray; rb >> recvBoostArray >> recvStdArray;
// Validate // Validate
WALBERLA_CHECK_FLOAT_EQUAL(recvD,testDouble); WALBERLA_CHECK_FLOAT_EQUAL(recvD,testDouble);
...@@ -254,6 +267,7 @@ void bufferTest() ...@@ -254,6 +267,7 @@ void bufferTest()
WALBERLA_CHECK_EQUAL(recvStdMultiMapEmpty, stdMultiMapEmpty); WALBERLA_CHECK_EQUAL(recvStdMultiMapEmpty, stdMultiMapEmpty);
WALBERLA_CHECK_EQUAL(recvBoostArray, boostArray); WALBERLA_CHECK_EQUAL(recvBoostArray, boostArray);
WALBERLA_CHECK_EQUAL(recvStdArray, stdArray);
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment