59 lines
1.3 KiB
C++
59 lines
1.3 KiB
C++
#include <algorithm>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <sstream>
|
|
|
|
#include <pfor/pfor.h>
|
|
|
|
#define K 1
|
|
|
|
std::size_t pfor::ParallelForParameters::nThreads{1};
|
|
|
|
template<std::size_t n>
|
|
constexpr auto _ = pfor::ctv<n>;
|
|
|
|
using T = int;
|
|
|
|
#define OPERAND(Type, name, size, filler) \
|
|
Type * name##_ = new Type[size]; \
|
|
{ \
|
|
std::size_t i = 0; \
|
|
std::generate_n(name##_, size, [&i]{ return filler; }); \
|
|
} \
|
|
auto name = pfor::Operand<Type*, class ID##name>(name##_);
|
|
|
|
void printer(std::size_t) {}
|
|
|
|
template<typename T, typename... Ts>
|
|
void printer(std::size_t n, T &&array, Ts&&... arrays) {
|
|
for(std::size_t i = 0; i < n; ++i)
|
|
std::clog << std::forward<T>(array)[i] << ", ";
|
|
std::clog << std::endl;
|
|
printer(n, std::forward<Ts>(arrays)...);
|
|
}
|
|
|
|
int main() {
|
|
std::size_t const N = 1000000;
|
|
|
|
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++);
|
|
|
|
for(std::size_t k = 0; k < K; ++k) {
|
|
parallelFor(pfor::Range{0, 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];
|
|
});
|
|
}
|
|
|
|
printer(N, a0_, a1_, a2_, a3_, a4_, a5_, a6_, a7_);
|
|
}
|