add mpi serialization specialization for std::vector<bool>

This commit is contained in:
Arne Morten Kvarving 2019-11-30 01:21:56 +01:00
parent 95ee6566d4
commit b33611077b
2 changed files with 45 additions and 0 deletions

View File

@ -128,12 +128,20 @@ std::size_t packSize(const std::vector<T,A>& data, Dune::MPIHelper::MPICommunica
return size;
}
template<class A>
std::size_t packSize(const std::vector<bool,A>& data, Dune::MPIHelper::MPICommunicator comm)
{
bool entry;
return packSize(data.size(), comm) + data.size()*packSize(entry,comm);
}
template<class Key, class Value>
std::size_t packSize(const OrderedMap<Key,Value>& data, Dune::MPIHelper::MPICommunicator comm)
{
return packSize(data.getIndex(), comm) + packSize(data.getStorage(), comm);
}
std::size_t packSize(const char* str, Dune::MPIHelper::MPICommunicator comm)
{
#if HAVE_MPI
@ -356,6 +364,17 @@ void pack(const std::vector<T, A>& data, std::vector<char>& buffer, int& positio
pack(entry, buffer, position, comm);
}
template<class A>
void pack(const std::vector<bool,A>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
pack(data.size(), buffer, position, comm);
for (const auto& entry : data) {
bool b = entry;
pack(b, buffer, position, comm);
}
}
template<class Key, class Value>
void pack(const OrderedMap<Key, Value>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
@ -604,6 +623,21 @@ void unpack(std::vector<T,A>& data, std::vector<char>& buffer, int& position,
unpack(entry, buffer, position, comm);
}
template<class A>
void unpack(std::vector<bool,A>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator 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<class Key, class Value>
void unpack(OrderedMap<Key,Value>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)

View File

@ -76,6 +76,9 @@ std::size_t packSize(const std::pair<T1,T2>& data, Dune::MPIHelper::MPICommunica
template<class T, class A>
std::size_t packSize(const std::vector<T,A>& data, Dune::MPIHelper::MPICommunicator comm);
template<class A>
std::size_t packSize(const std::vector<bool,A>& data, Dune::MPIHelper::MPICommunicator comm);
std::size_t packSize(const char* str, Dune::MPIHelper::MPICommunicator comm);
std::size_t packSize(const std::string& str, Dune::MPIHelper::MPICommunicator comm);
@ -124,6 +127,10 @@ template<class T, class A>
void pack(const std::vector<T,A>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);
template<class A>
void pack(const std::vector<bool,A>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);
template<class T1, class T2, class C, class A>
void pack(const std::map<T1,T2,C,A>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);
@ -174,6 +181,10 @@ template<class T, class A>
void unpack(std::vector<T,A>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);
template<class A>
void unpack(std::vector<bool,A>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);
template<class T1, class T2, class C, class A>
void unpack(std::map<T1,T2,C,A>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);