devinteske

cmb_bench_cpu.sh

Jul 4th, 2019
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.40 KB | None | 0 0
  1. #!/bin/sh
  2. : ${THREADS:=$( getconf _NPROCESSORS_ONLN )} ${SET:=38} ${AC:=}
  3. ABORTED=
  4. S=$( date +%s )
  5. T=$( cmb -otr $SET )
  6. C=$(( $T / $THREADS ))
  7. printf "Started: %s\n" "$( date )"
  8. printf "Spawning $THREADS threads to to solve C(%d,S)... " "$SET"
  9. for n in $( seq 1 $THREADS ); do
  10.     cmd="cmb -oSr"
  11.     if [ "$AC" ]; then # All-core stress test
  12.         $cmd $SET &
  13.     else
  14.         [ $n -eq $THREADS ] || cmd="$cmd -c $C"
  15.         $cmd -i $(( $C * ($n - 1) + 1 )) $SET &
  16.     fi
  17.     pids="$pids $!"
  18. done
  19. interrupt()
  20. {
  21.     printf "\nAborted.\n"
  22.     exec 2> /dev/null
  23.     kill $pids
  24.     ABORTED=1
  25. }
  26. trap interrupt SIGINT
  27. printf "done\n"
  28. printf "Total combinations in C(%d,S) is %'d\n" "$SET" "$T"
  29. if [ "$AC" ]; then # All-core stress test
  30.     printf "Each thread working on %'d combinations\n" "$T"
  31. else
  32.     printf "Each thread working on %'d combinations\n" "$C"
  33. fi
  34. printf "Waiting for threads to complete. Press Ctrl-C to cancel test.\n"
  35. n=20
  36. while :; do
  37.     running=
  38.     for pid in $pids; do
  39.         kill -0 $pid 2> /dev/null && running=1 && break
  40.     done
  41.     [ "$running" ] || break
  42.     if [ $(( $n % 20 )) -eq 0 ]; then
  43.         printf "%s -- load: %.2f\n" "$( date )" \
  44.             "$( uptime | awk '($0=$(NF-2)) sub(/,$/,"")' )"
  45.         n=1
  46.     else
  47.         n=$(( $n + 1 ))
  48.     fi
  49.     sleep 0.5
  50. done
  51. E=$(( $( date +%s ) - $S ))
  52. [ "$ABORTED" ] || printf "Solved C(%d,S): %s\n" "$SET" "$( date )"
  53. min=$(( $E / 60 ))
  54. sec=$(( $E - 60 * $min ))
  55. printf "Elapsed Time: %dm%ds\n" "$min" "$sec"
Add Comment
Please, Sign In to add comment