only allocate trans_ for globalTrans_

others are not needed for globalTrans_ for now. It will help to flatten
the peak memory usage for rank 0 during a parallel running.
This commit is contained in:
Kai Bao 2024-06-04 11:25:24 +02:00
parent 4cf8a50b26
commit 303a677a81
5 changed files with 31 additions and 17 deletions

View File

@ -190,7 +190,7 @@ public:
getPropValue<TypeTag, getPropValue<TypeTag,
Properties::EnableDispersion>()); Properties::EnableDispersion>());
// Re-ordering for ALUGrid // Re-ordering for ALUGrid
globalTrans_->update(false, [&](unsigned int i) { return gridEquilIdxToGridIdx(i);}); globalTrans_->update(false, true, [&](unsigned int i) { return gridEquilIdxToGridIdx(i);});
} }
} }
@ -351,6 +351,10 @@ protected:
std::unique_ptr<CartesianIndexMapper> cartesianIndexMapper_; std::unique_ptr<CartesianIndexMapper> cartesianIndexMapper_;
std::unique_ptr<EquilCartesianIndexMapper> equilCartesianIndexMapper_; std::unique_ptr<EquilCartesianIndexMapper> equilCartesianIndexMapper_;
std::unique_ptr<Factory> factory_; std::unique_ptr<Factory> factory_;
// \Note: this globalTrans_ is used for domain decomposition and INIT file output.
// It only contains trans_ due to permeability and does not contain thermalHalfTrans_,
// diffusivity_ abd dispersivity_. The main reason is to reduce the memory usage for rank 0
// during parallel running.
std::unique_ptr<TransmissibilityType> globalTrans_; std::unique_ptr<TransmissibilityType> globalTrans_;
int mpiRank; int mpiRank;
}; };

View File

@ -285,7 +285,7 @@ protected:
getPropValue<TypeTag, Properties::EnableEnergy>(), getPropValue<TypeTag, Properties::EnableEnergy>(),
getPropValue<TypeTag, Properties::EnableDiffusion>(), getPropValue<TypeTag, Properties::EnableDiffusion>(),
getPropValue<TypeTag, Properties::EnableDispersion>())); getPropValue<TypeTag, Properties::EnableDispersion>()));
globalTrans_->update(false); globalTrans_->update(false, true);
} }
double getTransmissibility(unsigned I, unsigned J) const override double getTransmissibility(unsigned I, unsigned J) const override
@ -306,6 +306,10 @@ protected:
this->doFilterConnections_(this->schedule()); this->doFilterConnections_(this->schedule());
} }
// \Note: this globalTrans_ is used for domain decomposition and INIT file output.
// It only contains trans_ due to permeability and does not contain thermalHalfTrans_,
// diffusivity_ abd dispersivity_. The main reason is to reduce the memory usage for rank 0
// during parallel running.
std::unique_ptr<TransmissibilityType> globalTrans_; std::unique_ptr<TransmissibilityType> globalTrans_;
}; };

View File

