mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-11 11:35:34 -06:00
changed: add helper template to serialize and broadcast static types
This commit is contained in:
parent
02ce13c800
commit
3396b31852
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -611,35 +611,13 @@ public:
|
||||
SolventModule::initFromDeck(vanguard.deck(), vanguard.eclState());
|
||||
PolymerModule::initFromDeck(vanguard.deck(), vanguard.eclState());
|
||||
FoamModule::initFromDeck(vanguard.deck(), vanguard.eclState());
|
||||
#if HAVE_MPI
|
||||
if (comm.size() > 1) {
|
||||
EclMpiSerializer ser(comm);
|
||||
size_t size = SolventModule::packSize(ser) +
|
||||
PolymerModule::packSize(ser) +
|
||||
FoamModule::packSize(ser);
|
||||
std::vector<char> buffer(size);
|
||||
int position = 0;
|
||||
SolventModule::pack(buffer, position, ser);
|
||||
PolymerModule::pack(buffer, position, ser);
|
||||
FoamModule::pack(buffer, position, ser);
|
||||
comm.broadcast(&position, 1, 0);
|
||||
comm.broadcast(buffer.data(), position, 0);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
#if HAVE_MPI
|
||||
int size;
|
||||
comm.broadcast(&size, 1, 0);
|
||||
std::vector<char> buffer(size);
|
||||
comm.broadcast(buffer.data(), size, 0);
|
||||
int position = 0;
|
||||
EclMpiSerializer ser(comm);
|
||||
SolventModule::unpack(buffer, position, ser);
|
||||
PolymerModule::unpack(buffer, position, ser);
|
||||
FoamModule::unpack(buffer, position, ser);
|
||||
#endif
|
||||
}
|
||||
|
||||
EclMpiSerializer ser(comm);
|
||||
ser.staticBroadcast<SolventModule>();
|
||||
ser.staticBroadcast<PolymerModule>();
|
||||
ser.staticBroadcast<FoamModule>();
|
||||
|
||||
// create the ECL writer
|
||||
eclWriter_.reset(new EclWriterType(simulator));
|
||||
|
||||
@ -2481,27 +2459,8 @@ private:
|
||||
if (comm.rank() == 0)
|
||||
FluidSystem::initFromDeck(deck, eclState);
|
||||
|
||||
#if HAVE_MPI
|
||||
if (comm.size() > 1) {
|
||||
if (comm.rank() == 0) {
|
||||
EclMpiSerializer ser(comm);
|
||||
size_t size = FluidSystem::packSize(ser);
|
||||
std::vector<char> buffer(size);
|
||||
int position = 0;
|
||||
FluidSystem::pack(buffer, position, ser);
|
||||
comm.broadcast(&position, 1, 0);
|
||||
comm.broadcast(buffer.data(), position, 0);
|
||||
} else {
|
||||
int size;
|
||||
comm.broadcast(&size, 1, 0);
|
||||
std::vector<char> buffer(size);
|
||||
comm.broadcast(buffer.data(), size, 0);
|
||||
int position = 0;
|
||||
EclMpiSerializer ser(comm);
|
||||
FluidSystem::unpack(buffer, position, ser);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
EclMpiSerializer ser(comm);
|
||||
ser.staticBroadcast<FluidSystem>();
|
||||
}
|
||||
|
||||
void readInitialCondition_()
|
||||
|
Loading…
Reference in New Issue
Block a user