How to Compile OpenFOAM-v9 on Linux-based HPC Server

A warm welcome to my blog!
I hope this post can be helpful to your research.

A brief introduction

In this post, we will walk through the procedures of compiling/installing OpenFOAM-v9 on your Linux-based High Performance Computing (HPC) server. Here, I use my case as an example to showcase the general method. Please note that you still need to modify a bit based on your server environment.

1) Downloading the source code

1
2
3
4
5
$ cd ~ //go to your home directory
$ mkdir OpenFOAM
$ cd OpenFOAM
$ git clone https://github.com/OpenFOAM/OpenFOAM-9.git
$ git clone https://github.com/OpenFOAM/ThirdParty-9.git

2) Loading the compiling environment

This step depends on your server. However, the most important dependencies for OpenFOAM are: gcc, mpi, boost, and sometimes cmake.
Here is a list of module I will load for my case:

1
2
3
$ module load gcc/8.2.0
$ module load boost/gcc/1.68.0
$ module load openmpi/gcc/4.0.2

If you happen to have a scotch module pre-compiled on your server, please do load it and you don’t need to compile it in the next step. But you need to add the module load command for scotch into your alias in Step 5.

3) Compiling third-party utilities

This step is probably the most essential to the success.
We firstly need to download some key packages to the ThirdParty-9/ directory:

1
2
3
4
5
6
7
8
9
$ cd ~/OpenFOAM/ThirdParty-9
$ wget https://cmake.org/files/v3.9/cmake-3.9.0-Linux-x86_64.tar.gz
$ tar xvzf cmake-3.9.0-rc2-Linux-x86_64.tar.gz cmake-3.9.0
$ wget http://134.100.28.207/files/src/cgal/CGAL-5.0.2.tar.gz
$ tar xvzf CGAL-5.0.2.tar.gz CGAL-5.0.2
$ wget https://src.fedoraproject.org/lookaside/pkgs/metis/metis-5.1.0.tar.gz/
$ tar xvzf metis-5.1.0.tar.gz metis-5.1.0
$ wget https://src.fedoraproject.org/lookaside/extras/scotch/scotch_6.0.9.tar.gz/
$ tar xvzf scotch_6.0.9.tar.gz scotch_6.0.9

Now, we have all the necessary packages in the ThirdParty-9/ directory, we can just compile them:

1
$ ./Allwmake

4) Compiling OpenFOAM

This step is pretty straightforward. Just to make sure you are in the OpenFOAM-9/ directory:

1
$ cd ~/OpenFOAM/OpenFOAM-9

and then type in:

1
$ ./Allwmake -j $Number of Cores

and change $Number of Cores to a number that your head machine allows. For my case, I normally use 8 cores on my head machine, which takes around 20 minutes to compile the whole OpenFOAM library.

5) Setting up an alias

After compiling OpenFOAM, you might want to set up an alias so that you don’t need to manually load the modules and source the bashrc file.
For example, you can choose to use echo:

1
$ echo "alias of9='module load gcc/8.2.0&&module load boost/gcc/1.68.0&&module load openmpi/gcc/4.0.2&&source $HOME/OpenFOAM/OpenFOAM-9/etc/bashrc WM_LABEL_SIZE=64'" >>$HOME/.bashrc

or, you can go to your $HOME directory and modify the .bashrc file manually using vim, nano, emacs or whatever text editor you prefer.

Note:

  1. You will mostly likely to have different versions of gcc and mpi on your server, and so you need to change a bit from my command line.
  2. If you are using openmpi instead of intel-mpi, be sure to load gcc before loading your mpi, otherwise you will very likely to have errors related to sharing libraries.
  3. Remember, after updating the .bashrc file, you will need to refresh the bash environment by typing:
    1
    $ bash

How to Compile OpenFOAM-v9 on Linux-based HPC Server

http://example.com/2021/12/19/openfoam-v9-installation-server/

Author

Yuxiang Zhang

Posted on

2021-12-19

Updated on

2022-01-30

Licensed under

Comments