thesis version
This commit is contained in:
97
benchmarks/seq.cpp
Normal file
97
benchmarks/seq.cpp
Normal file
@ -0,0 +1,97 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
constexpr std::size_t K = 1'000;
|
||||
|
||||
std::size_t pfor::ParallelForParameters::nThreads{1};
|
||||
|
||||
struct Arguments {
|
||||
std::size_t arraySize;
|
||||
std::string method;
|
||||
};
|
||||
|
||||
Arguments processCLA(int argc, char **argv) {
|
||||
if(argc < 2) {
|
||||
std::cerr << "Usage: " << *argv << " N method" << std::endl;
|
||||
std::cerr << " N: array size (1..1000000)" << std::endl;
|
||||
std::cerr << " method: {seq, gen}" << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
Arguments args;
|
||||
|
||||
{
|
||||
std::istringstream iss{argv[1]};
|
||||
iss >> args.arraySize;
|
||||
}
|
||||
args.method = std::string{argv[2]};
|
||||
|
||||
if(args.arraySize < 1 || args.arraySize > 1000000) {
|
||||
std::cerr << "N out of bounds" << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
if(args.method != "seq" && args.method != "gen") {
|
||||
std::cerr << "method out of bounds" << std::endl;
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
using T = int;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Arguments args = processCLA(argc, argv);
|
||||
std::size_t const N = args.arraySize;
|
||||
|
||||
OPERAND(T, a0, N, i++);
|
||||
OPERAND(T, a1, N, i++);
|
||||
OPERAND(T, a2, N, i++);
|
||||
OPERAND(T, a3, N, i++);
|
||||
OPERAND(T, a4, N, i++);
|
||||
OPERAND(T, a5, N, i++);
|
||||
OPERAND(T, a6, N, i++);
|
||||
OPERAND(T, a7, N, i++);
|
||||
|
||||
/*
|
||||
* Sample 0: sequential
|
||||
*/
|
||||
// arraysPrinter(K, N, a0, a1, a2, a5);
|
||||
|
||||
if(args.method == "seq") {
|
||||
BENCH(K)
|
||||
for(std::size_t i = 0; i < N-1; ++i) {
|
||||
a0_[i] = a0_[i+1] + a1_[i] * a2_[i];
|
||||
a1_[i] = a1_[i+1] + a2_[i] * a3_[i];
|
||||
a2_[i] = a2_[i+1] + a3_[i] * a4_[i];
|
||||
a5_[i] = a5_[i+1] + a6_[i] * a7_[i];
|
||||
}
|
||||
END_BENCH();
|
||||
} else if(args.method == "gen") {
|
||||
BENCH(K)
|
||||
pfor::parallelFor(pfor::Range{0, static_cast<long>(N-1)}, [&](pfor::Index i) {
|
||||
return
|
||||
a0[i] = a0[i+_<1>] + a1[i] * a2[i],
|
||||
a1[i] = a1[i+_<1>] + a2[i] * a3[i],
|
||||
a2[i] = a2[i+_<1>] + a3[i] * a4[i],
|
||||
a5[i] = a5[i+_<1>] + a6[i] * a7[i];
|
||||
});
|
||||
END_BENCH();
|
||||
}
|
||||
|
||||
if(rand() == rand()) arraysPrinter(1, N, a0_, a1_, a2_, a3_, a4_, a5_, a6_, a7_);
|
||||
|
||||
END_OPERAND(a0);
|
||||
END_OPERAND(a1);
|
||||
END_OPERAND(a2);
|
||||
END_OPERAND(a3);
|
||||
END_OPERAND(a4);
|
||||
END_OPERAND(a5);
|
||||
END_OPERAND(a6);
|
||||
END_OPERAND(a7);
|
||||
}
|
Reference in New Issue
Block a user