From bbe5b7ba5ec3d9aac035aec0757445d88dd9b96f Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 3 Sep 2019 21:49:32 -0500 Subject: [PATCH 1/3] Make sure MPI_Type_free is not called if MPI hasn't been initialized --- src/finalize.cpp | 4 +++- src/message_passing.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/finalize.cpp b/src/finalize.cpp index 120903f3f..7c39a7c19 100644 --- a/src/finalize.cpp +++ b/src/finalize.cpp @@ -127,7 +127,9 @@ int openmc_finalize() // Free all MPI types #ifdef OPENMC_MPI - MPI_Type_free(&mpi::bank); + int init_called; + MPI_Initialized(&init_called); + if (init_called) MPI_Type_free(&mpi::bank); #endif return 0; diff --git a/src/message_passing.cpp b/src/message_passing.cpp index 278bf924d..aea17f9f4 100644 --- a/src/message_passing.cpp +++ b/src/message_passing.cpp @@ -8,8 +8,8 @@ int n_procs {1}; bool master {true}; #ifdef OPENMC_MPI -MPI_Comm intracomm; -MPI_Datatype bank; +MPI_Comm intracomm {MPI_COMM_NULL}; +MPI_Datatype bank {MPI_DATATYPE_NULL}; #endif extern "C" bool openmc_master() { return mpi::master; } From 56322b9b3f57c5eeebfd967dff8dea44834b2dad Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 3 Sep 2019 21:50:16 -0500 Subject: [PATCH 2/3] Make sure capi.init is called with intracomm in tests when MPI is enabled --- tests/unit_tests/conftest.py | 11 +++++++++++ tests/unit_tests/test_capi.py | 8 ++++---- tests/unit_tests/test_complex_cell_capi.py | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/unit_tests/conftest.py b/tests/unit_tests/conftest.py index aa28be9c3..b69ef0b13 100644 --- a/tests/unit_tests/conftest.py +++ b/tests/unit_tests/conftest.py @@ -1,6 +1,17 @@ import openmc import pytest +from tests.regression_tests import config + + +@pytest.fixture(scope='module') +def mpi_intracomm(): + if config['mpi']: + from mpi4py import MPI + return MPI.COMM_WORLD + else: + return None + @pytest.fixture(scope='module') def uo2(): diff --git a/tests/unit_tests/test_capi.py b/tests/unit_tests/test_capi.py index ed0bfd441..c8ad0907c 100644 --- a/tests/unit_tests/test_capi.py +++ b/tests/unit_tests/test_capi.py @@ -50,8 +50,8 @@ def pincell_model(): @pytest.fixture(scope='module') -def capi_init(pincell_model): - openmc.capi.init() +def capi_init(pincell_model, mpi_intracomm): + openmc.capi.init(intracomm=mpi_intracomm) yield openmc.capi.finalize() @@ -408,11 +408,11 @@ def test_mesh(capi_init): assert msf.mesh == mesh -def test_restart(capi_init): +def test_restart(capi_init, mpi_intracomm): # Finalize and re-init to make internal state consistent with XML. openmc.capi.hard_reset() openmc.capi.finalize() - openmc.capi.init() + openmc.capi.init(intracomm=mpi_intracomm) openmc.capi.simulation_init() # Run for 7 batches then write a statepoint. diff --git a/tests/unit_tests/test_complex_cell_capi.py b/tests/unit_tests/test_complex_cell_capi.py index 365ce4808..a76fa6307 100644 --- a/tests/unit_tests/test_complex_cell_capi.py +++ b/tests/unit_tests/test_complex_cell_capi.py @@ -3,7 +3,7 @@ import openmc.capi import pytest @pytest.fixture(autouse=True) -def complex_cell(run_in_tmpdir): +def complex_cell(run_in_tmpdir, mpi_intracomm): openmc.reset_auto_ids() @@ -74,7 +74,7 @@ def complex_cell(run_in_tmpdir): model.export_to_xml() openmc.capi.finalize() - openmc.capi.init() + openmc.capi.init(intracomm=mpi_intracomm) yield From 1134b18cb9c65ea9473cbea40b44a736a9307525 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 3 Sep 2019 22:30:22 -0500 Subject: [PATCH 3/3] Set CMake policy CMP0079 when version >= 3.13 --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d6e62282..381f0cd7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,6 +120,11 @@ target_include_directories(pugixml PUBLIC vendor/pugixml/) # xtensor header-only library #=============================================================================== +# CMake 3.13+ will complain about policy CMP0079 unless it is set explicitly +if (NOT (CMAKE_VERSION VERSION_LESS 3.13)) + cmake_policy(SET CMP0079 NEW) +endif() + add_subdirectory(vendor/xtl) add_subdirectory(vendor/xtensor) target_link_libraries(xtensor INTERFACE xtl)