pfor/ctbenchmarks/gen_ct

169 lines
4.2 KiB
Plaintext
Raw Permalink Normal View History

2021-05-10 16:11:23 +00:00
#!/bin/bash
rand() {
echo $((RANDOM%($2-$1)+$1))
}
index_expr_rand() {
echo "pfor::ctv<$(rand 0 100)>*i+pfor::ctv<$(rand 0 100)>"
}
index_expr_fixed() {
echo "pfor::ctv<3>*i+pfor::ctv<2>"
}
header() {
cat<<EOF
#include <pfor/pfor.h>
#include <cstdio>
std::size_t pfor::ParallelForParameters::nThreads = 16;
constexpr unsigned n = BUFSIZ;
int main() {
pfor::Index i;
EOF
}
footer() {
cat<<EOF
}
EOF
}
variable() {
i=$1
echo -e "\tint v${i}_[n];\tauto v${i} = pfor::Operand<int*, class TID${i}>{v${i}_};"
}
independent_with() {
index_expr_str=$1; shift
index_expr() {
eval ${index_expr_str}
}
for i in $@; do
echo -ne ",\n\t\tv${i}[$(index_expr)] = v1[$(index_expr)]"
done
}
dependent_with() {
index_expr_str=$1; shift
index_expr() {
eval ${index_expr_str}
}
ii=$1; shift
for i in $@; do
echo -ne ",\n\t\tv${i}[$(index_expr)] = v${ii}[$(index_expr)]"
ii=$i
done
}
####
fixed_count=100
fixed_var_count() {
mode=$1; shift
opening=$1; shift
index_expr_str=$1; shift
header
for i in $(seq ${fixed_count}); do
variable "${i}"
done
echo -ne "\t${opening}"
eval "${mode} '${index_expr_str}' $*"
echo -e "\n\t);"
footer
}
fixed_instr_count() {
mode=$1; shift
opening=$1; shift
index_expr_str=$1; shift
var_count=$1
[ "${mode}" = 'dependent_with' ] && vars='1 ' || vars=
ntimes=$(((fixed_count+(var_count-1)-1)/(var_count-1) - 1))
vars_last="${vars}$(seq -s' ' 2 $((fixed_count-ntimes*(var_count-1) + 1)))"
vars="${vars}$(seq -s' ' 2 ${var_count})"
header
for i in $(seq ${var_count}); do
variable "${i}"
done
echo -ne "\t${opening}"
for i in $(seq ${ntimes}); do
eval "${mode} '${index_expr_str}' ${vars}"
done
eval "${mode} '${index_expr_str}' ${vars_last}"
echo -e "\n\t);"
footer
}
fixed_instr_var_count() {
mode=$1; shift
opening=$1; shift
index_expr_str=$1; shift
loop_count=$1
[ "${mode}" = 'dependent_with' ] && first_=1 || first_=2
[ "${mode}" = 'dependent_with' ] && offset=0 || offset=-1
instr_count=$((fixed_count/loop_count))
remainder=$((fixed_count - instr_count*loop_count))
header
for i in $(seq ${fixed_count}); do
variable "${i}"
done
first=${first_}
for i in $(seq $((loop_count))); do
n=$((instr_count + ! ! remainder))
last=$((first + n + offset))
if [ ${last} -gt ${fixed_count} ]; then
first=${first_}
last=$((first + n + offset))
fi
echo -ne "\t${opening}"
eval "${mode} '${index_expr_str}' $(seq -s' ' ${first} ${last})"
echo -e "\n\t);"
first=$((last+1))
remainder=$((remainder > 0 ? remainder-1 : 0))
done
footer
}
####
outdir=srcs
opening='pfor::parallelFor<pfor::ForLoopThread>(pfor::RangeCT<0,2>{n}'
for count in $(echo 5 $(seq 10 10 100)); do
fixed_var_count>"${outdir}/main_fixedv_indep_randi_${count}.cpp" independent_with "${opening}" 'index_expr_rand' $(seq 2 ${count})
fixed_var_count>"${outdir}/main_fixedv_dep_randi_${count}.cpp" dependent_with "${opening}" 'index_expr_rand' $(seq ${count})
fixed_var_count>"${outdir}/main_fixedv_indep_fixedi_${count}.cpp" independent_with "${opening}" 'index_expr_fixed' $(seq 2 ${count})
fixed_var_count>"${outdir}/main_fixedv_dep_fixedi_${count}.cpp" dependent_with "${opening}" 'index_expr_fixed' $(seq ${count})
# fixed_instr_count>"${outdir}/main_fixedi_indep_randi_${count}.cpp" independent_with "${opening}" 'index_expr_rand' "${count}"
# fixed_instr_count>"${outdir}/main_fixedi_dep_randi_${count}.cpp" dependent_with "${opening}" 'index_expr_rand' "${count}"
# fixed_instr_count>"${outdir}/main_fixedi_indep_fixedi_${count}.cpp" independent_with "${opening}" 'index_expr_fixed' "${count}"
# fixed_instr_count>"${outdir}/main_fixedi_dep_fixedi_${count}.cpp" dependent_with "${opening}" 'index_expr_fixed' "${count}"
fixed_instr_var_count>"${outdir}/main_fixediv_indep_randi_${count}.cpp" independent_with "${opening}" 'index_expr_rand' "${count}"
fixed_instr_var_count>"${outdir}/main_fixediv_dep_randi_${count}.cpp" dependent_with "${opening}" 'index_expr_rand' "${count}"
fixed_instr_var_count>"${outdir}/main_fixediv_indep_fixedi_${count}.cpp" independent_with "${opening}" 'index_expr_fixed' "${count}"
fixed_instr_var_count>"${outdir}/main_fixediv_dep_fixedi_${count}.cpp" dependent_with "${opening}" 'index_expr_fixed' "${count}"
done