#!/bin/bash # Index variables declare -i k l declare -i j=0 # Number of tries for each size declare -i lend=20 # Index for loop global size declare -i kstart=1024*1024 # 1 MB = 2^20 declare -i kend=4*1024*1024*1024 # 4 GB = 2^32 # Factor between each loop size declare -i factor=16 # 2^4 # Number of threads declare -a nb_process=(1 2 4 8 16 32 64 128 256 512 1024 2048 4096) # Compile Posix or Go version if [[ -z $1 ]] then echo "Empty argument : set 'posix' or 'go'" exit elif [[ $1 == posix ]] then echo "Posix benchmark" # Delete previous 'results_benchmark_posix.txt' file rm -f results_benchmark_posix.txt # Compile with gcc gcc -lpthread pi_mc_pthread.c -o pi_mc elif [[ $1 == go ]] then echo "Go benchmark" # Delete previous 'results_benchmark_go.txt' file rm -f results_benchmark_go.txt # Compile with go build go build pi_mc.go else echo "Invalid argument : set 'posix' or 'go'" exit fi # Main loop on global size for ((k=kstart;k<=kend;k=k*factor)) do echo "Current size of loop : "$k # Loop on number of threads while [ "${nb_process[$j]}" != "" ] do echo "Number of threads : "${nb_process[$j]} sum1=0 sum2=0 sum3=0 # Loop on number of tries for ((l=1;l<=lend;l++)) do # Store various parameters and reults output1=$(echo "${nb_process[$j]}") output2=$(./pi_mc $output1 $k) output3[$l]=$(echo "$output2" | awk 'NR==1' | awk '{ print $6}') output4[$l]=$(echo "$output2" | awk 'NR==3' | awk '{ print $5}') output5[$l]=$(echo "$output2" | awk 'NR==3' | awk '{ print $7}') sum1=$(echo "scale=7; $sum1+${output3[$l]}" | bc) sum2=$(echo "scale=7; $sum2+${output4[$l]}" | bc) sum3=$(echo "scale=7; $sum3+${output5[$l]}" | bc) done # Compute mean values output_mean1=$(echo "scale=12; $sum1/$lend" | bc) output_mean2=$(echo "scale=12; $sum2/$lend" | bc) output_mean3=$(echo "scale=12; $sum3/$lend" | bc) # Final results time_final=$(echo "scale=12; $output_mean2+(10^(-6)*$output_mean3)" | bc) # Print results echo "$output1 $k $time_final $output_mean1" | awk '{printf("%10d %10d %13.12f %13.12f\n",$1,$2,$3,$4)}' \ >> results_benchmark_$1.txt # Next number of threads j=$j+1 done # Blank line for separating blocks echo " " >> results_benchmark_$1.txt j=0 done