Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- : ${THREADS:=$( getconf _NPROCESSORS_ONLN )} ${SET:=38} ${AC:=}
- ABORTED=
- S=$( date +%s )
- T=$( cmb -otr $SET )
- C=$(( $T / $THREADS ))
- printf "Started: %s\n" "$( date )"
- printf "Spawning $THREADS threads to to solve C(%d,S)... " "$SET"
- for n in $( seq 1 $THREADS ); do
- cmd="cmb -oSr"
- if [ "$AC" ]; then # All-core stress test
- $cmd $SET &
- else
- [ $n -eq $THREADS ] || cmd="$cmd -c $C"
- $cmd -i $(( $C * ($n - 1) + 1 )) $SET &
- fi
- pids="$pids $!"
- done
- interrupt()
- {
- printf "\nAborted.\n"
- exec 2> /dev/null
- kill $pids
- ABORTED=1
- }
- trap interrupt SIGINT
- printf "done\n"
- printf "Total combinations in C(%d,S) is %'d\n" "$SET" "$T"
- if [ "$AC" ]; then # All-core stress test
- printf "Each thread working on %'d combinations\n" "$T"
- else
- printf "Each thread working on %'d combinations\n" "$C"
- fi
- printf "Waiting for threads to complete. Press Ctrl-C to cancel test.\n"
- n=20
- while :; do
- running=
- for pid in $pids; do
- kill -0 $pid 2> /dev/null && running=1 && break
- done
- [ "$running" ] || break
- if [ $(( $n % 20 )) -eq 0 ]; then
- printf "%s -- load: %.2f\n" "$( date )" \
- "$( uptime | awk '($0=$(NF-2)) sub(/,$/,"")' )"
- n=1
- else
- n=$(( $n + 1 ))
- fi
- sleep 0.5
- done
- E=$(( $( date +%s ) - $S ))
- [ "$ABORTED" ] || printf "Solved C(%d,S): %s\n" "$SET" "$( date )"
- min=$(( $E / 60 ))
- sec=$(( $E - 60 * $min ))
- printf "Elapsed Time: %dm%ds\n" "$min" "$sec"
Add Comment
Please, Sign In to add comment