Skip to content

Commit db2f6b4

Browse files
committed
Add debug option and cleanup
1 parent 6bdb435 commit db2f6b4

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

ncparallel

+23-6
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,8 @@ done
9191
input="${inputs[0]}"
9292

9393
# 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
9896
$silent || echo "Running command: $cmd"
9997
$debug && {
10098
echo "Input file(s): ${inputs[*]}"
@@ -133,6 +131,8 @@ done
133131
#-----------------------------------------------------------------------------#
134132
# Perform ncdivide inline
135133
#-----------------------------------------------------------------------------#
134+
# Divide files one by one
135+
136136
# Helper function that runs each process
137137
run() {
138138
# Arguments are the file index, output file, and input files.
@@ -154,7 +154,6 @@ run() {
154154
for i in $(seq 1 ${#inputs[@]}); do
155155
input=${inputs[i-1]}
156156
input_num=${inputs_num[i-1]}
157-
# echo "Copying $dimname,$d1,$d2 from ${input} to ${input_num}"
158157
$fixrec && ncdump -h "$input" | grep 'UNLIMITED' | grep $dimname &>/dev/null \
159158
&& iflag_ncks="--fix_rec_dmn $dimname" # required for mppnccombine
160159
ncks -O -h $flag_ncks $iflag_ncks \
@@ -198,7 +197,8 @@ time {
198197
inputs_num=("${inputs_num[@]/%/.${znum}.nc}")
199198

200199
# 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 &
202202

203203
# Store process IDs and output files
204204
pids+=($!)
@@ -216,6 +216,23 @@ time {
216216
pwait "$cmd" "${pids[@]}"
217217
}
218218

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+
219236
# Finally combine, and remove the temporary files
220237
# generated for parallel processing
221238
$silent || echo "Combining into file: ${output##*/}"

0 commit comments

Comments
 (0)