mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
changed: handle all vectors in eclmpiserializer
thus we can remove support in MPIPacker
This commit is contained in:
@@ -95,12 +95,16 @@ public:
|
||||
variant(data);
|
||||
} else if constexpr (is_optional<T>::value) {
|
||||
optional(data);
|
||||
} else if constexpr (is_vector<T>::value) {
|
||||
vector(const_cast<T&>(data));
|
||||
} else if constexpr (is_map<T>::value) {
|
||||
map(const_cast<T&>(data));
|
||||
} else if constexpr (is_array<T>::value) {
|
||||
array(const_cast<T&>(data));
|
||||
} else if constexpr (is_set<T>::value) {
|
||||
set(const_cast<T&>(data));
|
||||
} else if constexpr (has_serializeOp<detail::remove_cvr_t<T>>::value) {
|
||||
const_cast<T&>(data).serializeOp(*this);
|
||||
} else {
|
||||
if (m_op == Operation::PACKSIZE)
|
||||
m_packSize += Mpi::packSize(data, m_comm);
|
||||
@@ -124,6 +128,8 @@ public:
|
||||
pair(it);
|
||||
else if constexpr (is_ptr<T>::value)
|
||||
ptr(it);
|
||||
else if constexpr (is_vector<T>::value)
|
||||
vector(it);
|
||||
else if constexpr (has_serializeOp<T>::value)
|
||||
it.serializeOp(*this);
|
||||
else
|
||||
@@ -238,30 +244,19 @@ public:
|
||||
if (m_op == Operation::PACKSIZE) {
|
||||
m_packSize += Mpi::packSize(data.has_value(), m_comm);
|
||||
if (data.has_value()) {
|
||||
if constexpr (has_serializeOp<T>::value) {
|
||||
const_cast<T&>(*data).serializeOp(*this);
|
||||
} else
|
||||
m_packSize += Mpi::packSize(*data, m_comm);
|
||||
(*this)(*data);
|
||||
}
|
||||
} else if (m_op == Operation::PACK) {
|
||||
Mpi::pack(data.has_value(), m_buffer, m_position, m_comm);
|
||||
if (data.has_value()) {
|
||||
if constexpr (has_serializeOp<T>::value) {
|
||||
const_cast<T&>(*data).serializeOp(*this);
|
||||
} else {
|
||||
Mpi::pack(*data, m_buffer, m_position, m_comm);
|
||||
}
|
||||
(*this)(*data);
|
||||
}
|
||||
} else if (m_op == Operation::UNPACK) {
|
||||
bool has;
|
||||
Mpi::unpack(has, m_buffer, m_position, m_comm);
|
||||
if (has) {
|
||||
T res;
|
||||
if constexpr (has_serializeOp<T>::value) {
|
||||
res.serializeOp(*this);
|
||||
} else {
|
||||
Mpi::unpack(res, m_buffer, m_position, m_comm);
|
||||
}
|
||||
(*this)(res);
|
||||
const_cast<std::optional<T>&>(data) = res;
|
||||
}
|
||||
}
|
||||
@@ -334,7 +329,7 @@ public:
|
||||
auto handle = [&](auto& d)
|
||||
{
|
||||
if constexpr (is_vector<Data>::value)
|
||||
this->vector(d);
|
||||
vector(d);
|
||||
else if constexpr (is_ptr<Data>::value)
|
||||
ptr(d);
|
||||
else if constexpr (has_serializeOp<Data>::value)
|
||||
|
||||
@@ -67,28 +67,6 @@ std::size_t packSize(const std::pair<T1,T2>& data, Opm::Parallel::MPIComm comm)
|
||||
return packSize(data.first, comm) + packSize(data.second, comm);
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
std::size_t packSize(const std::vector<T,A>& data, Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
if (std::is_pod<T>::value)
|
||||
// size written automatically
|
||||
return packSize(data.data(), data.size(), comm);
|
||||
|
||||
std::size_t size = packSize(data.size(), comm);
|
||||
|
||||
for (const auto& entry: data)
|
||||
size += packSize(entry, comm);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
template<class A>
|
||||
std::size_t packSize(const std::vector<bool,A>& data, Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
bool entry = false;
|
||||
return packSize(data.size(), comm) + data.size()*packSize(entry,comm);
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -211,34 +189,6 @@ void pack(const std::pair<T1,T2>& data, std::vector<char>& buffer, int& position
|
||||
pack(data.second, buffer, position, comm);
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
void pack(const std::vector<T, A>& data, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
if (std::is_pod<T>::value)
|
||||
{
|
||||
// size written automatically
|
||||
pack(data.data(), data.size(), buffer, position, comm);
|
||||
return;
|
||||
}
|
||||
|
||||
pack(data.size(), buffer, position, comm);
|
||||
|
||||
for (const auto& entry: data)
|
||||
pack(entry, buffer, position, comm);
|
||||
}
|
||||
|
||||
template<class A>
|
||||
void pack(const std::vector<bool,A>& data, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
pack(data.size(), buffer, position, comm);
|
||||
for (const auto entry : data) { // Not a reference: vector<bool> range
|
||||
bool b = entry;
|
||||
pack(b, buffer, position, comm);
|
||||
}
|
||||
}
|
||||
|
||||
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&,
|
||||
@@ -340,39 +290,6 @@ void unpack(std::pair<T1,T2>& data, std::vector<char>& buffer, int& position,
|
||||
unpack(data.second, buffer, position, comm);
|
||||
}
|
||||
|
||||
template<class T, class A>
|
||||
void unpack(std::vector<T,A>& data, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
std::size_t length = 0;
|
||||
unpack(length, buffer, position, comm);
|
||||
data.resize(length);
|
||||
|
||||
if (std::is_pod<T>::value)
|
||||
{
|
||||
unpack(data.data(), data.size(), buffer, position, comm);
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto& entry: data)
|
||||
unpack(entry, buffer, position, comm);
|
||||
}
|
||||
|
||||
template<class A>
|
||||
void unpack(std::vector<bool,A>& data, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm)
|
||||
{
|
||||
size_t size;
|
||||
unpack(size, buffer, position, comm);
|
||||
data.clear();
|
||||
data.reserve(size);
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
bool entry;
|
||||
unpack(entry, buffer, position, comm);
|
||||
data.push_back(entry);
|
||||
}
|
||||
}
|
||||
|
||||
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&,
|
||||
@@ -438,38 +355,6 @@ void unpack([[maybe_unused]] Opm::time_point& data, std::vector<char>& buffer, i
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#define INSTANTIATE_PACK_VECTOR(...) \
|
||||
template std::size_t packSize(const std::vector<__VA_ARGS__>& data, \
|
||||
Opm::Parallel::MPIComm comm); \
|
||||
template void pack(const std::vector<__VA_ARGS__>& data, \
|
||||
std::vector<char>& buffer, int& position, \
|
||||
Opm::Parallel::MPIComm comm); \
|
||||
template void unpack(std::vector<__VA_ARGS__>& data, \
|
||||
std::vector<char>& buffer, int& position, \
|
||||
Opm::Parallel::MPIComm comm);
|
||||
|
||||
INSTANTIATE_PACK_VECTOR(float)
|
||||
INSTANTIATE_PACK_VECTOR(double)
|
||||
INSTANTIATE_PACK_VECTOR(std::vector<double>)
|
||||
INSTANTIATE_PACK_VECTOR(bool)
|
||||
INSTANTIATE_PACK_VECTOR(char)
|
||||
INSTANTIATE_PACK_VECTOR(int)
|
||||
INSTANTIATE_PACK_VECTOR(unsigned char)
|
||||
INSTANTIATE_PACK_VECTOR(unsigned int)
|
||||
INSTANTIATE_PACK_VECTOR(unsigned long int)
|
||||
INSTANTIATE_PACK_VECTOR(unsigned long long int)
|
||||
INSTANTIATE_PACK_VECTOR(std::time_t)
|
||||
INSTANTIATE_PACK_VECTOR(std::pair<bool,double>)
|
||||
INSTANTIATE_PACK_VECTOR(std::pair<std::string,std::vector<size_t>>)
|
||||
INSTANTIATE_PACK_VECTOR(std::pair<int,std::vector<int>>)
|
||||
INSTANTIATE_PACK_VECTOR(std::pair<int,std::vector<size_t>>)
|
||||
INSTANTIATE_PACK_VECTOR(std::string)
|
||||
|
||||
#undef INSTANTIATE_PACK_VECTOR
|
||||
|
||||
#undef INSTANTIATE_PACK_SET
|
||||
|
||||
#define INSTANTIATE_PACK(...) \
|
||||
template std::size_t packSize(const __VA_ARGS__& data, \
|
||||
Opm::Parallel::MPIComm comm); \
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <typeinfo>
|
||||
#include <vector>
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
@@ -78,12 +77,6 @@ std::size_t packSize(const T& data, Opm::Parallel::MPIComm comm)
|
||||
template<class T1, class T2>
|
||||
std::size_t packSize(const std::pair<T1,T2>& data, Opm::Parallel::MPIComm comm);
|
||||
|
||||
template<class T, class A>
|
||||
std::size_t packSize(const std::vector<T,A>& data, Opm::Parallel::MPIComm comm);
|
||||
|
||||
template<class A>
|
||||
std::size_t packSize(const std::vector<bool,A>& data, Opm::Parallel::MPIComm comm);
|
||||
|
||||
template<class... Ts>
|
||||
std::size_t packSize(const std::tuple<Ts...>& data, Opm::Parallel::MPIComm comm);
|
||||
|
||||
@@ -139,14 +132,6 @@ template<class T1, class T2>
|
||||
void pack(const std::pair<T1,T2>& data, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm);
|
||||
|
||||
template<class T, class A>
|
||||
void pack(const std::vector<T,A>& data, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm);
|
||||
|
||||
template<class A>
|
||||
void pack(const std::vector<bool,A>& data, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm);
|
||||
|
||||
template<class... Ts>
|
||||
void pack(const std::tuple<Ts...>& data, std::vector<char>& buffer,
|
||||
int& position, Opm::Parallel::MPIComm comm);
|
||||
@@ -206,14 +191,6 @@ template<class T1, class T2>
|
||||
void unpack(std::pair<T1,T2>& data, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm);
|
||||
|
||||
template<class T, class A>
|
||||
void unpack(std::vector<T,A>& data, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm);
|
||||
|
||||
template<class A>
|
||||
void unpack(std::vector<bool,A>& data, std::vector<char>& buffer, int& position,
|
||||
Opm::Parallel::MPIComm comm);
|
||||
|
||||
template<class... Ts>
|
||||
void unpack(std::tuple<Ts...>& data, std::vector<char>& buffer,
|
||||
int& position, Opm::Parallel::MPIComm comm);
|
||||
|
||||
Reference in New Issue
Block a user