Created
August 5, 2016 18:26
-
-
Save mcopik/1c0426d15189a777376f83e5f4ec7406 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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