@ -538,7 +538,7 @@ public:
}; };
// re-compute all quantities which may possibly be affected. // re-compute all quantities which may possibly be affected.
transmissibilities_.update(true, equilGridToGrid); transmissibilities_.update(true, false, equilGridToGrid);
this->referencePorosity_[1] = this->referencePorosity_[0]; this->referencePorosity_[1] = this->referencePorosity_[0];
updateReferencePorosity_(); updateReferencePorosity_();
updatePffDofData_(); updatePffDofData_();
@ -701,7 +701,7 @@ public:
[this](const bool global) [this](const bool global)
{ {
this->transmissibilities_ this->transmissibilities_
.update(global, [&vg = this->simulator().vanguard()] .update(global, false, [&vg = this->simulator().vanguard()]
(const unsigned int i) (const unsigned int i)
{ {
return vg.gridIdxToEquilGridIdx(i); return vg.gridIdxToEquilGridIdx(i);

View File

@ -128,7 +128,7 @@ public:
*/ */
void finishInit(const std::function<unsigned int(unsigned int)>& map = {}) void finishInit(const std::function<unsigned int(unsigned int)>& map = {})
{ {
this->update(true, map, /*applyNncMultRegT = */ true); this->update(true, false, map, /*applyNncMultRegT = */ true);
} }
/*! /*!
@ -138,6 +138,11 @@ public:
* processes. Also, this updates the "thermal half * processes. Also, this updates the "thermal half
* transmissibilities" if energy is enabled. * transmissibilities" if energy is enabled.
* *
* \param[in] onlyTrans Whether we only allocate and upate trans_ without considering
* thermalHalfTrans_, diffusivity_, dispersivity_. For many usage, we only need trans_,
* e.g. weights for domain decomposition, INIT file output. It might change following
* further development.
*
* \param[in] map Undocumented. * \param[in] map Undocumented.
* *
* \param[in] applyNncMultRegT Whether or not to apply regional * \param[in] applyNncMultRegT Whether or not to apply regional
@ -147,7 +152,7 @@ public:
* numerical aquifers. Default value: \c false, meaning do not apply * numerical aquifers. Default value: \c false, meaning do not apply
* regional multipliers to explicit NNCs. * regional multipliers to explicit NNCs.
*/ */
void update(bool global, const std::function<unsigned int(unsigned int)>& map = {}, bool applyNncMultRegT = false); void update(bool global, bool onlyTrans = false, const std::function<unsigned int(unsigned int)>& map = {}, bool applyNncMultRegT = false);
protected: protected:
void updateFromEclState_(bool global); void updateFromEclState_(bool global);

View File

@ -159,7 +159,8 @@ dispersivity(unsigned elemIdx1, unsigned elemIdx2) const
template<class Grid, class GridView, class ElementMapper, class CartesianIndexMapper, class Scalar> template<class Grid, class GridView, class ElementMapper, class CartesianIndexMapper, class Scalar>
void Transmissibility<Grid,GridView,ElementMapper,CartesianIndexMapper,Scalar>:: void Transmissibility<Grid,GridView,ElementMapper,CartesianIndexMapper,Scalar>::
update(bool global, const std::function<unsigned int(unsigned int)>& map, const bool applyNncMultregT) update(bool global, const bool onlyTrans,
const std::function<unsigned int(unsigned int)>& map, const bool applyNncMultregT)
{ {
const auto& cartDims = cartMapper_.cartesianDimensions(); const auto& cartDims = cartMapper_.cartesianDimensions();
const auto& transMult = eclState_.getTransMult(); const auto& transMult = eclState_.getTransMult();
@ -208,7 +209,7 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
transBoundary_.clear(); transBoundary_.clear();
// if energy is enabled, let's do the same for the "thermal half transmissibilities" // if energy is enabled, let's do the same for the "thermal half transmissibilities"
if (enableEnergy_) { if (enableEnergy_ && !onlyTrans) {
thermalHalfTrans_.clear(); thermalHalfTrans_.clear();
thermalHalfTrans_.reserve(numElements*6*1.05); thermalHalfTrans_.reserve(numElements*6*1.05);
@ -216,14 +217,14 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
} }
// if diffusion is enabled, let's do the same for the "diffusivity" // if diffusion is enabled, let's do the same for the "diffusivity"
if (updateDiffusivity) { if (updateDiffusivity && !onlyTrans) {
diffusivity_.clear(); diffusivity_.clear();
diffusivity_.reserve(numElements*3*1.05); diffusivity_.reserve(numElements*3*1.05);
extractPorosity_(); extractPorosity_();
} }
// if dispersion is enabled, let's do the same for the "dispersivity" // if dispersion is enabled, let's do the same for the "dispersivity"
if (updateDispersivity) { if (updateDispersivity && !onlyTrans) {
dispersivity_.clear(); dispersivity_.clear();
dispersivity_.reserve(numElements*3*1.05); dispersivity_.reserve(numElements*3*1.05);
extractDispersion_(); extractDispersion_();
@ -283,7 +284,7 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
// for boundary intersections we also need to compute the thermal // for boundary intersections we also need to compute the thermal
// half transmissibilities // half transmissibilities
if (enableEnergy_) { if (enableEnergy_ && !onlyTrans) {
Scalar transBoundaryEnergyIs; Scalar transBoundaryEnergyIs;
computeHalfDiffusivity_(transBoundaryEnergyIs, computeHalfDiffusivity_(transBoundaryEnergyIs,
faceAreaNormal, faceAreaNormal,
@ -334,15 +335,15 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
// *added to* by applyNncToGridTrans_() later. // *added to* by applyNncToGridTrans_() later.
assert(outsideFaceIdx == -1); assert(outsideFaceIdx == -1);
trans_[details::isId(elemIdx, outsideElemIdx)] = 0.0; trans_[details::isId(elemIdx, outsideElemIdx)] = 0.0;
if (enableEnergy_){ if (enableEnergy_ && !onlyTrans){
thermalHalfTrans_[details::directionalIsId(elemIdx, outsideElemIdx)] = 0.0; thermalHalfTrans_[details::directionalIsId(elemIdx, outsideElemIdx)] = 0.0;
thermalHalfTrans_[details::directionalIsId(outsideElemIdx, elemIdx)] = 0.0; thermalHalfTrans_[details::directionalIsId(outsideElemIdx, elemIdx)] = 0.0;
} }
if (updateDiffusivity) { if (updateDiffusivity && !onlyTrans) {
diffusivity_[details::isId(elemIdx, outsideElemIdx)] = 0.0; diffusivity_[details::isId(elemIdx, outsideElemIdx)] = 0.0;
} }
if (updateDispersivity) { if (updateDispersivity && !onlyTrans) {
dispersivity_[details::isId(elemIdx, outsideElemIdx)] = 0.0; dispersivity_[details::isId(elemIdx, outsideElemIdx)] = 0.0;
} }
continue; continue;
@ -459,7 +460,7 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
trans_[details::isId(elemIdx, outsideElemIdx)] = trans; trans_[details::isId(elemIdx, outsideElemIdx)] = trans;
// update the "thermal half transmissibility" for the intersection // update the "thermal half transmissibility" for the intersection
if (enableEnergy_) { if (enableEnergy_ && !onlyTrans) {
Scalar halfDiffusivity1; Scalar halfDiffusivity1;
Scalar halfDiffusivity2; Scalar halfDiffusivity2;
@ -484,7 +485,7 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
} }
// update the "diffusive half transmissibility" for the intersection // update the "diffusive half transmissibility" for the intersection
if (updateDiffusivity) { if (updateDiffusivity && !onlyTrans) {
Scalar halfDiffusivity1; Scalar halfDiffusivity1;
Scalar halfDiffusivity2; Scalar halfDiffusivity2;
@ -520,7 +521,7 @@ update(bool global, const std::function<unsigned int(unsigned int)>& map, const
} }
// update the "dispersivity half transmissibility" for the intersection // update the "dispersivity half transmissibility" for the intersection
if (updateDispersivity) { if (updateDispersivity && !onlyTrans) {
Scalar halfDispersivity1; Scalar halfDispersivity1;
Scalar halfDispersivity2; Scalar halfDispersivity2;