2020-03-16solps安装流程
将最新把版本的solps repository clone to 本地
1. 选择branch
image.png2. 选择clone 地址
获得ssh协议地址3. 配置ssh密钥
image.pngimage.png
复制公钥内容
4. clone repository到本地
clone repositoryimage.png由于仓库位置恒定,可以把这个仓库设置成远端
失败
下载成功,会在当前目录下生成 solps-iter文件夹
5. pro git 中文版
image.png共享空间,没有操作权限
git submodule init # 初始化本地配置文件
git submodule update # 从该项目中抓取所有数据并检出父项目中列出的合适提交
5. 编译solps
- 1. cd solps.iter
- 2. git submodule init
image.png初始化本地配置文件
-3. git submodule update
image.pngimage.png从project中抓取对应的数据
此时module中内容已经被下载
-4.开始编译
whereami
-
tr:装换或删除文件中的字符
image.png
-
-
nslookup
image.png
image.png
image.png
-
-
grep -m
image.png
-
-
hostname
image.png
image.png
image.png
-
- set:
set machine_location=`hostname`
image.png将hostname 置零的输出结果赋值给machine_location
image.png
image.png
image.png
set fullhost=`nslookup $machine_location | grep -m 1 Name | awk '/Name:/{print $2}' | tr 'A-Z' 'a-z'`
查询machine_location 对应变量的DNS信息,匹配第一个是含有 Name的行,打印改行的第二个字段,将第二个四段的大写字母全部换成小写。把结果复制给fullhost
image.png
image.png
image.png
$HOST_NAME 是自己设置的?
image.png
- if ... endif
if ("$fullhost" == "") then
set fullhost=`hostname -f`
endif
如果fullhost的值为空,则将其赋值为 hostname -f 对应的结果(本测试为 sms),即简略的hostname
- cut
set mephi_check=`echo $machine_location | cut -c1-4`
image.png
image.png
截取变量machine_location按字符计算的1-4个字节(machine_location对应'sms',只有三个字符),把结果赋值给mephi_check
- switch
set mephi_check=`echo $machine_location | cut -c1-4`
if ("$mephi_check" == "head" || "$mephi_check" == "node") then
switch ($fullhost)
case "*.cm.cluster":
breaksw
default:
echo "mephi_check = $mephi_check - special mephi cluster treatment applies"
set machine_location="cluster21.mephi.ru"
set fullhost=$machine_location
endsw
endif
如果mephi_check对应值为‘head’或者‘node’,则switch fullhost(本测试 fullhostname为‘sms.hlsm.local’)
- [ -d /af ] : 如果文件存在
[ -d /afs ] && echo ITM || echo MARCONI
image.png
小结:
image.pngwhereami脚本通过查询hostname,判断本地集群所在的位置。并将结果打印到屏幕
解决办法:直接输出你的集群名字,把这个脚本替换掉
image.png
image.png
- 1. 修改文件的过程脚本化
#!/bin/bash
# =================== 修改whereami 脚本 ===================== #
# 第二次运行该脚本,保留原始的whereami
if [ -f whereami_orgin ]
then
mv whereami_orgin whereami
fi
mv whereami whereami_orgin
# 将需要修改的内容重定向到whereami 文件
`echo -e "#!/bin/csh\n echo DUT-PSI"| cat > whereami`
# 给whereami文件加可执行权限
chmod u+x whereami
default_compiler
if (! $?HOST_NAME ) then
if (-e whereami) then
set HOST_NAME=`./whereami|tail -1`
else
set HOST_NAME="UNKNOWN"
endif
if ( $HOST_NAME == "*UNKNOWN*" ) then
set HOST_NAME=default
endif
echo "Using HOST_NAME = $HOST_NAME"
endif
image.png
-
$?HOST_NAME
image.png
-
如果 HOST_NAME的返回值为零,即HOST_NAME没有出错(正常退出的返回值为0)
-
( - e whereami )
image.png
-
如果whereami 当前目录存在,执行脚本 whereami,把输出结果的最后一行赋值给HOST_NAME
- 将DUT-PSI 添加到对应的位置
- sed 方法
sed -i '/CCFE/a\case "DUT-PSI"' default_compiler
在 “CCFE”行后添加本课题组的host_name,使编译器默认为 ifort64
image.png
- awk方法
# 获取CCFE所在行号
nt=`awk '$2 ~ "CCFE" {print NR} ' default_compiler`
# 在指定的行后添加内容
sed -i "${nt}a\case \"DUT-PSI\"" default_compiler
判断default_compiler中是否存在“DUT-PSI”
# 在指定的行后添加内容,如果不存在DUT-PSI,则添加
flag=`grep DUT-PSI default_compiler`
if [[ !${flag} ]]
then
sed -i "${nt}a\case \"DUT-PSI\"" default_compiler
fi
[: case: unary operator expected 错误
[ ** ] 表达式为空,通过[[ ** ]] ,可以消除错误
复制配置文件到lib
初始的lib/目录目前未知DUT.ifort64如何编译,使用编译好的库
- 指定源文件位置
用户指定
- 指定destination
full_path="${base_path}/lib"
# copy the completed lib to new solps package
if [ ! -d "${full_path}/DUT-PSI.ifort64" ]
then
cp -r ${lib_source} ${full_path}
else
echo "DUT-PSI.ifrot64 has existed"
fi
如果已经存在,则不复制
在bash脚本中启动 tcsh
- 不可用
-
可能的解决方案
image.png
image.png
-
不经济,暂停
解决方案——通过bash 产生tcsh脚本,通过bash,调用产生的tcsh脚本
#!/bin/bash
`echo -e "#!/bin/tcsh\n source setup.csh"| cat > start_solps_tcsh`
# 给whereami文件加可执行权限
chmod u+x start_solps_tcsh
./start_solps_tcsh
image.png
通过bash写一个tcsh 文件,重定向,加权限,在bash 中调入用tcsh
scr/first_setup
#! /usr/bin/env ksh
OLD_PWD=$PWD
filename=setup.csh.${HOST_NAME}.${COMPILER}
echo ${filename}
cd $SOLPSTOP/SETUP
[ -s ${filename} ] && {
echo "Non-empty ${filename} already present in $PWD: nothing done"
} || {
cp setup.csh.default.default ${filename}
echo "Created ${filename} from setup.csh.default.default in $PWD: please modify if needed"
}
filename=config.${HOST_NAME}.${COMPILER}
echo ${filename}
[ -s ${filename} ] && {
echo "Non-empty ${filename} already present in $PWD: nothing done"
} || {
cp config.default.default ${filename}
echo "Created ${filename} from config.default.default in $PWD: please modify if needed"
}
如果文件名存在,提示文件已存在,否则根据默认文件产生出示文件,以供修改。
操作的文件包括SETUP和modules的所有子文件夹
小结
通过bash,写文件,写脚本,加权限,然后调用。(终极套娃);通过bash写tcsh脚本,调用tcsh脚本从而实现,跨shell协作。
修改SETUP/config.DUT-PSI.ifort64
- 检查NCARG_ROOT 是否设置正确
awk 'BEGIN{FS = "/"} /NCARG_ROOT \?=/ {print $2}' config.DUT-PSI.ifort64
image.png
运行 first_setup,通过lib/DUT-PSI生成对应的modules&SETUP config 文件。
image.png
- 修改setup.csh.DUT-PSI.ifort64
- 在指定行之后添加多行文本
sed -i '/# Set/a\i am first\n i am second\n i am last!' cong
image.png
image.png
- awk 添加缺省项
sed 's/?=/& ${SOLPSLIB}/g' config.DUT-PSI.ifort64
awk修改文件
在匹配行的末尾添加文件
image.png
image.png
image.png
脚本迁移
- 给一个问价下所有脚本加权限
chmod -R u+x dir
- 添加快捷方式
定义群组 user defined
- 添加快捷方式
今日成果
- 完成编译配置文件自动修改脚本
- 编译成功solps-iter
- 关闭b2plot自动弹窗
- 通过编写脚本,熟悉awk命令,以及程序编写的渐进过程
- 实现在bash中调用tcsh
以下是脚本代码
input: lib/DUT-PSI.ifort64 dir's path
output: compeleted modified configuration file
#!/bin/bash
# =================== 修改whereami 脚本 ===================== #
# 第二次运行该脚本,保留原始的whereami
echo -e "==================== Modify whereami & default_compiler ======================\n "
if [ -f whereami_orgin ]
then
mv whereami_orgin whereami
fi
mv whereami whereami_orgin
# 将需要修改的内容重定向到whereami 文件
`echo -e "#!/bin/csh\n echo DUT-PSI"| cat > whereami`
# 给whereami文件加可执行权限
chmod u+x whereami
# =================== 修改default_complier ================== #
# sed 方法
#sed -i '/CCFE/a\case "DUT-PSI"' default_compiler
# awk 方法
nt=`awk '$2 ~ "CCFE" {print NR} ' default_compiler`
# 在指定的行后添加内容,如果不存在DUT-PSI,则添加
flag=`grep DUT-PSI default_compiler`
if [[ ! ${flag} ]]
then
sed -i "${nt}a\case \"DUT-PSI\"" default_compiler
else
echo "DUT-PSI has existed!"
fi
# =================== 复制编译好的库文件到 lib/ ============= #
# specify the source path (user sepcify)
echo -e "==================== Specify the lib/DUT-PSI source path ======================\n "
stop_source='/home/zhangyanjie/SOLPS_newest_bak/solps-iter'
lib_source="${stop_source}/lib/DUT-PSI.ifort64"
# get the destination path
base_path=`pwd`
full_path="${base_path}/lib"
# copy the completed lib to new solps package
if [ ! -d "${full_path}/DUT-PSI.ifort64" ]
then
cp -r ${lib_source} ${full_path}
echo "copy DUT-PSI.ifort64 success!"
else
echo "DUT-PSI.ifrot64 has existed."
fi
# ==================== 启动solps ============================= #
echo -e "==================== Start solps success! ==== ======================\n "
`echo -e "#!/bin/tcsh\n source setup.csh\n first_setup | cat > /dev/null"| cat > start_solps_tcsh`
# 给whereami文件加可执行权限
chmod u+x start_solps_tcsh
./start_solps_tcsh
echo -e "\n==================== Start modify SETUP config files ===============\n "
# ========================= modify the SETUP/ configuration files =============== #
# 获得SETUP/ path
setup_path="${base_path}/SETUP"
# modify the setup.DUT-PSI.ifort64
flag=`grep HL-2M "${setup_path}/setup.csh.DUT-PSI.ifort64"`
if [[ ! ${flag} ]]
then
sed -i '/# Set/a\if ( ! $?DEVICE) then\n setenv DEVICE HL-2M\nendif\nsetenv GLI_HOME ${SOLPSTOP}/{HOST_NAME}.${COMPILER}\nsetenv NCARG_ROOT ${SOLPSTOP}/lib/${HOST_NAME}.${COMPILER}/NCARG' "${setup_path}/setup.csh.DUT-PSI.ifort64"
echo "Modify setup.csh.DUT-PSI.ifort64 success!"
else
echo "setup.csh.DUT-PSI.ifort64 has changed."
fi
echo "SETUP/setup.csh.DUT-PSI.ifort64 change information."
sed -n '/DEVICE/,/NCARG/p' "${setup_path}/setup.csh.DUT-PSI.ifort64"
echo -e "===================================================================\n"
# modify the config.DUT-OSI.ifort64
# 注释掉第一行
sed -i 's/\$(error/#\$(error/' "${setup_path}/config.DUT-PSI.ifort64"
flag=`awk '/?=/ {print NF}' "${setup_path}/config.DUT-PSI.ifort64" | tail -n1`
if [ ${flag} -eq 2 ]
then
sed -i 's/?=/& ${SOLPSLIB}/g' "${setup_path}/config.DUT-PSI.ifort64"
sed -i '/NCARG_ROOT ?=/s/${SOLPSLIB}/${SOLPSLIB}\/NCARG/' "${setup_path}/config.DUT-PSI.ifort64"
sed -i '/MDSPLUS_DIR ?=/s/${SOLPSLIB}/${SOLPSLIB}\/MDSPLUS/' "${setup_path}/config.DUT-PSI.ifort64"
echo "Modify config.DUT-PSI.fort64 success!"
else
echo "config.DUT-PSI.ifort64 has changed."
fi
# add "#" for LD_MPI,delete /lib except for NCARG & MDSPLUS
flag=`awk '/^#L/ {print $1}' "${setup_path}/config.DUT-PSI.ifort64" `
if [[ ! ${flag} ]]
then
sed -i '/lmpi/s/LD_MPI/#LD_MPI/' "${setup_path}/config.DUT-PSI.ifort64"
echo "Modify the #LD_MPI success!"
else
echo "#LD_MPI has changed."
fi
sed -i '/LD_NETCDF/s/\/lib//' "${setup_path}/config.DUT-PSI.ifort64"
sed -i '/LD_MSCL/s/\/lib//' "${setup_path}/config.DUT-PSI.ifort64"
sed -i '/LD_GR/s/\/lib//' "${setup_path}/config.DUT-PSI.ifort64"
sed -i '/LD_NAG/s/\/lib//' "${setup_path}/config.DUT-PSI.ifort64"
grep error "${setup_path}/config.DUT-PSI.ifort64"
grep NCARG_ROOT "${setup_path}/config.DUT-PSI.ifort64" | head -n1
grep MDSPLUS_DIR "${setup_path}/config.DUT-PSI.ifort64" | head -n1
grep 'L\$' "${setup_path}/config.DUT-PSI.ifort64"
echo "Modify config.DUT-PSI.ifort64 successs!"
# ========================= modify modules configuration files ================== #
echo -e "========================= modify modules configuration files ==================="
module_path="${base_path}/modules" # modules path
# modify B2.5
flag=`grep ffreestanding "${module_path}/B2.5/config/config.DUT-PSI.ifort64"`
if [[ ! ${flag} ]]
then
sed -i 's/traditional/& -ffreestanding/g' "${module_path}/B2.5/config/config.DUT-PSI.ifort64"
echo "Modify the B2.5 configuration file success!"
else
echo "B2.5 ffreestranding has changed."
fi
# modify the mpiifort
nr=`awk '/USE_MPI/ {print NR}' "${module_path}/B2.5/config/config.DUT-PSI.ifort64" | head -n 1`
nt=`echo "${nr} + 1"|bc `
#echo ${nt}
sed -i "${nt}s/mpif90/mpiifort/" "${module_path}/B2.5/config/config.DUT-PSI.ifort64"
nr=`awk '/IMPG/ {print NR}' "${module_path}/B2.5/config/config.DUT-PSI.ifort64" | head -n 1`
nt1=`echo "${nr} + 1"|bc `
#echo ${nt}
sed -i "${nt1}s/mpif90/mpiifort/" "${module_path}/B2.5/config/config.DUT-PSI.ifort64"
# changed information
grep ffree "${module_path}/B2.5/config/config.DUT-PSI.ifort64"
echo "B2.5 mpiifort has changed."
grep mpiifort "${module_path}/B2.5/config/config.DUT-PSI.ifort64"
echo -e "===================================================================\n"
# modify Eirene
flag=`grep ffreestanding "${module_path}/Eirene/config/config.DUT-PSI.ifort64"`
if [[ ! ${flag} ]]
then
sed -i 's/traditional/& -ffreestanding/g' "${module_path}/Eirene/config/config.DUT-PSI.ifort64"
echo "Modify the Eirene configuration file success!"
else
echo "Eirene ffreestranding has changed."
fi
# modify the mpiifort
nr=`awk '/USE_MPI/ {print NR}' "${module_path}/Eirene/config/config.DUT-PSI.ifort64" | head -n 1`
nt=`echo "${nr} + 1"|bc `
#echo ${nt}
sed -i "${nt}s/mpif90/mpiifort/" "${module_path}/Eirene/config/config.DUT-PSI.ifort64"
nr=`awk '/IMPG/ {print NR}' "${module_path}/Eirene/config/config.DUT-PSI.ifort64" | head -n 1`
nt1=`echo "${nr} + 1"|bc `
#echo ${nt}
sed -i "${nt1}s/mpif90/mpiifort/" "${module_path}/Eirene/config/config.DUT-PSI.ifort64"
# changed information
grep ffree "${module_path}/Eirene/config/config.DUT-PSI.ifort64"
echo "Eirene mpiifort has changed."
grep mpiifort "${module_path}/Eirene/config/config.DUT-PSI.ifort64"
echo -e "===================================================================\n"
# modify Uinp
flag=`grep ffreestanding "${module_path}/Uinp/config/config.DUT-PSI.ifort64"`
if [[ ! ${flag} ]]
then
sed -i 's/traditional/& -ffreestanding/g' "${module_path}/Uinp/config/config.DUT-PSI.ifort64"
echo "Modify the Uinp configuration file success!"
else
echo "Uinp ffreestranding has changed."
fi
# modify the mpiifort
nr=`awk '/USE_MPI/ {print NR}' "${module_path}/Uinp/config/config.DUT-PSI.ifort64" | head -n 1`
nt=`echo "${nr} + 1"|bc `
#echo ${nt}
sed -i "${nt}s/mpif90/mpiifort/" "${module_path}/Uinp/config/config.DUT-PSI.ifort64"
# changed information
grep ffree "${module_path}/Uinp/config/config.DUT-PSI.ifort64"
echo "Uinp mpiifort has changed."
grep mpiifort "${module_path}/Uinp/config/config.DUT-PSI.ifort64"
echo -e "===================================================================\n"
# modify fxdr
flag=`grep ffreestanding "${module_path}/fxdr/config/config.default.ifort64"`
if [[ ! ${flag} ]]
then
sed -i 's/traditional/& -ffreestanding/g' "${module_path}/fxdr/config/config.default.ifort64"
echo "Modify the fxdr configuration file success!"
else
echo "Fxdr ffreestranding has changed."
fi
# delete the -vec_report0
sed -i 's/-vec_report0//' "${module_path}/fxdr/config/config.default.ifort64"
# changed information
grep ffree "${module_path}/fxdr/config/config.default.ifort64"
echo "Fxdr FFLAGS has changed."
grep FFLAGS "${module_path}/fxdr/config/config.default.ifort64" | awk 'NR==2 {print}'
echo -e "===================================================================\n"
# modify Carre
flag=`grep ffreestanding "${module_path}/Carre/config/config.DUT-PSI.ifort64"`
if [[ ! ${flag} ]]
then
sed -i 's/traditional/& -ffreestanding/g' "${module_path}/Carre/config/config.DUT-PSI.ifort64"
echo "Modify the Carre configuration file success!"
else
echo "Carre ffreestranding has changed."
fi
# delete the -vec_report0
sed -i 's/-vec_report0//' "${module_path}/Carre/config/config.DUT-PSI.ifort64"
# changed information
grep ffree "${module_path}/Carre/config/config.DUT-PSI.ifort64"
echo "Carre FFLAGS has changed."
grep FFLAGS "${module_path}/Carre/config/config.DUT-PSI.ifort64" | awk 'NR==2 {print}'
echo -e "===================================================================\n"
# modify Triang
flag=`grep ffreestanding "${module_path}/Triang/config/config.DUT-PSI.ifort64"`
if [[ ! ${flag} ]]
then
sed -i 's/traditional/& -ffreestanding/g' "${module_path}/Triang/config/config.DUT-PSI.ifort64"
echo "Modify the Triang configuration file success!"
else
echo "Triang ffreestranding has changed."
fi
# delete the -vec_report0
sed -i 's/-vec_report0//' "${module_path}/Triang/config/config.DUT-PSI.ifort64"
# changed information
grep ffree "${module_path}/Triang/config/config.DUT-PSI.ifort64"
echo "Triang vec_report has deleted."
grep FCOPTS "${module_path}/Triang/config/config.DUT-PSI.ifort64" | tail -n1
echo -e "===================================================================\n"
# modify Divgeo equtrn
flag=`grep ffreestanding "${module_path}/DivGeo/equtrn/config/config.DUT-PSI.ifort64"`
if [[ ! ${flag} ]]
then
sed -i 's/traditional/& -ffreestanding/g' "${module_path}/DivGeo/equtrn/config/config.DUT-PSI.ifort64"
echo "Modify the DG equtrn configuration file success!"
else
echo "DG equtrn ffreestranding has changed."
fi
# changed information
grep ffree "${module_path}/DivGeo/equtrn/config/config.DUT-PSI.ifort64"
echo -e "===================================================================\n"
# modify Divgeo convert
flag=`grep ffreestanding "${module_path}/DivGeo/convert/config/config.DUT-PSI.ifort64"`
if [[ ! ${flag} ]]
then
sed -i 's/traditional/& -ffreestanding/g' "${module_path}/DivGeo/convert/config/config.DUT-PSI.ifort64"
echo "Modify the DG convert configuration file success!"
else
echo "DG convert ffreestranding has changed."
fi
# changed information
grep ffree "${module_path}/DivGeo/convert/config/config.DUT-PSI.ifort64"
echo -e "========================================= start to compiler ======================================"
# ==================== 复制setup.csh到SETUP/ ================ #
#setup_path="${base_path}/SETUP"
#setup_source="${stop_source}/SETUP/setup.csh.DUT-PSI.ifort64"
#config_source="${stop_source}/SETUP/config.DUT-PSI.ifort64"
# copy setup.csh.DUT-PSI.ifort64
#if [ ! -f "${setup_path}/SETUP/setup.csh.DUT-PSI.ifort64" ]
#then
# cp ${setup_source} ${setup_path}
# echo "copy setup.csh success!"
#else
# echo "setup.csh.DUT-PSI.ifort64 has existed."
#fi
# copy config.DUT-PSI.ifort64
#if [ ! -f "${setup_path}/SETUP/config.DUT-PSI.ifort64" ]
#then
# cp ${config_source} ${setup_path}
# echo "copy config success!"
#else
# echo "config.DUT-PSI.ifort64 has existed."
#fi
# =================== modify the config.DUT-PSI.ifort64 =========== #
# check the NCARG,MDSPLUS ROOT
#echo -e "Begin check the config.DUT-PSI.ifort64!\n"
#ncarg_root=`awk 'BEGIN{FS = "/"} /NCARG_ROOT \?=/ {print $2}' "${setup_path}/config.DUT-PSI.ifort64"`
#if [ ${ncarg_root} == "NCARG" ]
#then
# echo "NCARG_ROOT is ok!"
#else
# echo "please check the NCARG_ROOT."
#fi
#mdsplus_root=`awk 'BEGIN{FS = "/"} /MDSPLUS_DIR \?=/ {print $2}' "${setup_path}/config.DUT-PSI.ifort64"`
#if [ ${mdsplus_root} == "MDSPLUS" ]
#then
# echo "MDSPLUS_DIR is ok!"
#else
# echo "please check the MDSPLUS_DIR."
#fi
#grep -m 2 "LD_NETCDF" "${setup_path}/config.DUT-PSI.ifort64" | tail -n 1
#grep -m 2 "LD_MSCL" "${setup_path}/config.DUT-PSI.ifort64" | tail -n 1
#grep -m 2 "LD_GR" "${setup_path}/config.DUT-PSI.ifort64" | tail -n 1
#grep -m 2 "LD_GKS" "${setup_path}/config.DUT-PSI.ifort64" | head -n 1
#grep -m 2 "LD_NCARG" "${setup_path}/config.DUT-PSI.ifort64" | head -n 1
#grep -m 2 "LD_NAG" "${setup_path}/config.DUT-PSI.ifort64" | tail -n 1
##grep -m 2 "LD_MDSPLUS" "${setup_path}/config.DUT-PSI.ifort64" | head -n 1
#grep -m 2 "LD_SONNET" "${setup_path}/config.DUT-PSI.ifort64" | head -n 1
#grep -m 2 "#LD_MPI" "${setup_path}/config.DUT-PSI.ifort64" | tail -n 1
# ==================== modify the modules config files ================== #
#modules_path="${base_path}/modules"
# copy the B2.5 config/ to new solps-iter
# modify the B2.5 config
#`echo tcsh` # 启动tcsh
#`echo source setup.csh`
#echo "test tcsh & source"