Instantly share code, notes, and snippets.

Embed
What would you like to do?
Compiles a program with a particular set of inputs, runs multiple times, and then outputs the average of each run. The program should submit a single integer to stdout. In this example, the outer loop passes the values 1, 2, 4, 8, etc. (as WORKGROUPSIZE) and the inner loop passes the values 1024, 2048, 4096, etc. (as ARRAYSIZE). The data is aver…
#!/bin/bash
# Create or clear output file
> data.csv
# Run for multiple tries and compute average
TRIES=10
WORKGROUPCOUNTER=1
while [ $WORKGROUPCOUNTER -le 256 ]
do
WORKGROUPSIZE=$(( WORKGROUPCOUNTER * 1 ))
ARRAYCOUNTER=1
while [ $ARRAYCOUNTER -le 8192 ]
do
SUM=0
ARRAYSIZE=$(( $ARRAYCOUNTER * 1024 ))
g++ main.cpp -DGLOBAL=${ARRAYSIZE} -DLOCAL=${WORKGROUPSIZE} -o main -lm -fopenmp
for TRY in $(seq ${TRIES})
do
OUTPUT=$(./main)
SUM=$(( (SUM + OUTPUT) ))
done
AVG=$(( SUM / TRIES ))
printf "$AVG" >> data.csv
printf ',' >> data.csv
ARRAYCOUNTER=$(( $ARRAYCOUNTER * 2 ))
done
echo >> data.csv
WORKGROUPCOUNTER=$(( $WORKGROUPCOUNTER * 2 ))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment