Created
July 1, 2014 21:08
-
-
Save Syntaf/058a91ab8cf420e0f0fd to your computer and use it in GitHub Desktop.
hpx::parallel
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
// Copyright (c) 2014 Hartmut Kaiser | |
// | |
// Distributed under the Boost Software License, Version 1.0. (See accompanying | |
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
#include <hpx/hpx_init.hpp> | |
#include <hpx/hpx.hpp> | |
#include <hpx/include/numeric.hpp> | |
#include <hpx/parallel/algorithm.hpp> | |
#include <hpx/util/lightweight_test.hpp> | |
#include "test_utils.hpp" | |
/////////////////////////////////////////////////////////////////////////////// | |
int hpx_main() | |
{ | |
double arr [] = {1.1, 2.2, 4.4, 6.6}; | |
double arr2 [] = {1.3, 5.5, 6.6, 7.7}; | |
double arr3 [] = {0.0, 0.0, 0.0, 0.0}; | |
double *xs = arr; | |
double *ys = arr2; | |
double *gs = arr3; | |
double result = 0.0; | |
hpx::parallel::transform(hpx::parallel::par, | |
xs, xs+4, ys, arr3, [](double a, double b) { | |
return a * b; | |
}); | |
std::cout << arr3[0] << " " << arr3[1] << " " << arr3[2] << " " << arr3[3] << std::endl; | |
double *h = arr3; | |
auto res = hpx::parallel::reduce(hpx::parallel::par, | |
h, h+4, (double)(0), [](double a, double b) { return a + b; }); | |
std::cout << res << std::endl; | |
return hpx::finalize(); | |
} | |
int main(int argc, char* argv[]) | |
{ | |
// By default this test should run on all available cores | |
std::vector<std::string> cfg; | |
cfg.push_back("hpx.os_threads=" + | |
boost::lexical_cast<std::string>(hpx::threads::hardware_concurrency())); | |
// Initialize and run HPX | |
HPX_TEST_EQ_MSG(hpx::init(argc, argv, cfg), 0, | |
"HPX main exited with non-zero status"); | |
return hpx::util::report_errors(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment