1 | #!/bin/ksh |
---|
2 | |
---|
3 | # CALLS: rebuild_nemo.exe |
---|
4 | |
---|
5 | #set -ax |
---|
6 | usage () |
---|
7 | { |
---|
8 | echo |
---|
9 | echo " NEMO Rebuild" |
---|
10 | echo " ************" |
---|
11 | echo |
---|
12 | echo " usage: ${0##*/} [-l -t -c -m -n] filebase ndomain [rebuild dimensions]" |
---|
13 | echo |
---|
14 | echo " flags: -l submit to compute node" |
---|
15 | echo " -t num use num threads" |
---|
16 | echo " -c num split 4D vars into time chuncks of size num" |
---|
17 | echo " -m force masking of global arrays (zero if no mdi)" |
---|
18 | echo " -d deflate_level deflate level for output files (key_netcdf4 only)" |
---|
19 | echo " -n namelist full path to namelist file to be created (otherwise default nam_rebuild+_process_id is used)" |
---|
20 | echo " -r memory Memory to request on compute node including units (Default = 10Gb)" |
---|
21 | echo |
---|
22 | exit 1 |
---|
23 | } |
---|
24 | |
---|
25 | while getopts c:n:t:d:r:lm opt |
---|
26 | do |
---|
27 | case ${opt} in |
---|
28 | l) |
---|
29 | BATCH="yes" |
---|
30 | BATCH_CMD="qsub" |
---|
31 | ARCH="XC40_METO" |
---|
32 | echo "Submitting job to compute node" |
---|
33 | ;; |
---|
34 | t) |
---|
35 | OMP_NUM_THREADS=${OPTARG} |
---|
36 | ;; |
---|
37 | c) |
---|
38 | NCHUNKSIZE=${OPTARG} |
---|
39 | ;; |
---|
40 | m) |
---|
41 | NMASK="TRUE" |
---|
42 | echo "mask" |
---|
43 | ;; |
---|
44 | d) |
---|
45 | DEFLATE=${OPTARG} |
---|
46 | ;; |
---|
47 | n) |
---|
48 | nam_rebuild=${OPTARG} |
---|
49 | ;; |
---|
50 | r) |
---|
51 | MEMORY=${OPTARG} |
---|
52 | ;; |
---|
53 | esac |
---|
54 | done |
---|
55 | shift $(expr ${OPTIND} - 1) |
---|
56 | |
---|
57 | if [[ $# -lt 2 ]] ; then |
---|
58 | usage |
---|
59 | fi |
---|
60 | |
---|
61 | script_dir=$(dirname $0) |
---|
62 | |
---|
63 | file=$1 |
---|
64 | ndomain=$2 |
---|
65 | DIM1=$3 |
---|
66 | DIM2=$4 |
---|
67 | export OMP_NUM_THREADS=${OMP_NUM_THREADS:-1} |
---|
68 | nam_rebuild=${nam_rebuild:-nam_rebuild_$$} |
---|
69 | MEMORY=${MEMORY:-10Gb} |
---|
70 | |
---|
71 | #Find out the maximum number of files that can be opened and increase if necessary) |
---|
72 | nopen=$(ulimit -n) |
---|
73 | if [[ $ndomain -gt $nopen ]] ; then |
---|
74 | nopen=$((ndomain+2)) |
---|
75 | fi |
---|
76 | |
---|
77 | if [[ -n ${DIM1} && -n ${DIM2} ]] ; then |
---|
78 | dim_str=" dims '${DIM1}','${DIM2}'" |
---|
79 | dims="dims='${DIM1}','${DIM2}'" |
---|
80 | fi |
---|
81 | |
---|
82 | echo "file ${file}, num_domains ${ndomain}, num_threads ${OMP_NUM_THREADS}${dim_str}" |
---|
83 | |
---|
84 | cat > $nam_rebuild << EOC |
---|
85 | &nam_rebuild |
---|
86 | filebase='${file}' |
---|
87 | ndomain=${ndomain} |
---|
88 | EOC |
---|
89 | if [[ -n ${dims} ]] ; then |
---|
90 | echo ${dims} >> $nam_rebuild |
---|
91 | fi |
---|
92 | if [[ -n ${NCHUNKSIZE} ]] ; then |
---|
93 | echo " nchunksize=${NCHUNKSIZE}" >> $nam_rebuild |
---|
94 | fi |
---|
95 | if [[ -n ${NMASK} ]] ; then |
---|
96 | echo " l_maskout=.true." >> $nam_rebuild |
---|
97 | fi |
---|
98 | if [[ -n ${DEFLATE} ]] ; then |
---|
99 | echo " deflate_level=${DEFLATE}" >> $nam_rebuild |
---|
100 | fi |
---|
101 | |
---|
102 | echo "/" >> $nam_rebuild |
---|
103 | |
---|
104 | if [[ ${BATCH} == "yes" ]] ; then |
---|
105 | batch_file=rebuild_nemo_batch_${ARCH} |
---|
106 | |
---|
107 | #Create a modified local copy of the batch submission file |
---|
108 | #The process ID is appended to the end of the file name so it is unique |
---|
109 | cat ${script_dir}/BATCH_TEMPLATES/${batch_file} | sed -e"s/NTHREADS/${OMP_NUM_THREADS}/" \ |
---|
110 | -e"s/MEMORY/${MEMORY}/" \ |
---|
111 | -e"s:INDIR:${script_dir}:" \ |
---|
112 | -e"s/NOPEN/${nopen}/" \ |
---|
113 | -e"s/NAMELIST/${nam_rebuild}/" > ${batch_file}_$$.sh |
---|
114 | |
---|
115 | #Submit the job |
---|
116 | $BATCH_CMD ${batch_file}_$$.sh |
---|
117 | |
---|
118 | else |
---|
119 | ulimit -n $nopen |
---|
120 | ${script_dir}/rebuild_nemo.exe $nam_rebuild |
---|
121 | fi |
---|
122 | |
---|