Closed mkavulich closed 2 years ago
There are a couple of steps to build the srweather-app, with first one is to build the hpc-stack library collection, and the next one is to build the srweather-app.
Steps to build the hpc-stack libraries on MacOS x86_64 or M1 /arm64 are listed below. The documentation for the HPC-stack build is currently being updated.
The following two options shown below have been tested; an example below is for the bash shell environment in the Terminal.app. Option 1: MacBookAir 2020, M1 chip (arm64), 4+4 cores, Big Sur 11.6.4, GNU compiler suite v.11.2.0_3 (gcc, gfortran, g++); no MPI pre-installed, running natively (no Rosetta emulator) Option 2: MacBook Pro 2015, 2.8 GHz Quad-Core Intel Core i7 (x86_64), Catalina OS X 10.15.7, GNU compiler suite v.11.2.0_3 (gcc, gfortran, g++); no MPI pre-installed
1.1. Install Homebrew and Xcode Command-Line Tools (CLT). Open Terminal.app and a web browser. Go to https://brew.sh, copy the command-line installation directive, and run it in a new Terminal window. Terminal will request a ‘sudo’ access password. The installation command would look similar to the following:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
It installs Homebrew, Xcode Command Line tools, and Ruby.
Alternative way of installing the Xcode command-line tools (CLT) done by the following:
$ xcode-select --install
1.2. Install GNU compiler Suite (e.g., version 11, with gcc, g++) and gfortran:
$ brew install gcc@11
Create symbolic links from the version-specific binaries to gcc and g++; a ‘sudo’ password may be requested. The path will likely be /opt/homebrew/bin/gcc-11 (Option 1), or /usr/local/bin/gcc-11
(Option 2)
$ which gcc-11
$ cd /usr/local/bin/
(Option2) (or /opt/homebrew/bin/
, Option 1 )
$ ln -s gcc-11 gcc
$ ln -s g++-11 g++
There is no need to create a link for gfortran if this is the first installation of this compiler. In case an earlier version of gfortran is present, you may rename it (e.g., to gfortran-old), and create a link to a newly installed gfortran as follows:
$ ln -s gfortran-11 gfortran
Verify the paths for the compiler binaries:
$ which gcc
$ which g++
$ which gfortran
Verify that they show the correct version of GNU installed:
$ gcc --version
$ g++ --version
$ gfortran --version
1.3. Install cmake utility via homebrew:
$ brew install cmake
1.4. Install or upgrade make utility via homebrew:
$ brew install cmake
or $ brew upgrade make
1.5. Install Lmod, module management environment:
$ brew install lmod
Add the init script to the shell you are using to be sourced for Lmod environment initialization. E.g., if you use bash, add the following to your $HOME/.bashrc file (on mac x8664) and to the config/configsource /usr/local/opt/lmod/init/profile
1.6. Install the libpng library:
$ brew install libpng
This library has issues when building on the Mac OS during the HPC-stack bundled build, and thus needs to be pre-build.
1.7. Install wget:
$ brew install wget
1.8. Install or update python3. Verify python3 is installed and check the current version:
$ which python3 (/usr/bin/python3)
$ python3 --version ( Python 3.8.2)
Download the updated version for MacOS from https://www.python.org/downloads . Recommended: 64-bit universal2 installer, e.g., version 3.9.11 package is python-3.9.11-macosc10.9.pkg. Double-click on the installer package, accept the License terms. You will be requested an Admin-level password for the installation. At the end of the installation, run the "Install Certificates.command" , double-click on the shell script in the Finder.app that opens, and run it. Start a new bash session (type "bash" in the existing terminal), verify the installed version:
$ python3 --version
(should correspond to your installed version, e.g:) Python 3.9.11.
1.9. Install git and dependencies:
$ brew install git
2.1. Download HPC-stack building code from github.com:
$ git clone git@github.com:NOAA-EMC/hpc-stack.git
$ cd hpc-stack
2.2. Configuration files are ./config/config
2.2. Verify the initialization of Lmod environment, or add it to the configuration file config/configsource /opt/homebrew/opt/lmod/init/profile
(Option 1)
source /usr/local/opt/lmod/init/profile
(Option 2)
2.3. Additionally, specify combination of compilers, python libraries used, and type of the MPI libraries, in the configuration file ./config/config
export HPC_COMPILER="gnu/11.2.0_3"
export HPC_MPI="openmpi/4.1.2"
(Option 1) or export HPC_MPI="mpich/3.3.2”
(Option 2)
export HPC_PYTHON="python/3.10.2"
2.4. When using gfortran higher than version 10, set the following flag in config_export STACK_FFLAGS="-fallow-argument-mismatch -fallow-invalid-boz"
Option 2:
export STACK_FFLAGS="-fallow-argument-mismatch -fallow-invalid-boz -march=native"
export STACK_CFLAGS="-march=native"
export STACK_CXXFLAGS="-march=native"
2.5. Set environmental variables for compiler paths in config/config_GNU=/opt/homebrew/bin/gcc
(Option 1), or GNU=/usr/local/bin
(Option 2).
export CC=${GNU}/gcc
export FC=${GNU}/gfortran
export CXX=${GNU}/g++
export SERIAL_CC=${GNU}/gcc
export SERIAL_FC=${GNU}/gfortran
export SERIAL_CXX=${GNU}/g++
2.6. Specify the libraries to be built within the hpc-stack in the ./stack/stack_
mpi:
build: YES
flavor: openmpi
(or mpich
)
version: 4.1.2
(or 3.3.2
)
2.7. Set building libpng library to NO in ./stack/stack
2.8. Set up the modules and the environment:
$ ./setup_modules.sh -c config/config_<machine>.sh -p ${HPC_INSTALL_DIR} | tee setup_modules.log
where <_machine_> is “_mac_m1gnu” (Option 1), or “_macgnu” (Option 2); and _${HPC_INSTALLDIR} is the absolute path for the installation directory of the hpc-stack. You will be asked to choose whether or not you want to use "native" installations of python, compiler, and MPI. "Native" means that they are already installed on your system. Thus, you answer "YES" to python, "YES" to gnu compilers, and "NO" for MPI/mpich.
NB: "-p" option requires an absolute path (full path) of the installation directory to be provided.
2.9. Building HPC-stack modules and libraries:
$ ./build_stack.sh -c config/config_<machine>.sh -p ${HPC_INSTALL_DIR} -y stack/stack_<machine>.yaml -m | tee build_stack.log
NB: “-m” option: it is needed to build separate modules for each library package.
3.1. Download the application:
$ git clone -b develop https://github.com/ufs-community/ufs-srweather-app.git
A new directory ufs-srweather-app is created, which contains a git repository. Make this directory your SRW environmental variable:
export SRW_HOME=${HOME}/ufs-srweather-app
3.2. Run the executable that pulls the SRW App components from external repositories:
$ cd ufs-srweather-app
$ ./manage_externals/checkout_externals
3.3. Customization of the environment for building the SRW is done using scripts located in ${SRW}/env/, in particular, build
# Setup instructions for macOS (build_macosx_gnu.env)
module purge
source /opt/homebrew/opt/lmod/init/profile (Option 1)
# source /usr/local/opt/lmod/init/profile (Option 2)
module use ${HPC_INSTALL_DIR}/modulefiles/stack
module load hpc
module load hpc-python
module load hpc-gnu
module load openmpi
module load hpc-openmpi
export SRW=${HOME}/SRW/ufs-srweather-app
source ${SRW}/env/srw_common
module list
export CC=/opt/homebrew/bin/gcc
export CXX=/opt/homebrew/bin/g++
export FC=/opt/homebrew/bin/gfortran
export MPI_CC=mpicc
export MPI_CXX=mpicxx
export MPI_FC=mpif90
export CMAKE_C_COMPILER=${MPI_CC}
export CMAKE_CXX_COMPILER=${MPI_CXX}
export CMAKE_Fortran_COMPILER=${MPI_FC}
export CMAKE_Platform=macosx.gnu
export CMAKE_Fortran_COMPILER_ID="GNU"
export LDFLAGS="-L${MPI_ROOT}/lib"
export FFLAGS="-DNO_QUAD_PRECISION -fallow-argument-mismatch "
Source the configuration file:
$ source ${SRW}/env/build_macosx_gnu.env
3.4. (Required for the Option 1, may be changed for Option 2 but not required.)
Make the following change to the file _${SRW}/src/ufs-weather-model/FV3/atmos_cubedsphere/CMakeLists.txt . Turn off the option for using QUAD_PRECISION, and change a line 35 to the following:
option(ENABLE_QUAD_PRECISION "Enable compiler definition -DENABLE_QUAD_PRECISION" OFF)
3.5. Build the SRW:
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_INSTALL_PREFIX=..
$ make -j 4 &> build.out &
3.6. Verify that the following binaries are built in the directory ${SRW}/bin:
chgres_cube
- Reads in raw external model (global or regional) and surface climatology data to create initial and lateral boundary conditions
filter_topo
- Filters topography based on resolution
global_equiv_resol
- Calculates a global, uniform, cubed-sphere equivalent resolution for the regional - Extended Schmidt Gnomonic (ESG) grid
make_solo_mosaic
- Creates mosaic files with halos
upp.x
- Post-processor for the model output
ufs_model
- UFS Weather Model executable
orog
- Generates orography, land mask, and gravity wave drag files from fixed files
regional_esg_grid
- Generates an ESG regional grid based on a user-defined namelist
sfc_climo_gen
Creates surface climatology fields from fixed files for use in _chgrescube
shave
- Shaves the excess halo rows down to what is required for the lateral boundary conditions (LBC’s) in the orography and grid files
vcoord_gen
- Generates hybrid coordinate interface profiles
fvcom_to_FV3
- Determines lake surface conditions for the Great Lakes
make_hgrid
- Computes geo-referencing parameters (e.g., latitude, longitude, grid cell area) for global uniform grids
emcsfc_ice_blend
- Blends National Ice Center sea ice cover and EMC sea ice concentration data to create a global sea ice analysis used to update the GFS once per day
emcsfc_snow2mdl
- Blends National Ice Center snow cover and Air Force snow depth data to create a global depth analysis used to update the GFS snow field once per day
global_cycle
- Updates the GFS surface conditions using external snow and sea ice analyses
inland
- Creates an inland land mask by determining in-land (i.e. non-coastal) points and assigning a value of 1. Default value is 0.
orog_gsl
- Ceates orographic statistics fields required for the orographic drag suite developed by NOAA’s Global Systems Laboratory (GSL)
fregrid
- Remaps data from the input mosaic grid to the output mosaic grid
lakefrac
- Calculates the ratio of the lake area to the grid cell area at each atmospheric grid point.
@natalie-perlin, thank you for the update and the thorough documentation! I will try this procedure on my MacOS machine today and I will update you on my results.
@mkavulich - Updated the directions to build the HPC-stack and SRW on the Macs!
@natalie-perlin Thanks for writing this up! I'm trying it with mac_m1_gnu, and building hpc-stack fails at hdf5. It is set with version 1.10.6 as-is, which I can't find as a branch on the repo, but even when trying something else there seems to be an issue with the way build_hdf5.sh sets up names for the directories as it clones and builds, and I haven't gotten to a workaround yet. Did you run into any issue like this? Thanks!
@willmayfield - no issues building the hdf5 v.1.10.6... trying to attach my log hdf5.log ! You are welcome to email me directly any log files or errors you get: nperlin@redlineperf.com or natalie.perlin@noaa.gov
hdf5.log !
@willmayfield - could this issue marked as resolved? More documentation for running SRW on Mac is under review, #240
Closing the issue. The builds are done on several Mac platforms (Intel/x86_64, M1/arm64) and OS versions (Darwin 19,20,21/ Catalina, Big Sur, Monterey). Documentation has been updated, and some more corrections for the SRW build on Mac OS will done before the release of public-v2 SRW version.
Description
See also https://github.com/ufs-community/regional_workflow/issues/684
The original PR implementing MacOS capabilities on the develop branch (#539), instructions were provided in the form of a Google Doc (https://docs.google.com/document/d/14jlvL3nOi85NJCWSNnhHjjBsrAsR-mr8JfGFvVIybFI/edit). These tests worked at the time on my MacOS Catalina 10.15.7 machine, using gnu 9.4.0 compilers installed with Homebrew. However, the app will no longer build, specifically due to a UFS_UTILS compilation error as described below.
Steps to Reproduce
Additional Context
I have not been able to isolate exactly why this error is occurring. Nothing relevant in the fvcom_tools_lib.dir directory of UFS_UTILS seems to have changed since the last successful tests. I saw the same failure with both the develop branch and tag v1.2.0 of hpc-stack (the tag originally tested), and when I attempted to use the older hash from when this capability was first merged, I was met with CMake errors:
The only difference between the original tests and my current test is that my MacOS version has been updated; original tests were on MacOS Catalina (10.15.7), whereas my laptop has since been upgraded to MacOS Big Sur (11.6.4). I even re-installed Homebrew and the compilers and other packages installed, this had no effect.
Unfortunately I am short on hours for working on this project, so I am hoping someone else will be able to troubleshoot this issue in the near term.