91
91
input=" ${inputs[0]} "
92
92
93
93
# Time format and message
94
- if [ -z " ${TIMEFORMAT: +set} " ]; then
95
- export TIMEFORMAT=$' real %3lR user %3lU sys %3lS' # default format
96
- $silent && export TIMEFORMAT=' ' # set to empty string
97
- fi
94
+ export TIMEFORMAT=$' real %3R user %3U sys %3S' # default format in seconds
95
+ $silent && export TIMEFORMAT=' ' # set to empty string
98
96
$silent || echo " Running command: $cmd "
99
97
$debug && {
100
98
echo " Input file(s): ${inputs[*]} "
133
131
# -----------------------------------------------------------------------------#
134
132
# Perform ncdivide inline
135
133
# -----------------------------------------------------------------------------#
134
+ # Divide files one by one
135
+
136
136
# Helper function that runs each process
137
137
run () {
138
138
# Arguments are the file index, output file, and input files.
@@ -154,7 +154,6 @@ run() {
154
154
for i in $( seq 1 ${# inputs[@]} ) ; do
155
155
input=${inputs[i-1]}
156
156
input_num=${inputs_num[i-1]}
157
- # echo "Copying $dimname,$d1,$d2 from ${input} to ${input_num}"
158
157
$fixrec && ncdump -h " $input " | grep ' UNLIMITED' | grep $dimname & > /dev/null \
159
158
&& iflag_ncks=" --fix_rec_dmn $dimname " # required for mppnccombine
160
159
ncks -O -h $flag_ncks $iflag_ncks \
@@ -198,7 +197,8 @@ time {
198
197
inputs_num=(" ${inputs_num[@]/%/ .${znum} .nc} " )
199
198
200
199
# Run command in parallel along slice
201
- run " $fnum " " $output_num " " ${inputs_num[@]} " & > $log &
200
+ # split "$fnum" "${inputs_num[@]}" &>$log &
201
+ run " $fnum " " $output_num " " ${inputs_num[@]} " & >> $log &
202
202
203
203
# Store process IDs and output files
204
204
pids+=($! )
@@ -216,6 +216,23 @@ time {
216
216
pwait " $cmd " " ${pids[@]} "
217
217
}
218
218
219
+ # Message showing average time for each process
220
+ avgtime () {
221
+ cat " ${logs[@]} " | awk "
222
+ c && ! --c
223
+ /${1} / {c=1}
224
+ " | awk ' {print $2" "$4" "$6}' | tr -d s | awk '
225
+ {real += $1; user += $2; sys += $3}
226
+ END {print "user " real / NR "s user " user / NR "s sys " sys / NR "s"}
227
+ '
228
+ }
229
+ $debug && {
230
+ echo " Average split time"
231
+ avgtime ' ^Copying slab'
232
+ echo " Average command time"
233
+ avgtime ' ^Running command'
234
+ }
235
+
219
236
# Finally combine, and remove the temporary files
220
237
# generated for parallel processing
221
238
$silent || echo " Combining into file: ${output##*/ } "
0 commit comments