Compiling and Running Dynare on a linux cluster running CentOS or RHEL

Maybe this is of use to some of you who want to run Dynare on a cluster:

Linux Cluster running CentOS7

Our University-wide cluster PALMA II runs CentOS 7 and uses a module system, i.e. software like compilers or certain libraries can can be accessed via environment modules that then set environmental variables. (Un-)fortunately, I don’t have admin access to it, so in order to run Dynare I need to compile it from source or ask the admins to make it available. So this is how I managed to do so, feel free to update this thread if you’re experience differs.

1. Load the required modules

Dynare has some requirements, which I was able to load using the module command. You might use module avail to see what is available on your cluster and ask the admin to install maybe a newer version of software. In may case, I asked the admins to install a newer version of bison and MATIO on the cluster. However, one can also install this locally without admin rights. You might want to check out the install instructions for Fedora, CentOS, RHEL.

Anyways, let’s load the modules:

module load foss zlib HDF5 Boost Bison Automake Autoconf flex GSL Doxygen MATIO SuiteSparse matlab

Unfortunately, slicot and x13as are not prepackaged on CentOS or RHEL and need to be compiled from source, see below. Also I don’t need the packages for documentation on the cluster, so I’ll skip these. The Intel Fortran compiler also works for me and can be loaded by module load ifort.

2. Directories

I create a folder dynare in my home folder and also some subfolders for slicot and x13as.

export DYNARE_DIR=/home/w/w_muts01/dynare
mkdir -p $DYNARE_DIR
mkdir -p $DYNARE_DIR/slicot/lib
mkdir -p $DYNARE_DIR/x13as
mkdir -p ~/.local/bin

Of course you need to find out the directory of MATLAB by e.g. running

whereis matlab
# matlab: /Applic.ZIV/Matlab/R2020b/bin/matlab

So the directory is /Applic.ZIV/Matlab/R2020b

3. Compile slicot

Compile slicot from source and put it into $DYNARE_DIR/slicot/lib/:

cd $DYNARE_DIR/slicot
wget https://deb.debian.org/debian/pool/main/s/slicot/slicot_5.0+20101122.orig.tar.gz
tar xf slicot_5.0+20101122.orig.tar.gz
cd slicot-5.0+20101122
make FORTRAN=gfortran OPTS="-O2 -fPIC -fdefault-integer-8" LOADER=gfortran lib
cp slicot.a $DYNARE_DIR/slicot/lib/libslicot64_pic.a

4. Compile x13as

Compile x13as from source and put it into $HOME/.local/bin:

cd $DYNARE_DIR/x13as
wget https://www.census.gov/ts/x13as/unix/x13assrc_V1.1_B39.tar.gz
tar xf x13assrc_V1.1_B39.tar.gz
sed -i "s|-static| |" makefile.gf # this removes '-static' in the makefile.gf
make -f makefile.gf FFLAGS="-O2 -std=legacy" PROGRAM=x13as
ln -s $DYNARE_DIR/x13as/x13as ~/.local/bin

Check whether ~/.local/bin is on your PATH by running echo $PATH, otherwise add it.

5. Compile dynare

Stable version

This will compile the stable 4.6 version of dynare:

git clone --recurse-submodules --single-branch --branch 4.6 https://git.dynare.org/Dynare/dynare.git $DYNARE_DIR/stable-4.6
cd stable-4.6
autoreconf -si
./configure --with-matlab=/Applic.ZIV/Matlab/R2020b --disable-octave --disable-doc --with-slicot=$DYNARE_DIR/slicot
make -j20

Unstable version

This will compile the unstable version of dynare:

git clone --recurse-submodules --single-branch --branch master https://git.dynare.org/Dynare/dynare.git $DYNARE_DIR/unstable
cd unstable
autoreconf -si
./configure --with-matlab=/Applic.ZIV/Matlab/R2020b --disable-octave --disable-doc --with-slicot=$DYNARE_DIR/slicot
make -j20

6. Prepare Dynare parallel

I put the following configuration file called .dynare into my home folder:

[cluster]
Name = Local
Members = n1

[node]
Name = n1
ComputerName = localhost
CPUnbr = 72
NumberOfThreadsPerJob = 9

