Share Pastebin
Guest
Public paste!

Joshua

By: a guest | Jun 19th, 2010 | Syntax: Bash | Size: 0.51 KB | Hits: 370 | Expires: Never
Copy text to clipboard
  1. N=`cat /proc/cpuinfo | grep processor | wc -l`
  2.  
  3. cat /proc/cpuinfo | grep "model name"
  4. echo
  5. echo "Calculating the first 5000 decimals of pi using $N parallel processes"
  6. TimeBegin=`date +%s.%N`
  7.  
  8. for ((i=1; i<=$N; i++))
  9. do
  10.         echo "scale=5000; 4*a(1)" | bc -l -q > /dev/null &
  11. done
  12. wait
  13.  
  14. TimeEnd=`date +%s.%N`
  15. DT=`echo "scale=2; ($TimeEnd - $TimeBegin) / 1" | bc`
  16. echo "Total time: $DT seconds"
  17. DTc=`echo "scale=2; ($TimeEnd - $TimeBegin) / $N" | bc`
  18. echo "Average time per calculation: $DTc seconds"