Installing WRF on CentOS 7

WRF (Weather Research and Forecasting) is a powerful numerical simulation tool in atmospheric science. It is maintained by UCAR, and has been under continuous development. There has been a lot of official (ARW user guide)/ unofficial installation guides, but not so much information for CentOS 7 system. There are some minor differences in CentOS 7 that we have to configure manually. This, however, is pretty straightforward if you are familiar with Linux. Here I will show how to set up the basic dependencies, and how to compile WRF, as well as the related WPS and RIP4. Also here I will give out the steps for GNU compiler installation and Intel compiler installation.

0. My system

It is running CentOS 7, and basically it is after a fresh install, which was described in my other post.

To make the Intel version live in my system happily with the GNU version, I installed those libs/tools that were compiled by Intel compiler at /usr/intel, while those from GNU compiler at /usr/gnu. You will need root privilege to create these 2 directories.

Intel version

1. Install Intel compiler

There are already a lot of tutorials out there, and I found it good to accept the Intel’s default setting. By default, the software will be in /opt/intel directory. To make icc and ifort available, we need to have our shell read several environment variables setting scripts. I added the following lines to my ~/.bashrc file. Note if you are using csh or tcsh, the files will be a little bit different, and you can find them in these directories.

source /opt/intel/vtune_amplifier_xe_2015/ quiet
source /opt/intel/inspector_xe_2015/ quiet
source /opt/intel/advisor_xe_2015/ quiet
source /opt/intel/bin/ intel64

2. Solve dependencies

2.1   NetCDF

NetCDF is available from package manager (which is yum in CentOS). However, if we install it through yum then it is compiled by GNU compiler, which is not what we want. So let’s compile it from the source code. The source code has been separated as NetCDF-C and NetCDF-Fortran versions now. WRF requires Fortran version, but Fortran version depends on C version, so we will install both. Download the codes at Unidata.

2.1.1 NetCDF-C

First set some environment variables. This is for both icc and ifort.

export CC=icc
export CXX=icpc
export CFLAGS='-O3 -xHost -ip -no-prec-div -static-intel'
export CXXFLAGS='-O3 -xHost -ip -no-prec-div -static-intel'
export F77=ifort
export FC=ifort
export F90=ifort
export FFLAGS='-O3 -xHost -ip -no-prec-div -static-intel'
export CPP='icc -E'
export CXXCPP='icpc -E'

Then install NetCDF-C.

tar -zxf netcdf-
cd netcdf-
configure --prefix=/usr/intel/netcdf
make check # This is just to check the compilation. You can skip this if you want.
make install

2.1.2 NetCDF-Fortran

Most of the environment variables needed should have been set by the above lines. But there is still one more:

export CPPFLAGS="-I/usr/intel/netcdf/include"

Now go ahead and install it:

tar -zxf netcdf-fortran-4.4.2.tar.gz
cd netcdf-fortran-4.4.2
configure --prefix=/usr/intel/netcdf
make check # Similarly, you can skip this is you want.
make install


I am not sure if OpenMP works. Theoritically it should work, but I did not have enough time to try it. Set the following environmental variables first. These blank values are to erase the values we just wrote above, for NetCDF.

export F90=
export F90FLAGS=
export FC=ifort
export FCLAGS='-O3 -xHost -ip -no-prec-div -static-intel'
tar -zxf mpich-3.1.4.tar.gz
cd mpich-3.1.4
configure --prefix=/usr/intel/mpich

2.3 zlib

Have these two variables set, then install the zlib.

export LDFLAGS="-L/usr/intel/grib2/lib "
export CPPFLAGS="-I/usr/intel/grib2/include"
tar -zxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
configure --prefix=/usr/intel/grib2
make install

2.4 libpng

tar -zxf libpng-1.6.17.tar.gz
cd libpng-1.6.17
configure --prefix=/usr/intel/grib2
make install

2.5 jasper

Nothing special here. Just follow the general procedure of installing a software from source codes.

tar -zxf jasper-1.900.1.tar.gz
cd jasper-1.900.1
configure --prefix=/usr/intel/grib2
make install

 Now we need to modify the PATH variable, adding these new paths.

export NETCDF=/usr/intel/netcdf
export PATH="$NETCDF/bin:/usr/intel/mpich/bin:/usr/intel/grib2/bin:.:$PATH"

3. Build WRF

Building WRF is relatively easy, once all the libraries have been installed. Here are just some quick note.

1) When choosing the system, go with icc+ifort (serial) first. This will help to check if the dependencies are OK. Once this is done successfully, go with icc+ifort (dmpar). I checked and played with the both smpar and dmpar, and here is what I have found:

