added: primitive serializer support for std::bitset

This commit is contained in:
Arne Morten Kvarving 2022-09-05 08:55:26 +02:00
parent 69b32f7004
commit 237832b86d
2 changed files with 54 additions and 0 deletions

View File

@ -409,6 +409,27 @@ struct Packing<data::Segment>
}
};
template <std::size_t Size>
struct Packing<std::bitset<Size>>
{
static std::size_t packSize(const std::bitset<Size>& data, Opm::Parallel::MPIComm comm)
{
return Mpi::packSize(data.to_ullong(), comm);
}
static void pack(const std::bitset<Size>& data, std::vector<char>& buffer, int& position, Opm::Parallel::MPIComm comm)
{
Mpi::pack(data.to_ullong(), buffer, position, comm);
}
static void unpack(std::bitset<Size>& data, std::vector<char>& buffer, int& position, Opm::Parallel::MPIComm comm)
{
unsigned long long d;
Mpi::unpack(d, buffer, position, comm);
data = std::bitset<Size>(d);
}
};
std::size_t packSize(const data::NumericAquiferData& data, Opm::Parallel::MPIComm comm)
{
return packSize(data.initPressure, comm);
@ -498,6 +519,12 @@ std::size_t packSize(const data::Segment& data, Opm::Parallel::MPIComm comm)
return Packing<data::Segment>::packSize(data, comm);
}
template<std::size_t Size>
std::size_t packSize(const std::bitset<Size>& data, Opm::Parallel::MPIComm comm)
{
return Packing<std::bitset<Size>>::packSize(data, comm);
}
std::size_t packSize(const data::CellData& data, Opm::Parallel::MPIComm comm)
{
return packSize(data.dim, comm) + packSize(data.data, comm) + packSize(data.target, comm);
@ -877,6 +904,13 @@ void pack(const data::Segment& data, std::vector<char>& buffer, int& position,
Packing<data::Segment>::pack(data, buffer, position, comm);
}
template<std::size_t Size>
void pack(const std::bitset<Size>& data, std::vector<char>& buffer,
int& position, Opm::Parallel::MPIComm comm)
{
Packing<std::bitset<Size>>::pack(data, buffer, position, comm);
}
void pack(const data::GroupAndNetworkValues& data, std::vector<char>& buffer, int& position,
Opm::Parallel::MPIComm comm)
{
@ -1246,6 +1280,13 @@ void unpack(data::Segment& data, std::vector<char>& buffer, int& position,
Packing<data::Segment>::unpack(data, buffer, position, comm);
}
template<std::size_t Size>
void unpack(std::bitset<Size>& data, std::vector<char>& buffer, int& position,
Opm::Parallel::MPIComm comm)
{
Packing<std::bitset<Size>>::unpack(data, buffer, position, comm);
}
void unpack(data::GroupAndNetworkValues& data, std::vector<char>& buffer, int& position,
Opm::Parallel::MPIComm comm)
{

View File

@ -31,7 +31,9 @@
#include <opm/simulators/utils/ParallelCommunication.hpp>
#include <bitset>
#include <chrono>
#include <cstddef>
#include <optional>
#include <map>
#include <set>
@ -153,6 +155,9 @@ std::size_t packSize(const std::map<T1,T2,C,A>& data, Opm::Parallel::MPIComm com
template<class T1, class T2, class H, class P, class A>
std::size_t packSize(const std::unordered_map<T1,T2,H,P,A>& data, Opm::Parallel::MPIComm comm);
template<std::size_t Size>
std::size_t packSize(const std::bitset<Size>& data, Opm::Parallel::MPIComm comm);
////// pack routines
template<class T>
@ -241,6 +246,10 @@ void pack(const std::unordered_map<T1,T2,H,P,A>& data, std::vector<char>& buffer
void pack(const char* str, std::vector<char>& buffer, int& position,
Opm::Parallel::MPIComm comm);
template<size_t Size>
void pack(const std::bitset<Size>& data, std::vector<char>& buffer, int& position,
Opm::Parallel::MPIComm comm);
/// unpack routines
template<class T>
@ -330,6 +339,10 @@ void unpack(std::unordered_map<T1,T2,H,P,A>& data, std::vector<char>& buffer, in
void unpack(char* str, std::size_t length, std::vector<char>& buffer, int& position,
Opm::Parallel::MPIComm comm);
template<size_t Size>
void unpack(std::bitset<Size>& data, std::vector<char>& buffer, int& position,
Opm::Parallel::MPIComm comm);
/// prototypes for complex types
#define ADD_PACK_PROTOTYPES(T) \