int hpx_main(variables_map& vm) { int r = master(vm); finalize(); return r; }
int hpx_main( variables_map& vm ) { { if (vm.count("no-header")) header = false; if (vm.count("csv-header")) csv_header = true; if (0 == tasks) throw std::invalid_argument("count of 0 tasks specified\n"); if (suspended_tasks > tasks) throw std::invalid_argument( "suspended tasks must be smaller than tasks\n"); std::uint64_t const os_thread_count = get_os_thread_count(); /////////////////////////////////////////////////////////////////////// stage_worker_function stage_worker; if ("static-balanced-stackbased" == distribution) stage_worker = &stage_worker_static_balanced_stackbased; else if ("static-imbalanced" == distribution) stage_worker = &stage_worker_static_imbalanced; else if ("round-robin" == distribution) stage_worker = &stage_worker_round_robin; else throw std::invalid_argument( "invalid distribution type specified (valid options are " "\"static-balanced\", \"static-imbalanced\" or \"round-robin\")" ); /////////////////////////////////////////////////////////////////////// std::uint64_t tasks_per_feeder = 0; //std::uint64_t total_tasks = 0; std::uint64_t suspended_tasks_per_feeder = 0; std::uint64_t total_suspended_tasks = 0; if ("strong" == scaling) { if (tasks % os_thread_count) throw std::invalid_argument( "tasks must be cleanly divisable by OS-thread count\n"); if (suspended_tasks % os_thread_count) throw std::invalid_argument( "suspended tasks must be cleanly divisable by OS-thread " "count\n"); tasks_per_feeder = tasks / os_thread_count; //total_tasks = tasks; suspended_tasks_per_feeder = suspended_tasks / os_thread_count; total_suspended_tasks = suspended_tasks; } else if ("weak" == scaling) { tasks_per_feeder = tasks; //total_tasks = tasks * os_thread_count; suspended_tasks_per_feeder = suspended_tasks; total_suspended_tasks = suspended_tasks * os_thread_count; } else throw std::invalid_argument( "invalid scaling type specified (valid options are \"strong\" " "or \"weak\")"); /////////////////////////////////////////////////////////////////////// if (suspended_tasks != 0) { std::uint64_t gcd = boost::math::gcd(tasks_per_feeder , suspended_tasks_per_feeder); suspend_step = suspended_tasks_per_feeder / gcd; // We check earlier to make sure that there are never more // suspended tasks than tasks requested. no_suspend_step = (tasks_per_feeder / gcd) - suspend_step; } /////////////////////////////////////////////////////////////////////// std::vector<std::string> counter_shortnames; std::vector<std::string> counters; if (vm.count("counter")) { std::vector<std::string> raw_counters = vm["counter"].as<std::vector<std::string> >(); for (std::uint64_t i = 0; i < raw_counters.size(); ++i) { std::vector<std::string> entry; boost::algorithm::split(entry, raw_counters[i], boost::algorithm::is_any_of(","), boost::algorithm::token_compress_on); HPX_ASSERT(entry.size() == 2); counter_shortnames.push_back(entry[0]); counters.push_back(entry[1]); } } std::shared_ptr<hpx::util::activate_counters> ac; if (!counters.empty()) ac.reset(new hpx::util::activate_counters(counters)); /////////////////////////////////////////////////////////////////////// // Start the clock. high_resolution_timer t; if (ac) ac->reset_counters(); // This needs to stay here; we may have suspended as recently as the // performance counter reset (which is called just before the staging // function). std::uint64_t const num_thread = hpx::get_worker_thread_num(); for (std::uint64_t i = 0; i < os_thread_count; ++i) { if (num_thread == i) continue; register_work(hpx::util::bind(&stage_workers , i , tasks_per_feeder , stage_worker ) , "stage_workers" , hpx::threads::pending , hpx::threads::thread_priority_normal , i ); } stage_workers(num_thread, tasks_per_feeder, stage_worker); double warmup_estimate = t.elapsed(); // Schedule a low-priority thread; when it is executed, it checks to // make sure all the tasks (which are normal priority) have been // executed, and then it hpx::lcos::local::barrier finished(2); register_work(hpx::util::bind(&wait_for_tasks , std::ref(finished) , total_suspended_tasks ) , "wait_for_tasks", hpx::threads::pending , hpx::threads::thread_priority_low); finished.wait(); // Stop the clock double time_elapsed = t.elapsed(); print_results(os_thread_count, time_elapsed, warmup_estimate , counter_shortnames, ac); } if (suspended_tasks != 0) // Force termination of all suspended tasks. hpx::get_runtime().get_thread_manager().abort_all_suspended_threads(); return finalize(); }
// The input on the Intel call is a pair of pointers to arrays of dep structs, // and the length of these arrays. // The structs contain a pointer and a flag for in or out dep void hpx_runtime::create_df_task( int gtid, kmp_task_t *thunk, int ndeps, kmp_depend_info_t *dep_list, int ndeps_noalias, kmp_depend_info_t *noalias_dep_list ) { auto task = get_task_data(); auto team = task->team; if(team->num_threads == 1 ) { create_task(thunk->routine, gtid, thunk); } vector<shared_future<void>> dep_futures; dep_futures.reserve( ndeps + ndeps_noalias); //Populating a vector of futures that the task depends on for(int i = 0; i < ndeps;i++) { if(task->df_map.count( dep_list[i].base_addr) > 0) { dep_futures.push_back(task->df_map[dep_list[i].base_addr]); } } for(int i = 0; i < ndeps_noalias;i++) { if(task->df_map.count( noalias_dep_list[i].base_addr) > 0) { dep_futures.push_back(task->df_map[noalias_dep_list[i].base_addr]); } } shared_future<void> new_task; if(task->in_taskgroup) { } else { *(task->num_child_tasks) += 1; } #ifndef OMP_COMPLIANT team->num_tasks++; #endif if(dep_futures.size() == 0) { #ifdef OMP_COMPLIANT if(task->in_taskgroup) { new_task = hpx::async( *(task->tg_exec), tg_task_setup, gtid, thunk, task->icv, task->tg_exec, team); } else { new_task = hpx::async( *(team->exec), task_setup, gtid, thunk, task->icv, task->num_child_tasks, team); } #else new_task = hpx::async( task_setup, gtid, thunk, task->icv, task->num_child_tasks, team); #endif } else { #ifdef OMP_COMPLIANT //shared_future<shared_ptr<local_priority_queue_executor>> tg_exec = hpx::make_ready_future(task->tg_exec); if(task->in_taskgroup) { new_task = dataflow( *(task->tg_exec), unwrapping(df_tg_task_wrapper), gtid, thunk, task->icv, task->tg_exec, team, hpx::when_all(dep_futures) ); } else { new_task = dataflow( *(team->exec), unwrapping(df_task_wrapper), gtid, thunk, task->icv, task->num_child_tasks, team, hpx::when_all(dep_futures) ); } #else new_task = dataflow( unwrapping(df_task_wrapper), gtid, thunk, task->icv, task->num_child_tasks, team, hpx::when_all(dep_futures) ); #endif } for(int i = 0 ; i < ndeps; i++) { if(dep_list[i].flags.out) { task->df_map[dep_list[i].base_addr] = new_task; } } for(int i = 0 ; i < ndeps_noalias; i++) { if(noalias_dep_list[i].flags.out) { task->df_map[noalias_dep_list[i].base_addr] = new_task; } } //task->last_df_task = new_task; }
void test_object_actions() { std::vector<id_type> localities = hpx::find_all_localities(); BOOST_FOREACH(id_type id, localities) { bool is_local = id == find_here(); // test size_t(movable_object const&) if (is_local) { HPX_TEST_EQ(( pass_object<pass_movable_object_action, movable_object>(id) ), 1u); // bind HPX_TEST_EQ(( move_object<pass_movable_object_action, movable_object>(id) ), 0U); } else { HPX_TEST_EQ(( pass_object<pass_movable_object_action, movable_object>(id) ), 2u); // transfer_action + bind //! should be: transfer_action HPX_TEST_EQ(( move_object<pass_movable_object_action, movable_object>(id) ), 1u); // bind //! should be: - } // test size_t(non_movable_object const&) if (is_local) { HPX_TEST_EQ(( pass_object<pass_non_movable_object_action, non_movable_object>(id) ), 2u); // bind + function HPX_TEST_EQ(( move_object<pass_non_movable_object_action, non_movable_object>(id) ), 2u); // bind + function } else { HPX_TEST_EQ(( pass_object<pass_non_movable_object_action, non_movable_object>(id) ), 3u); // transfer_action + bind + function HPX_TEST_EQ(( move_object<pass_non_movable_object_action, non_movable_object>(id) ), 3u); // transfer_action + bind + function } // test size_t(movable_object) if (is_local) { HPX_TEST_EQ(( pass_object<pass_movable_object_value_action, movable_object>(id) ), 1u); // call HPX_TEST_EQ(( move_object<pass_movable_object_value_action, movable_object>(id) ), 0u); } else { HPX_TEST_EQ(( pass_object<pass_movable_object_value_action, movable_object>(id) ), 2u); // transfer_action + bind //! should be: transfer_action HPX_TEST_EQ(( move_object<pass_movable_object_value_action, movable_object>(id) ), 1u); // bind //! should be: - } // test size_t(non_movable_object) if (is_local) { HPX_TEST_EQ(( pass_object<pass_non_movable_object_value_action, non_movable_object>(id) ), 3u); // bind + function + call HPX_TEST_EQ(( move_object<pass_non_movable_object_value_action, non_movable_object>(id) ), 3u); // bind + function + call } else { HPX_TEST_EQ(( pass_object<pass_non_movable_object_value_action, non_movable_object>(id) ), 4u); // transfer_action + bind + function + call HPX_TEST_EQ(( move_object<pass_non_movable_object_value_action, non_movable_object>(id) ), 4u); // transfer_action + bind + function + call } // test movable_object() if (is_local) { HPX_TEST_EQ(( return_object< return_movable_object_action, movable_object >(id) ), 1u); // value_or_error(r) //! should be: - HPX_TEST_EQ(( return_move_object< return_movable_object_action, movable_object >(id) ), 0u); } else { HPX_TEST_EQ(( return_object< return_movable_object_action, movable_object >(id) ), 2u); // transfer_action + value_or_error(r) //! should be: - HPX_TEST_EQ(( return_move_object< return_movable_object_action, movable_object >(id) ), 1u); // transfer_action //! should be: - } // test non_movable_object() if (is_local) { HPX_TEST_RANGE(( return_object< return_non_movable_object_action, non_movable_object >(id) ), 3u, 6u); // ?call + value_or_error(w) + value_or_error(r) + // future_data::get_data + ?future::get + ?return //! should be: ?call + value_or_error(w) + ?return HPX_TEST_RANGE(( return_move_object< return_non_movable_object_action, non_movable_object >(id) ), 3u, 6u); // ?call + value_or_error(w) + value_or_error(r) + // future_data::move_data + ?future::move + ?return //! should be: ?call + value_or_error(w) + ?future::move + ?return } else { HPX_TEST_RANGE(( return_object< return_non_movable_object_action, non_movable_object >(id) ), 6u, 9u); // transfer_action + bind + function + ?call + // value_or_error(w) + value_or_error(r) + // future_data::get_data + ?future::get + ?return //! should be: transfer_action + bind + function + ?call + // value_or_error(w) + ?return HPX_TEST_RANGE(( return_move_object< return_non_movable_object_action, non_movable_object >(id) ), 6u, 9u); // transfer_action + bind + function + ?call + // value_or_error(w) + value_or_error(r) + // future_data::move_data + ?future::move + ?return //! should be: transfer_action + bind + function + ?call + // value_or_error(w) + ?future::move + ?return } }
int hpx_main() { using hpx::make_continuation; increment_action inc; increment_with_future_action inc_f; mult2_action mult; // test locally, fully equivalent to plain hpx::async { hpx::future<int> f1 = hpx::async_continue( inc, make_continuation(), hpx::find_here(), 42); HPX_TEST_EQ(f1.get(), 43); hpx::promise<std::int32_t> p; hpx::shared_future<std::int32_t> f = p.get_future(); hpx::future<int> f2 = hpx::async_continue( inc_f, make_continuation(), hpx::find_here(), f); p.set_value(42); HPX_TEST_EQ(f2.get(), 43); } // test remotely, if possible, fully equivalent to plain hpx::async std::vector<hpx::id_type> localities = hpx::find_remote_localities(); if (!localities.empty()) { hpx::future<int> f1 = hpx::async_continue( inc, make_continuation(), localities[0], 42); HPX_TEST_EQ(f1.get(), 43); hpx::promise<std::int32_t> p; hpx::shared_future<std::int32_t> f = p.get_future(); hpx::future<int> f2 = hpx::async_continue( inc_f, make_continuation(), localities[0], f); p.set_value(42); HPX_TEST_EQ(f2.get(), 43); } // test chaining locally { hpx::future<int> f = hpx::async_continue( inc, make_continuation(mult), hpx::find_here(), 42); HPX_TEST_EQ(f.get(), 86); f = hpx::async_continue(inc, make_continuation(mult, make_continuation()), hpx::find_here(), 42); HPX_TEST_EQ(f.get(), 86); f = hpx::async_continue(inc, make_continuation(mult, make_continuation(inc)), hpx::find_here() ,42); HPX_TEST_EQ(f.get(), 87); f = hpx::async_continue(inc, make_continuation(mult, make_continuation(inc, make_continuation())), hpx::find_here(), 42); HPX_TEST_EQ(f.get(), 87); } // test chaining remotely, if possible if (!localities.empty()) { hpx::future<int> f = hpx::async_continue(inc, make_continuation(mult, localities[0]), localities[0], 42); HPX_TEST_EQ(f.get(), 86); f = hpx::async_continue(inc, make_continuation(mult, localities[0], make_continuation()), localities[0], 42); HPX_TEST_EQ(f.get(), 86); f = hpx::async_continue(inc, make_continuation(mult, localities[0], make_continuation(inc)), localities[0], 42); HPX_TEST_EQ(f.get(), 87); f = hpx::async_continue(inc, make_continuation(mult, localities[0], make_continuation(inc, make_continuation())), localities[0], 42); HPX_TEST_EQ(f.get(), 87); f = hpx::async_continue(inc, make_continuation(mult, localities[0], make_continuation(inc, localities[0])), localities[0], 42); HPX_TEST_EQ(f.get(), 87); f = hpx::async_continue(inc, make_continuation(mult, localities[0], make_continuation(inc, localities[0], make_continuation())), localities[0], 42); HPX_TEST_EQ(f.get(), 87); f = hpx::async_continue(inc, make_continuation(mult), localities[0], 42); HPX_TEST_EQ(f.get(), 86); f = hpx::async_continue(inc, make_continuation(mult, make_continuation()), localities[0], 42); HPX_TEST_EQ(f.get(), 86); } return hpx::finalize(); }
int hpx_main( variables_map& vm ) { { std::size_t count = 0; callback cb(count); /////////////////////////////////////////////////////////////////////// HPX_SANITY_EQ(0U, cb.count()); cb(0); HPX_SANITY_EQ(1U, cb.count()); cb.reset(); HPX_SANITY_EQ(0U, cb.count()); /////////////////////////////////////////////////////////////////////// id_type const here_ = find_here(); /////////////////////////////////////////////////////////////////////// // Async wait, single future, void return. { wait(async<null_action>(here_), cb); HPX_TEST_EQ(1U, cb.count()); HPX_TEST_EQ(1U, void_counter.load()); cb.reset(); void_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Async wait, single future, non-void return. { wait(async<null_result_action>(here_), cb); HPX_TEST_EQ(1U, cb.count()); HPX_TEST_EQ(1U, result_counter.load()); cb.reset(); result_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Async wait, vector of futures, void return. { std::vector<future<void> > futures; futures.reserve(64); for (std::size_t i = 0; i < 64; ++i) futures.push_back(async<null_action>(here_)); wait(futures, cb); HPX_TEST_EQ(64U, cb.count()); HPX_TEST_EQ(64U, void_counter.load()); cb.reset(); void_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Async wait, vector of futures, non-void return. { std::vector<future<bool> > futures; futures.reserve(64); for (std::size_t i = 0; i < 64; ++i) futures.push_back(async<null_result_action>(here_)); wait(futures, cb); HPX_TEST_EQ(64U, cb.count()); HPX_TEST_EQ(64U, result_counter.load()); cb.reset(); result_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, single future, void return. { wait(async<null_action>(here_)); HPX_TEST_EQ(1U, void_counter.load()); void_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, single future, non-void return. { HPX_TEST_EQ(true, wait(async<null_result_action>(here_))); HPX_TEST_EQ(1U, result_counter.load()); result_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, multiple futures, void return. { wait(async<null_action>(here_) , async<null_action>(here_) , async<null_action>(here_)); HPX_TEST_EQ(3U, void_counter.load()); void_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, multiple futures, non-void return. { HPX_STD_TUPLE<bool, bool, bool> r = wait(async<null_result_action>(here_) , async<null_result_action>(here_) , async<null_result_action>(here_)); HPX_TEST_EQ(true, HPX_STD_GET(0, r)); HPX_TEST_EQ(true, HPX_STD_GET(1, r)); HPX_TEST_EQ(true, HPX_STD_GET(2, r)); HPX_TEST_EQ(3U, result_counter.load()); result_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, vector of futures, void return. { std::vector<future<void> > futures; futures.reserve(64); for (std::size_t i = 0; i < 64; ++i) futures.push_back(async<null_action>(here_)); wait(futures); HPX_TEST_EQ(64U, void_counter.load()); void_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, vector of futures, non-void return. { std::vector<future<bool> > futures; futures.reserve(64); std::vector<bool> values; values.reserve(64); for (std::size_t i = 0; i < 64; ++i) futures.push_back(async<null_result_action>(here_)); wait(futures, values); HPX_TEST_EQ(64U, result_counter.load()); for (std::size_t i = 0; i < 64; ++i) HPX_TEST_EQ(true, values[i]); result_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, vector of futures, non-void return ignored. { std::vector<future<bool> > futures; futures.reserve(64); for (std::size_t i = 0; i < 64; ++i) futures.push_back(async<null_result_action>(here_)); wait(futures); HPX_TEST_EQ(64U, result_counter.load()); result_counter.store(0); } } finalize(); return report_errors(); }
int hpx_main( variables_map& vm ) { if (vm.count("no-header")) header = false; std::size_t num_os_threads = hpx::get_os_thread_count(); int num_executors = vm["executors"].as<int>(); if (num_executors <= 0) throw std::invalid_argument("number of executors to use must be larger than 0"); if (std::size_t(num_executors) > num_os_threads) throw std::invalid_argument("number of executors to use must be smaller than number of OS threads"); std::size_t num_cores_per_executor = vm["cores"].as<int>(); if ((num_executors - 1) * num_cores_per_executor > num_os_threads) throw std::invalid_argument("number of cores per executor should not cause oversubscription"); if (0 == tasks) throw std::invalid_argument("count of 0 tasks specified\n"); // Start the clock. high_resolution_timer t; // create the executor instances using hpx::threads::executors::local_priority_queue_executor; { std::vector<local_priority_queue_executor> executors; for (std::size_t i = 0; i != std::size_t(num_executors); ++i) { // make sure we don't oversubscribe the cores, the last executor will // be bound to the remaining number of cores if ((i + 1) * num_cores_per_executor > num_os_threads) { BOOST_ASSERT(i == num_executors - 1); num_cores_per_executor = num_os_threads - i * num_cores_per_executor; } executors.push_back(local_priority_queue_executor(num_cores_per_executor)); } t.restart(); if (0 == vm.count("no-stack")) { // schedule normal threads for (boost::uint64_t i = 0; i < tasks; ++i) executors[i % num_executors].add(HPX_STD_BIND(&invoke_worker, delay)); } else { // schedule stackless threads for (boost::uint64_t i = 0; i < tasks; ++i) executors[i % num_executors].add(HPX_STD_BIND(&invoke_worker, delay), "", hpx::threads::pending, true, hpx::threads::thread_stacksize_nostack); } // destructors of executors will wait for all tasks to finish executing } print_results(num_os_threads, t.elapsed()); return finalize(); }
void plain_arguments() { void_f4_count.store(0); int_f4_count.store(0); { future<void> f1 = dataflow(&void_f4, 42); future<int> f2 = dataflow(&int_f4, 42); f1.wait(); HPX_TEST_EQ(void_f4_count, 1u); HPX_TEST_EQ(f2.get(), 84); HPX_TEST_EQ(int_f4_count, 1u); } { future<void> f1 = dataflow(hpx::launch::async, &void_f4, 42); future<int> f2 = dataflow(hpx::launch::async, &int_f4, 42); f1.wait(); HPX_TEST_EQ(void_f4_count, 2u); HPX_TEST_EQ(f2.get(), 84); HPX_TEST_EQ(int_f4_count, 2u); } void_f5_count.store(0); int_f5_count.store(0); { future<void> f1 = dataflow(&void_f5, 42, async(&int_f)); future<int> f2 = dataflow(&int_f5, 42, async(&int_f)); f1.wait(); HPX_TEST_EQ(void_f5_count, 1u); HPX_TEST_EQ(f2.get(), 126); HPX_TEST_EQ(int_f5_count, 1u); } { future<void> f1 = dataflow(hpx::launch::async, &void_f5, 42, async(&int_f)); future<int> f2 = dataflow(hpx::launch::async, &int_f5, 42, async(&int_f)); f1.wait(); HPX_TEST_EQ(void_f5_count, 2u); HPX_TEST_EQ(f2.get(), 126); HPX_TEST_EQ(int_f5_count, 2u); } }
void function_pointers() { void_f_count.store(0); int_f_count.store(0); void_f1_count.store(0); int_f1_count.store(0); int_f2_count.store(0); future<void> f1 = dataflow(unwrapped(&void_f1), async(&int_f)); future<int> f2 = dataflow( unwrapped(&int_f1) , dataflow( unwrapped(&int_f1) , make_ready_future(42)) ); future<int> f3 = dataflow( unwrapped(&int_f2) , dataflow( unwrapped(&int_f1) , make_ready_future(42) ) , dataflow( unwrapped(&int_f1) , make_ready_future(37) ) ); int_f_vector_count.store(0); std::vector<future<int> > vf; for(std::size_t i = 0; i < 10; ++i) { vf.push_back(dataflow(unwrapped(&int_f1), make_ready_future(42))); } future<int> f4 = dataflow(unwrapped(&int_f_vector), std::move(vf)); future<int> f5 = dataflow( unwrapped(&int_f1) , dataflow( unwrapped(&int_f1) , make_ready_future(42)) , dataflow( unwrapped(&void_f) , make_ready_future()) ); f1.wait(); HPX_TEST_EQ(f2.get(), 126); HPX_TEST_EQ(f3.get(), 163); HPX_TEST_EQ(f4.get(), 10 * 84); HPX_TEST_EQ(f5.get(), 126); HPX_TEST_EQ(void_f_count, 1u); HPX_TEST_EQ(int_f_count, 1u); HPX_TEST_EQ(void_f1_count, 1u); HPX_TEST_EQ(int_f1_count, 16u); HPX_TEST_EQ(int_f2_count, 1u); }
int hpx_main( variables_map& vm ) { { num_iterations = vm["delay-iterations"].as<boost::uint64_t>(); const boost::uint64_t count = vm["futures"].as<boost::uint64_t>(); k1 = vm["k1"].as<std::size_t>(); k2 = vm["k2"].as<std::size_t>(); k3 = vm["k3"].as<std::size_t>(); const id_type here = find_here(); if (HPX_UNLIKELY(0 == count)) throw std::logic_error("error: count of 0 futures specified\n"); std::vector<unique_future<double> > futures; futures.reserve(count); // start the clock /* k1 = 1; k2 = 2; for(; k1 < 256; k1 = k1 * 2)*/ { //for(; k2 < 2056; k2 = k2 * 2) { high_resolution_timer walltime; for (boost::uint64_t i = 0; i < count; ++i) futures.push_back(async<null_action>(here, i)); wait(futures, [&] (std::size_t, double r) { global_scratch += r; }); // stop the clock const double duration = walltime.elapsed(); if (vm.count("csv")) cout << ( boost::format("%3%,%4%,%5%,%2%\n") % count % duration % k1 % k2 % k3 ) << flush; else cout << ( boost::format("invoked %1% futures in %2% seconds (k1 = %3%, k2 = %4%, k3 = %5%)\n") % count % duration % k1 % k2 % k3 ) << flush; } } } finalize(); return 0; }
int hpx_main(variables_map& vm) { { { any any1(big_object(30, 40)); std::stringstream buffer; buffer << any1; HPX_TEST_EQ(buffer.str(), "3040"); } { typedef uint64_t index_type; typedef hpx::util::any elem_type; typedef hpx::util::hash_any hash_elem_functor; typedef boost::unordered_multimap<elem_type, index_type, hash_elem_functor> field_index_map_type; typedef field_index_map_type::iterator field_index_map_iterator_type; field_index_map_type field_index_map_; field_index_map_iterator_type it; elem_type elem(std::string("first string")); index_type id = 1; std::pair<elem_type, index_type> pp=std::make_pair(elem,id); it = field_index_map_.insert(pp); } // test equality { any any1(7), any2(7), any3(10), any4(std::string("seven")); HPX_TEST_EQ(any1, 7); HPX_TEST_NEQ(any1, 10); HPX_TEST_NEQ(any1, 10.0f); HPX_TEST_EQ(any1, any1); HPX_TEST_EQ(any1, any2); HPX_TEST_NEQ(any1, any3); HPX_TEST_NEQ(any1, any4); std::string long_str = std::string("This is a looooooooooooooooooooooooooong string"); std::string other_str = std::string("a different string"); any1 = long_str; any2 = any1; any3 = other_str; any4 = 10.0f; HPX_TEST_EQ(any1, long_str); HPX_TEST_NEQ(any1, other_str); HPX_TEST_NEQ(any1, 10.0f); HPX_TEST_EQ(any1, any1); HPX_TEST_EQ(any1, any2); HPX_TEST_NEQ(any1, any3); HPX_TEST_NEQ(any1, any4); } { if (sizeof(small_object) <= sizeof(void*)) std::cout << "object is small\n"; else std::cout << "object is large\n"; small_object const f(17); any any1(f); any any2(any1); any any3; any3 = any1; HPX_TEST_EQ((any_cast<small_object>(any1)) (7), uint64_t(17+7)); HPX_TEST_EQ((any_cast<small_object>(any2)) (9), uint64_t(17+9)); HPX_TEST_EQ((any_cast<small_object>(any3)) (11), uint64_t(17+11)); } { if (sizeof(big_object) <= sizeof(void*)) std::cout << "object is small\n"; else std::cout << "object is large\n"; big_object const f(5, 12); any any1(f); any any2(any1); any any3 = any1; HPX_TEST_EQ((any_cast<big_object>(any1)) (0, 1), uint64_t(5+12+0+1)); HPX_TEST_EQ((any_cast<big_object>(any2)) (1, 0), uint64_t(5+12+1+0)); HPX_TEST_EQ((any_cast<big_object>(any3)) (1, 1), uint64_t(5+12+1+1)); } // move semantics { any any1(5); HPX_TEST(!any1.empty()); any any2(std::move(any1)); HPX_TEST(!any2.empty()); HPX_TEST(any1.empty()); } { any any1(5); HPX_TEST(!any1.empty()); any any2; HPX_TEST(any2.empty()); any2 = std::move(any1); HPX_TEST(!any2.empty()); HPX_TEST(any1.empty()); } } // non serializable version { // test equality { any_nonser any1_nonser(7), any2_nonser(7), any3_nonser(10), any4_nonser(std::string("seven")); HPX_TEST_EQ(any1_nonser, 7); HPX_TEST_NEQ(any1_nonser, 10); HPX_TEST_NEQ(any1_nonser, 10.0f); HPX_TEST_EQ(any1_nonser, any1_nonser); HPX_TEST_EQ(any1_nonser, any2_nonser); HPX_TEST_NEQ(any1_nonser, any3_nonser); HPX_TEST_NEQ(any1_nonser, any4_nonser); std::string long_str = std::string("This is a looooooooooooooooooooooooooong string"); std::string other_str = std::string("a different string"); any1_nonser = long_str; any2_nonser = any1_nonser; any3_nonser = other_str; any4_nonser = 10.0f; HPX_TEST_EQ(any1_nonser, long_str); HPX_TEST_NEQ(any1_nonser, other_str); HPX_TEST_NEQ(any1_nonser, 10.0f); HPX_TEST_EQ(any1_nonser, any1_nonser); HPX_TEST_EQ(any1_nonser, any2_nonser); HPX_TEST_NEQ(any1_nonser, any3_nonser); HPX_TEST_NEQ(any1_nonser, any4_nonser); } { if (sizeof(small_object) <= sizeof(void*)) std::cout << "object is small\n"; else std::cout << "object is large\n"; small_object const f(17); any_nonser any1_nonser(f); any_nonser any2_nonser(any1_nonser); any_nonser any3_nonser = any1_nonser; HPX_TEST_EQ((any_cast<small_object>(any1_nonser)) (2), uint64_t(17+2)); HPX_TEST_EQ((any_cast<small_object>(any2_nonser)) (4), uint64_t(17+4)); HPX_TEST_EQ((any_cast<small_object>(any3_nonser)) (6), uint64_t(17+6)); } { if (sizeof(big_object) <= sizeof(void*)) std::cout << "object is small\n"; else std::cout << "object is large\n"; big_object const f(5, 12); any_nonser any1_nonser(f); any_nonser any2_nonser(any1_nonser); any_nonser any3_nonser = any1_nonser; HPX_TEST_EQ((any_cast<big_object>(any1_nonser)) (3,4), uint64_t(5+12+3+4)); HPX_TEST_EQ((any_cast<big_object>(any2_nonser)) (5,6), uint64_t(5+12+5+6)); HPX_TEST_EQ((any_cast<big_object>(any3_nonser)) (7,8), uint64_t(5+12+7+8)); } // move semantics { any_nonser any1(5); HPX_TEST(!any1.empty()); any_nonser any2(std::move(any1)); HPX_TEST(!any2.empty()); HPX_TEST(any1.empty()); } { any_nonser any1(5); HPX_TEST(!any1.empty()); any_nonser any2; HPX_TEST(any2.empty()); any2 = std::move(any1); HPX_TEST(!any2.empty()); HPX_TEST(any1.empty()); } } finalize(); return hpx::util::report_errors(); }
int hpx_main(variables_map& vm) { parameter par; // default pars par->loglevel = 2; par->nt0 = 100; par->nx0 = 101; par->grain_size = 10; par->allowedl = 0; par->num_neighbors = 2; par->out_every = 5.0; par->refine_every = 100; par->ethreshold = 1.e-4; par->ghostwidth = 9; // application specific parameters par->cfl = 0.01; par->disip = 0.005; par->Rmin = -5.0; par->Rout = 15.0; par->tau = 1.0; par->lambda = 1.0; par->v = 0.1; par->amp = 0.0001; par->x0 = 10.0; par->id_sigma = 0.9; par->outdir = "./"; id_type rt_id = get_applier().get_runtime_support_gid(); section root; hpx::components::stubs::runtime_support::get_config(rt_id, root); if (root.has_section("adaptive1d")) { section pars = *(root.get_section("adaptive1d")); appconfig_option<std::size_t>("loglevel", pars, par->loglevel); appconfig_option<std::size_t>("nx0", pars, par->nx0); appconfig_option<std::size_t>("nt0", pars, par->nt0); appconfig_option<std::size_t>("allowedl", pars, par->allowedl); appconfig_option<std::size_t>("grain_size", pars, par->grain_size); appconfig_option<std::size_t>("num_neighbors", pars, par->num_neighbors); appconfig_option<double>("out_every", pars, par->out_every); appconfig_option<std::string>("output_directory", pars, par->outdir); appconfig_option<std::size_t>("refine_every", pars, par->refine_every); appconfig_option<double>("ethreshold", pars, par->ethreshold); appconfig_option<std::size_t>("ghostwidth", pars, par->ghostwidth); // Application parameters appconfig_option<double>("cfl", pars, par->cfl); appconfig_option<double>("disip", pars, par->disip); appconfig_option<double>("Rmin", pars, par->Rmin); appconfig_option<double>("Rout", pars, par->Rout); appconfig_option<double>("tau", pars, par->tau); appconfig_option<double>("lambda", pars, par->lambda); appconfig_option<double>("v", pars, par->v); appconfig_option<double>("amp", pars, par->amp); appconfig_option<double>("x0", pars, par->x0); appconfig_option<double>("id_sigma", pars, par->id_sigma); } // derived parameters if ( (par->nx0 % 2) == 0 ) { std::string msg = boost::str(boost::format( "mesh dimensions (%1%) must be odd " ) % par->nx0 ); HPX_THROW_IN_CURRENT_FUNC(bad_parameter, msg); } if ( (par->nt0 % 2) != 0 ) { std::string msg = boost::str(boost::format( "nt0 needs to be even: (%1%) " ) % par->nt0); HPX_THROW_IN_CURRENT_FUNC(bad_parameter, msg); } if ( par->grain_size <= 3*par->num_neighbors ) { std::string msg = boost::str(boost::format( "Increase grain size (%1%) or decrease the num_neighbors (%2%) " ) % par->grain_size % par->num_neighbors); HPX_THROW_IN_CURRENT_FUNC(bad_parameter, msg); } if ( par->refine_every < 1 ) { // no adaptivity par->refine_every = par->nt0; } if ( (par->refine_every % 2) != 0 ) { std::string msg = boost::str(boost::format( "refine_every needs to be even: (%1%) " ) % par->refine_every); HPX_THROW_IN_CURRENT_FUNC(bad_parameter, msg); } if ( (par->nt0 % par->refine_every ) != 0 ) { std::string msg = boost::str(boost::format( "nt0 (%1%) needs to be evenly divisible by refine_every (%2%) " ) % par->nt0 % par->refine_every); HPX_THROW_IN_CURRENT_FUNC(bad_parameter, msg); } std::size_t time_grain_size = par->nt0/par->refine_every; std::cout << " Parameters : " << std::endl; std::cout << " nx0 : " << par->nx0 << std::endl; std::cout << " nt0 : " << par->nt0 << std::endl; std::cout << " refine_every : " << par->refine_every << std::endl; std::cout << " allowedl : " << par->allowedl << std::endl; std::cout << " grain_size : " << par->grain_size << std::endl; std::cout << " num_neighbors : " << par->num_neighbors << std::endl; std::cout << " out_every : " << par->out_every << std::endl; std::cout << " output_directory : " << par->outdir << std::endl; std::cout << " --------------: " << std::endl; std::cout << " loglevel : " << par->loglevel << std::endl; std::cout << " --------------: " << std::endl; std::cout << " Application " << std::endl; std::cout << " --------------: " << std::endl; std::cout << " cfl : " << par->cfl << std::endl; std::cout << " disip : " << par->disip << std::endl; std::cout << " Rmin : " << par->Rmin << std::endl; std::cout << " Rout : " << par->Rout << std::endl; std::cout << " tau : " << par->tau << std::endl; std::cout << " lambda : " << par->lambda << std::endl; std::cout << " v : " << par->v << std::endl; std::cout << " amp : " << par->amp << std::endl; std::cout << " x0 : " << par->x0 << std::endl; std::cout << " id_sigma : " << par->id_sigma << std::endl; // number stencils std::size_t number_stencils = par->nx0/par->grain_size; // compute derived parameters par->minx0 = par->Rmin; par->maxx0 = par->Rout; par->h = (par->maxx0 - par->minx0)/(par->nx0-1); par->levelp.resize(par->allowedl+1); par->levelp[0] = 0; // Compute the grid sizes boost::shared_ptr<std::vector<id_type> > placeholder; double initial_time = 0.0; int rc = level_refine(-1,par,placeholder,initial_time); for (std::size_t i=0;i<par->allowedl;i++) { rc = level_refine(i,par,placeholder,initial_time); } for (std::size_t i=1;i<=par->allowedl;i++) { rc = level_bbox(i,par); } // TEST // Check grid structure //for (std::size_t i=0;i<=par->allowedl;i++) { // int gi = level_return_start(i,par); // while ( grid_return_existence(gi,par) ) { // std::cout << " TEST level : " << i << " nx : " << par->gr_nx[gi] << " minx : " << par->gr_minx[gi] << " maxx : " << par->gr_maxx[gi] << " test dx : " << (par->gr_maxx[gi]-par->gr_minx[gi])/(par->gr_nx[gi]-1) << " actual h " << par->gr_h[gi] << " end: " << par->gr_minx[gi] + (par->gr_nx[gi]-1)*par->gr_h[gi] << std::endl; // std::cout << " TEST bbox : " << par->gr_lbox[gi] << " " << par->gr_rbox[gi] << std::endl; // gi = par->gr_sibling[gi]; // } //} // END TEST rc = compute_numrows(par); rc = compute_rowsize(par); //std::cout << " num_rows " << par->num_rows << std::endl; //std::cout << " rowsize " << par->rowsize[0] << " number stencils " << number_stencils << std::endl; // get component types needed below component_type function_type = get_component_type<stencil>(); component_type logging_type = get_component_type<logging>(); { id_type here = get_applier().get_runtime_support_gid(); high_resolution_timer t; dataflow_stencil um; um.create(here); int numsteps = par->refine_every/2; boost::shared_ptr<std::vector<id_type> > result_data(new std::vector<id_type>); for (std::size_t j=0;j<time_grain_size;j++) { double time = j*par->refine_every*par->cfl*par->h; result_data = um.init_execute(*result_data,time,function_type, par->rowsize[0], numsteps, par->loglevel ? logging_type : component_invalid, par); // Regrid time = (j+1)*par->refine_every*par->cfl*par->h; std::cout << " Completed time: " << time << std::endl; } std::cout << "Elapsed time: " << t.elapsed() << " [s]" << std::endl; for (std::size_t i = 0; i < result_data->size(); ++i) hpx::components::stubs::memory_block::free((*result_data)[i]); } // mesh needs to go out of scope before shutdown // initiate shutdown of the runtime systems on all localities finalize(); return 0; }
int hpx_main(variables_map&) { std::vector<id_type> localities = hpx::find_all_localities(); BOOST_FOREACH(id_type id, localities) { bool is_local = id == find_here(); if (is_local) { // test the void actions locally only (there is no way to get the // overall copy count back) HPX_TEST_EQ(( pass_object_void< pass_movable_object_void_action, movable_object >() ), 1u); HPX_TEST_EQ(( pass_object_void< pass_movable_object_void_direct_action, movable_object >() ), 1u); HPX_TEST_EQ(( pass_object_void< pass_non_movable_object_void_action, non_movable_object >() ), 3u); HPX_TEST_EQ(( pass_object_void< pass_non_movable_object_void_direct_action, non_movable_object >() ), 1u); HPX_TEST_EQ(( move_object_void< pass_movable_object_void_action, movable_object >() ), 1u); HPX_TEST_EQ(( move_object_void< pass_movable_object_void_direct_action, movable_object >() ), 1u); HPX_TEST_EQ(( move_object_void< pass_non_movable_object_void_action, non_movable_object >() ), 3u); HPX_TEST_EQ(( move_object_void< pass_non_movable_object_void_direct_action, non_movable_object >() ), 1u); } // test for movable object ('normal' actions) HPX_TEST_EQ(( pass_object<pass_movable_object_action, movable_object>(id) ), is_local ? 1u : 1u); // test for movable object (direct actions) HPX_TEST_EQ(( pass_object<pass_movable_object_direct_action, movable_object>(id) ), is_local ? 1u : 1u); // test for a non-movable object ('normal' actions) HPX_TEST_EQ(( pass_object<pass_non_movable_object_action, non_movable_object>(id) ), is_local ? 3u : 3u); // test for a non-movable object (direct actions) HPX_TEST_EQ(( pass_object<pass_non_movable_object_direct_action, non_movable_object>(id) ), is_local ? 1u : 1u); // test for movable object ('normal' actions) HPX_TEST_EQ(( move_object<pass_movable_object_action, movable_object>(id) ), is_local ? 1u : 1u); // test for movable object (direct actions) HPX_TEST_EQ(( move_object<pass_movable_object_direct_action, movable_object>(id) ), is_local ? 1u : 1u); // test for a non-movable object ('normal' actions) HPX_TEST_EQ(( move_object<pass_non_movable_object_action, non_movable_object>(id) ), is_local ? 3u : 3u); // test for a non-movable object (direct actions) HPX_TEST_EQ(( move_object<pass_non_movable_object_direct_action, non_movable_object>(id) ), is_local ? 1u : 1u); HPX_TEST_LTE(( return_object< return_movable_object_action, movable_object >(id) ), is_local ? 5u : 5u); HPX_TEST_LTE(( return_object< return_movable_object_direct_action, movable_object >(id) ), is_local ? 5u : 5u); HPX_TEST_LTE(( return_object< return_non_movable_object_action, non_movable_object >(id) ), is_local ? 8u : 10u); HPX_TEST_LTE(( return_object< return_non_movable_object_direct_action, non_movable_object >(id) ), is_local ? 8u : 10u); HPX_TEST_LTE(( return_move_object< return_movable_object_action, movable_object >(id) ), is_local ? 4u : 4u); HPX_TEST_LTE(( return_move_object< return_movable_object_direct_action, movable_object >(id) ), is_local ? 4u : 4u); HPX_TEST_RANGE(( return_move_object< return_non_movable_object_action, non_movable_object >(id) ), is_local ? 7u : 10u, is_local ? 10u : 12u); HPX_TEST_RANGE(( return_move_object< return_non_movable_object_direct_action, non_movable_object >(id) ), is_local ? 7u : 10u, is_local ? 10u : 12u); }
int master(variables_map& vm) { // Get options. const rational64 lower_bound = vm["lower-bound"].as<rational64>(); const rational64 upper_bound = vm["upper-bound"].as<rational64>(); const rational64 tolerance = vm["tolerance"].as<rational64>(); const boost::uint64_t top_segs = vm["top-segments"].as<boost::uint64_t>(); const boost::uint64_t regrid_segs = vm["regrid-segments"].as<boost::uint64_t>(); // Handle for the root discovery component. discovery disc_root; // Create the first discovery component on this locality. disc_root.create(find_here()); cout << "deploying discovery infrastructure" << endl; // Deploy the scheduling infrastructure. std::vector<id_type> discovery_network = disc_root.build_network_sync(); cout << ( boost::format("root discovery server is at %1%") % disc_root.get_gid()) << endl; // Get this localities topology map LVA. topology_map* topology_ptr = reinterpret_cast<topology_map*>(disc_root.topology_lva_sync()); topology_map& topology = *topology_ptr; // Print out the system topology. boost::uint32_t total_shepherds = 0; for (std::size_t i = 1; i <= topology.size(); ++i) { cout << ( boost::format("locality %1% has %2% shepherds") % i % topology[i]) << endl; total_shepherds += topology[i]; } cout << ( boost::format("%1% localities, %2% shepherds total") % topology.size() % total_shepherds) << endl; // Create the function that we're integrating. function<rational64(rational64 const&)> f(new math_function_action); // Handle for the root integrator component. integrator<rational64> integ_root; // Create the initial integrator component on this locality. integ_root.create(find_here()); cout << "deploying integration infrastructure" << endl; const rational64 eps(1, boost::integer_traits<boost::int64_t>::const_max); // Now, build the integration infrastructure on all nodes. std::vector<id_type> integrator_network = integ_root.build_network_sync (discovery_network, f, tolerance, regrid_segs, eps); cout << ( boost::format("root integration server is at %1%") % integ_root.get_gid()) << endl; // Print out the GIDs of the discovery and integrator servers. for (std::size_t i = 0; i < integrator_network.size(); ++i) { // These vectors are sorted from lowest prefix to highest prefix. cout << ( boost::format("locality %1% infrastructure\n" " discovery server at %2%\n" " integration server at %3%") % (i + 1) % discovery_network[i] % integrator_network[i]) << endl; } // Start the timer. high_resolution_timer t; // Solve the integral using an adaptive trapezoid algorithm. rational64 r = integ_root.solve_sync(lower_bound, upper_bound, top_segs); double elapsed = t.elapsed(); cout << ( boost::format("integral from %1% to %2% is %3%\n" "computation took %4% seconds") % boost::rational_cast<long double>(lower_bound) % boost::rational_cast<long double>(upper_bound) % boost::rational_cast<long double>(r) % elapsed) << endl; return 0; }
int hpx_main(variables_map&) { std::vector<id_type> localities = hpx::find_all_localities(); BOOST_FOREACH(id_type id, localities) { bool is_local = (id == find_here()) ? true : false; if (is_local) { // test the void actions locally only (there is no way to get the // overall copy count back) HPX_TEST_EQ(( pass_object_void< pass_movable_object_void_action, movable_object >() ), 1u); /* TODO: Make this compile HPX_TEST_EQ(( pass_object_void< pass_movable_object_void_direct_action, movable_object >() ), 0u); */ HPX_TEST_EQ(( pass_object_void< pass_non_movable_object_void_action, non_movable_object >() ), 4u); /* TODO: Make this compile HPX_TEST_EQ(( pass_object_void< pass_non_movable_object_void_direct_action, non_movable_object >() ), 0u); */ HPX_TEST_EQ(( move_object_void< pass_movable_object_void_action, movable_object >() ), 1u); /* TODO: Make this compile HPX_TEST_EQ(( move_object_void< pass_movable_object_void_direct_action, movable_object >() ), 0u); */ HPX_TEST_EQ(( move_object_void< pass_non_movable_object_void_action, non_movable_object >() ), 4u); /* TODO: Make this compile HPX_TEST_EQ(( move_object_void< pass_non_movable_object_void_direct_action, non_movable_object >() ), 0u); */ } // test for movable object ('normal' actions) HPX_TEST_EQ(( pass_object<pass_movable_object_action, movable_object>(id) ), is_local ? 1u : 1u); /* TODO: Make this compile // test for movable object (direct actions) HPX_TEST_EQ(( pass_object<pass_movable_object_direct_action, movable_object>(id) ), is_local ? 0u : 0u); */ // test for a non-movable object ('normal' actions) HPX_TEST_EQ(( pass_object<pass_non_movable_object_action, non_movable_object>(id) ), is_local ? 4u : 4u); /* TODO: Make this compile // test for a non-movable object (direct actions) HPX_TEST_EQ(( pass_object<pass_non_movable_object_direct_action, non_movable_object>(id) ), is_local ? 0u : 0u); */ // test for movable object ('normal' actions) HPX_TEST_EQ(( move_object<pass_movable_object_action, movable_object>(id) ), is_local ? 1u : 1u); /* TODO: Make this compile // test for movable object (direct actions) HPX_TEST_EQ(( move_object<pass_movable_object_direct_action, movable_object>(id) ), is_local ? 0u : 0u); */ // test for a non-movable object ('normal' actions) HPX_TEST_EQ(( move_object<pass_non_movable_object_action, non_movable_object>(id) ), is_local ? 4u : 4u); /* TODO: Make this compile // test for a non-movable object (direct actions) HPX_TEST_EQ(( move_object<pass_non_movable_object_direct_action, non_movable_object>(id) ), is_local ? 0u : 0u); */ HPX_TEST_EQ(( return_object< return_movable_object_action, movable_object >(id) ), is_local ? 1u : 2u); /* TODO: Make this compile HPX_TEST_EQ(( return_object< return_movable_object_direct_action, movable_object >(id) ), is_local ? 1u : 1u); */ HPX_TEST_EQ(( return_object< return_non_movable_object_action, non_movable_object >(id) ), is_local ? 2u : 7u); /* TODO: Make this compile HPX_TEST_EQ(( return_object< return_non_movable_object_direct_action, non_movable_object >(id) ), is_local ? 2u : 7u); */ HPX_TEST_EQ(( return_move_object< return_movable_object_action, movable_object >(id) ), is_local ? 0u : 0u); /* TODO: Make this compile HPX_TEST_EQ(( return_move_object< return_movable_object_direct_action, movable_object >(id) ), is_local ? 0u : 0u); */ HPX_TEST_EQ(( return_move_object< return_non_movable_object_action, non_movable_object >(id) ), is_local ? 2u : 2u); /* TODO: Make this compile HPX_TEST_EQ(( return_move_object< return_non_movable_object_direct_action, non_movable_object >(id) ), is_local ? 2u : 7u); */ }
int hpx_main(variables_map& vm) { std::size_t hpxthread_count = 0; if (vm.count("hpxthreads")) hpxthread_count = vm["hpxthreads"].as<std::size_t>(); std::size_t mutex_count = 0; if (vm.count("mutexes")) mutex_count = vm["mutexes"].as<std::size_t>(); std::size_t iterations = 0; if (vm.count("iterations")) iterations = vm["iterations"].as<std::size_t>(); std::size_t wait = 0; if (vm.count("wait")) wait = vm["wait"].as<std::size_t>(); for (std::size_t i = 0; i < iterations; ++i) { std::cout << "iteration: " << i << "\n"; // Have the fifo preallocate storage. fifo_type hpxthreads(hpxthread_count); std::vector<mutex*> m(mutex_count, 0); barrier b0(hpxthread_count + 1), b1(hpxthread_count + 1); // Allocate the mutexes. for (std::size_t j = 0; j < mutex_count; ++j) m[j] = new mutex; for (std::size_t j = 0; j < hpxthread_count; ++j) { // Compute the mutex to be used for this thread. const std::size_t index = j % mutex_count; register_thread(boost::bind (&lock_and_wait, boost::ref(*m[index]) , boost::ref(b0) , boost::ref(b1) , boost::ref(hpxthreads) , wait) , "lock_and_wait"); } // Tell all hpxthreads that they can start running. b0.wait(); // Wait for all hpxthreads to finish. b1.wait(); // {{{ Print results for this iteration. std::pair<thread_id_type, std::size_t>* entry = 0; while (hpxthreads.pop(entry)) { HPX_ASSERT(entry); std::cout << " " << entry->first << "," << entry->second << "\n"; delete entry; } // }}} // Destroy the mutexes. for (std::size_t j = 0; j < mutex_count; ++j) { HPX_ASSERT(m[j]); delete m[j]; } } // Initiate shutdown of the runtime system. finalize(); return 0; }
int hpx_main( variables_map& vm ) { { boost::atomic<std::size_t> count(0); /////////////////////////////////////////////////////////////////////// id_type const here_ = find_here(); /////////////////////////////////////////////////////////////////////// // Sync wait, single future, void return. { unwrapped(async<null_action>(here_)); HPX_TEST_EQ(1U, void_counter.load()); void_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, single future, non-void return. { HPX_TEST_EQ(true, unwrapped(async<null_result_action>(here_))); HPX_TEST_EQ(1U, result_counter.load()); result_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, multiple futures, void return. { unwrapped(async<null_action>(here_) , async<null_action>(here_) , async<null_action>(here_)); HPX_TEST_EQ(3U, void_counter.load()); void_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, multiple futures, non-void return. { hpx::util::tuple<bool, bool, bool> r = unwrapped(async<null_result_action>(here_) , async<null_result_action>(here_) , async<null_result_action>(here_)); HPX_TEST_EQ(true, hpx::util::get<0>(r)); HPX_TEST_EQ(true, hpx::util::get<1>(r)); HPX_TEST_EQ(true, hpx::util::get<2>(r)); HPX_TEST_EQ(3U, result_counter.load()); result_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, vector of futures, void return. { std::vector<future<void> > futures; futures.reserve(64); for (std::size_t i = 0; i < 64; ++i) futures.push_back(async<null_action>(here_)); unwrapped(futures); HPX_TEST_EQ(64U, void_counter.load()); void_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, vector of futures, non-void return. { std::vector<future<bool> > futures; futures.reserve(64); std::vector<bool> values; values.reserve(64); for (std::size_t i = 0; i < 64; ++i) futures.push_back(async<null_result_action>(here_)); values = unwrapped(futures); HPX_TEST_EQ(64U, result_counter.load()); for (std::size_t i = 0; i < 64; ++i) HPX_TEST_EQ(true, values[i]); result_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Sync wait, vector of futures, non-void return ignored. { std::vector<future<bool> > futures; futures.reserve(64); for (std::size_t i = 0; i < 64; ++i) futures.push_back(async<null_result_action>(here_)); unwrapped(futures); HPX_TEST_EQ(64U, result_counter.load()); result_counter.store(0); } /////////////////////////////////////////////////////////////////////// // Functional wrapper, single future { future<int> future = hpx::make_ready_future(42); HPX_TEST_EQ(unwrapped(&increment)(future), 42 + 1); } /////////////////////////////////////////////////////////////////////// // Functional wrapper, vector of future { std::vector<future<int> > futures; futures.reserve(64); for (std::size_t i = 0; i < 64; ++i) futures.push_back(hpx::make_ready_future(42)); HPX_TEST_EQ(unwrapped(&accumulate)(futures), 42 * 64); } /////////////////////////////////////////////////////////////////////// // Functional wrapper, tuple of future { hpx::util::tuple<future<int>, future<int> > tuple = hpx::util::forward_as_tuple( hpx::make_ready_future(42), hpx::make_ready_future(42)); HPX_TEST_EQ(unwrapped(&add)(tuple), 42 + 42); } /////////////////////////////////////////////////////////////////////// // Functional wrapper, future of tuple of future { hpx::future< hpx::util::tuple<future<int>, future<int> > > tuple_future = hpx::make_ready_future(hpx::util::make_tuple( hpx::make_ready_future(42), hpx::make_ready_future(42))); HPX_TEST_EQ(unwrapped2(&add)(tuple_future), 42 + 42); } } finalize(); return report_errors(); }
void test_object_direct_actions() { std::vector<id_type> localities = hpx::find_all_localities(); for (id_type const& id : localities) { bool is_local = id == find_here(); // test std::size_t(movable_object const&) if (is_local) { HPX_TEST_EQ(( pass_object<pass_movable_object_direct_action, movable_object>(id) ), 0u); HPX_TEST_EQ(( move_object<pass_movable_object_direct_action, movable_object>(id) ), 0u); } else { HPX_TEST_EQ(( pass_object<pass_movable_object_direct_action, movable_object>(id) ), 1u); // transfer_action HPX_TEST_EQ(( move_object<pass_movable_object_direct_action, movable_object>(id) ), 0u); } // test std::size_t(non_movable_object const&) if (is_local) { HPX_TEST_EQ(( pass_object<pass_non_movable_object_direct_action, non_movable_object>(id) ), 0u); HPX_TEST_EQ(( move_object<pass_non_movable_object_direct_action, non_movable_object>(id) ), 0u); } else { HPX_TEST_EQ(( pass_object<pass_non_movable_object_direct_action, non_movable_object>(id) ), 3u); // transfer_action + bind + function HPX_TEST_EQ(( move_object<pass_non_movable_object_direct_action, non_movable_object>(id) ), 3u); // transfer_action + bind + function } // test std::size_t(movable_object) if (is_local) { HPX_TEST_EQ(( pass_object<pass_movable_object_value_direct_action, movable_object>(id) ), 1u); // call HPX_TEST_EQ(( move_object<pass_movable_object_value_direct_action, movable_object>(id) ), 0u); } else { HPX_TEST_EQ(( pass_object<pass_movable_object_value_direct_action, movable_object>(id) ), 1u); // transfer_action HPX_TEST_EQ(( move_object<pass_movable_object_value_direct_action, movable_object>(id) ), 0u); } // test std::size_t(non_movable_object) if (is_local) { HPX_TEST_EQ(( pass_object<pass_non_movable_object_value_direct_action, non_movable_object>(id) ), 1u); // call HPX_TEST_EQ(( move_object<pass_non_movable_object_value_direct_action, non_movable_object>(id) ), 1u); // call } else { HPX_TEST_EQ(( pass_object<pass_non_movable_object_value_direct_action, non_movable_object>(id) ), 4u); // transfer_action + bind + function + call HPX_TEST_EQ(( move_object<pass_non_movable_object_value_direct_action, non_movable_object>(id) ), 4u); // transfer_action + bind + function + call } // test movable_object() if (is_local) { HPX_TEST_EQ(( return_object< return_movable_object_direct_action, movable_object >(id) ), 0u); } else { HPX_TEST_EQ(( return_object< return_movable_object_direct_action, movable_object >(id) ), 0u); } // test non_movable_object() if (is_local) { HPX_TEST_RANGE(( return_object< return_non_movable_object_direct_action, non_movable_object >(id) ), 1u, 3u); // ?call + set_value + ?return } else { //FIXME: bumped number for intel compiler HPX_TEST_RANGE(( return_object< return_non_movable_object_direct_action, non_movable_object >(id) ), 4u, 8u); // transfer_action + bind + function + ?call + // set_value + ?return } } }
void sys( const state_type &x , state_type &dxdt , const double dt ) { const size_t N = x.size(); for( size_t i=0 ; i<N ; ++i ) dxdt[i] = dataflow< rhs_operation_action >( find_here() , x[i] ); }
int hpx_main() { BMP SetImage; SetImage.SetBitDepth(24); SetImage.SetSize(sizeX * 2,sizeY); hpx::util::high_resolution_timer t; { using namespace std; using hpx::future; using hpx::async; using hpx::wait_all; int const max_iteration = 255; vector<future<int> > iteration; iteration.reserve(sizeX*sizeY); hpx::cout << "Initial setup completed in " << t.elapsed() << "s. Initializing and running futures...\n"; t.restart(); hpx::id_type const here = hpx::find_here(); fractals_action fractal_pixel; for (int i = 0; i < sizeX; i++) { for (int j = 0; j < sizeY; j++) { float x0 = (float)i * 3.5f / (float)sizeX - 2.5f; float y0 = (float)j * 2.0f / (float)sizeY - 1.0f; iteration.push_back(async(fractal_pixel, here, x0, y0, max_iteration)); } } wait_all(iteration); hpx::cout << sizeX*sizeY << " calculations run in " << t.elapsed() << "s. Transferring from futures to general memory...\n"; t.restart(); for (int i = 0; i < sizeX; ++i) { for (int j = 0; j < sizeY; ++j) { int it = iteration[i*sizeX + j].get(); for (int k = 0; k < 2; ++k) { int p = (it * 255) / max_iteration; SetImage.SetPixel(i * 2 + k, j, RGBApixel(p, p, p)); } } } } hpx::cout << "Transfer process completed in " << t.elapsed() << "s. Writing to hard disk...\n"; t.restart(); SetImage.WriteToFile("out.bmp"); hpx::cout << "Fractal image written to file \"out.bmp\" from memory in " << t.elapsed() << "s.\nInitializing shutdown process.\n"; return hpx::finalize(); // Handles HPX shutdown }
int hpx_main(boost::program_options::variables_map& vm) { const std::size_t N1 = vm["N1"].as<std::size_t>(); const std::size_t N2 = vm["N2"].as<std::size_t>(); const bool fully_random = vm["fully_random"].as<bool>(); const std::size_t init_length = vm["init_length"].as<std::size_t>(); const std::size_t steps = vm["steps"].as<std::size_t>(); const double dt = vm["dt"].as<double>(); std::size_t G = 8; while( G <= N1/hpx::get_os_thread_count() ) { const std::size_t M = N1/G; double avrg_time = 0.0; for( size_t n=0 ; n<10 ; ++n ) { dvecvec p_init( N1 , dvec( N2 , 0.0 ) ); std::uniform_real_distribution<double> distribution( -1.0 , 1.0 ); std::mt19937 engine( 0 ); // Mersenne twister MT19937 auto generator = std::bind(distribution, engine); if( fully_random ) { for( size_t j=0 ; j<N1 ; j++ ) std::generate( p_init[j].begin() , p_init[j].end() , std::ref(generator) ); } else { for( size_t j=N1/2-init_length/2 ; j<N1/2+init_length/2 ; j++ ) std::generate( p_init[j].begin()+N2/2-init_length/2 , p_init[j].begin()+N2/2+init_length/2 , std::ref(generator) ); } state_type q_in( M ); state_type p_in( M ); state_type q_out( M ); state_type p_out( M ); for( size_t i=0 ; i<M ; ++i ) { q_in[i] = dataflow< initialize_2d_action >( find_here() , std::allocate_shared< dvecvec >( std::allocator<dvecvec>() ) , G , N2 , 0.0 ); p_in[i] = dataflow< initialize_2d_from_data_action >( find_here() , std::allocate_shared< dvecvec >( std::allocator<dvecvec>() ) , p_init , i*G , G ); q_out[i] = dataflow< initialize_2d_action >( find_here() , std::allocate_shared< dvecvec >( std::allocator<dvecvec>() ) , G , N2 , 0.0 ); p_out[i] = dataflow< initialize_2d_action >( find_here() , std::allocate_shared< dvecvec >( std::allocator<dvecvec>() ) , G , N2 , 0.0 ); } std::vector< future<shared_vec> > futures_q( M ); std::vector< future<shared_vec> > futures_p( M ); for( size_t i=0 ; i<M ; ++i ) { futures_q[i] = q_in[i].get_future(); futures_p[i] = p_in[i].get_future(); } wait( futures_q ); wait( futures_p ); hpx::util::high_resolution_timer timer; stepper_type stepper; spreading_observer obs; for( size_t t=0 ; t<steps ; ++t ) { auto in = std::make_pair( boost::ref(q_in) , boost::ref(p_in) ); auto out = std::make_pair( boost::ref(q_out) , boost::ref(p_out) ); stepper.do_step( system_2d , in , t*dt , out , dt ); synchronized_swap( q_in , q_out ); synchronized_swap( p_in , p_out ); } for( size_t i=0 ; i<M ; ++i ) { futures_q[i] = q_in[i].get_future(); futures_p[i] = p_in[i].get_future(); } wait( futures_q ); wait( futures_p ); avrg_time += timer.elapsed(); } hpx::cout << (boost::format("%d\t%f\n") % G % (avrg_time/10)) << hpx::flush; //std::clog << "Integration complete, energy: " << energy( futures_q , futures_p ) << std::endl; G *= 2; } return hpx::finalize(); }
void future_function_pointers(Executor& exec) { future_void_f1_count.store(0); future_void_f2_count.store(0); future_int_f1_count.store(0); future_int_f2_count.store(0); future<void> f1 = dataflow(exec, &future_void_f1 , async(&future_void_sf1, shared_future<void>(make_ready_future())) ); f1.wait(); HPX_TEST_EQ(future_void_f1_count, 2u); future_void_f1_count.store(0); future<void> f2 = dataflow(exec, &future_void_f2 , async(&future_void_sf1, shared_future<void>(make_ready_future())) , async(&future_void_sf1, shared_future<void>(make_ready_future())) ); f2.wait(); HPX_TEST_EQ(future_void_f1_count, 2u); HPX_TEST_EQ(future_void_f2_count, 1u); future_void_f1_count.store(0); future_void_f2_count.store(0); future_int_f1_count.store(0); future_int_f2_count.store(0); future<int> f3 = dataflow(exec, &future_int_f1 , make_ready_future() ); HPX_TEST_EQ(f3.get(), 1); HPX_TEST_EQ(future_int_f1_count, 1u); future_int_f1_count.store(0); future<int> f4 = dataflow(exec, &future_int_f2 , dataflow(exec, &future_int_f1, make_ready_future()) , dataflow(exec, &future_int_f1, make_ready_future()) ); HPX_TEST_EQ(f4.get(), 2); HPX_TEST_EQ(future_int_f1_count, 2u); HPX_TEST_EQ(future_int_f2_count, 1u); future_int_f1_count.store(0); future_int_f2_count.store(0); future_int_f_vector_count.store(0); std::vector<future<int> > vf; for(std::size_t i = 0; i < 10; ++i) { vf.push_back(dataflow(exec, &future_int_f1, make_ready_future())); } future<int> f5 = dataflow(exec, &future_int_f_vector, boost::ref(vf)); HPX_TEST_EQ(f5.get(), 10); }
int hpx_main(variables_map& vm) { { { if (sizeof(small_object) <= sizeof(void*)) std::cout << "object is small\n"; else std::cout << "object is large\n"; small_object const f(17); function<boost::uint64_t(boost::uint64_t const&)> f0(f); function<boost::uint64_t(boost::uint64_t const&)> f1(f0); function<boost::uint64_t(boost::uint64_t const&)> f2; f2 = f0; f0(7); f1(9); f2(11); } { if (sizeof(big_object) <= sizeof(void*)) std::cout << "object is small\n"; else std::cout << "object is large\n"; big_object const f(5, 12); function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&)> f0(f); function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&)> f1(f0); function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&)> f2; f2 = f0; f0(0, 1); f1(1, 0); f2(1, 1); } } // non serializable version { { if (sizeof(small_object) <= sizeof(void*)) std::cout << "object is small\n"; else std::cout << "object is large\n"; small_object const f(17); function<boost::uint64_t(boost::uint64_t const&), void, void> f0(f); function<boost::uint64_t(boost::uint64_t const&), void, void> f1(f0); function<boost::uint64_t(boost::uint64_t const&), void, void> f2; f2 = f0; f0(2); f1(4); f2(6); } { if (sizeof(big_object) <= sizeof(void*)) std::cout << "object is small\n"; else std::cout << "object is large\n"; big_object const f(5, 12); function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&), void, void> f0(f); function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&), void, void> f1(f0); function<boost::uint64_t(boost::uint64_t const&, boost::uint64_t const&), void, void> f2; f2 = f0; f0(3, 4); f1(5, 6); f2(7, 8); } } finalize(); return 0; }
int hpx_main( variables_map& vm ) { if (vm.count("no-header")) header = false; // delay in seconds delay_sec = delay * 1.0E-6; std::size_t num_os_threads = hpx::get_os_thread_count(); int num_executors = vm["executors"].as<int>(); if (num_executors <= 0) throw std::invalid_argument("number of executors to use must be larger than 0"); if (num_executors > std::size_t(num_os_threads)) throw std::invalid_argument("number of executors to use must be smaller than number of OS threads"); std::size_t num_cores_per_executor = vm["cores"].as<int>(); if ((num_executors - 1) * num_cores_per_executor > num_os_threads) throw std::invalid_argument("number of cores per executor should not cause oversubscription"); if (0 == tasks) throw std::invalid_argument("count of 0 tasks specified\n"); // Reset performance counters (if specified on command line) reset_active_counters(); // Start the clock. high_resolution_timer t; // create the executor instances using hpx::threads::executors::local_priority_queue_executor; { std::vector<local_priority_queue_executor> executors; for (std::size_t i = 0; i != std::size_t(num_executors); ++i) { // make sure we don't oversubscribe the cores, the last executor will // be bound to the remaining number of cores if ((i + 1) * num_cores_per_executor > num_os_threads) { HPX_ASSERT(i == num_executors - 1); num_cores_per_executor = num_os_threads - i * num_cores_per_executor; } executors.push_back(local_priority_queue_executor(num_cores_per_executor)); } t.restart(); for (boost::uint64_t i = 0; i < tasks; ++i) executors[i % num_executors].add(HPX_STD_BIND(&invoke_worker_timed, delay_sec)); // destructors of executors will wait for all tasks to finish executing } // Stop the clock double time_elapsed = t.elapsed(); // Stop Performance Counters stop_active_counters(); print_results(get_os_thread_count(), time_elapsed); return finalize(); }
int hpx_main(variables_map& vm) { bool do_logging = false; if (vm.count("verbose")) do_logging = true; std::size_t timesteps = 0; if (vm.count("timesteps")) timesteps = vm["timesteps"].as<std::size_t>(); std::size_t grain_size = 3; if (vm.count("grain-size")) grain_size = vm["grain-size"].as<std::size_t>(); std::size_t allowedl = 0; if (vm.count("refinement")) allowedl = vm["refinement"].as<std::size_t>(); std::size_t nx0 = 0; if (vm.count("dimensions")) nx0 = vm["dimensions"].as<std::size_t>(); parameter par; // default pars par->allowedl = allowedl; par->loglevel = 2; par->output = 1.0; par->output_stdout = 1; par->lambda = 0.15; par->nt0 = timesteps; par->minx0 = -15.0; par->maxx0 = 15.0; par->ethreshold = 0.005; par->R0 = 8.0; par->amp = 0.1; par->amp_dot = 0.1; par->delta = 1.0; par->gw = 5; par->eps = 0.0; par->output_level = 0; par->granularity = grain_size; for (std::size_t i = 0; i < HPX_SMP_AMR3D_MAX_LEVELS; i++) par->refine_level[i] = 1.5; id_type rt_id = get_applier().get_runtime_support_gid(); section root; hpx::components::stubs::runtime_support::get_config(rt_id, root); if (root.has_section("smp_amr3d")) { section pars = *(root.get_section("smp_amr3d")); appconfig_option<double>("lambda", pars, par->lambda); appconfig_option<std::size_t>("refinement", pars, par->allowedl); appconfig_option<std::size_t>("loglevel", pars, par->loglevel); appconfig_option<double>("output", pars, par->output); appconfig_option<std::size_t>("output_stdout", pars, par->output_stdout); appconfig_option<std::size_t>("output_level", pars, par->output_level); appconfig_option<std::size_t>("dimensions", pars, nx0); appconfig_option<std::size_t>("timesteps", pars, par->nt0); appconfig_option<double>("maxx0", pars, par->maxx0); appconfig_option<double>("minx0", pars, par->minx0); appconfig_option<double>("ethreshold", pars, par->ethreshold); appconfig_option<double>("R0", pars, par->R0); appconfig_option<double>("delta", pars, par->delta); appconfig_option<double>("amp", pars, par->amp); appconfig_option<double>("amp_dot", pars, par->amp_dot); appconfig_option<std::size_t>("ghostwidth", pars, par->gw); appconfig_option<double>("eps", pars, par->eps); appconfig_option<std::size_t>("grain_size", pars, par->granularity); for (std::size_t i = 0; i < par->allowedl; i++) { std::string ref_level = "refine_level_" + lexical_cast<std::string>(i); appconfig_option<double>(ref_level, pars, par->refine_level[i]); } } // derived parameters if ((nx0 % par->granularity) != 0) { std::string msg = boost::str(boost::format( "dimensions (%1%) must be cleanly divisible by the grain-size " "(%2%)") % nx0 % par->granularity); HPX_THROW_IN_CURRENT_FUNC(bad_parameter, msg); } // the number of timesteps each px thread can take independent of // communication par->time_granularity = par->granularity / 3; // set up refinement centered around the middle of the grid par->nx[0] = nx0 / par->granularity; for (std::size_t i = 1; i < (par->allowedl + 1); ++i) { par->nx[i] = std::size_t(par->refine_level[i - 1] * par->nx[i - 1]); if ((par->nx[i] % 2) == 0) par->nx[i] += 1; if (par->nx[i] > (2 * par->nx[i - 1] - 5)) par->nx[i] = 2 * par->nx[i - 1] - 5; } // for each row, record what the lowest level on the row is std::size_t num_rows = 1 << par->allowedl; // account for prolongation and restriction (which is done every other step) if (par->allowedl > 0) num_rows += (1 << par->allowedl) / 2; num_rows *= 2; // we take two timesteps in the mesh par->num_rows = num_rows; int ii = -1; for (std::size_t i = 0; i < num_rows; ++i) { if (((i + 5) % 3) != 0 || (par->allowedl == 0)) ii++; int level = -1; for (std::size_t j = par->allowedl; j>=0; --j) { if ((ii % (1 << j)) == 0) { level = par->allowedl - j; par->level_row.push_back(level); break; } } } par->dx0 = (par->maxx0 - par->minx0) / (nx0 - 1); par->dt0 = par->lambda * par->dx0; par->min.resize(par->allowedl + 1); par->max.resize(par->allowedl + 1); par->min[0] = par->minx0; par->max[0] = par->maxx0; for (std::size_t i = par->allowedl; i > 0; --i) { par->min[i] = 0.5 * (par->maxx0 - par->minx0) + par->minx0 - (par->nx[i] - 1) / 2 * par->dx0 / (1 << i) * par->granularity; par->max[i] = par->min[i] + ((par->nx[i] - 1) * par->granularity + par->granularity - 1) * par->dx0 / (1 << i); } par->rowsize.resize(par->allowedl + 1); for (int i = 0; i <= par->allowedl; ++i) { par->rowsize[i] = 0; for (int j = par->allowedl; j >= i; --j) par->rowsize[i] += par->nx[j] * par->nx[j] * par->nx[j]; } // get component types needed below component_type function_type = get_component_type<stencil>(); component_type logging_type = get_component_type<logging>(); { id_type here = get_applier().get_runtime_support_gid(); high_resolution_timer t; // we are in spherical symmetry, r=0 is the smallest radial domain point unigrid_mesh um; um.create(here); boost::shared_ptr<std::vector<id_type> > result_data = um.init_execute(function_type, par->rowsize[0], par->nt0, par->loglevel ? logging_type : component_invalid, par); std::cout << "Elapsed time: " << t.elapsed() << " [s]" << std::endl; for (std::size_t i = 0; i < result_data->size(); ++i) hpx::components::stubs::memory_block::free((*result_data)[i]); } // unigrid_mesh needs to go out of scope before shutdown // initiate shutdown of the runtime systems on all localities finalize(); return 0; }
int hpx_main() { BMP SetImage; SetImage.SetBitDepth(24); SetImage.SetSize(sizeX * 2, sizeY); hpx::util::high_resolution_timer t; { using namespace std; using hpx::future; using hpx::async; using hpx::wait_all; int const max_iteration = 255; vector<future<int> > iteration; iteration.reserve(sizeX*sizeY); hpx::cout << "Initial setup completed in " << t.elapsed() << "s. Initializing and running futures...\n" << hpx::flush; t.restart(); { hpx::threads::executors::local_queue_executor exec; for (int i = 0; i < sizeX; ++i) { for (int j = 0; j < sizeY; ++j) { float x0 = (float)i * 3.5f / (float)sizeX - 2.5f; float y0 = (float)j * 2.0f / (float)sizeY - 1.0f; iteration.push_back(async(exec, &fractal_pixel_value, x0, y0, max_iteration)); } } // the executor's destructor will wait for all spawned tasks to // finish executing } hpx::cout << sizeX*sizeY << " calculations run in " << t.elapsed() << "s. Transferring from futures to general memory...\n" << hpx::flush; t.restart(); for (int i = 0; i < sizeX; ++i) { for (int j = 0; j < sizeY; ++j) { int it = iteration[i*sizeX + j].get(); for (int k = 0; k < 2; ++k) { int p = (it * 255) / max_iteration; SetImage.SetPixel(i * 2 + k, j, RGBApixel(p, p, p)); } } } } hpx::cout << "Transfer process completed in " << t.elapsed() << "s. Writing to hard disk...\n" << hpx::flush; t.restart(); SetImage.WriteToFile("out.bmp"); hpx::cout << "Fractal image written to file \"out.bmp\" from memory in " << t.elapsed() << "s.\nShutting down process.\n" << hpx::flush; return hpx::finalize(); // Handles HPX shutdown }
int hpx_main(variables_map& vm) { std::size_t elements = 0; if (vm.count("elements")) elements = vm["elements"].as<std::size_t>(); // get list of all known localities std::vector<id_type> prefixes = hpx::find_remote_localities(); id_type prefix; // execute the qsort() function on any of the remote localities if (!prefixes.empty()) prefix = prefixes[0]; // execute the qsort() function locally else prefix = hpx::find_here(); { // create a (remote) memory block memory_block mb; mb.create<int, uint8_t>(prefix, elements); access_memory_block<int> data(mb.get()); // randomly fill the vector std::generate(data.get_ptr(), data.get_ptr() + elements, std::rand); std::cout << "serial quicksort" << std::endl; high_resolution_timer t; quicksort_serial<int>::call(data.get_ptr(), 0, elements); double elapsed = t.elapsed(); std::cout << " elapsed=" << elapsed << "\n" << " count=" << quicksort_serial<int>::sort_count << "\n"; // int* it = data.get_ptr(); // int* end = data.get_ptr() + elements; // for (; it < end; ++it) // std::cout << *it << "\n"; std::generate(data.get_ptr(), data.get_ptr() + elements, std::rand); std::cout << "parallel quicksort" << std::endl; t.restart(); future<void> n = async<quicksort_int_action>( prefix, prefix, mb.get_gid(), 0, elements); ::hpx::wait_all(n); elapsed = t.elapsed(); std::cout << " elapsed=" << elapsed << "\n" << " count=" << quicksort_parallel<int>::sort_count << "\n"; // it = data.get_ptr(); // end = data.get_ptr() + elements; // for (; it < end; ++it) // std::cout << *it << "\n"; mb.free(); } // initiate shutdown of the runtime systems on all localities finalize(1.0); return 0; }
int hpx_main(boost::program_options::variables_map&) { using hpx::lcos::future; using hpx::async; { future<int> p = async<test_action>(hpx::find_here()); HPX_TEST_EQ(p.get(), 42); } { test_action do_test; future<int> p = async(do_test, hpx::find_here()); HPX_TEST_EQ(p.get(), 42); } { bool data_cb_called = false; bool error_cb_called = false; future<int> f = async<test_action>(hpx::find_here()); future<int> p = f.then(boost::bind(future_callback, boost::ref(data_cb_called), boost::ref(error_cb_called), _1)); HPX_TEST_EQ(p.get(), 42); HPX_TEST(data_cb_called); HPX_TEST(!error_cb_called); } { bool data_cb_called = false; bool error_cb_called = false; test_action do_test; future<int> f = async(do_test, hpx::find_here()); // The HPX_STD_FUNCTION is a workaround for a GCC bug, see the // async_callback_non_deduced_context regression test. future<int> p = f.then( HPX_STD_FUNCTION<int(hpx::lcos::future<int>)>( boost::bind(future_callback, boost::ref(data_cb_called), boost::ref(error_cb_called), _1))); HPX_TEST_EQ(p.get(), 42); HPX_TEST(data_cb_called); HPX_TEST(!error_cb_called); } { future<int> p = async<test_error_action>(hpx::find_here()); std::string what_msg; try { p.get(); // throws HPX_TEST(false); } catch (std::exception const& e) { HPX_TEST(true); what_msg = e.what(); } HPX_TEST_EQ(what_msg, error_msg); } { test_error_action do_error; future<int> p = async(do_error, hpx::find_here()); std::string what_msg; try { p.get(); // throws HPX_TEST(false); } catch (std::exception const& e) { HPX_TEST(true); what_msg = e.what(); } HPX_TEST_EQ(what_msg, error_msg); } { bool data_cb_called = false; bool error_cb_called = false; future<int> f = async<test_error_action>(hpx::find_here()); future<int> p = f.then(boost::bind(future_callback, boost::ref(data_cb_called), boost::ref(error_cb_called), _1)); std::string what_msg; try { f.get(); // throws p.get(); HPX_TEST(false); } catch (std::exception const& e) { HPX_TEST(true); what_msg = e.what(); } HPX_TEST_EQ(what_msg, error_msg); HPX_TEST(!data_cb_called); HPX_TEST(error_cb_called); } { bool data_cb_called = false; bool error_cb_called = false; test_error_action do_test_error; future<int> f = async(do_test_error, hpx::find_here()); // The HPX_STD_FUNCTION is a workaround for a GCC bug, see the // async_callback_non_deduced_context regression test. future<int> p = f.then( HPX_STD_FUNCTION<int(hpx::lcos::future<int>)>( boost::bind(future_callback, boost::ref(data_cb_called), boost::ref(error_cb_called), _1))); std::string what_msg; try { f.get(); // throws p.get(); HPX_TEST(false); } catch (std::exception const& e) { HPX_TEST(true); what_msg = e.what(); } HPX_TEST_EQ(what_msg, error_msg); HPX_TEST(!data_cb_called); HPX_TEST(error_cb_called); } hpx::finalize(); return hpx::util::report_errors(); }
int hpx_main( variables_map& vm ) { if (vm.count("no-header")) header = false; /////////////////////////////////////////////////////////////////////////// // Initialize the PRNG seed. if (!seed) seed = boost::uint64_t(std::time(0)); { /////////////////////////////////////////////////////////////////////// // Validate command-line arguments. if (0 == tasks) throw std::invalid_argument("count of 0 tasks specified\n"); if (min_delay > max_delay) throw std::invalid_argument("minimum delay cannot be larger than " "maximum delay\n"); if (min_delay > total_delay) throw std::invalid_argument("minimum delay cannot be larger than" "total delay\n"); if (max_delay > total_delay) throw std::invalid_argument("maximum delay cannot be larger than " "total delay\n"); if ((min_delay * tasks) > total_delay) throw std::invalid_argument("minimum delay is too small for the " "specified total delay and number of " "tasks\n"); if ((max_delay * tasks) < total_delay) throw std::invalid_argument("maximum delay is too small for the " "specified total delay and number of " "tasks\n"); /////////////////////////////////////////////////////////////////////// // Randomly generate a description of the heterogeneous workload. std::vector<boost::uint64_t> payloads; payloads.reserve(tasks); // For random numbers, we use a 64-bit specialization of Boost.Random's // mersenne twister engine (good uniform distribution up to 311 // dimensions, cycle length 2 ^ 19937 - 1) boost::random::mt19937_64 prng(seed); boost::uint64_t current_sum = 0; for (boost::uint64_t i = 0; i < tasks; ++i) { // Credit to Spencer Ruport for putting this algorithm on // stackoverflow. boost::uint64_t const low_calc = (total_delay - current_sum) - (max_delay * (tasks - 1 - i)); bool const negative = (total_delay - current_sum) < (max_delay * (tasks - 1 - i)); boost::uint64_t const low = (negative || (low_calc < min_delay)) ? min_delay : low_calc; boost::uint64_t const high_calc = (total_delay - current_sum) - (min_delay * (tasks - 1 - i)); boost::uint64_t const high = (high_calc > max_delay) ? max_delay : high_calc; // Our range is [low, high]. boost::random::uniform_int_distribution<boost::uint64_t> dist(low, high); boost::uint64_t const payload = dist(prng); if (payload < min_delay) throw std::logic_error("task delay is below minimum"); if (payload > max_delay) throw std::logic_error("task delay is above maximum"); current_sum += payload; payloads.push_back(payload); } // Randomly shuffle the entire sequence to deal with drift. boost::function<boost::uint64_t(boost::uint64_t)> shuffler_f = boost::bind(&shuffler, boost::ref(prng), _1); std::random_shuffle(payloads.begin(), payloads.end() , shuffler_f); /////////////////////////////////////////////////////////////////////// // Validate the payloads. if (payloads.size() != tasks) throw std::logic_error("incorrect number of tasks generated"); boost::uint64_t const payloads_sum = std::accumulate(payloads.begin(), payloads.end(), 0ULL); if (payloads_sum != total_delay) throw std::logic_error("incorrect total delay generated"); /////////////////////////////////////////////////////////////////////// // Start the clock. high_resolution_timer t; /////////////////////////////////////////////////////////////////////// // Queue the tasks in a serial loop. for (boost::uint64_t i = 0; i < tasks; ++i) register_work(HPX_STD_BIND(&invoke_worker, payloads[i])); /////////////////////////////////////////////////////////////////////// // Wait for the work to finish. do { // Reschedule hpx_main until all other px-threads have finished. We // should be resumed after most of the null px-threads have been // executed. If we haven't, we just reschedule ourselves again. suspend(); } while (get_thread_count(hpx::threads::thread_priority_normal) > 1); /////////////////////////////////////////////////////////////////////// // Print the results. print_results(get_os_thread_count(), t.elapsed()); } finalize(); return 0; }
int hpx_main() { { using namespace std; ifstream fin; string path = __FILE__; string wordlist_path; string remove = "spell_check.cpp"; for (int i = 0; i < path.length() - remove.length(); i++) { wordlist_path.push_back(path[i]); if (path[i] == '\\') { wordlist_path.push_back(path[i]); } } //list of American English words in alphabetical order. Provided by Kevin at http://wordlist.sourceforge.net/ wordlist_path = wordlist_path + "5desk.txt"; fin.open(wordlist_path); int wordcount = 0; cout << "Reading dictionary file to memory...\n"; hpx::util::high_resolution_timer t; if(fin.is_open()) { string temp; while (fin.good()) { getline(fin, temp); for (int i = 0; i < temp.length(); i++) temp[i] = tolower(temp[i]); words.push_back(temp); wordcount++; } cout << wordcount << " words loaded in " << t.elapsed() << "s.\n"; } else { cout << "Error: Unable to open file.\n"; return hpx::finalize(); } fin.close(); char* word = new char[1024]; cout << "Enter the words you would like to spellcheck, separated by a \"Space\", and then press \"Enter\".\n"; cin.getline(word,1024, '\n'); vector<bool> contraction; vector<string> strs; { vector<string> temp; boost::split(temp, word, boost::is_any_of("\n\t -")); for (int i = 0; i < temp.size(); i++) { bool isContraction = false; string holder; for (int j = 0; j < temp[i].size(); j++) { //a size check to avoid errors if (temp[i].size() - j - 1 == 2) { //if this is a contraction, ignore the rest of it... if (temp[i][j+1] == '\'' && temp[i][j] == 'n' && temp[i][j+2] == 't') { //but label this as a contraction isContraction = true; break; } } //remove any garbage characters if (toupper(temp[i][j]) >= 'A' && toupper(temp[i][j]) <= 'Z') holder.push_back(tolower(temp[i][j])); } if (holder.size() > 0) { contraction.push_back(isContraction); strs.push_back(holder); } } } t.restart(); { using hpx::lcos::future; using hpx::async; using hpx::wait_all; vector<search_action> sAct;//[sizeX * sizeY]; vector<future<string>> wordRun; wordRun.reserve(strs.size()); for (int i = 0; i < strs.size(); ++i) { string& single = strs[i]; int start = 0; hpx::naming::id_type const locality_id = hpx::find_here(); search_action temp; wordRun.push_back(async(temp, locality_id, start, wordcount, single)); sAct.push_back(temp); //cout << search(0, wordcount, single) << endl; } wait_all(wordRun); cout << "Search completed in " << t.elapsed() << "s.\n"; for (int i = 0; i < strs.size(); i++) { cout << "Word number " << i + 1 << ":\n"; if (contraction[i]) cout << "Note: This word seems to be a contraction.\nThe last two letters have been ignored.\n"; cout << wordRun[i].get(); } } } return hpx::finalize(); // Handles HPX shutdown }