On MacOS with Homebrew¶
Following the MFEM website, the simplest way to install MFEM on MacOS consists in using the package manager Homebrew (see https://brew.sh for more details):
By default, this MFEM installation depends on hypre, metis, openblas and suite-sparse.
SLOTH only requires a parallel MFEM (MPI, HYPRE, METIS): the Homebrew formula can be used as is.
Adding dependencies to MFEM (optional)
This is not needed by SLOTH, only for your own extensions. It is possible to rebuild MFEM with additional dependencies (see https://formulae.brew.sh/formula/mfem for more details).
Here, let us consider the petsc dependency. Two changes are needed in the formula file mfem.rb:
- Get the formula: run
brew edit mfemto open the defaultmfem.rbfile, or get it from GitHub. - Add the dependency with the
depends_ondirective: - Enable it in the MFEM configuration, by adding the corresponding option to the CMake arguments of the
installblock of the formula:depends_ononly installs the package: without the CMake option, MFEM is built without PETSc. - Save the file and run:
The installation with PETSc can be checked in the installed MFEM configuration:
which must returnYES. Each dependency can be installed easily using Homebrew.
Local formula files
Recent versions of Homebrew may refuse to install a formula from a local file. In that case, create a local tap and install the formula from it:
Once MFEM is installed, SLOTH can be built using the envSloth.sh shell script.
This script loads MFEM, defines several environment variables, and compiles SLOTH.
Build SLOTH using the envSloth.sh shell script
The envSloth.sh shell script cannot be run directly from the root of the SLOTH repository.
Users must create a separate build directory to compile SLOTH.
Installing Sympy
Please ensure that Sympy is installed. Sympy is a mandatory prerequisite to build SLOTH as it is used to handle physical properties.
The Python provided by Homebrew may refuse a global pip install. In that case, install Sympy in a dedicated environment and activate it before building SLOTH, either with a virtual environment:
brew install micromamba
micromamba create -n sloth -c conda-forge python sympy
micromamba activate sloth
envSloth.sh is run.
Once MFEM and Sympy are installed, please run the following commands to build SLOTH:
where [OPTIONS] are:Build type (default: --release):
--release Release, with -march=native
--portable Release without -march=native (generic x86-64 target on x86)
--debug | --coverage | --optim | --minsizerel | --relwithdebinfo
Dependencies:
--mfem=DIR local MFEM build (instead of spack on Linux / Homebrew on macOS)
--exprtk=DIR ExprTk (directory containing exprtk.hpp)
--voro=DIR Voro++ installation prefix
--libtorch=DIR LibTorch installation prefix
--external=EXT_LIBDIR,EXT_LIBNAME
link Sloth with an external library
Other options:
--shared build Sloth as a shared library
--install=DIR installation directory (default: ../SlothInstall)
--np=N number of parallel compilation jobs (default: 4)
-h | --help print this help
Everything after "--" is passed unchanged to CMake, e.g.:
bash ../envSloth.sh --exprtk=../../exprtk -- -DMATOOLS_VERBOSITY_LEVEL_1=ON
bash ../envSloth.sh --help.
By default, this command builds a static library of SLOTH with release compiler options.
Building a shared library of SLOTH
The --shared option enables building a shared library of SLOTH.
However, the user must ensure that the library type used for MFEM is compatible. Certain combinations of static and shared libraries may require specific compiler options, such as -fPIC.
The make command within the envSloth.sh script does not compile the tests. To compile tests after SLOTH has been built, run the following command:
where N is a number of CPUs to use for building the tests in parallel.
Once the tests are compiled, users can verify the build by running all tests with ctest:
Finally, users can install the SLOTH library, headers, and scripts into the SlothInstall directory by running:
Installing SLOTH in user-defined repository
By default, SLOTH is installed in a SlothInstall directory at the same level as the repository.
Users can specify another directory with the --install option of the envSloth.sh script.
Reinstalling after a dependency change
The installed CMake files (SlothInstall/lib/cmake/Sloth/SlothTargets.cmake) keep the link flags of MFEM at the time SLOTH was built. Homebrew may upgrade MFEM or its dependencies automatically (brew upgrade): in that case, SLOTH must be rebuilt and reinstalled from an empty build directory.
To prevent automatic upgrades of MFEM, run brew pin mfem.
Using the installed SLOTH
To build your own programs with the installed SLOTH (find_package(Sloth)) and try the
example provided with the installation, see Using an installed SLOTH in your own project.