Skip to content

Compiling on MacBook M1 chip using conda environment

Marshall Ward edited this page Apr 11, 2024 · 8 revisions

Follow these steps to compile MOM6 on Apple Macbook M1 chips using conda environment. These steps should (most probably) help you in successfully installing and running MOM6.

Assumption is that you have miniconda installed and are familiar with installing libraries with conda.

Create a conda environment:

conda create --name mommy

mommy is name of environment for MOM6. You can use a custom name.

conda config --set channel_priority strict
conda install -c conda-forge gfortran -y
conda install -c conda-forge netcdf4 -y
conda install -c conda-forge netcdf-fortran -y
conda install -c conda-forge mpich -y

Create a folder mkdir ~/mom6_folder cd ~/mom6_folder

Git clone MOM6_examples.

Create a Directory: mkdir Datasets And download datasets from the gfdl ftp server into it. Downloading might take 20-30 mins.

The appropriate make file is: mom6_folder/MOM6-examples/src/mkmf/templates/osx-gcc10.mk

Compilation:

Compiling FMS:

Create a compile script vi compileFMS.bash

and copy paste the following:

#!/bin/bash

mkdir -p build/fms/
(cd build/fms; rm -f path_names; \
../../src/mkmf/bin/list_paths -l ../../src/FMS; \
../../src/mkmf/bin/mkmf -t ../../src/mkmf/templates/osx-gcc10.mk -p libfms.a -c "-Duse_libMPI -Duse_netCDF" path_names)

(cd build/fms/; source ../env; make NETCDF=4 REPRO=1 libfms.a -j)

Compile: bash compileFMS.bash

Compiling Ocean only:

vi compileOcean.bash

copy paste the following:

#!/bin/bash
 
mkdir -p build/ocean_only/
(cd build/ocean_only/; rm -f path_names; \
../../src/mkmf/bin/list_paths -l ./ ../../src/MOM6/{config_src/infra/FMS1,config_src/memory/dynamic_symmetric,config_src/drivers/solo_driver,config_src/external,src/{*,*/*}}/ ; \
../../src/mkmf/bin/mkmf -t ../../src/mkmf/templates/osx-gcc10.mk -o '-I../fms' -p MOM6 -l '-L../fms -lfms' path_names)
 
(cd build/ocean_only/; source ../env; make REPRO=1 MOM6 -j)

Compile: bash compileOcean.bash

Compiling Ice-SIS2:

vi compileSIS2.bash

#!/bin/bash
 
mkdir -p build/ice_ocean_SIS2/
(cd build/ice_ocean_SIS2/; rm -f path_names; \
../../src/mkmf/bin/list_paths -l ./ ../../src/MOM6/config_src/{infra/FMS1,memory/dynamic_symmetric,drivers/FMS_cap,external} ../../src/MOM6/src/{*,*/*}/ ../../src/{atmos_null,coupler,land_null,ice_param,icebergs/src,SIS2,FMS/coupler,FMS/include}/)
(cd build/ice_ocean_SIS2/; \
../../src/mkmf/bin/mkmf -t ../../src/mkmf/templates/osx-gcc10.mk -o '-I../fms' -p MOM6 -l '-L../fms -lfms' -c '-Duse_AM3_physics -D_USE_LEGACY_LAND_' path_names )
 
(cd build/ice_ocean_SIS2/; source ../env; make REPRO=1 MOM6 -j)

Compile:

bash compileSIS2.bash

Restart your shell, or restart your laptop.

Launch the conda environment conda activate mommy

and add the executable to your path: export PATH="/Users/$USER/mom6_folder/MOM6-examples/build/ocean_only/:$PATH" This has to be done every time you restart the shell or laptop. You can add the path to your .zshrc file to avoid adding path every time.

Running MOM6:

To run MOM6, type this in your project folder: Go to folder:
cd /Users/$USER/mom6_folder/MOM6-examples/ocean_only/double_gyre

And then type:

/Users/$USER/mom6_folder/MOM6-examples/build/ocean_only/MOM6

Also see Running a test case

If the model runs, some lines will be displayed. If ocean.stats file contains lines similar to this:

Step,       Day,  Truncs,      Energy/Mass,      Maximum CFL,  Mean sea level,   Total Mass,    Frac Mass Err
            [days]                 [m2 s-2]           [Nondim]        [m]             [kg]           [Nondim]
     0,       0.000,     0, En 1.42372419504191276E-13, CFL  0.00000, SL  4.2775E-12, Mass 5.28818E+18, Me  0.00E+00

MOM6 has been successfully compiled and can be run! Hurray! :D

Clone this wiki locally