changed: add helper template to serialize and broadcast static types

This commit is contained in:
Arne Morten Kvarving
2020-01-22 00:32:46 +01:00
parent 02ce13c800
commit 3396b31852
2 changed files with 34 additions and 50 deletions
+27 -2
View File
@@ -27,7 +27,7 @@ namespace Opm {
class EclMpiSerializer {
public:
EclMpiSerializer(Dune::MPIHelper::MPICommunicator comm) :
EclMpiSerializer(Dune::CollectiveCommunication<Dune::MPIHelper::MPICommunicator> comm) :
m_comm(comm)
{}
@@ -46,8 +46,33 @@ public:
Mpi::unpack(data, buffer, pos, m_comm);
}
template<class T>
void staticBroadcast()
{
if (m_comm.size() == 1)
return;
#if HAVE_MPI
if (m_comm.rank() == 0) {
size_t size = T::packSize(*this);
std::vector<char> buffer(size);
int position = 0;
T::pack(buffer, position, *this);
m_comm.broadcast(&position, 1, 0);
m_comm.broadcast(buffer.data(), position, 0);
} else {
int size;
m_comm.broadcast(&size, 1, 0);
std::vector<char> buffer(size);
m_comm.broadcast(buffer.data(), size, 0);
int position = 0;
T::unpack(buffer, position, *this);
}
#endif
}
protected:
Dune::MPIHelper::MPICommunicator m_comm;
Dune::CollectiveCommunication<Dune::MPIHelper::MPICommunicator> m_comm;
};
}