This is a guide for compiling Delft3D for Linux using Windows Subsystem for Linux (WSL). Because the Linux compilation instructions are quite specific using WSL gives the advantage of easily using any Linux distribution. The Deltares compilation notes are provided for CentOS version 7, so we will recreate a similar environment using WSL. An outline of the steps in this guide is as follows:
- Set up WSL
- Install CentOS 7 in WSL
- Install dependencies in CentOS
- Install Delft3D
- Test Delft3D
Follow the official guide from Microsoft for installing WSL for Windows 10 or 11. An important prerequisite is that Windows 10 users must have build 19041 or higher. See the "About your PC" screen in the system settings to check.
Because CentOS 7 is old, we require a WSL distribution from the now
discontinued CentWSL project. Download the version 7 release and
remember to unzip the download to a permanent location, as the path can
not be changed once the OS is installed. An example path is
C:\Users\<USER>\WSL\CentOS7
where <USER>
refers to your Windows user name.
Now follow this guide from how2shout.com to install the distribution. Next, we will set a password for the root user. Start CentOS as the root user (the angle bracket is used to indicate commands in the powershell prompt):
> wsl -d CentOS7 -u root
Now use the command below to reset the password (the hash sign is used to indicate commands in the CentOS terminal):
# passwd
Now set up a normal user with the commands below. For this guide I will call
the user delft3D
. You can use any name you choose.
# adduser delft3D
# passwd delft3D
Next, make the normal account the default when CentOS is started. First open
a new file with the vi
editor:
# vi /etc/wsl.conf
Now press the i
key to start editing and type in the following (remembering
to replace delft3D
with the username you chose):
[user]
default=delft3D
Now press the escape key and then type :wq
and press enter to save the file.
After restarting WSL and logging back into CentOS, we should now be the normal
user.
# exit
> wsl --shutdown
> wsl -d CentOS7
[delft3D@COMPUTER Path]#
As stated in the "Linux Required software" section of the Delft3D compilation guide, a number of dependencies must be built using the same compiler as Delft3D. For this guide we will use the Intel oneAPI compiler for Linux to build the necessary dependencies and Delft3D. Fortunately, not every dependency must be built and we can install a number of them using CentOS's "YUM" package manager.
First, add the Intel YUM repositories by following the instructions in this guide from Intel. Now switch to the root user, using the password we set up earlier, and then use YUM to install the OneAPI package and gcc:
# su -
# yum install intel-hpckit gcc
Logout as root by using CTRL-D or using the exit
command. Now we must make
sure that the ifort
compiler is accessible through the terminal. Again,
using vi
, edit the .bashrc
file in your CentOS home directory as follows:
# vi ~/.bashrc
Use the arrow keys to move to the last line of the file and then type A
(capital A) to start editing from the end of the line. Then add a new line with
this text:
. /opt/intel/oneapi/setvars.sh
Press enter and add another line which will switch off shared memory control (which can cause segfaults if not switched off):
export I_MPI_SHM="off"
Press escape to stop editing and then type :wq
to save the file and exit vi
.
To check that the setup has worked, log out and back into CentOS and then issue
the command:
# ifort --version
Now we will install the dependencies which can be retrieved with YUM. We become the root user again and then install the required packages as follows:
# su -
# yum group install "Development Tools"
# yum install wget libfabric-devel infinipath-psm-devel libpsm2-devel rdma-core-devel libnl3-devel libcurl-devel expat-devel ruby
# exit
Now we need to build the dependencies that must be compiled using the same
compiler as Delft3D. The packages will be installed into the path
${HOME}/d3d_local
where ${HOME}
in an environment variable representing
the current user's home directory. We will download all of the packages into
a folder with path ${HOME}/Downloads
. To create it and move there, issue
the commands:
# mkdir "${HOME}/Downloads"
# cd "${HOME}/Downloads"
Next, simply issue the commands for each package in the sections below to download, compile and install.
# wget --no-check-certificate http://www.mpich.org/static/downloads/3.4.2/mpich-3.4.2.tar.gz
# tar -xf mpich-3.4.2.tar.gz
# cd mpich-3.4.2
# ./configure CC=icc CXX=icpc F77=ifort FC=ifort --prefix="${HOME}/d3d_local" 2>&1 | tee c.txt
# make 2>&1 | tee m.txt
# make check 2>&1 | tee mc.txt
# make install 2>&1 | tee mi.txt
# cd ..
# wget https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.10/hdf5-1.10.6/src/hdf5-1.10.6.tar.bz2
# tar -xf hdf5-1.10.6.tar.bz2
# cd hdf5-1.10.6
# ./configure CC="${HOME}/d3d_local/bin/mpicc" --enable-parallel --enable-shared --prefix="${HOME}/d3d_local" 2>&1 | tee c.txt
# make 2>&1 | tee m.txt
# make check 2>&1 | tee mc.txt
# make install 2>&1 | tee mi.txt
# cd ..
# wget https://github.com/Unidata/netcdf-c/archive/refs/tags/v4.6.1.tar.gz -O netcdf-c-4.6.1.tar.gz
# tar -xf netcdf-c-4.6.1.tar.gz
# cd netcdf-c-4.6.1
# ./configure CC="${HOME}/d3d_local/bin/mpicc" CPPFLAGS="-I${HOME}/d3d_local/include" LDFLAGS="-L${HOME}/d3d_local/lib" --disable-dap-remote-tests --prefix="${HOME}/d3d_local" 2>&1 | tee c.txt
# make 2>&1 | tee m.txt
# make check 2>&1 | tee mc.txt
# make install 2>&1 | tee mi.txt
# cd ..
# wget https://github.com/Unidata/netcdf-fortran/archive/refs/tags/v4.5.0.tar.gz -O netcdf-fortran-4.5.0.tar.gz
# tar -xf netcdf-fortran-4.5.0.tar.gz
# cd netcdf-fortran-4.5.0
# NCDIR="${HOME}/d3d_local"
# export LD_LIBRARY_PATH=${NCDIR}/lib:${LD_LIBRARY_PATH}
# ./configure CC="${HOME}/d3d_local/bin/mpicc" F77="${HOME}/d3d_local/bin/mpif77" FC="${HOME}/d3d_local/bin/mpif90" CPPFLAGS="-I${NCDIR}/include" LDFLAGS="-L${NCDIR}/lib" --prefix="${HOME}/d3d_local" 2>&1 | tee c.txt
# make 2>&1 | tee m.txt
# make check 2>&1 | tee mc.txt
# make install 2>&1 | tee mi.txt
# cd ..
With all the necessary dependencies installed, we can now download, compile
and install Delft3D. Note that you must have a Deltares SVN server account to
download the source code. If you need to register, see the "Steps needed to
use the Delft3D source code" section of the Delft3D compilation guide. In
the compilation instructions below, replace <username>
and <password>
with
the SVN login details that Deltares sent you. The commands below will install
tag 68819, the recommended tag for Delft3D-FM. This time the binaries are
placed ${HOME}/Downloads/delft3dfm-68819/src
directory, the standard location.
# svn checkout --username <username> --password <password> https://svn.oss.deltares.nl/repos/delft3d/tags/delft3dfm/68819/ delft3dfm-68819
# cp delft3dfm-68819/src/third_party_open/swan/src/*.[fF]* delft3dfm-68819/src/third_party_open/swan/swan_mpi
# cp delft3dfm-68819/src/third_party_open/swan/src/*.[fF]* delft3dfm-68819/src/third_party_open/swan/swan_omp
# cd delft3dfm-68819/src
# export FC="${HOME}/d3d_local/bin/mpifort"
# ./autogen.sh --verbose 2>&1 | tee a.txt
# ./configure CC="${HOME}/d3d_local/bin/mpicc" CXX="${HOME}/d3d_local/bin/mpicxx" MPICXX="${HOME}/d3d_local/bin/mpicxx" F77="${HOME}/d3d_local/bin/mpif77" MPIF77="${HOME}/d3d_local/bin/mpif77" FC="${HOME}/d3d_local/bin/mpifort" MPIFC="${HOME}/d3d_local/bin/mpifort" CPPFLAGS="-I${HOME}/d3d_local/include" NETCDF_CFLAGS="-I${HOME}/d3d_local/include -I${HOME}/d3d_local/include" NETCDF_LIBS="-L${HOME}/d3d_local/lib -lnetcdf" CFLAGS='-O2 ' CXXFLAGS='-O2 ' AM_FFLAGS='-lifcoremt ' FFLAGS='-O1 -qopenmp' AM_FCFLAGS='-lifcoremt ' FCFLAGS='-O1 -qopenmp' AM_LDFLAGS='-lifcoremt ' --prefix="${HOME}/Downloads/delft3dfm-68819/src" 2>&1 | tee c.txt
# make ds-install 2>&1 | tee md.txt
# make ds-install -C engines_gpl/dflowfm | tee mdfm.txt
# cd ..
To test the installation, we use the example files provided in the Delft3D
source code. It is assumed that the current directory is the root of the
Delft3D source code, i.e. ${HOME}/Downloads/delft3dfm-68819
. To test a
structured mesh example, issue the following commands:
# pushd examples/01_standard
# ./run.sh
# popd
Then, to test a flexible mesh example, issue the following:
# pushd examples/12_dflowfm/test_data/e02_f14_c040_westerscheldt
# ./run.sh
# popd
Hi Mathew, I just want to say thank you for your great and well planned though tutorial you posted here: https://youtu.be/o1iQvO3x8A0. I followed it through up to the point where you run the 'make ds-install 2>&1 | tee md.txt' command. Unfortunately I had an error @ 37:26 https://youtu.be/o1iQvO3x8A0?t=2246.
SwanCompUnstruc.f90:(.text+0x69): undefined reference to `__kmpc_global_thread_num'
make[3]: *** [swan_mpi] Error 1
make[3]: Leaving directory
/home/delft3D/Downloads/delft3dfm-68819/src/third_party_open/swan/swan_mpi' make[2]: *** [install-recursive] Error 1 make[2]: Leaving directory
/home/delft3D/Downloads/delft3dfm-68819/src/third_party_open/swan'make[1]: *** [install-recursive] Error 1
make[1]: Leaving directory `/home/delft3D/Downloads/delft3dfm-68819/src/third_party_open'
make: *** [install-recursive] Error 1
I think the issue might be related to the swan_mpi and the swan_omp libraries that are not explicitly linked in the configure flags via the long ./configure command here: https://gist.github.com/H0R5E/c4af6db788b227de702a12e01b64cf46#install-delft3d. I guess itโs just a simple case of updating the flags. It is however a little strange that you did not receive any error granted that I followed the exact installation instructions you outlined via the video and document.
I'm not too experienced with compiling Intel or FORTRAN code. I would really appreciate your support in order to fix this presumably small bug. I think a few other users also reported the issue on your YouTube tutorial, so I'm sure this will help quite a few others in the community!
I would really appreciate a rather swift reply on this as Iโm currently needed to use Delft3d in a project.
Thank you very much in advance for your support! ๐
Best,
Josh