add mpi serialization for std::unique_ptr

This commit is contained in:
Arne Morten Kvarving 2019-12-13 15:51:17 +01:00
parent 1860141771
commit 6e8b82ae7d
2 changed files with 44 additions and 0 deletions

View File

@ -1158,6 +1158,17 @@ std::size_t packSize(const std::shared_ptr<T>& data,
template std::size_t packSize(const std::shared_ptr<SpiralICD>& data,
Dune::MPIHelper::MPICommunicator comm);
template<class T>
std::size_t packSize(const std::unique_ptr<T>& data,
Dune::MPIHelper::MPICommunicator comm)
{
std::size_t size = packSize(bool(), comm);
if (data)
size += packSize(*data, comm);
return size;
}
std::size_t packSize(const Dimension& data,
Dune::MPIHelper::MPICommunicator comm)
{
@ -2654,6 +2665,15 @@ void pack(const std::shared_ptr<T>& data, std::vector<char>& buffer, int& positi
pack(*data, buffer, position, comm);
}
template<class T>
void pack(const std::unique_ptr<T>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
pack(data != nullptr, buffer, position, comm);
if (data)
pack(*data, buffer, position, comm);
}
template void pack(const std::shared_ptr<SpiralICD>& data, std::vector<char>& buffer,
int& position, Dune::MPIHelper::MPICommunicator comm);
@ -4632,6 +4652,18 @@ void unpack(std::shared_ptr<T>& data, std::vector<char>& buffer, int& position,
}
}
template<class T>
void unpack(std::unique_ptr<T>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
bool hasVal;
unpack(hasVal, buffer, position, comm);
if (hasVal) {
data.reset(new T);
unpack(*data, buffer, position, comm);
}
}
template void unpack(std::shared_ptr<SpiralICD>& data,
std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);

View File

@ -194,6 +194,10 @@ std::size_t packSize(const std::shared_ptr<T>& data,
template<class T, std::size_t N>
std::size_t packSize(const std::array<T,N>& data, Dune::MPIHelper::MPICommunicator comm);
template<class T>
std::size_t packSize(const std::unique_ptr<T>& 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);
@ -327,6 +331,10 @@ template<class T, size_t N>
void pack(const std::array<T,N>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);
template<class T>
void pack(const std::unique_ptr<T>& 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);
@ -481,6 +489,10 @@ template<class T, size_t N>
void unpack(std::array<T,N>& data, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);
template<class T>
void unpack(std::unique_ptr<T>& 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);