Skip to content

Instantly share code, notes, and snippets.

@alxmjo
Last active June 1, 2018 20:37
Show Gist options
  • Save alxmjo/074be226114eb1dc2c0da9edc95d44ae to your computer and use it in GitHub Desktop.
Save alxmjo/074be226114eb1dc2c0da9edc95d44ae to your computer and use it in GitHub Desktop.
Compiles a program with a particular set of inputs, runs multiple times, and then outputs the average of each run to data.csv. 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).
#!/bin/bash
# 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 averaged TRIES times and saved to data.csv. Note that as
# this is a bash script, only integer values are computed.
#
# Run: $ average-script.sh
# 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 # may need to be modified
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