Merge pull request #2295 from akva2/noecl_flush_matman

Avoid deck usage on non-root processes setting up MaterialLawManager
This commit is contained in:
Joakim Hove 2020-01-22 15:09:57 +01:00 committed by GitHub
commit 2cfe1dce7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 150 additions and 2 deletions

View File

@ -27,7 +27,7 @@ namespace Opm {
class EclMpiSerializer {
public:
EclMpiSerializer(Dune::CollectiveCommunication<Dune::MPIHelper::MPICommunicator> comm) :
explicit EclMpiSerializer(Dune::CollectiveCommunication<Dune::MPIHelper::MPICommunicator> comm) :
m_comm(comm)
{}
@ -71,6 +71,31 @@ public:
#endif
}
template<class T>
void broadcast(T& data)
{
if (m_comm.size() == 1)
return;
#if HAVE_MPI
if (m_comm.rank() == 0) {
size_t size = data.packSize(*this);
std::vector<char> buffer(size);
int position = 0;
data.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;
data.unpack(buffer, position, *this);
}
#endif
}
protected:
Dune::CollectiveCommunication<Dune::MPIHelper::MPICommunicator> m_comm;
};

View File

@ -2345,6 +2345,7 @@ private:
const auto& vanguard = simulator.vanguard();
const auto& deck = vanguard.deck();
const auto& eclState = vanguard.eclState();
const auto& comm = vanguard.gridView().comm();
// the PVT and saturation region numbers
updatePvtnum_();
@ -2369,7 +2370,12 @@ private:
compressedToCartesianElemIdx[elemIdx] = vanguard.cartesianIndex(elemIdx);
materialLawManager_ = std::make_shared<EclMaterialLawManager>();
materialLawManager_->initFromDeck(deck, eclState);
if (comm.rank() == 0)
materialLawManager_->initFromDeck(deck, eclState);
EclMpiSerializer ser(comm);
ser.broadcast(*materialLawManager_);
materialLawManager_->initParamsForElements(eclState, compressedToCartesianElemIdx);
////////////////////////////////
}

View File

@ -23,6 +23,9 @@
#include "ParallelRestart.hpp"
#include <opm/common/OpmLog/Location.hpp>
#include <opm/material/fluidmatrixinteractions/EclEpsScalingPoints.hpp>
#include <opm/material/fluidmatrixinteractions/EclTwoPhaseMaterialParams.hpp>
#include <opm/material/fluidmatrixinteractions/EclMultiplexerMaterialParams.hpp>
#include <opm/parser/eclipse/EclipseState/Runspec.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/NNC.hpp>
#include <opm/parser/eclipse/EclipseState/InitConfig/Equil.hpp>
@ -1082,6 +1085,33 @@ std::size_t packSize(const WaterPvtThermal<Scalar>& data,
template std::size_t packSize(const WaterPvtThermal<double>& data,
Dune::MPIHelper::MPICommunicator comm);
template<class Scalar>
std::size_t packSize(const EclEpsScalingPointsInfo<Scalar>& data,
Dune::MPIHelper::MPICommunicator comm)
{
return packSize(data.Swl, comm) +
packSize(data.Sgl, comm) +
packSize(data.Sowl, comm) +
packSize(data.Sogl, comm) +
packSize(data.krCriticalEps, comm) +
packSize(data.Swcr, comm) +
packSize(data.Sgcr, comm) +
packSize(data.Sowcr, comm) +
packSize(data.Sogcr, comm) +
packSize(data.Swu, comm) +
packSize(data.Sgu, comm) +
packSize(data.Sowu, comm) +
packSize(data.Sogu, comm) +
packSize(data.maxPcow, comm) +
packSize(data.maxPcgo, comm) +
packSize(data.pcowLeverettFactor, comm) +
packSize(data.pcgoLeverettFactor, comm) +
packSize(data.maxKrw, comm) +
packSize(data.maxKrow, comm) +
packSize(data.maxKrog, comm) +
packSize(data.maxKrg, comm);
}
std::size_t packSize(const OilVaporizationProperties& data,
Dune::MPIHelper::MPICommunicator comm)
{
@ -3934,6 +3964,33 @@ void pack(const FaultCollection& data,
pack(data.getFaults(), buffer, position, comm);
}
template<class Scalar>
void pack(const EclEpsScalingPointsInfo<Scalar>& data, std::vector<char>& buffer,
int& position, Dune::MPIHelper::MPICommunicator comm)
{
pack(data.Swl, buffer, position, comm);
pack(data.Sgl, buffer, position, comm);
pack(data.Sowl, buffer, position, comm);
pack(data.Sogl, buffer, position, comm);
pack(data.krCriticalEps, buffer, position, comm);
pack(data.Swcr, buffer, position, comm);
pack(data.Sgcr, buffer, position, comm);
pack(data.Sowcr, buffer, position, comm);
pack(data.Sogcr, buffer, position, comm);
pack(data.Swu, buffer, position, comm);
pack(data.Sgu, buffer, position, comm);
pack(data.Sowu, buffer, position, comm);
pack(data.Sogu, buffer, position, comm);
pack(data.maxPcow, buffer, position, comm);
pack(data.maxPcgo, buffer, position, comm);
pack(data.pcowLeverettFactor, buffer, position, comm);
pack(data.pcgoLeverettFactor, buffer, position, comm);
pack(data.maxKrw, buffer, position, comm);
pack(data.maxKrow, buffer, position, comm);
pack(data.maxKrog, buffer, position, comm);
pack(data.maxKrg, buffer, position, comm);
}
/// unpack routines
template<class T>
@ -4131,6 +4188,33 @@ void unpack(DynamicVector<T>& data, std::vector<char>& buffer, int& position,
data = DynamicVector<T>(ddata);
}
template<class Scalar>
void unpack(EclEpsScalingPointsInfo<Scalar>& data, std::vector<char>& buffer,
int& position, Dune::MPIHelper::MPICommunicator comm)
{
unpack(data.Swl, buffer, position, comm);
unpack(data.Sgl, buffer, position, comm);
unpack(data.Sowl, buffer, position, comm);
unpack(data.Sogl, buffer, position, comm);
unpack(data.krCriticalEps, buffer, position, comm);
unpack(data.Swcr, buffer, position, comm);
unpack(data.Sgcr, buffer, position, comm);
unpack(data.Sowcr, buffer, position, comm);
unpack(data.Sogcr, buffer, position, comm);
unpack(data.Swu, buffer, position, comm);
unpack(data.Sgu, buffer, position, comm);
unpack(data.Sowu, buffer, position, comm);
unpack(data.Sogu, buffer, position, comm);
unpack(data.maxPcow, buffer, position, comm);
unpack(data.maxPcgo, buffer, position, comm);
unpack(data.pcowLeverettFactor, buffer, position, comm);
unpack(data.pcgoLeverettFactor, buffer, position, comm);
unpack(data.maxKrw, buffer, position, comm);
unpack(data.maxKrow, buffer, position, comm);
unpack(data.maxKrog, buffer, position, comm);
unpack(data.maxKrg, buffer, position, comm);
}
void unpack(char* str, std::size_t length, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm)
{
@ -6699,8 +6783,10 @@ INSTANTIATE_PACK_VECTOR(double)
INSTANTIATE_PACK_VECTOR(std::vector<double>)
INSTANTIATE_PACK_VECTOR(bool)
INSTANTIATE_PACK_VECTOR(char)
INSTANTIATE_PACK_VECTOR(int)
INSTANTIATE_PACK_VECTOR(Opm::Tabulated1DFunction<double>)
INSTANTIATE_PACK_VECTOR(std::array<double, 3>)
INSTANTIATE_PACK_VECTOR(EclEpsScalingPointsInfo<double>)
#undef INSTANTIATE_PACK_VECTOR
#define INSTANTIATE_PACK_SHARED_PTR(...) \
@ -6736,6 +6822,9 @@ INSTANTIATE_PACK(int)
INSTANTIATE_PACK(std::array<short,3>)
INSTANTIATE_PACK(std::array<bool,3>)
INSTANTIATE_PACK(unsigned char)
INSTANTIATE_PACK(EclEpsScalingPointsInfo<double>)
INSTANTIATE_PACK(EclTwoPhaseApproach)
INSTANTIATE_PACK(EclMultiplexerApproach)
#undef INSTANTIATE_PACK
} // end namespace Mpi

View File

@ -86,6 +86,7 @@ class Dimension;
class EclHysterConfig;
class EclipseConfig;
class Eqldims;
template<class Scalar> struct EclEpsScalingPointsInfo;
class EDITNNC;
class EndpointScaling;
class Equil;
@ -304,6 +305,10 @@ std::size_t packSize(const WaterPvtThermal<Scalar>& data, Dune::MPIHelper::MPICo
template<class T>
std::size_t packSize(const IOrderSet<T>& data, Dune::MPIHelper::MPICommunicator comm);
template<class Scalar>
std::size_t packSize(const EclEpsScalingPointsInfo<Scalar>& data,
Dune::MPIHelper::MPICommunicator comm);
////// pack routines
template<class T>
@ -464,6 +469,10 @@ template<class T>
void pack(const IOrderSet<T>& data, std::vector<char>& buffer,
int& position, Dune::MPIHelper::MPICommunicator comm);
template<class Scalar>
void pack(const EclEpsScalingPointsInfo<Scalar>& data, std::vector<char>& buffer,
int& position, Dune::MPIHelper::MPICommunicator comm);
void pack(const char* str, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);
@ -623,6 +632,10 @@ template<class T>
void unpack(IOrderSet<T>& data, std::vector<char>& buffer,
int& position, Dune::MPIHelper::MPICommunicator comm);
template<class Scalar>
void unpack(EclEpsScalingPointsInfo<Scalar>& data, std::vector<char>& buffer,
int& position, Dune::MPIHelper::MPICommunicator comm);
void unpack(char* str, std::size_t length, std::vector<char>& buffer, int& position,
Dune::MPIHelper::MPICommunicator comm);

View File

@ -25,6 +25,7 @@
#include <boost/test/unit_test.hpp>
#include <opm/common/OpmLog/Location.hpp>
#include <opm/material/fluidmatrixinteractions/EclEpsScalingPoints.hpp>
#include <opm/material/fluidsystems/blackoilpvt/DryGasPvt.hpp>
#include <opm/material/fluidsystems/blackoilpvt/SolventPvt.hpp>
#include <opm/material/fluidsystems/blackoilpvt/WetGasPvt.hpp>
@ -2526,6 +2527,20 @@ BOOST_AUTO_TEST_CASE(FaultCollection)
}
BOOST_AUTO_TEST_CASE(EclEpsScalingPointsInfo)
{
#ifdef HAVE_MPI
Opm::EclEpsScalingPointsInfo<double> val1{ 1.0, 2.0, 3.0, 4.0, 5.0,
6.0, 7.0, 8.0, 9.0, 10.0,
11.0, 12.0, 13.0, 14.0, 15.0,
16.0, 17.0, 18.0, 19.0, 20.0, 21};
auto val2 = PackUnpack(val1);
BOOST_CHECK(std::get<1>(val2) == std::get<2>(val2));
BOOST_CHECK(val1 == std::get<0>(val2));
#endif
}
bool init_unit_test_func()
{
return true;