If we use smpar option, then there is no need to call mpich to run WRF in parallel. Instead, we just need (for real case):

wrf.exe >& log.wrf.txt &

A quick reminder is in this mode, do not use mpirun to run your wrf.exe. This just creates two wrf.exe running, but they are all doing the identical thing. Meanwhile, this will create a wrf.exe process that takes up all the CPU resources. In my case my machine has 12 cores, and they will all be 100% occupied.

Things are a little different with dmpar. With this option, we can run wrf.exe by using:

mpirun -np 8 wrf.exe >& log.wrf.txt &

This will only allow wrf.exe(s) to use only 8 cores, so the machine will not get totally stuck in my case.

4. Building WPS

WPS can only be built after WRF has been compiled successfully. Follow the instructions in WRF user guide (i.e. a basic source code installation).

5. Building RIP4

5.1 Install NCL

RIP4 relies on NCL (NCAR Command Language). I did not compile it from the source codes, but just installed a pre-compiled binary file as suggested at NCL official website. Download the file from here. I went with “ncl_ncarg-6.3.0.Linux_RHEL6.4_x86_64_nodap_intel1215.tar.gz”.

tar -zxf ncl_ncarg-6.3.0.Linux_RHEL6.4_x86_64_nodap_intel1215.tar.gz
sudo mkdir /usr/intel/ncl
sudo cp -r bin include lib /usr/intel/ncl/

Before running NCL, make sure the following environment variables are set.

export NCARG_ROOT=/usr/intel/ncl
export PATH="$NCARG_ROOT/bin:$PATH"
export LD_LIBRARY_PATH="/opt/intel/composer_xe_2015.0.090/compiler/lib/intel64:$LD_LIBRARY_PATH"

Now you can try you luck with

ng4ex gsun01n -clean

 If NCL was installed successfully, you will get several plots.

5.2 Install RIP4

First set RIP_ROOT as your RIP4 directory. Then configure it, as always. But you may get several problems when compiling it. Here are the solutions for my problems.

Basically it cannot find several lib files. They are not installed by default in CentOS 7, so we need to get them and modify the configure.rip4 file:

1) For NetCDF issues, change “NETCDFLIB=-L${NETCDF}/lib -lnetcdf” into “NETCDFLIB=-L${NETCDF}/lib -lnetcdff -lnetcdf”. Note “-netcdff” must come before “-netcdf”. “-lnetcdf” means the netcdf-C libraries, but the program is also looking for netcdf-Fortran libraries, so we use “-lnetcdff”. Similarly, “-lnetcdf_c++” is for netcdf-C++ libraries.

2) For “cairo”/”freetype” issues, instal cairo-devel and freetype-devel, and modify “NCARGLIBS=-L${NCARG_ROOT}/lib -lncarg -lcgm -lncarg_gks -lncarg_c -lX11 -lm”. Here is what you should do:

First use “locate” to find out the library location:

$ locate

Then add “-L/usr/lib64 -lcairo” to NCARGLIBS. Similarly, for freetype libs, add “-L<dir_of_freetype_lib> -lfreetype” to NCARGLIBS.

Now a basic WRF setup is done. We can start playing with it, and be our “god of weather”!

GNU version

The installation using GNU compilers (gcc and gfortran) is simpler. Most of the steps are identical to Intel version, except for some basic difference in the paths to all the bin files (i.e.  /usr/gnu instead of /usr/intel). You should be able to tell this and figure out the correct commands based on Intel version.

# 1. netcdf for C
export CC=gcc
export CXX=g++
export FC=gfortran
export FCFLAGS=-m64
export F77=gfortran
export FFLAGS=-m64

# 2. netcdf for Fortran
#export CPPFLAGS="-I/usr/gnu/netcdf/include"

# 3. zlib
export LDFLAGS="-L/usr/gnu/grib2/lib"
export CPPFLAGS="-I/usr/gnu/grib2/include"

# 4. RIP4
export NCARG_ROOT="/usr/gnu/ncl"

Main reference:

[1] WRF official website

[2] A tutorial on how to compile WRF

[3] Intel NetCDF installation guide

2 thoughts on “Installing WRF on CentOS 7

  1. Hi pal!
    Very interesting and simple tutorial. I just wonder what’s the difference if I wanna compile it with PGI compiler? PGI Fortran compiler is now available for free .

    • Hi,

      I have not tried PGI compiler yet, but I think you can take the GCC/GFORTRAN version as a start point. I know WRF has read-to-use option for PGI, so as long as you can have the prerequisite libraries installed correctly, WRF/WPS compilation should not be a big problem. Let me know if you find any “tricks” regarding PGI, and I can update the post with your info!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s