void exclusive_scan_algo_tests_with_policy( std::size_t size, DistPolicy const& dist_policy, hpx::partitioned_vector<T>& in, std::vector<T> ver, ExPolicy const& policy) { msg7(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(), regular, size, dist_policy.get_num_partitions(), dist_policy.get_localities().size()); hpx::util::high_resolution_timer t1; std::vector<T> out(in.size()); T val(0); double e1 = t1.elapsed(); t1.restart(); hpx::parallel::exclusive_scan(policy, in.begin(), in.end(), out.begin(), val, opt<T>()); double e2 = t1.elapsed(); t1.restart(); HPX_TEST(std::equal(out.begin(), out.end(), ver.begin())); double e3 = t1.elapsed(); std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3 << "\n"; }
void exclusive_scan_algo_tests_segmented_out_with_policy( std::size_t size, DistPolicy const& in_dist_policy, DistPolicy const& out_dist_policy, hpx::partitioned_vector<T>& in, hpx::partitioned_vector<T> out, std::vector<T> ver, ExPolicy const& policy) { msg9(typeid(ExPolicy).name(), typeid(DistPolicy).name(), typeid(T).name(), segmented, size, in_dist_policy.get_num_partitions(), in_dist_policy.get_localities().size(), out_dist_policy.get_num_partitions(), out_dist_policy.get_localities().size()); hpx::util::high_resolution_timer t1; T val(0); double e1 = t1.elapsed(); t1.restart(); hpx::parallel::exclusive_scan(policy, in.begin(), in.end(), out.begin(), val, opt<T>()); double e2 = t1.elapsed(); t1.restart(); verify_values(out, ver); double e3 = t1.elapsed(); std::cout << std::setprecision(4) << "\t" << e1 << " " << e2 << " " << e3 << "\n"; }
void iota_vector(hpx::partitioned_vector<T>& v, T val) { auto first = v.begin(); auto last = v.end(); typedef hpx::traits::segmented_iterator_traits<decltype(first)> traits; typedef typename traits::segment_iterator segment_iterator; typedef typename traits::local_iterator local_iterator_type; segment_iterator sit = traits::segment(first); segment_iterator send = traits::segment(last); T temp_val = val; for (; sit != send; ++sit) { local_iterator_type beg = traits::begin(sit); local_iterator_type end = traits::end(sit); hpx::parallel::v1::detail::dispatch(traits::get_id(sit), iota(), hpx::parallel::seq, std::true_type(), beg, end, temp_val ); temp_val = T(temp_val + std::distance(beg, end)); } }
void test_all_async(ExPolicy&& policy, hpx::partitioned_vector<T>& xvalues, Func&& f, bool expected_result) { bool result = hpx::parallel::all_of(policy, xvalues.begin(), xvalues.end(), f).get(); HPX_TEST_EQ(result, expected_result); }
hpx::future<T> test_transform_reduce_binary_async(ExPolicy&& policy, hpx::partitioned_vector<T>& xvalues, hpx::partitioned_vector<T>& yvalues) { return hpx::parallel::transform_reduce(policy, xvalues.begin(), xvalues.end(), yvalues.begin(), T(1), std::plus<T>(), std::multiplies<T>()); }
explicit partitioned_vector_view(hpx::partitioned_vector<T>& data) : segment_iterator_(data.segment_begin(hpx::get_locality_id())) { #if defined(HPX_DEBUG) // this view assumes that there is exactly one segment per locality typedef typename traits::local_segment_iterator local_segment_iterator; local_segment_iterator sit = segment_iterator_; HPX_ASSERT(++sit == data.segment_end(hpx::get_locality_id())); #endif }
void test_for_each_n(ExPolicy && policy, hpx::partitioned_vector<T>& v, T val) { verify_values(policy, v, val); verify_values_count(policy, v, val); hpx::parallel::for_each_n(policy, v.begin(), v.end() - v.begin(), pfo()); verify_values(policy, v, ++val); verify_values_count(policy, v, val); }
void test_transform_binary2(ExPolicy && policy, hpx::partitioned_vector<T>& v, hpx::partitioned_vector<U>& w, hpx::partitioned_vector<V>& x, V val) { verify_values(policy, v, val); verify_values_count(policy, v, val); verify_values(policy, w, val); verify_values_count(policy, w, val); hpx::parallel::transform(policy, v.begin(), v.end(), w.begin(), w.end(), x.begin(), add<V>()); verify_values(policy, x, 2*val); verify_values_count(policy, x, 2*val); }
void verify_values(ExPolicy && policy, hpx::partitioned_vector<T> const& v, U const& val) { typedef typename hpx::partitioned_vector<T>::const_iterator const_iterator; std::size_t size = 0; const_iterator end = v.end(); for (const_iterator it = v.begin(); it != end; ++it, ++size) { HPX_TEST_EQ(*it, val); } HPX_TEST_EQ(size, v.size()); }
double run_minmax_element_benchmark(int test_count, hpx::partitioned_vector<int> const& v) { boost::uint64_t time = hpx::util::high_resolution_clock::now(); for (int i = 0; i != test_count; ++i) { // invoke minmax using namespace hpx::parallel; /*auto iters = */minmax_element(par, v.begin(), v.end()); } time = hpx::util::high_resolution_clock::now() - time; return (time * 1e-9) / test_count; }
void initialize(hpx::partitioned_vector<T>& xvalues) { T init_array[SIZE] = {1, 2, 3, 4, 5, 1, 2, 3, 3, 5, 5, 3, 4, 2, 3, 2, 1, 2, 3, 4, 5, 6, 5, 6, 1, 2, 3, 4, 1, 1, 2, 3, 4, 5, 4, 3, 2, 1, 1, 2, 3, 4, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 7, 6, 5, 7, 5, 4, 2, 3, 4, 5, 2}; for (int i = 0; i < SIZE; i++) { xvalues.set_value(i, init_array[i]); } }
void verify_values(hpx::partitioned_vector<T> v1, std::vector<T> v2) { auto first = v1.begin(); auto last = v1.end(); typedef hpx::traits::segmented_iterator_traits<decltype(first)> traits; typedef typename traits::segment_iterator segment_iterator; typedef typename traits::local_iterator local_iterator_type; segment_iterator sit = traits::segment(first); segment_iterator send = traits::segment(last); auto beg2 = v2.begin(); std::vector<bool> results; for (; sit != send; ++sit) { local_iterator_type beg = traits::begin(sit); local_iterator_type end = traits::end(sit); std::vector<T> test(std::distance(beg, end)); std::copy_n(beg2, test.size(), test.begin()); results.push_back( hpx::parallel::v1::detail::dispatch(traits::get_id(sit), verify<bool>(), hpx::parallel::seq, std::true_type(), beg, end, test )); beg2 += std::distance(beg, end); } bool final_result = std::all_of(results.begin(), results.end(), [](bool v) { return v; }); HPX_TEST(final_result); }
void test_adjacent_find(ExPolicy&& policy, hpx::partitioned_vector<T>& xvalues) { auto result = hpx::parallel::adjacent_find(policy, xvalues.begin(), xvalues.end()); HPX_TEST_EQ(std::distance(xvalues.begin(), result), 31); result = hpx::parallel::adjacent_find(policy, xvalues.begin(), xvalues.end(), pred()); HPX_TEST_EQ(std::distance(xvalues.begin(), result), 4); }
void verify_values_count_async(ExPolicy && policy, hpx::partitioned_vector<T> const& v, U const& val) { HPX_TEST_EQ( std::size_t(hpx::parallel::count( policy, v.begin(), v.end(), val).get()), v.size()); HPX_TEST_EQ( std::size_t(hpx::parallel::count_if( policy, v.begin(), v.end(), cmp<T>(val)).get()), v.size()); }
void compare_vectors(hpx::partitioned_vector<T> const& v1, hpx::partitioned_vector<T> const& v2, bool must_be_equal = true) { typedef typename hpx::partitioned_vector<T>::const_iterator const_iterator; HPX_TEST_EQ(v1.size(), v2.size()); const_iterator it1 = v1.begin(), it2 = v2.begin(); const_iterator end1 = v1.end(), end2 = v2.end(); for (/**/; it1 != end1 && it2 != end2; ++it1, ++it2) { if (must_be_equal) { HPX_TEST_EQ(*it1, *it2); } else { HPX_TEST_NEQ(*it1, *it2); } } }
void fill_vector(hpx::partitioned_vector<T>& v, T const& val) { typename hpx::partitioned_vector<T>::iterator it = v.begin(), end = v.end(); for (/**/; it != end; ++it) *it = val; }