mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
changed: handle tuples in eclmpiserializer
thus we can remove support in MPIPacker
This commit is contained in:
parent
e7d186b416
commit
fdb2743ca9
@ -93,6 +93,8 @@ public:
|
||||
pair(data);
|
||||
} else if constexpr (is_variant<T>::value) {
|
||||
variant(data);
|
||||
} else if constexpr (is_tuple<T>::value) {
|
||||
tuple(data);
|
||||
} else if constexpr (is_optional<T>::value) {
|
||||
optional(data);
|
||||
} else if constexpr (is_vector<T>::value) {
|
||||
@ -177,6 +179,8 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Handler for arrays.
|
||||
//! \param data The array to (de-)serialize
|
||||
template <class Array>
|
||||
void array(Array& data)
|
||||
{
|
||||
@ -260,7 +264,26 @@ public:
|
||||
const_cast<std::optional<T>&>(data) = res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Handler for std::tuple.
|
||||
//! \param data The tuple to (de-)serialize
|
||||
template<class... Args>
|
||||
void tuple(const std::tuple<Args...>& data)
|
||||
{
|
||||
if (m_op == Operation::PACKSIZE) {
|
||||
m_op = Operation::PACKSIZE;
|
||||
m_packSize = 0;
|
||||
tuple_call(data);
|
||||
} else if (m_op == Operation::PACK) {
|
||||
m_position = 0;
|
||||
m_buffer.resize(m_packSize);
|
||||
tuple_call(data);
|
||||
} else if (m_op == Operation::UNPACK) {
|
||||
m_position = 0;
|
||||
m_op = Operation::UNPACK;
|
||||
tuple_call(data);
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Handler for maps.
|
||||
@ -321,6 +344,9 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
//! \brief Handler for sets.
|
||||
//! \tparam Set set type
|
||||
//! \param data The set to (de-)serialize
|
||||
template<class Set>
|
||||
void set(Set& data)
|
||||
{
|
||||
@ -498,6 +524,20 @@ protected:
|
||||
variadic_call(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template<std::size_t I = 0, typename Tuple>
|
||||
typename std::enable_if<I == std::tuple_size<Tuple>::value, void>::type
|
||||
tuple_call(const Tuple&)
|
||||
{
|
||||
}
|
||||
|
||||
template<std::size_t I = 0, typename Tuple>
|
||||
typename std::enable_if<I != std::tuple_size<Tuple>::value, void>::type
|
||||
tuple_call(const Tuple& tuple)
|
||||
{
|
||||
(*this)(std::get<I>(tuple));
|
||||
tuple_call<I+1>(tuple);
|
||||
}
|
||||
|
||||
//! \brief Enumeration of operations.
|
||||
enum class Operation {
|
||||
PACKSIZE, //!< Calculating serialization buffer size
|
||||
@ -538,6 +578,17 @@ protected:
|
||||
constexpr static bool value = true;
|
||||
};
|
||||
|
||||
//! \brief Predicate for detecting tuples.
|
||||
template<class T>
|
||||
struct is_tuple {
|
||||
constexpr static bool value = false;
|
||||
};
|
||||
|
||||
template<class... Ts>
|
||||
struct is_tuple<std::tuple<Ts...>> {
|
||||
constexpr static bool value = true;
|
||||
};
|
||||
|
||||
//! \brief Predicate for smart pointers.
|
||||
template<class T>
|
||||
struct is_ptr {
|
||||
|
@ -61,26 +61,6 @@ std::size_t packSize(const T* data, std::size_t l, Opm::Parallel::MPIComm comm)
|
||||
return packSize(data, l, comm, typename std::is_pod<T>::type());
|
||||
}
|
||||
|
||||
template<std::size_t I = 0, typename Tuple>
|
||||
typename std::enable_if<I == std::tuple_size<Tuple>::value, std::size_t>::type
|
||||
pack_size_tuple_entry(const Tuple&, Opm::Parallel::MPIComm)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<std::size_t I = 0, typename Tuple>
|
||||
typename std::enable_if<I != std::tuple_size<Tuple>::value, std::size_t>::type
|
||||
pack_size_tuple_entry(const Tuple& tuple, Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
return packSize(std::get<I>(tuple), comm) + pack_size_tuple_entry<I+1>(tuple, comm);
|
||||
}
|
||||
|
||||
template<class... Ts>
|
||||
std::size_t packSize(const std::tuple<Ts...>& data, Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
return pack_size_tuple_entry(data, comm);
|
||||
}
|
||||
|
||||
std::size_t packSize(const char* str, Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
#if HAVE_MPI
|
||||
@ -175,29 +155,6 @@ void pack(const T* data, std::size_t l, std::vector<char>& buffer, int& position
|
||||
pack(data, l, buffer, position, comm, typename std::is_pod<T>::type());
|
||||
}
|
||||
|
||||
template<std::size_t I = 0, typename Tuple>
|
||||
typename std::enable_if<I == std::tuple_size<Tuple>::value, void>::type
|
||||
pack_tuple_entry(const Tuple&, std::vector<char>&, int&,
|
||||
Opm::Parallel::MPIComm)
|
||||
{
|
||||
}
|
||||
|
||||
template<std::size_t I = 0, typename Tuple>
|
||||
typename std::enable_if<I != std::tuple_size<Tuple>::value, void>::type
|
||||
pack_tuple_entry(const Tuple& tuple, std::vector<char>& buffer,
|
||||
int& position, Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
pack(std::get<I>(tuple), buffer, position, comm);
|
||||
pack_tuple_entry<I+1>(tuple, buffer, position, comm);
|
||||
}
|
||||
|
||||
template<class... Ts>
|
||||
void pack(const std::tuple<Ts...>& data, std::vector<char>& buffer,
|
||||
int& position, Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
pack_tuple_entry(data, buffer, position, comm);
|
||||
}
|
||||
|
||||
void pack(const char* str, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
@ -268,29 +225,6 @@ void unpack(T* data, const std::size_t& l, std::vector<char>& buffer, int& posit
|
||||
unpack(data, l, buffer, position, comm, typename std::is_pod<T>::type());
|
||||
}
|
||||
|
||||
template<std::size_t I = 0, typename Tuple>
|
||||
typename std::enable_if<I == std::tuple_size<Tuple>::value, void>::type
|
||||
unpack_tuple_entry(Tuple&, std::vector<char>&, int&,
|
||||
Opm::Parallel::MPIComm)
|
||||
{
|
||||
}
|
||||
|
||||
template<std::size_t I = 0, typename Tuple>
|
||||
typename std::enable_if<I != std::tuple_size<Tuple>::value, void>::type
|
||||
unpack_tuple_entry(Tuple& tuple, std::vector<char>& buffer,
|
||||
int& position, Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
unpack(std::get<I>(tuple), buffer, position, comm);
|
||||
unpack_tuple_entry<I+1>(tuple, buffer, position, comm);
|
||||
}
|
||||
|
||||
template<class... Ts>
|
||||
void unpack(std::tuple<Ts...>& data, std::vector<char>& buffer,
|
||||
int& position, Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
unpack_tuple_entry(data, buffer, position, comm);
|
||||
}
|
||||
|
||||
void unpack(char* str, std::size_t length, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include <bitset>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace Opm
|
||||
@ -74,9 +73,6 @@ std::size_t packSize(const T& data, Opm::Parallel::MPIComm comm)
|
||||
return packSize(data, comm, typename std::is_pod<T>::type());
|
||||
}
|
||||
|
||||
template<class... Ts>
|
||||
std::size_t packSize(const std::tuple<Ts...>& data, Opm::Parallel::MPIComm comm);
|
||||
|
||||
std::size_t packSize(const char* str, Opm::Parallel::MPIComm comm);
|
||||
|
||||
template<std::size_t Size>
|
||||
@ -125,10 +121,6 @@ void pack(const T& data, std::vector<char>& buffer, int& position,
|
||||
pack(data, buffer, position, comm, typename std::is_pod<T>::type());
|
||||
}
|
||||
|
||||
template<class... Ts>
|
||||
void pack(const std::tuple<Ts...>& data, std::vector<char>& buffer,
|
||||
int& position, Opm::Parallel::MPIComm comm);
|
||||
|
||||
void pack(const char* str, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm);
|
||||
|
||||
@ -180,10 +172,6 @@ void unpack(T& data, std::vector<char>& buffer, int& position,
|
||||
unpack(data, buffer, position, comm, typename std::is_pod<T>::type());
|
||||
}
|
||||
|
||||
template<class... Ts>
|
||||
void unpack(std::tuple<Ts...>& data, std::vector<char>& buffer,
|
||||
int& position, Opm::Parallel::MPIComm comm);
|
||||
|
||||
void unpack(char* str, std::size_t length, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user