7. Use the batch system to run your mod file

I use the following template for the batch system on the cluster:

#!/bin/bash
 
# set the number of nodes
#SBATCH --nodes=1
 
# set the number of CPU cores per node
#SBATCH --ntasks 72
 
# set a partition
#SBATCH --partition normal
 
# set max wallclock time
#SBATCH --time=48:00:00
 
# set name of job
#SBATCH --job-name=MyModFile
 
# set an output file
#SBATCH --output MyModFile.dat

# mail alert at start, end and abortion of execution
#SBATCH --mail-type=ALL

# send mail to this address
#SBATCH --mail-user=willi.mutschler@uni-muenster.de
 
# In the u0dawin queue, you will need the following line
# source /etc/profile.d/modules.sh; source /etc/profile.d/modules_local.sh
 
# run the application
# source/etc/profile.d/modules.sh
 
module load foss zlib HDF5 Boost Bison Automake Autoconf flex GSL Doxygen MATIO SuiteSparse matlab

cd /scratch/tmp/w_muts01/MyFolder
matlab -softwareopengl -r "addpath('/home/w/w_muts01/dynare/stable/matlab'); dynare parallel MyModFile"

That’s it! Let me know if you need more assistance! This should also work on RHEL systems.

4 Likes

Hi! thanks for this. I was just wondering if there were any updates on these commands for dynare 5.0? I also noticed that at least the link for x13as is no longer valid

@wmutschl Do you know?

The commands should more or less work the same, note though that CentOS is end-of-life and people will move on to other server distributions. You should probably checkout the instructions here as well:

Regarding the URL for x13as: you are right, they changed it and the correct one is now:
https://www2.census.gov/software/x-13arima-seats/x13as/unix-linux/program-archives/x13as_asciisrc-v1-1-b58.tar.gz

But please post any required changes in this post for other people to see them.

1 Like

Hello,
I help out with training and support for a RHEL 7 HPC. We have MatLab and the parallel toolbox, I saw this post as we have gotten requests to add Dynare to the cluster and it has been very helpful! Thank you for the detailed information!
One quick question,will Dynare work with batch submissions? Our HPC uses batch submission with platform load sharing facility for batch scheduling.
Thanks!

Hi,
what has been your experience so far with Dynare and the Batch system?
On our HPC I use Matlab as a module and have compiled Dynare versions in my home directory. Then I typically create MATLAB script to run via the batch system, in this script I add the path of Dynare and run it.

Recently, docker images have been available, and I could run dynare using Apptainer on an hpc with Cent OS. This is the first time I have used containers, so my solution might need improvements/corrections. But it seems to be working. Here is what I did:

1. mkdir dynare
2. cd dynare

3. mkdir examples

4. touch examples/example1.mod

5. module load Apptainer

6. apptainer build dynare.sif docker://dynare/dynare:latest

7. apptainer exec \
8.     --env MLM_LICENSE_FILE=27000@matlab-campus.uni-tuebingen.de \
9.     dynare.sif \
10.    matlab -batch \
11.    "addpath('/home/matlab/dynare/matlab'); cd examples; dynare example1"

12. module unload Apptainer

Explanation:
Line 1: Make a folder, named ‘dynare’

Line 2: Enter the folder

Line 3: Make a folder, named ‘examples’

Line 4: Make an empty model file inside the examples folder, names ‘example1.mod’

Line 5: Load the ‘Apptainer’ module

Line 6: Build .sif file pulling the docker images from docker hub

Line 7: exec subcommand lets us run a command within the container

Line 8: Pass your matlab license as an environmental variable with --env

Line 9: Give the container image to exec

Line 10: Matlab should run line 11

Line 11: Commands to be executed inside matlab

Line 12: Unload the Apptainer module

If dynare works, we should see some dynare errors printed out, as our example1.mod file is empty. We should also make sure to change 27000@matlab-campus.uni-tuebingen.de according to our own license.

1 Like

Thanks, glad that it works! I also link your post in the post on docker containers.

1 Like

At some point, matlab started asking me for my mathworks account, even though I defined MLM_LICENSE_FILE. Providing --cleanenv option to exec subcommand solved the problem.