-
Notifications
You must be signed in to change notification settings - Fork 616
Compiling FDS with GNU Fortran on Apple (M1 & M2) macOS
This wiki describes building FDS natively on the new Apple M1 and M2 chips on macOS. The process is actually a bit simpler than x86, as we cannot compile open-mpi and MKL. So, we opt to install the open-mpi binaries from Homebrew and omit MKL (hence, the code will currently not work with GEOM, since this requires the ULMAT pressure solver based on MKL libraries from Intel).
Navigate to the Homebrew website https://brew.sh and follow install instructions.
In your command window type:
$ brew update
$ brew install gcc
$ brew install openmpi
Make the open-mpi directories available to your environment by adding to your ~/.zprofile
(if using zsh) or ~/.bash_profile
(if using bash) startup file:
# MPI Library:
export MPIDIST=/opt/homebrew/Cellar/open-mpi/5.0.3
export PATH=$MPIDIST/bin:$PATH
export LD_LIBRARY_PATH=$MPIDIST/lib:$LD_LIBRARY_PATH
Finally, either log out and log in, or open a new terminal to apply your environment changes. Check you are locating these executables.
$ which mpirun
/opt/homebrew/Cellar/open-mpi/5.0.3/bin/mpirun
This should show where your open-mpi executables (mpifort
, mpicc
compiler wrappers, mpirun
, etc.) are located.
Also, make sure mpifort
points to gfortran
installed via Homebrew.
$ mpifort -v
Using built-in specs.
COLLECT_GCC=/opt/homebrew/bin/gfortran
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc/13.2.0/bin/../libexec/gcc/aarch64-apple-darwin23/13/lto-wrapper
Target: aarch64-apple-darwin23
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc --libdir=/opt/homebrew/opt/gcc/lib/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-13 --with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr --with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl --with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 13.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --with-system-zlib --build=aarch64-apple-darwin23 --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.0 (Homebrew GCC 13.2.0)
To run finite-rate chemistry using the CVODE solver you need to install Sundials from Lawrence Livermore National Laboratory.
$ brew install llvm
$ brew install cmake
Step 2: Download the sundials-6.7.0.tar.gz file (currently this is the only version that is supported in FDS) and unzip it in a local directory in your user account, <path-to-sundials>
.
$ cd <path-to-sundials>/sundials-6.7.0
$ mkdir BUILDDIR
$ mkdir INSTDIR
$ cd BUILDDIR
Next, copy the following to a text file and replace <path-to-sundials>
with the full path of the Sundials parent directory. Then copy it back to your terminal and hit enter
.
$ cmake ../ \
-DCMAKE_INSTALL_PREFIX=<path-to-sundials>/sundials-6.7.0/INSTDIR \
-DEXAMPLES_INSTALL_PATH=<path-to-sundials>/sundials-6.7.0/INSTDIR/examples \
-DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang \
-DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ \
-DBUILD_FORTRAN_MODULE_INTERFACE=ON \
-DEXAMPLES_ENABLE_CXX=ON \
-DEXAMPLES_ENABLE_CUDA=OFF \
-DEXAMPLES_ENABLE_F2003=ON \
-DENABLE_OPENMP=ON
Finally, make
and make install
.
$ make
$ make install
# Sundials:
export SUNDIALS_HOME=<path-to-sundials>/sundials-6.7.0/INSTDIR
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<path-to-sundials>/sundials-6.7.0/INSTDIR/lib
Go to your updated repo for FDS. You should be able to build the ompi_gnu_osx
, ompi_gnu_osx_dv
, and ompi_gnu_osx_db
targets by typing, for example,
$ cd Build/ompi_gnu_osx_db
$ ./make_fds.sh
If you have multiple meshes, it is most efficient to use MPI to run the job in parallel. First, determine how many cores are available: Click the Apple icon in the upper left of your Desktop and go to About This Mac
, then More info...
, then System Report...
at the bottom. My MacBook has 4 "performance" cores. Cd to the fds/Verification/
directory and run the case dancing_eddies_default.fds
, which has four (4) meshes.
$ mpirun -n 4 /Users/rmcdermo/GitHub/firemodels/fds/Build/ompi_gnu_osx/fds_ompi_gnu_osx dancing_eddies_default.fds
Starting FDS ...
MPI Process 0 started on PN122745
MPI Process 3 started on PN122745
MPI Process 2 started on PN122745
MPI Process 1 started on PN122745
Reading FDS input file ...
Fire Dynamics Simulator
Current Date : January 8, 2024 13:48:02
Revision : FDS-6.8.0-1179-gb478c5d-master
Revision Date : Mon Jan 8 13:12:13 2024 -0500
Compiler : Gnu gfortran GCC
Compilation Date : Jan 08, 2024 13:45:47
Number of MPI Processes: 4
MPI version: 3.1
MPI library version: Open MPI v5.0.1, package: Open MPI [email protected] Distribution, ident: 5.0.1, repo rev: v5.0.1, Dec 20, 2023
Job TITLE : Simple 2D Tunnel
Job ID string : dancing_eddies_default
Time Step: 1, Simulation Time: 0.004 s
Time Step: 2, Simulation Time: 0.008 s
Time Step: 3, Simulation Time: 0.01 s
Time Step: 4, Simulation Time: 0.02 s
...
Time Step: 4600, Simulation Time: 1.98 s
Time Step: 4679, Simulation Time: 2.00 s
STOP: FDS completed successfully (CHID: dancing_eddies_default)