# CESM <img src="https://upload.wikimedia.org/wikipedia/zh/thumb/d/d8/Red_Hat_logo.svg/1920px-Red_Hat_logo.svg.png" width=150px>
## 前置作業
### add perl library
```
yum install -y "perl(XML::LibXML)"
```
### icc module file 生成
```bash
echo "#%Module" > /usr/share/Modules/modulefiles/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" >> /usr/share/Modules/modulefiles/intel
```
### soft link
```bash
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
```
module purge
```
#### cURL
```bash
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
```
#### load module
```
module load intel mpi
```
#### environment variables
```bash
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
```
#### zlib
```bash
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
```bash
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 --enable-fortran --with-zlib=${ZDIR} --prefix=${H5DIR}
make -j4
make install -j4
```
#### netcdf-c
```bash
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
```bash
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.0.166/linux/mpi/intel64/bin \
--enable-shared
make -j4
make install -j4
```
#### netcdf-c with pnetcdf support
```bash
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
```bash
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
```bash
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
```bash
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
prepend-path LD_LIBRARY_PATH /usr/local/lib
cd /usr/share/Modules/modulefiles
ln -s /root/cdf cdf
```
之後, 可以`module load cdf`load cdf的module
## CESM
### install cesm
```bash
git clone https://github.com/escomp/cesm.git cesm
cd cesm
git checkout release-cesm2.1.1
echo p | svn list https://svn-ccsm-models.cgd.ucar.edu/cam1/release_tags/cam_cesm2_1_rel_29/components/cam
./manage_externals/checkout_externals
```
### Create Case
```bash
./create_newcase --case /root/redhat --compset B1850 --res f19_g17
./check_case
./case.setup
./case.build
```
<hr>
### Reference
<a href="https://software.intel.com/en-us/articles/using-environment-modules-with-the-intel-development-tools" class="text-warning">ICC Module file</a>
<a href="https://www.unidata.ucar.edu/software/netcdf/docs/getting_and_building_netcdf.html#build_parallel" class="text-warning">Parallel I/O</a>
<a href="https://software.intel.com/en-us/articles/performance-tools-for-software-developers-building-netcdf-with-the-intel-compilers" class="text-warning">Intel 環境變數</a>
<a href="https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor" class="text-warning">Intel linker</a>
{"metaMigratedAt":"2023-06-15T02:51:45.144Z","metaMigratedFrom":"Content","title":"CESM <img src=\"https://upload.wikimedia.org/wikipedia/zh/thumb/d/d8/Red_Hat_logo.svg/1920px-Red_Hat_logo.svg.png\" width=150px>","breaks":true,"contributors":"[{\"id\":\"f1475160-f0a7-4781-baef-4196b50d39f6\",\"add\":14844,\"del\":24198},{\"id\":\"36065126-2c6a-42fe-8cf3-655defab0d78\",\"add\":27841,\"del\":13168},{\"id\":\"e07295cb-cd72-47b7-b8f4-5d54523f37b3\",\"add\":1,\"del\":0}]"}