Skip to content

Ubuntu compiler environment

Alistair Adcroft edited this page Oct 12, 2022 · 22 revisions

Supplementary instructions for Ubuntu Linux environments

These instructions closely follow the instructions outlined for GFDL's HPC platforms using FMS's mkmf tool for creating a Makefile.

Ubuntu versions (read!)

Each release of Ubuntu has different version of the compilers and libraries. There is an mkmf template for each version of Ubuntu.

  • Ubuntu 22.04.1 "Jammy Jellyfish", use mkmf/templates/linux-ubuntu-jammy-gnu.mk
  • Ubuntu 20.04.5 "Focal Fossa", use mkmf/templates/linux-ubuntu-focal-gnu.mk
  • Ubuntu 18.04.6 "Bionic Beaver", use mkmf/templates/linux-ubuntu-bionic-gnu.mk
  • Ubuntu 16.04.07 "Xenial Xerus", use mkmf/templates/linux-ubuntu-xenial-gnu.mk
  • Ubuntu 14.04.06 "Trusty Tahr", use mkmf/templates/linux-ubuntu-trusty-gnu.mk

The instructions below use "jammy" which have been tested on Ubuntu 22.04.01 LTS. Which distribution of Linux do you have? Try cat /etc/*-release.

Setup a compiler environment on Ubuntu

Execute the following commands to install the compilation prerequisites on an Ubuntu machine:

sudo apt install make gfortran netcdf-bin libnetcdf-dev libnetcdff-dev openmpi-bin libopenmpi-dev

If the above fails you might have to do sudo apt update first.

Create a blank env file

The following commands make use of a file build/env that can contain any local environment changes need for compilation:

mkdir -p build
echo > build/env

Building libfms.a

To build the Makefile use:

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/linux-ubuntu-jammy-gnu.mk -p libfms.a -c "-Duse_libMPI -Duse_netCDF -DSPMD" path_names)

To build the FMS library (libfms.a):

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

Building the ocean-only MOM6 executable

To create the Makefile for compiling MOM6:

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/linux-ubuntu-jammy-gnu.mk -o '-I../fms' -p 'MOM6 -L../fms -lfms' -c "-Duse_libMPI -Duse_netCDF -DSPMD" path_names)

To build the MOM6 executable:

(cd build/ocean_only/; source ../env; make NETCDF=3 REPRO=1 MOM6 -j)

Run MOM6 ocean-only

For any example in ocean_only/ that does NOT have an INPUT/ directory, e.g. double_gyre:

cd ocean_only/double_gyre/
mkdir RESTART
mpirun -np 4 ../../build/ocean_only/MOM6

Ubuntu platform notes

14.10: nc-config within the template will work fine.

15.10: We noticed that you also need to install the package libnetcdff-dev and change nc-config to nf-config within the template file.

Windows Subsystem for Linux (WSL)

Windows now has well supported access to Linux distributions via the Windows Subsystem for Linux (WSL). To install an Ubuntu distribution the simplest approach is via the "Microsoft Store":

  • Open the Microsoft Store from the Start Menu and search for "Ubuntu LTS" (LTS stands for long term support)
  • Select a version (e.g. Ubuntu 22.04.01 LTS) and then click Install
  • In your Start Menu, there will now be a new "app" “Ubuntu 22.04.01 LTS” (or equivalent). YOu might find it under “Recently added” if you have that enabled. Click to start the app. This triggers the configuration of the linux instance.
  • You’ll be prompted to create a username and password (this is local to the linux installation and independent of the host and all other accounts). It should then provide a linux prompt.
  • First thing to do is issue sudo apt update and enter your password if prompted (this updates the database of packages so we can install the required software).

Hereafter, you can follow the environment setup steps above for Ubuntu linux.

Clone this wiki locally