From a4fd6c9ca3dbab0fc5019a30fd96435acd8572da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Fri, 20 Mar 2026 05:09:00 +0100 Subject: [PATCH 1/2] Add HAVE_ZOLTAN guards to allow building without Zoltan Several source files use Zoltan types (ZOLTAN_ID_PTR, Zoltan_Struct) and functions guarded only by #if HAVE_MPI. When Zoltan is not available, these cause compilation failures. Add #if HAVE_ZOLTAN guards to: - GraphOfGridWrappers.hpp: Zoltan callback declarations and Zoltan-specific partitioning function declarations - GraphOfGridWrappers.cpp: Corresponding implementations - test_graphofgrid.cpp: Test cases that call Zoltan functions Non-Zoltan functions (well handling, import/export list management) remain available under #if HAVE_MPI. --- opm/grid/GraphOfGridWrappers.cpp | 10 ++++++++-- opm/grid/GraphOfGridWrappers.hpp | 10 ++++++++-- tests/test_graphofgrid.cpp | 8 ++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/opm/grid/GraphOfGridWrappers.cpp b/opm/grid/GraphOfGridWrappers.cpp index 34e540df6..ebe835034 100644 --- a/opm/grid/GraphOfGridWrappers.cpp +++ b/opm/grid/GraphOfGridWrappers.cpp @@ -27,11 +27,13 @@ #include "GraphOfGridWrappers.hpp" #include #include // function scatterExportInformation +#if HAVE_ZOLTAN #include // makeImportAndExportLists when allowDistributedWells==true +#endif namespace Opm { -#if HAVE_MPI +#if HAVE_MPI && HAVE_ZOLTAN int getGraphOfGridNumVertices(void* pGraph, int *err) { const GraphOfGrid& gog = *static_cast*>(pGraph); @@ -152,7 +154,7 @@ void setGraphOfGridZoltanGraphFunctions(Zoltan_Struct *zz, Zoltan_Set_Edge_List_Multi_Fn(zz, getGraphOfGridEdgeList, pGraph); } } -#endif // HAVE_MPI +#endif // HAVE_MPI && HAVE_ZOLTAN void addFutureConnectionWells(GraphOfGrid& gog, const std::unordered_map>& wells, @@ -491,6 +493,7 @@ makeImportAndExportLists(const GraphOfGrid& gog, std::move(myImportList) ); } +#if HAVE_ZOLTAN namespace { void setDefaultZoltanParameters(Zoltan_Struct* zz) { @@ -653,6 +656,7 @@ zoltanPartitioningWithGraphOfGrid(const Dune::CpGrid& grid, return importExportLists; } +#endif // HAVE_ZOLTAN std::vector > makeExportListsFromGIDtoRank(const std::vector& gIDtoRank, int ccsize) @@ -669,6 +673,7 @@ makeExportListsFromGIDtoRank(const std::vector& gIDtoRank, int ccsize) return exportedCells; } +#if HAVE_ZOLTAN namespace { std::tuple> applySerialZoltan (const Dune::CpGrid& grid, @@ -849,6 +854,7 @@ zoltanSerialPartitioningWithGraphOfGrid(const Dune::CpGrid& grid, std::move(myImportList), std::move(wellConnections)); } +#endif // HAVE_ZOLTAN #endif // HAVE_MPI // explicit template instantiations diff --git a/opm/grid/GraphOfGridWrappers.hpp b/opm/grid/GraphOfGridWrappers.hpp index 8e4d9c729..d3911ee96 100644 --- a/opm/grid/GraphOfGridWrappers.hpp +++ b/opm/grid/GraphOfGridWrappers.hpp @@ -30,7 +30,9 @@ #include #include +#if HAVE_ZOLTAN #include // defines Zoltan and null-callback-functions +#endif namespace Opm { /* @@ -40,7 +42,7 @@ namespace Opm { Additionally, parsing wells is done here. */ -#if HAVE_MPI +#if HAVE_MPI && HAVE_ZOLTAN /// \brief callback function for ZOLTAN_NUM_OBJ_FN /// /// returns the number of vertices in the graph @@ -97,7 +99,7 @@ template void setGraphOfGridZoltanGraphFunctions(Zoltan_Struct *zz, GraphOfGrid& gog, bool pretendNull); -#endif +#endif // HAVE_MPI && HAVE_ZOLTAN /// \brief Adds well to the GraphOfGrid /// @@ -217,6 +219,7 @@ wellsOnThisRank(const std::vector& wells, const Dune::cpgrid::CpGridDataTraits::Communication& cc, int root); +#if HAVE_ZOLTAN /// \brief Transform Zoltan output into tuples /// /// \param gog GraphOfGrid, has ref. to CpGrid and knows how well-cells were contracted @@ -273,6 +276,7 @@ zoltanPartitioningWithGraphOfGrid(const Dune::CpGrid& grid, bool allowDistributedWells, const std::map& params, int level); +#endif // HAVE_ZOLTAN /// \brief Make complete export lists from a vector holding destination rank for each global ID /// @@ -284,6 +288,7 @@ zoltanPartitioningWithGraphOfGrid(const Dune::CpGrid& grid, std::vector > makeExportListsFromGIDtoRank(const std::vector& gIDtoRank, int ccsize); +#if HAVE_ZOLTAN /// \brief Call serial Zoltan partitioner on GraphOfGrid /// /// GraphOfGrid represents a well by one vertex, so wells can not be @@ -302,6 +307,7 @@ zoltanSerialPartitioningWithGraphOfGrid(const Dune::CpGrid& grid, const double zoltanImbalanceTol, bool allowDistributedWells, const std::map& params); +#endif // HAVE_ZOLTAN #endif // HAVE_MPI } // end namespace Opm diff --git a/tests/test_graphofgrid.cpp b/tests/test_graphofgrid.cpp index e6520bbba..f0f1f6e51 100644 --- a/tests/test_graphofgrid.cpp +++ b/tests/test_graphofgrid.cpp @@ -304,7 +304,7 @@ BOOST_AUTO_TEST_CASE(SimpleGraphWithInactiveCells) } #endif -#if HAVE_MPI +#if HAVE_MPI && HAVE_ZOLTAN BOOST_AUTO_TEST_CASE(WrapperForZoltan) { Dune::CpGrid grid; @@ -535,7 +535,7 @@ BOOST_AUTO_TEST_CASE(IntersectingWells) BOOST_REQUIRE( *wellList.rbegin()==well1 ); } } -#endif // HAVE_MPI +#endif // HAVE_MPI && HAVE_ZOLTAN BOOST_AUTO_TEST_CASE(WellWithBuffers) { @@ -665,7 +665,7 @@ namespace { } // end anonymous namespace #endif -#if HAVE_MPI && HAVE_OPM_COMMON +#if HAVE_MPI && HAVE_OPM_COMMON && HAVE_ZOLTAN // Create yet another small grid with wells and test graph properties. // This time wells are supplied via OpmWellType interface BOOST_AUTO_TEST_CASE(addWellConnections) @@ -774,7 +774,7 @@ BOOST_AUTO_TEST_CASE(addWellConnections) } } -#endif // HAVE_MPI && HAVE_OPM_COMMON +#endif // HAVE_MPI && HAVE_OPM_COMMON && HAVE_ZOLTAN #if HAVE_OPM_COMMON BOOST_AUTO_TEST_CASE(gIDtoRankCorrection) From f384cd3267c844702d74773280b5b71d65777265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Fri, 20 Mar 2026 05:09:11 +0100 Subject: [PATCH 2/2] Move CombinedGridWellGraph constructor out of HAVE_ZOLTAN guard CombinedGridWellGraph is used by the vanilla/simple partitioner (via createListsFromParts -> makeImportAndExportLists -> postProcessPartitioningForWells) regardless of whether Zoltan is available. Its constructor was inside #if HAVE_ZOLTAN, causing a linker error without Zoltan and a SIGSEGV when falling through to the simple partitioner with a null gridAndWells pointer. Move the constructor to a #if HAVE_MPI block and the required includes (OpmWellType.hpp, ZoltanGraphFunctions.hpp) outside the Zoltan guard. Zoltan-specific functions (setCpGridZoltanGraphFunctions, etc.) remain under #if defined(HAVE_ZOLTAN) && defined(HAVE_MPI). --- opm/grid/common/ZoltanGraphFunctions.cpp | 27 +++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/opm/grid/common/ZoltanGraphFunctions.cpp b/opm/grid/common/ZoltanGraphFunctions.cpp index fdcd5384a..5e00210f2 100644 --- a/opm/grid/common/ZoltanGraphFunctions.cpp +++ b/opm/grid/common/ZoltanGraphFunctions.cpp @@ -23,11 +23,10 @@ #endif #include - -#if defined(HAVE_ZOLTAN) && defined(HAVE_MPI) #include - #include + +#if defined(HAVE_ZOLTAN) && defined(HAVE_MPI) #include namespace Dune @@ -340,6 +339,18 @@ void getCpGridWellsEdgeList(void *graphPointer, int sizeGID, int sizeLID, #endif } +} // end namespace cpgrid +} // end namespace Dune +#endif // defined(HAVE_ZOLTAN) && defined(HAVE_MPI) + +// CombinedGridWellGraph is used by non-Zoltan partitioners too (e.g. vanilla), +// so its implementation must be available even without Zoltan. +#if HAVE_MPI +namespace Dune +{ +namespace cpgrid +{ + CombinedGridWellGraph::CombinedGridWellGraph(const CpGrid& grid, const std::vector * wells, const std::unordered_map>& possibleFutureConnections, @@ -370,6 +381,16 @@ CombinedGridWellGraph::CombinedGridWellGraph(const CpGrid& grid, findMaxMinTrans(); } +} // end namespace cpgrid +} // end namespace Dune +#endif // HAVE_MPI + +#if defined(HAVE_ZOLTAN) && defined(HAVE_MPI) +namespace Dune +{ +namespace cpgrid +{ + void setCpGridZoltanGraphFunctions(Zoltan_Struct *zz, const Dune::CpGrid& grid, bool pretendNull) {