Skip to content

Instantly share code, notes, and snippets.

@mcopik
Created August 5, 2016 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcopik/1c0426d15189a777376f83e5f4ec7406 to your computer and use it in GitHub Desktop.
Save mcopik/1c0426d15189a777376f83e5f4ec7406 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iterator>
#include <cassert>
#include <cmath>
#include <chrono>
#include <hpx/hpx_init.hpp>
#include <hpx/hpx.hpp>
#include <hpx/version.hpp>
#include <hpx/include/parallel_algorithm.hpp>
#include <hpx/include/parallel_executors.hpp>
int main()
{
const int size = 1000000;
float * a = new float[size], * b = new float[size], *c = new float[size];
hpx::parallel::fill(hpx::parallel::seq, a, a + size, 1.0f);
hpx::parallel::fill(hpx::parallel::seq, b, b + size, 2.0f);
auto start = std::chrono::high_resolution_clock::now();
hpx::parallel::for_loop(hpx::parallel::seq, 0, size,
[&] (int i) {
c[i] = a[i] + b[i];
}
);
auto end = std::chrono::high_resolution_clock::now();
std::cout << "Time: " << std::chrono::duration<double>(end-start).count() << std::endl;
for(int i = 0; i < size; ++i)
assert( fabs(c[i] - 3.0f) < 1e-6);
delete[] a;
delete[] b;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment