RQL's Blog 菜鸟成长记

cesm模式运行的一般流程

2018-03-21
renql

CESM1.2 User Guide

一、运行CESM的一般流程

1. 设置CESM的环境变量,否则有些命令在其他目录下无法使用

source  ~/.bashrc_cesm

2. 创建案例

create_newcase -case $CASENAME -compset B1850CN -res f19_g16 -mach yellowstone
#-case(案例名称),-compset(模块设置类型),-res(精度),-mach(CESM机器)这四个参数是必须的
#./create_newcase后面可以跟-h(即help),-list(可列出后面可以跟的参数)
#-list后还可加[compsets, grids, machines]以列出相应参数可以有的内容是什么

compset name 网站超链接 resolution 网站超链接

运行create_newcase后,生成的有用的文件:

  • README.case 写有关于你这个案例的所有设置内容,后期可手动将自己对于该案例设置的修改记录于此,以便以后查看
  • CaseStatus 写有你在何时对案例进行了何种操作,例如 build complete 2017-10-20 19:51:58
  • SourceMods 若模式的代码有改动,则将改动后的代码放于该目录下

3. 修改env_*.xml文件

修改方法:一直接用vi修改该文件,二用命令./xmlchange NTASKS = $NTASKS。
修改的文件及相应可修改的内容有:

  • env_mach_pes.xml 在setup前修改,可修改 ntasks,nthrds,rootpe,ninst env_mach_pes.xml variables 超链接
  • env_build.xml ,在build前修改,可修改 EXEROOT, CALENDAR (NO_LEAP) env_build.xml variables 超链接
  • env_run.xml 在run前修改,可修改 RUNDIR, RUNTYPE(hybrid,branch,startup), STOP_OPTION, STOP_N, REST_OPTION, REST_N, RESUBMIT, DIN_LOC_ROOT, DIN_LOC_ROOT_CLMFORC,也可设置short term archiving and long term archiving,也可修改SST等强迫的文件路径 env_run.xml variables 超链接

在env_run.xml中也可设置积分步长,不过是通过设置ATM_NCPL值来决定积分步长(dtime)。
ATM_NCPL in env_run.xml specifies the number of coupling intervals per day between the atmosphere/land and the coupled system. Based on ATM_NCPL, the scripts will automatically compute the timestep for the atmosphere and land (DTIME) and populate the namelist files accordingly.

4. setup

setup前需要修改env_mach_pes.xml,设置跑模式用的节点数。

./cesm_setup

该操作后生成的有用的文件有:

  • user_nl_xxx 修改输入模式中的一些变量如CO2浓度、太阳辐射、海温资料、植被资料等等,也可设定输出数据的频率和类型(至于是否修改成功可通过运行preview_namelists来查看,可修改的常量在CaseDocs/xxx_in),在build前修改即可  
  • CaseDocs 存放有各模块在run时需要用到的变量名,供参考
  • env_derived 存放有从其他设置中获得的环境变量,用户不能修改

另外关于所有变量介绍的说明文件可以在这里找到: http://www.cesm.ucar.edu/models/cesm1.2/     可通过一开始的搜索寻找想要查找的变量名称。

最常用的CAM模块的 variable namelist 的网址是 http://www.cesm.ucar.edu/cgi-bin/eaton/namelist/nldef2html-cam5_3

5. build

build前需要做的:修改env_build.xml, user_nl_xxx(修改输入模式中的一些变量如CO2浓度、太阳辐射、海温资料、植被资料等等,也可设定输出数据的频率和类型),在SourceMods中修改源代码

./$CASENAME.build

build过程中,

  1. 检查模式运转时需要的输入数据,若数据缺失,build会终止并列出缺失数据,此时可用 ./check_input_data -export 获得缺失的数据文件,然后可以用 ./check_input_data --download 自动下载缺失文件,也可以自己去该网页下载 https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata
  2. 创建 build/run 目录,里面放有模式运转时用到的namelist(即xxx_in),后面输出的数据文件也放于此处。

若build后又有修改源代码,可以直接build,不需要clean build     build后会在 $RUNDIR 生成 xxx_in ,不能再修改。同时这也是模式实际运行时用到的参数变量, 可通过检查这些文件以确定模式是否按照你设定的方向运行

另外,$casename/Buildconf/XXX.input_data_list 文件列出了模式在运行中所需要的外部输入文件。

6. run

run前需要做的:修改env_run.xml(经常修改的有 RUNTYPE(hybrid,branch,startup), STOP_OPTION, STOP_N, REST_OPTION, REST_N,CONTINUE_RUN,SST强迫的文件路径)

在天河,需要通过修改 AMIP_CAM5_NG4550.run 来修改提交任务的名字,可在vim中通过搜索yhbatch来修改。AMIP_CAM5_NG4550.sh中的任务名字没有影响。

./$CASENAME.run

提交作业,该命令在四期会通过运行run.pbs来提交作业至集群系统中的多个节点。

if ( "$MPILIB" == "mpi-serial" ) then
    $EXEROOT/cesm.exe >&! cesm.log.$LID
else
    qsub run.pbs
endif
wait
echo "`date` -- CSM EXECUTION HAS FINISHED"

而run.pbs最后主要是通过mpirun运行EXEROOT下面的cesm.exe

但在天河中,$casename.run则通过yhbatch来提交一个sh文件,sh文件中又用yhrun来运行cesm.exe

二、三类runtype

