From c7c29483e740c9b12475a977e02d70bc265e6cbd Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Tue, 11 May 2021 14:48:50 +0200 Subject: [PATCH] fix regression: unconditional dereferences equilGrid and equilCartesianMapper can only be dereferenced on rank 0. --- ebos/collecttoiorank.cc | 14 +++++++------- ebos/collecttoiorank.hh | 4 ++-- ebos/eclwriter.hh | 6 ++++-- tests/test_ecl_output.cc | 4 ++-- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ebos/collecttoiorank.cc b/ebos/collecttoiorank.cc index b2c73fcdc..bc5c5ac23 100644 --- a/ebos/collecttoiorank.cc +++ b/ebos/collecttoiorank.cc @@ -667,10 +667,10 @@ private: template CollectDataToIORank:: -CollectDataToIORank(const Grid& grid, const EquilGrid& equilGrid, +CollectDataToIORank(const Grid& grid, const EquilGrid* equilGrid, const GridView& localGridView, const Dune::CartesianIndexMapper& cartMapper, - const Dune::CartesianIndexMapper& equilCartMapper) + const Dune::CartesianIndexMapper* equilCartMapper) : toIORankComm_() { // index maps only have to be build when reordering is needed @@ -701,9 +701,9 @@ CollectDataToIORank(const Grid& grid, const EquilGrid& equilGrid, // We need a mapping from local to global grid, here we // use equilGrid which represents a view on the global grid // reserve memory - const size_t globalSize = equilGrid.leafGridView().size(0); + const size_t globalSize = equilGrid->leafGridView().size(0); globalCartesianIndex_.resize(globalSize, -1); - const EquilGridView equilGridView = equilGrid.leafGridView(); + const EquilGridView equilGridView = equilGrid->leafGridView(); using EquilElementMapper = Dune::MultipleCodimMultipleGeomTypeMapper; EquilElementMapper equilElemMapper(equilGridView, Dune::mcmgElementLayout()); @@ -713,11 +713,11 @@ CollectDataToIORank(const Grid& grid, const EquilGrid& equilGrid, grid.scatterData(handle); // loop over all elements (global grid) and store Cartesian index - auto elemIt = equilGrid.leafGridView().template begin<0>(); - const auto& elemEndIt = equilGrid.leafGridView().template end<0>(); + auto elemIt = equilGrid->leafGridView().template begin<0>(); + const auto& elemEndIt = equilGrid->leafGridView().template end<0>(); for (; elemIt != elemEndIt; ++elemIt) { int elemIdx = equilElemMapper.index(*elemIt); - int cartElemIdx = equilCartMapper.cartesianIndex(elemIdx); + int cartElemIdx = equilCartMapper->cartesianIndex(elemIdx); globalCartesianIndex_[elemIdx] = cartElemIdx; } diff --git a/ebos/collecttoiorank.hh b/ebos/collecttoiorank.hh index a74139e86..cb138cd0c 100644 --- a/ebos/collecttoiorank.hh +++ b/ebos/collecttoiorank.hh @@ -58,10 +58,10 @@ public: !std::is_same::value; CollectDataToIORank(const Grid& grid, - const EquilGrid& equilGrid, + const EquilGrid* equilGrid, const GridView& gridView, const Dune::CartesianIndexMapper& cartMapper, - const Dune::CartesianIndexMapper& equilCartMapper); + const Dune::CartesianIndexMapper* equilCartMapper); // gather solution to rank 0 for EclipseWriter void collect(const Opm::data::Solution& localCellData, diff --git a/ebos/eclwriter.hh b/ebos/eclwriter.hh index 05061d158..2d3f765b2 100644 --- a/ebos/eclwriter.hh +++ b/ebos/eclwriter.hh @@ -191,10 +191,12 @@ public: EclWriter(Simulator& simulator) : simulator_(simulator) , collectToIORank_(simulator_.vanguard().grid(), - simulator_.vanguard().equilGrid(), + simulator_.vanguard().grid().comm().rank() == 0 ? + &simulator_.vanguard().equilGrid() : nullptr, simulator_.vanguard().gridView(), simulator_.vanguard().cartesianIndexMapper(), - simulator_.vanguard().equilCartesianIndexMapper()) + simulator_.vanguard().grid().comm().rank() == 0 ? + &simulator_.vanguard().equilCartesianIndexMapper() : nullptr) { std::vector wbp_index_list; diff --git a/tests/test_ecl_output.cc b/tests/test_ecl_output.cc index 873765961..17a3cc474 100644 --- a/tests/test_ecl_output.cc +++ b/tests/test_ecl_output.cc @@ -151,10 +151,10 @@ BOOST_AUTO_TEST_CASE(Summary) using GridView = Opm::GetPropType; using CollectDataToIORankType = Opm::CollectDataToIORank; CollectDataToIORankType collectToIORank(simulator->vanguard().grid(), - simulator->vanguard().equilGrid(), + &simulator->vanguard().equilGrid(), simulator->vanguard().gridView(), simulator->vanguard().cartesianIndexMapper(), - simulator->vanguard().equilCartesianIndexMapper()); + &simulator->vanguard().equilCartesianIndexMapper()); Opm::EclOutputBlackOilModule eclOutputModule(*simulator, {}, collectToIORank); typedef Opm::EclWriter EclWriterType;