---
# System prepended metadata

title: 'CESM <img src="https://i.imgur.com/IapgZfi.png" width=150px>'

---

# CESM <img src="https://i.imgur.com/IapgZfi.png" width=150px> 
## 前置作業
### add perl library
```
yum install -y "perl(XML::LibXML)"
```
### icc module file 生成
```
echo "#%Module" > /root/intel
git clone https://git.code.sf.net/p/env2/code env2-code
cd env2-code/
perl env2 -from bash -to modulecmd \
"/opt/intel/parallel_studio_xe_2020.0.088/psxevars.sh intel64" >> /root/intel
```
### soft link
```
cd /usr/share/Modules/modulefiles
ln -s /opt/intel/impi/2019.6.166/intel64/modulefiles/mpi mpi
ln -s /root/intel intel
```


### Parellel I/O
#### 架構
<img src="https://ncar.github.io/ParallelIO/PIO_Library_Architecture1.jpg"></img>
#### 以下步驟都是為了裝parallel I/O
#### load module
```
module load intel mpi
```
#### environment variables
```
export ZDIR=/usr/local/zlib
export H5DIR=/usr/local/hdf5
export NCDIR=/usr/local/netcdf-c
export PNDIR=/usr/local/pnetcdf
export NFDIR=/usr/local/netcdf-fortran

export CC=mpiicc
export CXX=mpiicpc
export CPP='icc -E'
export FC=mpiifort
export CFLAGS='-O3 -xHost -ip -no-prec-div'
export CXXFLAGS='-O3 -xHost -ip -no-prec-div'
export CXXCPP='icpc -E'
export FFLAGS='-O3 -xHost -ip -no-prec-div'

export F77=mpiifort
export F90=mpiifort
```


#### cURL
``` 
yum install -y openssl-devel
rpm -e --nodeps curl
wget https://curl.haxx.se/download/curl-7.68.0.tar.gz
tar xvf curl-7.68.0.tar.gz
cd curl-7.68.0

./configure --with-ssl
make -j4
make install -j4
exec bash
```

#### zlib
```
wget https://www.zlib.net/zlib-1.2.11.tar.gz
tar xvf zlib-1.2.11.tar.gz
cd zlib-1.2.11

./configure --prefix=${ZDIR}
make -j4
make install -j4
```
#### HDF5 
```
wget https://hdf-wordpress-1.s3.amazonaws.com/wp-content/uploads/manual/HDF5/HDF5_1_10_6/source/hdf5-1.10.6.tar.gz
tar xvf hdf5-1.10.6.tar.gz
cd hdf5-1.10.6

./configure --enable-parallel --with-zlib=${ZDIR} --prefix=${H5DIR}
make -j4
make install -j4
```
#### netcdf-c
```
wget https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-c-4.7.3.tar.gz
tar xvf netcdf-c-4.7.3.tar.gz
cd netcdf-c-4.7.3

CPPFLAGS=-I${H5DIR}/include LDFLAGS=-L${H5DIR}/lib \
    ./configure --enable-parallel-tests --prefix=${NCDIR} --disable-dap
make -j4
make install -j4
```
#### pnetcdf
```
wget https://parallel-netcdf.github.io/Release/pnetcdf-1.12.1.tar.gz
tar xvf pnetcdf-1.12.1.tar.gz
cd pnetcdf-1.12.1

./configure --prefix=${PNDIR} \
--with-mpi=/opt/intel/compilers_and_libraries_2020.1.217/linux/mpi/intel64/bin \
--enable-shared
make -j4
make install -j4
```
#### netcdf-c with pnetcdf support
```
cd netcdf-c-4.7.3

CPPFLAGS="-I${H5DIR}/include -I${PNDIR}/include" \
  LDFLAGS="-L${H5DIR}/lib -L${PNDIR}/lib" \
  ./configure \
  --enable-pnetcdf  --enable-parallel-tests \
  --prefix=${NCDIR} --disable-dap
make -j4
make install -j4
```
#### netcdf-fortran
```
wget https://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-fortran-4.5.2.tar.gz
tar xvf netcdf-fortran-4.5.2.tar.gz
cd netcdf-fortran-4.5.2

export LD_LIBRARY_PATH=${NCDIR}/lib:$LD_LIBRARY_PATH

CPPFLAGS=-I${NCDIR}/include \
LDFLAGS=-L${NCDIR}/lib \
    ./configure --enable-parallel-tests --prefix=${NFDIR} \
    --disable-fortran-type-check 
make -j4
make install
```
### pio
```
wget https://github.com/NCAR/ParallelIO/releases/download/pio2_5_0/pio-2.5.0.tar.gz
tar xvf pio-2.5.0.tar.gz
cd pio-2.5.0

export LD_LIBRARY_PATH=${PNDIR}/lib:$LD_LIBRARY_PATH
export CPPFLAGS="-I${NCDIR}/include -I${PNDIR}/include -I${NFDIR}/include -std=c99"
export LDFLAGS="-L${NCDIR}/lib -L${PNDIR}/lib -L${NFDIR}/lib"

./configure --enable-fortran
make -j4
make install -j4
```
### cdf 系列 module file
```
vim /root/cdf

#%Module
prepend-path    PATH                    /usr/local/hdf5/bin
prepend-path    PATH                    /usr/local/netcdf-c/bin
prepend-path    PATH                    /usr/local/netcdf-fortran/bin
prepend-path    PATH                    /usr/local/pnetcdf/bin
prepend-path    LD_LIBRARY_PATH         /usr/local/zlib/lib
prepend-path    LD_LIBRARY_PATH         /usr/local/hdf5/lib
prepend-path    LD_LIBRARY_PATH         /usr/local/netcdf-c/lib
prepend-path    LD_LIBRARY_PATH         /usr/local/netcdf-fortran/lib
prepend-path    LD_LIBRARY_PATH         /usr/local/pnetcdf/lib

cd /usr/share/Modules/modulefiles
ln -s /root/cdf cdf
```
之後, 可以`module load cdf`load cdf的module
## CESM
### install cesm
```
echo p | svn list https://svn-ccsm-models.cgd.ucar.edu/cam1/release_tags/cam_cesm2_1_rel_29/components/cam
git clone https://github.com/escomp/cesm.git cesm
cd cesm
git checkout release-cesm2.1.1
./manage_externals/checkout_externals
```
### Create Case
```
./create_newcase --case /root/cent --compset B1850 --res f19_g17
./check_case
./case.setup
./case.build
```