void system_2d( const state_type &q , state_type &dpdt ) { // works on shared data, but coupling data is provided as copy const size_t N = q.size(); //state_type dpdt_(N); // first row dpdt[0] = dataflow< system_first_block_action >( find_here() , q[0] , dataflow< first_row_action >( find_here() , q[1] ) , dpdt[0] , 0 ); // middle rows for( size_t i=1 ; i<N-1 ; i++ ) { dpdt[i] = dataflow< system_center_block_action >( find_here() , q[i] , dataflow< last_row_action >( find_here() , q[i-1] ) , dataflow< first_row_action >( find_here() , q[i+1] ) , dpdt[i] , i ); } dpdt[N-1] = dataflow< system_last_block_action >( find_here() , q[N-1] , dataflow< last_row_action >( find_here() , q[N-2] ) , dpdt[N-1] , N-1); // coupling synchronization step // dpdt[0] = dataflow< sys_sync1_action >( fing_here() , dpdt_[0] , dpdt_[1] ); // for( size_t i=1 ; i<N-1 ; i++ ) // { // dpdt[i] = dataflow< sys_sync2_action >( find_here() , dpdt_[i] , dpdt_[i] , q[i+1] , dpdt[i] ); // } // dpdt_[N-1] = dataflow< system_last_block_action >( find_here() , q[N-1] , q[N-2] , dpdt[N-1] ); }
void split( id_type const& from , id_type const& target , boost::uint16_t old_credit ) { cout << "[" << find_here() << "/" << target << "]: " << old_credit << ", " << get_credit(target) << ", " << get_management_type_name(target.get_management_type()) << "\n" << flush; // If we have more credits than the sender, then we're done. if (old_credit < get_credit(target)) return; id_type const here = find_here(); if (get_locality_id_from_id(from) == get_locality_id_from_id(here)) throw std::logic_error("infinite recursion detected, split was " "invoked locally"); // Recursively call split on the sender locality. async<split_action>(from, here, target, get_credit(target)).get(); cout << " after split: " << get_credit(target) << "\n" << flush; }
void synchronized_swap( state_type &x_in , state_type &x_out ) { const size_t N = x_in.size(); for( size_t n=0 ; n<N ; ++n ) { dataflow_base< shared_vec > x_tmp = dataflow< sync_identity2_action >( find_here() , x_in[n] , x_out[n] ); x_in[n] = dataflow< sync_identity2_action >( find_here() , x_out[n] , x_tmp ); x_out[n] = dataflow< sync_identity2_action >( find_here() , x_tmp , x_out[n] ); } }
void hpx_test_main( variables_map& vm ) { boost::uint64_t const delay = vm["delay"].as<boost::uint64_t>(); { /// AGAS reference-counting test 1 (from #126): /// /// Create a component locally and let all references to it go out /// of scope. The component should be deleted. Client monitor(find_here()); cout << "id: " << monitor.get_gid() << " " << get_management_type_name (monitor.get_gid().get_management_type()) << "\n" << flush; { // Detach the reference. id_type id = monitor.detach().get(); // The component should still be alive. HPX_TEST_EQ(false, monitor.is_ready(milliseconds(delay))); } // Flush pending reference counting operations. garbage_collect(); garbage_collect(); // The component should be out of scope now. HPX_TEST_EQ(true, monitor.is_ready(milliseconds(delay))); } }
void measure_action_futures(boost::uint64_t count, bool csv) { const id_type here = find_here(); std::vector<unique_future<double> > futures; futures.reserve(count); // start the clock high_resolution_timer walltime; for (boost::uint64_t i = 0; i < count; ++i) futures.push_back(async<null_action>(here)); wait(futures, [&] (std::size_t, double r) { global_scratch += r; }); // stop the clock const double duration = walltime.elapsed(); if (csv) cout << ( boost::format("%1%,%2%\n") % count % duration) << flush; else cout << ( boost::format("invoked %1% futures (actions) in %2% seconds\n") % count % duration) << flush; }
std::size_t pass_object_void() { Object obj; async<Action>(find_here(), obj).get(); return obj.get_count(); }
int hpx_main(variables_map& vm) { boost::uint64_t const futures = vm["futures"].as<boost::uint64_t>(); boost::uint64_t const grain_size = vm["grain-size"].as<boost::uint64_t>(); { id_type const prefix = find_here(); thread_id_type thread_id = register_thread_nullary (boost::bind(&test_dummy_thread, futures)); boost::uint64_t thread = boost::uint64_t(thread_id); // Flood the queues with suspension operations before the rescheduling // attempt. future<void> before = async<tree_boot_action>(prefix, futures, grain_size, prefix, thread); set_thread_state(thread_id, pending, wait_signaled); // Flood the queues with suspension operations after the rescheduling // attempt. future<void> after = async<tree_boot_action>(prefix, futures, grain_size, prefix, thread); before.get(); after.get(); set_thread_state(thread_id, pending, wait_terminate); } finalize(); return 0; }
std::size_t move_object_void() { Object obj; async<Action>(find_here(), boost::move(obj)).get(); return obj.get_count(); }
std::size_t pass_object_void() { Object obj; dataflow<Action>(find_here(), obj).get_future().get(); return obj.get_count(); }
void hpx_test_main( variables_map& vm ) { boost::uint64_t const delay = vm["delay"].as<boost::uint64_t>(); { /// AGAS reference-counting test 3 (from #126): /// /// Create two components locally, and have the second component /// store a reference to the first component. Let the original /// references to both components go out of scope. Both components /// should be deleted. Client monitor0(find_here()); Client monitor1(find_here()); cout << "id0: " << monitor0.get_id() << " " << get_management_type_name (monitor0.get_id().get_management_type()) << "\n" << "id1: " << monitor1.get_id() << " " << get_management_type_name (monitor1.get_id().get_management_type()) << "\n" << flush; { // Have the second object store a reference to the first object. monitor1.take_reference(monitor0.get_id()); // Detach the references. id_type id1 = monitor0.detach().get(); id_type id2 = monitor1.detach().get(); // Both components should still be alive. HPX_TEST_EQ(false, monitor0.is_ready(milliseconds(delay))); HPX_TEST_EQ(false, monitor1.is_ready(milliseconds(delay))); } // Flush pending reference counting operations. garbage_collect(); garbage_collect(); // Both components should be out of scope now. HPX_TEST_EQ(true, monitor0.is_ready(milliseconds(delay))); HPX_TEST_EQ(true, monitor1.is_ready(milliseconds(delay))); } }
int main() { test_client t = test_client::create(find_here()); HPX_TEST_NEQ(hpx::naming::invalid_id, t.get_gid()); t.check_gid(); return hpx::util::report_errors(); }
void hpx_test_main( variables_map& vm ) { boost::uint64_t const delay = vm["delay"].as<boost::uint64_t>(); { /// AGAS reference-counting test 4 (from #126): /// /// Create two components, one locally and one one remotely. /// Have the local component store a reference to the remote /// component. Let the original references to both components go /// out of scope. Both components should be deleted. typedef typename Client::server_type server_type; component_type ctype = get_component_type<server_type>(); std::vector<id_type> remote_localities = hpx::find_remote_localities(ctype); if (remote_localities.empty()) throw std::logic_error("this test cannot be run on one locality"); Client monitor_remote(remote_localities[0]); Client monitor_local(find_here()); cout << "id_remote: " << monitor_remote.get_gid() << " " << get_management_type_name (monitor_remote.get_gid().get_management_type()) << "\n" << "id_local: " << monitor_local.get_gid() << " " << get_management_type_name (monitor_local.get_gid().get_management_type()) << "\n" << flush; { // Have the local object store a reference to the remote object. monitor_local.take_reference(monitor_remote.get_gid()); // Detach the references. id_type id1 = monitor_remote.detach().get(); id_type id2 = monitor_local.detach().get(); // Both components should still be alive. HPX_TEST_EQ(false, monitor_remote.is_ready(milliseconds(delay))); HPX_TEST_EQ(false, monitor_local.is_ready(milliseconds(delay))); } // Flush pending reference counting operations. garbage_collect(remote_localities[0]); garbage_collect(); garbage_collect(remote_localities[0]); garbage_collect(); // Both components should be out of scope now. HPX_TEST_EQ(true, monitor_remote.is_ready(milliseconds(delay))); HPX_TEST_EQ(true, monitor_local.is_ready(milliseconds(delay))); } }
int main() { // action too big to compile... dataflow_base<double> df = dataflow<large_action>( find_here() , 1 , 1 , 1 , 1 , 1 , 1 , 1); HPX_TEST_EQ(df.get_future().get(), 1); return hpx::util::report_errors(); }
void hpx_test_main( variables_map& vm ) { boost::uint64_t const delay = vm["delay"].as<boost::uint64_t>(); { /// AGAS reference-counting test 7 (from #126): /// /// Create a component locally, and register a symbolic name for it. /// Then, let all references to the component go out of scope. The /// component should still be alive. Finally, unregister the /// symbolic name. The component should be deleted after the /// symbolic name is unregistered. char const name[] = "/tests(refcnt_checker#7)"; Client monitor(find_here()); cout << "id: " << monitor.get_id() << " " << get_management_type_name (monitor.get_id().get_management_type()) << "\n" << flush; // Associate a symbolic name with the object. HPX_TEST_EQ(true, register_name_sync(name, monitor.get_id())); hpx::naming::gid_type gid; { // Detach the reference. id_type id = monitor.detach().get(); // The component should still be alive. HPX_TEST_EQ(false, monitor.is_ready(milliseconds(delay))); gid = id.get_gid(); // let id go out of scope } // The component should still be alive, as the symbolic binding holds // a reference to it. HPX_TEST_EQ(false, monitor.is_ready(milliseconds(delay))); // Remove the symbolic name. This should return the final credits // to AGAS. HPX_TEST_EQ(gid, unregister_name_sync(name).get_gid()); // Flush pending reference counting operations. garbage_collect(); garbage_collect(); // The component should be destroyed. HPX_TEST_EQ(true, monitor.is_ready(milliseconds(delay))); } }
void osc_sys( const state_type &q , state_type &dpdt ) { const size_t N = q.size(); //std::cout << "system call with N=" << N << std::endl; dpdt[0] = dataflow< osc_operation_action >( find_here() , q[0] , q[N-1] , q[1] , dpdt[0] ); for( size_t i=1 ; i<N-1 ; ++i ) dpdt[i] = dataflow< osc_operation_action >( find_here() , q[i] , q[i-1] , q[i+1] , dpdt[i] ); dpdt[N-1] = dataflow< osc_operation_action >( find_here() , q[N-1] , q[N-2] , q[0] , dpdt[N-1] ); //std::cout << "-------" << std::endl; }
int hpx_main(variables_map& vm) { here = find_here(); pi = boost::math::constants::pi<double>(); // dt = vm["dt-value"].as<double>(); // dx = vm["dx-value"].as<double>(); // c = vm["c-value"].as<double>(); nx = vm["nx-value"].as<boost::uint64_t>(); nt = vm["nt-value"].as<boost::uint64_t>(); c = 1.0; dt = 1.0/(nt-1); dx = 1.0/(nx-1); alpha_squared = (c*dt/dx)*(c*dt/dx); // check that alpha_squared satisfies the stability condition if (0.25 < alpha_squared) { cout << (("alpha^2 = (c*dt/dx)^2 should be less than 0.25 for stability!\n")) << flush; } u = std::vector<std::vector<data> >(nt, std::vector<data>(nx)); cout << (boost::format("dt = %1%\n") % dt) << flush; cout << (boost::format("dx = %1%\n") % dx) << flush; cout << (boost::format("alpha^2 = %1%\n") % alpha_squared) << flush; { // Keep track of the time required to execute. high_resolution_timer t; std::vector<future<double> > futures; for (boost::uint64_t i=0;i<nx;i++) futures.push_back(async<wave_action>(here,nt-1,i)); // open file for output std::ofstream outfile; outfile.open ("output.dat"); wait(futures, [&](std::size_t i, double n) { double x_here = i*dx; outfile << (boost::format("%1% %2%\n") % x_here % n) << flush; }); outfile.close(); char const* fmt = "elapsed time: %1% [s]\n"; std::cout << (boost::format(fmt) % t.elapsed()); } finalize(); return 0; }
int main() { test_client t; t.create(find_here()); t.check_gid(); return 0; }
void for_each3( S &s1 , const S &s2 , const S &s3 , Op op ) { const size_t N = boost::size( s1 ); for( size_t i=0 ; i<N ; ++i ) { typedef std::vector< double > dvec; typedef std::shared_ptr< dvec > shared_vec; typedef hpx_odeint_actions::operation2d_3_action< typename S::value_type::result_type,Op> action; s1[i] = dataflow< action >( find_here() , s1[i] , s2[i] , s3[i] , op ); } }
void hpx_test_main( variables_map& vm ) { boost::uint64_t const delay = vm["delay"].as<boost::uint64_t>(); { /// AGAS reference-counting test 9 (from #126): /// /// Create a component locally, and register it's credit-stripped /// raw gid with a symbolic name. Then, let all references to the /// component go out of scope. The component should be destroyed. /// Finally, unregister the symbolic name. Unregistering the /// symbolic name should not cause any errors. char const name[] = "/tests(refcnt_checker#9)"; Client monitor(find_here()); cout << "id: " << monitor.get_gid() << " " << get_management_type_name (monitor.get_gid().get_management_type()) << "\n" << flush; // Associate a symbolic name with the object. The symbol namespace // should not reference-count the name, as the GID we're passing has // no credits. gid_type raw_gid = strip_credit_from_gid(monitor.get_raw_gid()); HPX_TEST_EQ(true, register_name(name, raw_gid)); { // Detach the reference. id_type id = monitor.detach().get(); // The component should still be alive. HPX_TEST_EQ(false, monitor.ready(milliseconds(delay))); // let id go out of scope } // The component should still be alive, as the symbolic binding holds // a reference to it. HPX_TEST_EQ(false, monitor.ready(milliseconds(delay))); // Remove the symbolic name. HPX_TEST_EQ(raw_gid, unregister_name(name).get_gid()); // The component should be out of scope now. HPX_TEST_EQ(true, monitor.ready(milliseconds(delay))); } }
// Time async action execution using wait each on futures vector void measure_action_futures_wait_all(std::uint64_t count, bool csv) { const id_type here = find_here(); std::vector<future<double> > futures; futures.reserve(count); // start the clock high_resolution_timer walltime; for (std::uint64_t i = 0; i < count; ++i) futures.push_back(async<null_action>(here)); wait_all(futures); // stop the clock const double duration = walltime.elapsed(); print_stats("Actions", "WaitAll", "no-executor", count, duration, csv); }
void hpx_test_main( variables_map& vm ) { boost::uint64_t const delay = vm["delay"].as<boost::uint64_t>(); typedef typename Client::server_type server_type; component_type ctype = get_component_type<server_type>(); std::vector<id_type> remote_localities = hpx::find_remote_localities(ctype); if (remote_localities.empty()) throw std::logic_error("this test cannot be run on one locality"); id_type const here = find_here(); Client monitor(here); { id_type id = monitor.detach().get(); cout << "id: " << id << " " << get_management_type_name(id.get_management_type()) << "\n" << flush; async<split_action>(remote_localities[0] , here , id , get_credit(id)).get(); cout << "after split: " << get_credit(id) << "\n" << flush; } // Flush pending reference counting operations. garbage_collect(); garbage_collect(remote_localities[0]); garbage_collect(); garbage_collect(remote_localities[0]); // The component should be out of scope now. HPX_TEST_EQ(true, monitor.is_ready(milliseconds(delay))); }
int hpx_main(variables_map& vm) { boost::uint64_t const futures = vm["futures"].as<boost::uint64_t>(); boost::uint64_t const grain_size = vm["grain-size"].as<boost::uint64_t>(); { id_type const prefix = find_here(); thread_id_type thread = register_thread_nullary (hpx::util::bind(&test_dummy_thread, futures)); tree_boot(futures, grain_size, prefix, reinterpret_cast<boost::uint64_t>(thread.get())); set_thread_state(thread, pending, wait_terminate); } finalize(); return 0; }
int hpx_main(boost::program_options::variables_map& vm) { const std::size_t N = vm["N"].as<std::size_t>(); const std::size_t steps = vm["steps"].as<std::size_t>(); const double dt = vm["dt"].as<double>(); std::clog << "system size: " << N << ", steps: " << steps << ", dt: " << dt << std::endl; state_type x( N , dataflow< identity_action >( find_here() , 100.0 ) ); double t = 0.0; hpx::util::high_resolution_timer timer; // do the numerical integration using dataflow objects boost::numeric::odeint::integrate_n_steps( stepper_type() , sys , x , t , dt , steps ); std::clog << "Dependency tree built" << std::endl; std::vector< future<double> > futures( N ); for( size_t i=0 ; i<N ; ++i ) { futures[i] = x[i].get_future(); } // here we wait for the results wait( futures ); std::clog << "Calculation finished in " << timer.elapsed() << "s" << std::endl; // print the values // for( size_t i=0 ; i<N ; ++i ) // std::cout << futures[i].get() << '\t'; // std::cout << std::endl; return hpx::finalize(); }
// syncronized swap emulating nearest neighbor coupling void synchronized_swap( state_type &x_in , state_type &x_out ) { const size_t N = x_in.size(); dataflow_base< shared_vec > x_0 = x_out[0]; dataflow_base< shared_vec > x_left = x_out[0]; dataflow_base< shared_vec > x_tmp = dataflow< sync_identity_action >( find_here() , x_in[0] , x_out[0] , x_out[N-1] , x_out[1] ); x_in[0] = dataflow< sync_identity2_action >( find_here() , x_out[0] , x_tmp ); x_out[0] = x_tmp; for( size_t n=1 ; n<N-1 ; ++n ) { x_tmp = dataflow< sync_identity_action >( find_here() , x_in[n] , x_out[n] , x_left , x_out[n+1] ); x_left = x_out[n]; x_in[n] = dataflow< sync_identity2_action >( find_here() , x_out[n] , x_tmp ); x_out[n] = x_tmp; } x_tmp = dataflow< sync_identity_action >( find_here() , x_in[N-1] , x_out[N-1] , x_left , x_0 ); x_in[N-1] = dataflow< sync_identity2_action >( find_here() , x_out[N-1] , x_tmp ); x_out[N-1] = x_tmp; }
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 ) { { 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(); }
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(); }
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 } }
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(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(); }