Skip to content

Commit

Permalink
Tiny updates from experience building on Mac (#2894)
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
  • Loading branch information
gridley and paulromano committed Apr 20, 2024
1 parent 5111aa2 commit b53b601
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 55 deletions.
21 changes: 13 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(openmc C CXX)
project(openmc CXX)

# Set version numbers
set(OPENMC_VERSION_MAJOR 0)
Expand Down Expand Up @@ -80,6 +80,14 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build" FORCE)
endif()

#===============================================================================
# OpenMP for shared-memory parallelism (and GPU support some day!)
#===============================================================================

if(OPENMC_USE_OPENMP)
find_package(OpenMP REQUIRED)
endif()

#===============================================================================
# MPI for distributed-memory parallelism
#===============================================================================
Expand Down Expand Up @@ -192,13 +200,6 @@ endif()
# Skip for Visual Studio which has its own configurations through GUI
if(NOT MSVC)

if(OPENMC_USE_OPENMP)
find_package(OpenMP REQUIRED)
# In CMake 3.9+, can use the OpenMP::OpenMP_CXX imported target
list(APPEND cxxflags ${OpenMP_CXX_FLAGS})
list(APPEND ldflags ${OpenMP_CXX_FLAGS})
endif()

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(OPENMC_ENABLE_PROFILE)
Expand Down Expand Up @@ -522,6 +523,10 @@ if (PNG_FOUND)
target_link_libraries(libopenmc PNG::PNG)
endif()

if (OPENMC_USE_OPENMP)
target_link_libraries(libopenmc OpenMP::OpenMP_CXX)
endif()

if (OPENMC_USE_MPI)
target_link_libraries(libopenmc MPI::MPI_CXX)
endif()
Expand Down
4 changes: 4 additions & 0 deletions cmake/OpenMCConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ if(@OPENMC_USE_MPI@)
find_package(MPI REQUIRED)
endif()

if(@OPENMC_USE_OPENMP@)
find_package(OpenMP REQUIRED)
endif()

if(@OPENMC_USE_MCPL@)
find_package(MCPL REQUIRED)
endif()
63 changes: 43 additions & 20 deletions docs/source/quickinstall.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,31 +107,54 @@ can be used to access the installed packages.
.. _Spack: https://spack.readthedocs.io/en/latest/
.. _setup guide: https://spack.readthedocs.io/en/latest/getting_started.html

--------------------------------
Installing from Source on Ubuntu
--------------------------------
-------------------------------
Manually Installing from Source
-------------------------------

To build OpenMC from source, several :ref:`prerequisites <prerequisites>` are
needed. If you are using Ubuntu or higher, all prerequisites can be installed
directly from the package manager:
Obtaining prerequisites on Ubuntu
---------------------------------

When building OpenMC from source, all :ref:`prerequisites <prerequisites>` can
be installed using the package manager:

.. code-block:: sh
sudo apt install g++ cmake libhdf5-dev libpng-dev
After the packages have been installed, follow the instructions below for
building and installing OpenMC from source.
After the packages have been installed, follow the instructions to build from
source below.

-------------------------------------------
Installing from Source on Linux or Mac OS X
-------------------------------------------
Obtaining prerequisites on macOS
--------------------------------

For an OpenMC build with multithreading enabled, a package manager like
`Homebrew <https://brew.sh>`_ should first be installed. Then, the following
packages should be installed, for example in Homebrew via:

.. code-block:: sh
brew install llvm cmake xtensor hdf5 python libomp libpng
The compiler provided by the above LLVM package should be used in place of the
one provisioned by XCode, which does not support the multithreading library used
by OpenMC. Consequently, the C++ compiler should explicitly be set before
proceeding:

.. code-block:: sh
export CXX=/opt/homebrew/opt/llvm/bin/clang++
After the packages have been installed, follow the instructions to build from
source below.

Building Source on Linux or macOS
---------------------------------

All OpenMC source code is hosted on `GitHub
<https://github.com/openmc-dev/openmc>`_. If you have `git
<https://git-scm.com>`_, the `gcc <https://gcc.gnu.org/>`_ compiler suite,
`CMake <https://cmake.org>`_, and `HDF5
<https://www.hdfgroup.org/solutions/hdf5/>`_ installed, you can download and
install OpenMC be entering the following commands in a terminal:
<https://git-scm.com>`_, a modern C++ compiler, `CMake <https://cmake.org>`_,
and `HDF5 <https://www.hdfgroup.org/solutions/hdf5/>`_ installed, you can
download and install OpenMC by entering the following commands in a terminal:

.. code-block:: sh
Expand All @@ -151,14 +174,14 @@ should specify an installation directory where you have write access, e.g.
cmake -DCMAKE_INSTALL_PREFIX=$HOME/.local ..
The :mod:`openmc` Python package must be installed separately. The easiest way
to install it is using `pip <https://pip.pypa.io/en/stable/>`_, which is
included by default in Python 3.4+. From the root directory of the OpenMC
distribution/repository, run:
to install it is using `pip <https://pip.pypa.io/en/stable/>`_.
From the root directory of the OpenMC repository, run:

.. code-block:: sh
python -m pip install .
If you want to build a parallel version of OpenMC (using OpenMP or MPI),
directions can be found in the :ref:`detailed installation instructions
By default, OpenMC will be built with multithreading support. To build
distributed-memory parallel versions of OpenMC using MPI or to configure other
options, directions can be found in the :ref:`detailed installation instructions
<usersguide_build>`.
8 changes: 4 additions & 4 deletions docs/source/usersguide/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,11 @@ can typically be set for a single command, i.e.
.. _compile_linux:

Compiling on Linux and Mac OS X
-------------------------------
Compiling on Linux and macOS
----------------------------

To compile OpenMC on Linux or Max OS X, run the following commands from within
the root directory of the source code:
To compile OpenMC on Linux or macOS, run the following commands from within the
root directory of the source code:

.. code-block:: sh
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(openmc_sources CXX)
add_library(source SHARED source_ring.cpp)
find_package(OpenMC REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion examples/parameterized_custom_source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(openmc_sources CXX)
add_library(parameterized_source SHARED parameterized_source_ring.cpp)
find_package(OpenMC REQUIRED)
Expand Down
9 changes: 5 additions & 4 deletions openmc/data/multipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,10 +1169,11 @@ def _evaluate(self, E, T):
sqrtE = sqrt(E)
invE = 1.0 / E

# Locate us. The i_window calc omits a + 1 present in F90 because of
# the 1-based vs. 0-based indexing. Similarly startw needs to be
# decreased by 1. endw does not need to be decreased because
# range(startw, endw) does not include endw.
# Locate us. The i_window calc omits a + 1 present from the legacy
# Fortran version of OpenMC because of the 1-based vs. 0-based
# indexing. Similarly startw needs to be decreased by 1. endw does
# not need to be decreased because range(startw, endw) does not include
# endw.
i_window = min(self.n_windows - 1,
int(np.floor((sqrtE - sqrt(self.E_min)) / self.spacing)))
startw = self.windows[i_window, 0] - 1
Expand Down
2 changes: 1 addition & 1 deletion openmc/mgxs/mdgxs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'delayed-nu-fission matrix'
)

# Maximum number of delayed groups, from src/constants.F90
# Maximum number of delayed groups, from include/openmc/constants.h
MAX_DELAYED_GROUPS = 8


Expand Down
27 changes: 17 additions & 10 deletions src/nuclide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,16 +634,23 @@ void Nuclide::calculate_xs(
}
}

// Ensure these values are set
// Note, the only time either is used is in one of 4 places:
// 1. physics.cpp - scatter - For inelastic scatter.
// 2. physics.cpp - sample_fission - For partial fissions.
// 3. tally.F90 - score_general - For tallying on MTxxx reactions.
// 4. nuclide.cpp - calculate_urr_xs - For unresolved purposes.
// It is worth noting that none of these occur in the resolved
// resonance range, so the value here does not matter. index_temp is
// set to -1 to force a segfault in case a developer messes up and tries
// to use it with multipole.
/*
* index_temp, index_grid, and interp_factor are used only in the
* following places:
* 1. physics.cpp - scatter - For inelastic scatter.
* 2. physics.cpp - sample_fission - For partial fissions.
* 3. tallies/tally_scoring.cpp - score_general -
* For tallying on MTxxx reactions.
* 4. nuclide.cpp - calculate_urr_xs - For unresolved purposes.
* It is worth noting that none of these occur in the resolved resonance
* range, so the value here does not matter. index_temp is set to -1 to
* force a segfault in case a developer messes up and tries to use it with
* multipole.
*
* However, a segfault is not necessarily guaranteed with an out-of-bounds
* access, so this technique should be replaced by something more robust
* in the future.
*/
micro.index_temp = -1;
micro.index_grid = -1;
micro.interp_factor = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion src/tallies/filter_energy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <fmt/core.h>

#include "openmc/capi.h"
#include "openmc/constants.h" // For F90_NONE
#include "openmc/constants.h" // For C_NONE
#include "openmc/mgxs_interface.h"
#include "openmc/search.h"
#include "openmc/settings.h"
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/cpp_driver/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def cpp_driver(request):
openmc_dir = Path(str(request.config.rootdir)) / 'build'
with open('CMakeLists.txt', 'w') as f:
f.write(textwrap.dedent("""
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(openmc_cpp_driver CXX)
add_executable(cpp_driver driver.cpp)
find_package(OpenMC REQUIRED HINTS {})
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/dagmc/external/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def cpp_driver(request):
openmc_dir = Path(str(request.config.rootdir)) / 'build'
with open('CMakeLists.txt', 'w') as f:
f.write(textwrap.dedent("""
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(openmc_cpp_driver CXX)
add_executable(main main.cpp)
find_package(OpenMC REQUIRED HINTS {})
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/external_moab/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def cpp_driver(request):
openmc_dir = Path(str(request.config.rootdir)) / 'build'
with open('CMakeLists.txt', 'w') as f:
f.write(textwrap.dedent("""
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(openmc_cpp_driver CXX)
add_executable(main main.cpp)
find_package(OpenMC REQUIRED HINTS {})
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/source_dlopen/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def compile_source(request):
openmc_dir = Path(str(request.config.rootdir)) / 'build'
with open('CMakeLists.txt', 'w') as f:
f.write(textwrap.dedent("""
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(openmc_sources CXX)
add_library(source SHARED source_sampling.cpp)
find_package(OpenMC REQUIRED HINTS {})
Expand Down
2 changes: 1 addition & 1 deletion tests/regression_tests/source_parameterized_dlopen/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def compile_source(request):
openmc_dir = Path(str(request.config.rootdir)) / 'build'
with open('CMakeLists.txt', 'w') as f:
f.write(textwrap.dedent("""
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(openmc_sources CXX)
add_library(source SHARED parameterized_source_sampling.cpp)
find_package(OpenMC REQUIRED HINTS {})
Expand Down

0 comments on commit b53b601

Please sign in to comment.