Last active
August 29, 2015 14:03
-
-
Save Syntaf/778f120bb44383654c37 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 <hpx/hpx_init.hpp> | |
#include <hpx/hpx.hpp> | |
#include <hpx/include/algorithm.hpp> | |
//... | |
std::vector<int> c(10007); | |
//fill the vector with random values | |
std::iota(boost::begin(c), boost::end(c), std::rand()); | |
int const val = 42; | |
auto op = | |
[val](int v1, int v2) { | |
return v1 + v2 + val; | |
}; | |
//call reduce with a parallel execution policy | |
int r1 = hpx::parallel::reduce(hpx::parallel::par, | |
boost::begin(c), boost::end(c), val, op); | |
//the above execution is equivalent to: | |
int r2 = std::accumulate(boost::begin(c), boost::end(c), val, op); | |
//these values are the SAME, but the parallel execution is much faster! | |
HPX_TEST_EQ(r1, r2); | |
///////////////////////////////////////////////////////////////////////////////////// | |
//using futures | |
std::vector<int> c(10007); | |
//fill vector with random values | |
std::iota(boost::begin(c), boost::end(c), std::rand()); | |
int const val = 42; | |
hpx::future<int> f = | |
hpx::parallel::reduce(hpx::parallel::task, | |
boost::begin(c), boost::end(c), val) | |
//wait for future | |
f.wait(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment