Installing WRF/Chem on CentOS 7(转载修正)

来源:互联网 发布:路由追踪命令 linux 编辑:程序博客网 时间:2024/06/18 05:03

WRF (Weather Research and Forecast) is a powerful numerical simulation tool in atmospheric science. It is maintained by UCAR, and in continuous development. There has been a lot of official (ARW user guide)/ unofficial installation guide, 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. Here I will give out the steps for Intel compiler installation.

0.My system

It is running CentOS 7, and basically it is after a fresh install.
CentOS 安装及 intel 编译安装参考 “用CentOS 7打造合适的科研环境”.

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/amplxe-vars.sh quietsource /opt/intel/inspector_xe_2015/inspxe-vars.sh quietsource /opt/intel/advisor_xe_2015/advixe-vars.sh quietsource /opt/intel/bin/compilervars.sh intel64source /opt/intel/bin/ifortvars.sh intel64source /opt/intel/bin/iccvars.sh intel64

(Here, it is better to create a sh file in /etc/profile.d/, and add the lines above in the sh file.) The last two lines are for the installation of NETCDF.

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 install from source code. The source codes have been seperated as NetCDF-C and NetCDF-Fortran version now. WRF requires Fortran version, but Fortran version depends on C version, so we will install both. Download the codes at Unidata.

2.1.0 Solve dependencies of netcdf
http://www.unidata.ucar.edu/software/netcdf/docs/getting_and_building_netcdf.html

The usual way of building netCDF requires the HDF5, zlib, and curl libraries. Versions required are at least HDF5 1.8.9, zlib 1.2.5, and curl 7.18.0 or later.

HDF5 and zlib packages are available from the HDF5 downloads site and the zlib home site. If you wish to use the remote data client code, then you will also need libcurl, which can be obtained from the curl website.
The version I installed are hdf5-1.8.16, zlib-1.2.8, and netcdf-4.3.3.1.

If “make check” fails for either zlib or HDF5, the problem must be resolved before the netCDF-4 installation can continue. For HDF5 problems, see the HDF5 help services.

To build zlib from source, specify where you want to install zlib in a shell variable you will also use later (ZDIR, for example), and build it like this from the top-level zlib source directory

$ # Build and install zlib$ ZDIR=/usr/local$ ./configure --prefix=${ZDIR}$ make check$ make install   # or sudo make install, if root permissions required

Next, specify where you want to install HDF5 in another shell variable, for example H5DIR, and build it from the HDF5 top-level source directory:

$ # Build and install HDF5$ H5DIR=/usr/local$ ./configure --with-zlib=${ZDIR} --prefix=${H5DIR}$ make check$ make install   # or sudo make install, if root permissions required

add another line before make check to avoid an error

make     

In all cases, the installation location specified with the –prefix option must be different from the source directory where the software is being built.

Before building netCDF, you may need to add ${H5DIR}/lib to the LD_LIBRARY_PATH environment variable if that lib directory is not searched by default. See the netCDF FAQ for more details on using shared libraries.

2.1.1 NetCDF-C

First set some environment variables. This is for both icc and ifort. Then install NetCDF-C.

Indicate where you want to install netCDF in another shell variable, for example NCDIR. Then run the netCDF configure script, specifying where HDF5 was installed using the CPPFLAGS and LDFLAGS environment variables. For example, from the top-level netCDF source directory:

$ # Build and install netCDF-4$ NCDIR=/usr/local$ CPPFLAGS=-I${H5DIR}/include LDFLAGS=-L${H5DIR}/lib ./configure --prefix=${NCDIR}$ make check$ make install  # or sudo make install

Here there will be problem if just use the lines above.
Just like

icc: warning #10237: -lcilkrts linked in dynamically, static library not available
ld: warning: libimf.so, needed by /usr/local/netcdf4.3-intel/nc430_hdf5_189sz/lib/libnetcdf.so, not found (try using -rpath or -rpath-link)

Use the following lines instead will install the netcdf successfully.

ZDIR=/usr/localH5DIR=/usr/localexport CC=iccexport CXX=icpcexport CFLAGS='-O3 -xHost -ip -no-prec-div -static-intel'export CXXFLAGS='-O3 -xHost -ip -no-prec-div -static-intel'export F77=ifortexport FC=ifortexport F90=ifortexport FFLAGS='-O3 -xHost -ip -no-prec-div -static-intel'export CPP='icc -E'export CXXCPP='icpc -E'CPPFLAGS=-I${H5DIR}/include LDFLAGS=-L${H5DIR}/libLD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}./configure --prefix=/usr/intel/netcdfmakemake 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.gzcd netcdf-fortran-4.4.2configure --prefix=/usr/intel/netcdfmakemake check # Similarly, you can skip this is you want.make install

The lines above are not enough.

Follow the instructions on ucar:
http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-fortran-install.html

First make sure the netCDF C library has been built, tested, and installed under directory ${DIR1}, as specified by –prefix=${DIR1} to the C library configure script, or under directory /usr/local by default.
For the Fortran netCDF library, use the same C compiler as used to create the netCDF C library, specified with the CC environment variable, if necessary.

If the netCDF C library was installed as a shared library in a location that is not searched by default, you will need to set the LD_LIBRARY_PATH environment variable (or DYLD_LIBRARY_PATH on OSX) to specify that directory before running the configure script, for example:
export LD_LIBRARY_PATH=${DIR1}/lib:${LD_LIBRARY_PATH}

If you set the LD_LIBRARY_PATH (or DYLD_LIBRARY_PATH) environment variable in the previous step, don’t use the “sudo” command before the following “configure” or “make check” commands. Using “sudo” causes the LD_* environment variables to be ignored, as a security precaution. You can use “sudo make install” as the last step, but you shouldn’t need to use “sudo” before that.

For the configure script, set CPPFLAGS and LDFLAGS variables to specify the include and lib directories for the netCDF C library. For example, to install the Fortran libraries in the same directory ${DIR1} where the C netCDF library is installed:
CPPFLAGS=-I\${DIR1}/include LDFLAGS=-L\${DIR1}/lib ./configure –prefix=\${DIR1}
If you are cross-compiling, you should also include the configure option “–disable-fortran-type-check”, as in:
CPPFLAGS=-I\${DIR1}/include LDFLAGS=-L\${DIR1}/lib \
./configure –disable-fortran-type-check –prefix=\${DIR1}
If that succeeds, run “make check”.
If that succeeds, run “make install” or “sudo make install”.

The codes are:

DIR1=/usr/intel/netcdfexport LD_LIBRARY_PATH=${DIR1}/lib:${LD_LIBRARY_PATH}CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure --prefix=${DIR1}makemake checksudo make install

Add the following line to .bashrc file in the user home directory, then can use the commands like ”ncdump”.

export PATH=$PATH:/usr/intel/netcdf/bin/

2.2 MPICH

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=ifortexport FCLAGS='-O3 -xHost -ip -no-prec-div -static-intel'

Download mpich from http://www.mpich.org/downloads/, and then install it as below:

tar xvzf mpich-3.2.tar.gz cd mpich-3.2/./configure --prefix=/usr/intel/mpichmakemake checkmake install (error occur... but seems that WRF does not need mpich if only runs on one pc, so check later)

2.3 zlib
Have these two variables set, then install the zlib.
(have installed, check the context above)

2.4 libpng
Download the package from http://www.libpng.org/pub/png/libpng.html.

tar xvzf libpng-1.6.21.tar.gzcd libpng-1.6.21/export CC=iccexport CXX=icpc./configure --prefix=/usr/intel/libpngmakemake checksudo make install

2.5 jasper
Nothing special here. Just follow the general procedure of installing from source codes.
Download the code from http://www.ece.uvic.ca/~frodo/jasper/#download

tar -zxf jasper-1.900.1.tar.gzcd jasper-1.900.1export CC=iccexport CXX=icpc./configure --prefix=/usr/intel/jaspermakemake checksudo make install

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

export PATH=$PATH:/usr/intel/netcdf/bin/export PATH=$PATH:/usr/intel/jasper/bin/export PATH=$PATH:/usr/intel/libpng/bin/

and these

JASPER=/usr/intel/jasper;export JASPERJASPERLIB=/usr/intel/jasper/lib/;export JASPERLIBJASPERINC=/usr/intel/jasper/include/;export JASPERINCZLIB=/usr/intel/zlib;export ZLIBZLIBLIB=/usr/intel/zlib/lib/;export ZLIBLIBZLIBINC=/usr/intel/zlib/include/;export ZLIBINCexport LD_LIBRARY_PATH=/usr/intel/netcdf/lib/:$LD_LIBRARY_PATHexport LD_LIBRARY_PATH=/usr/intel/jasper/lib/:$LD_LIBRARY_PATHexport LD_LIBRARY_PATH=/usr/intel/libpng/lib/:$LD_LIBRARY_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).

export EM_CORE=1export NMM_CORE=0export WRF_CHEM=1export WRF_KPP=0
NetCDF users note: This installation of NetCDF supports large file support.  To enable large file support in NetCDF, set the environment variable WRFIO_NCD_LARGE_FILE_SUPPORT to 1 and run configure again. Set to any other value to avoid this message.$ export WRFIO_NCD_LARGE_FILE_SUPPORT=1

When I compile the WRF using ./compile em_real, there is an error due to a gcc “bug”: CPP adds extra comments.

/* Copyright (C) 1991-2012 Free Software Foundation, Inc. 1Error: Invalid character in name at (1)

Refer to a similar error post: http://stackoverflow.com/questions/25118052/gcc-e-p-c-adds-extra-comments

Resolve the error by the use of -nostdinc option
vim ./configure.wrf
change the line

CPP             =      /lib/cpp -C -P

to

CPP             =      /lib/cpp -C -P -nostdinc

Then WRF can be compiled smoothly.

Fix another error
tc_em.f90(138): error #6418: This name has already been assigned a data type. [ITMP]
INTEGER :: julyr , julday ,itmp,icnt

vim main/tc_em.F, and change the line
INTEGER :: julyr , julday ,itmp,icnt
to INTEGER :: julyr , julday

Check the exe files
$ ls main/*.exe
main/ndown.exe main/nup.exe main/real.exe main/tc.exe main/wrf.exe

Time for play!

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 I have 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 &

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).

$ cd WPS351/$ ./configureselect the  Intel compiler $ ./compile &> compile.log &

Same gcc ‘bug’ error:

wrf_debug.f90(1): error #5082: Syntax error, found '/' when expecting one of: <LABEL> <END-OF-STATEMENT> ; BLOCK PROGRAM BLOCKDATA MODULE INTEGER REAL COMPLEX .../* Copyright (C) 1991-2012 Free Software Foundation, Inc.

vim configure.wps
change the line CPP = /lib/cpp -C -P -traditional to CPP = /lib/cpp -C -P -traditional -nostdinc

Error2

png.h: No such file or directory #include <png.h>

locate the png.h, then vim configure.wps, find the line
COMPRESSION_INC = -I/data3a/mp/gill/WPS_LIBS/local/include \
and add the libpng include directory
COMPRESSION_INC = -I/data3a/mp/gill/WPS_LIBS/local/include \
-I/usr/intel/libpng/include/

Error3:

enc_png.c: In functionenc_png_’:enc_png.c:101:31: error: ‘voidp’ undeclared (first use in this function)     png_set_write_fn(png_ptr,(voidp)&write_io_ptr,(png_rw_ptr)user_write_data,

Solution: change voidp to png_voidp.

Error4:

dec_png.c: In functiondec_png_’:dec_png.c:101:30: error: ‘voidp’ undeclared (first use in this function)     png_set_read_fn(png_ptr,(voidp)&read_io_ptr,(png_rw_ptr)user_read_data);

Solution: change voidp to png_voidp.

Error 5:

ld: cannot find -ljasperld: cannot find -lpng12ld: cannot find -lpng

vim configure.wps, change

COMPRESSION_LIBS        =       -L/data3a/mp/gill/WPS_LIBS/local/lib                                 -ljasper -lpng12 -lpng -lz

to

COMPRESSION_LIBS        =       -L/data3a/mp/gill/WPS_LIBS/local/lib \                                -L/usr/intel/jasper/lib \                                -L/usr/intel/libpng/lib \                                -ljasper -lpng16 -lpng -lz

Error 6:

ld: cannot find -lncargld: cannot find -lncarg_gksld: cannot find -lncarg_cld: cannot find -lX11

After NCL installed, the first 3 errors gone. Now deal with the last one.
Try to change the line

                                -L/usr/X11R6/lib -lX11

to

                                -L/usr/lib -lX11

No luck…. but seems the exe files are generated and perform well. Test confirmed.

5. Building RIP4

5.1 Install NCL

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

Find the install file from the page https://www.ncl.ucar.edu/Download/install.shtml

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

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

export NCARG_ROOT=/usr/intel/nclexport PATH="$NCARG_ROOT/bin:$PATH"export LD_LIBRARY_PATH="/opt/intel/composer_xe_2015.6.233/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
(This part is skipped)

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 comes 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 libcairo.so/usr/lib64/libcairo.so

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

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

6. WRF/Chem Test.

An error occur: “wrf Segmentation fault (core dumped)”
Solution:
Refer to http://forum.wrfforum.com/viewtopic.php?f=6&t=4391,
“Early segmentation faults often are a simple memory issue.
Did you try the command “ulimit -s unlimited” before running WRF? ”
After typing the command, the wrf/chem worked.


[1] 用CentOS 7打造合适的科研环境 http://seisman.info/linux-environment-for-seismology-research.html
[2] Installing WRF on CentOS 7 https://wolfscie.wordpress.com/2015/04/23/installing-wrf-on-centos-7/
[3] [netCDF #JZT-105309]: neCDF 4.3.0 installation issue - Can’t find or link to the hdf5 library https://www.unidata.ucar.edu/support/help/MailArchives/netcdf/msg11947.html
[4] Building the netCDF-4.2 and later Fortran libraries
http://www.unidata.ucar.edu/software/netcdf/docs/netcdf-fortran-install.html
[5] WRF official website
http://www.wrf-model.org/index.php
[6] A tutorial on how to compile WRF
http://www2.mmm.ucar.edu/wrf/OnLineTutorial/compilation_tutorial.php

0 0