env_run.xml 文件中的 ` $RUN_TYPE ` 选项决定了模式初始化的类型,有以下三个选择。该选项只在 ` $CONTINUE_RUN = FALSE` 时有效。

  • branch(分支), 模式从RUN_REFCASERUN_REFDATE设定的 restart file(文件名中有 *.r.* )开始继续往下模拟, 同restart run(当CONTINUE_RUN是TRUE时),但需要有相应时间的restart文件。当两个case之间的各种参数都一样时,他们跑出来的数据也是一模一样的。常用于敏感性实验。
    branch run中, $RUN_STARTDATE 这一参数会被忽略.
    All model components are initialized from restart files generated by a user-specified CESM simulation.
    Use branch run: only for applications which require exact restart. You CANNOT specify a new start date for your model run. It will be assigned by the reference case (RUN_REFDATE).

  • hybrid,同startup一样初始话,只是其初始化数据来自以往跑的一个算例的restart数据,有点类似branch但该设置的约束较少。也需要设定RUN_REFCASERUN_REFDATE ,当其各种参数设置同reference case时,其气候态数据也同reference case,但每一天的数据不一定一样。
    在这个选项中,开始模拟的日期可以用 $RUN_STARTDATE 设置。在hybrid的初始化中,海洋模式也是在模式模拟的第二天开始耦合。在没有restart file时是冷启动。 The atmosphere and land are initialized from initial condition files generated by a user-specified CESM simulation.
    The ocean and ice are initialized from restart files generated by a user-specified CESM simulation.  
    Initial conditions and restart files use the same reference case and reference date.
    Use a hybrid run: for most applica4ons where you do NOT need bit for bit restart. You CAN specify a new start date for your model run.

  • startup,默认选项,一般不需要设置参考算例(RUN_REFCASE和RUN_REFDATE),All model components are initialized from basic default initial conditions. 相当于模式从头开始跑。其中,海洋模式一般在模式模拟的第二天开始耦合

User Guide 的解释 http://www.cesm.ucar.edu/models/cesm1.2/cesm/doc/usersguide/c1113.html

三、create_case.sh脚本

该脚本中主要定义了casename,compset,分辨率,运行时间(stop_option,stop_n),计算节点数及所用阵列,然后进行了$./cesm_setup并输出run.pbs文件

# Name of your case, your name to be prefix, e.g. LZN_HEAT
CASENAME=test_x

# Component set of your case
COMPSET=X

#Resolution of your case
RES=f45_g37

#Stop option of your case, should be nyears, nmonths, ndays, etc.
STOP_OPTION=nyears

#Stop N of your case, when stop_option set to be 'nyear' and stop N
#set to 5, it means the model will run for 5 years
STOP_N=30

#How many processors you will use for your case, sequential only
#Multiple of 16, such as 32, 48, 64, 80, 96, 112, 128, etc#
#CAM4 f19 works fine below  96PEs#
#CAM5 f19 works fine below 384PEs. However, there are not so many 
#CPUs for this kind of work#
NTASKS=64

#Which que you will use for your case, such as 'ys', 'few', 'medium',
#and much
QUENAME=ys

#rm -rf $CASENAME

#*************************************************************
#---------------Above for user defined part-------------------
#*************************************************************

#*************Below to execute the change*********************
# WARNING:
#   If you are willing to change anything below, you need to be
# VERY CAUTIOUS to do so.
#*************************************************************

create_newcase -case $CASENAME -compset $COMPSET -res $RES -mach sigon
cd $CASENAME

#Change compile out and run out roots
./xmlchange EXEROOT=`pwd`/exe
./xmlchange RUNDIR=`pwd`/exe

#Change PE layers
./xmlchange NTASKS_ATM=$NTASKS
./xmlchange NTASKS_LND=$NTASKS
./xmlchange NTASKS_ICE=$NTASKS
./xmlchange NTASKS_OCN=$NTASKS
./xmlchange NTASKS_GLC=$NTASKS
./xmlchange NTASKS_WAV=$NTASKS
./xmlchange NTASKS_ROF=$NTASKS
./xmlchange NTASKS_CPL=$NTASKS

#./cesm_setup

#Compile Process, It will take long...
#./${CASENAME}.build

#Link the input data to your caseroot,
#NEVER POLLUTE THE ORIGINAL INPUTROOT!!!
#link_dirtree $CSMDATA ./input

#./xmlchange DIN_LOC_ROOT=`pwd`/input

./xmlchange STOP_OPTION=$STOP_OPTION
./xmlchange STOP_N=$STOP_N

#Deal with que and nodes
NNODES=$[NTASKS/16]

if [ $QUENAME = "ys" ]; then
    WALLTIME=999
elif [ $QUENAME = "few" ]; then
    WALLTIME=720
elif [ $QUENAME = "medium" ]; then
    WALLTIME=168
else
    WALLTIME=48
fi

#--------------------------------------
#------Now generate the pbs file-------
#--------------------------------------
cat << EOF > run.pbs
#!/bin/sh
#PBS -N lzn_$CASENAME  # define the name of the job, remember to modify
#PBS -q $QUENAME
#PBS -l walltime=$WALLTIME:00:00
#PBS -l nodes=$NNODES:ppn=16
#PBS -r n
#PBS -o cesmrun.log
#PBS -e cesmrun.err
#PBS -V 
echo "This jobs is "\$PBS_JOBID@\$PBS_QUEUE
echo running >& \$EXEROOT/../run_status
MPIBIN=/public/mpi/mvapich2-18-intel/bin
cd \$EXEROOT
\$MPIBIN/mpirun -np $NTASKS -hostfile \$PBS_NODEFILE  ./cesm.exe >& ../run.log
echo finished >& \$EXEROOT/../run_status
EOF

支持 支付宝鼓励 鸡腿鸡腿

喜欢此文!

Content