|
|
@@ -0,0 +1,75 @@ |
|
|
#include <hpx/hpx.hpp> |
|
|
#include <hpx/hpx_init.hpp> |
|
|
#include <hpx/parallel/algorithms/reverse.hpp> |
|
|
|
|
|
#include <algorithm> |
|
|
#include <execution> |
|
|
#include <functional> |
|
|
#include <random> |
|
|
#include <vector> |
|
|
#include "stopwatch.hpp" |
|
|
|
|
|
using namespace std; |
|
|
|
|
|
constexpr size_t dataSize = 10'000; |
|
|
constexpr size_t iterations = 1000; |
|
|
|
|
|
template<class ExecutionPolicy> |
|
|
void test(ExecutionPolicy&& exec, vector<unsigned int>& v) { |
|
|
for (size_t iter = 0; iter < iterations; ++iter) { |
|
|
std::reverse(std::forward<ExecutionPolicy>(exec), v.begin(), v.end()); |
|
|
} |
|
|
} |
|
|
|
|
|
template<class ExecutionPolicy> |
|
|
void test_hpx(ExecutionPolicy&& exec, vector<unsigned int>& v) { |
|
|
for (size_t iter = 0; iter < iterations; ++iter) { |
|
|
hpx::parallel::reverse(std::forward<ExecutionPolicy>(exec), v.begin(), v.end()); |
|
|
} |
|
|
} |
|
|
|
|
|
#pragma optimize("", off) |
|
|
int hpx_main(boost::program_options::variables_map& vm) |
|
|
{ |
|
|
puts("reverse parallelism test"); |
|
|
printf("iterations: %zu elements: %zu size: %zu\n", iterations, dataSize, dataSize * sizeof(unsigned int)); |
|
|
|
|
|
random_device rd{}; |
|
|
vector<unsigned int> data(dataSize); |
|
|
generate(data.begin(), data.end(), ref(rd)); |
|
|
|
|
|
stopwatch std_sequential; |
|
|
std_sequential.start(); |
|
|
test(execution::seq, data); |
|
|
std_sequential.stop(); |
|
|
std_sequential.print("std seq"); |
|
|
|
|
|
stopwatch std_parallel; |
|
|
std_parallel.start(); |
|
|
test(execution::par, data); |
|
|
std_parallel.stop(); |
|
|
std_parallel.print("std par"); |
|
|
|
|
|
printf("std par speedup: %f\n", std_parallel.compare(std_sequential)); |
|
|
|
|
|
stopwatch sequential; |
|
|
sequential.start(); |
|
|
test_hpx(hpx::parallel::execution::seq, data); |
|
|
sequential.stop(); |
|
|
sequential.print("HPX seq"); |
|
|
|
|
|
stopwatch parallel; |
|
|
parallel.start(); |
|
|
test_hpx(hpx::parallel::execution::par_unseq, data); |
|
|
parallel.stop(); |
|
|
parallel.print("HPX par_unseq"); |
|
|
|
|
|
printf("HPX par speedup: %f\n", parallel.compare(sequential)); |
|
|
return hpx::finalize(); |
|
|
} |
|
|
#pragma optimize("", on) |
|
|
|
|
|
int main(int argc, char* argv[]) |
|
|
{ |
|
|
return hpx::init(argc, argv); |
|
|
} |