From 5764067c8099e8552366b3875abcf757154fcc1a Mon Sep 17 00:00:00 2001 From: John Biddiscombe Date: Thu, 19 Oct 2017 14:48:23 +0100 Subject: [PATCH] Debugging async continuation problem --- .../resource_partitioner/guided_pool_test.cpp | 21 ++++++-- .../executors/guided_pool_executor.hpp | 49 +++++++++++++++++++ .../threads/executors/pool_executor.cpp | 2 +- 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/examples/resource_partitioner/guided_pool_test.cpp b/examples/resource_partitioner/guided_pool_test.cpp index 9ef5b3369ec4..9404e0df90d6 100644 --- a/examples/resource_partitioner/guided_pool_test.cpp +++ b/examples/resource_partitioner/guided_pool_test.cpp @@ -116,13 +116,20 @@ int hpx_main(boost::program_options::variables_map& vm) std::size_t num_threads = hpx::get_num_worker_threads(); std::cout << "HPX using threads = " << num_threads << std::endl; + std::cout << "----------------------------------------------" << std::endl; + std::cout << "Testing async guided exec " << std::endl; + std::cout << "----------------------------------------------" << std::endl; // we must specialize the numa callback hint for the function type we are invoking using hint_type1 = pool_numa_hint; // create an executor using that hint type hpx::threads::executors::guided_pool_executor guided_exec(CUSTOM_POOL_NAME); - // invoke an asyn function using our numa hint executor + // invoke an async function using our numa hint executor hpx::future gf1 = hpx::async(guided_exec, &async_guided, 5, true, "Guided function"); + gf1.get(); + std::cout << "----------------------------------------------" << std::endl; + std::cout << "Testing async guided exec lambda" << std::endl; + std::cout << "----------------------------------------------" << std::endl; // specialize the numa hint callback for a lambda type invocation // the args of the async lambda must match the args of the hint type using hint_type2 = pool_numa_hint; @@ -136,18 +143,24 @@ int hpx_main(boost::program_options::variables_map& vm) return 3.1415; }, 5, 2.718, "Guided function 2"); + gf2.get(); + std::cout << "----------------------------------------------" << std::endl; + std::cout << "Testing async guided exec continuation" << std::endl; + std::cout << "----------------------------------------------" << std::endl; // specialize the numa hint callback for another lambda type invocation // the args of the async lambda must match the args of the hint type using hint_type3 = pool_numa_hint; // create an executor using the numa hint type hpx::threads::executors::guided_pool_executor guided_cont_exec(CUSTOM_POOL_NAME); // invoke the lambda asynchronously and use the numa executor - auto new_future = gf2.then(guided_cont_exec, [](hpx::future &&df) { - double d = df.get(); + auto new_future = hpx::async([]() -> double { return 3.1415;} ).then( + guided_cont_exec, hpx::util::unwrapping([](double df) + { + double d = df; // .get(); std::cout << "received a double of value " << d << std::endl; return d*2; - }); + })); new_future.get(); diff --git a/hpx/runtime/threads/executors/guided_pool_executor.hpp b/hpx/runtime/threads/executors/guided_pool_executor.hpp index 507250adf852..94cbe38eb3fc 100644 --- a/hpx/runtime/threads/executors/guided_pool_executor.hpp +++ b/hpx/runtime/threads/executors/guided_pool_executor.hpp @@ -20,6 +20,53 @@ #include +// +#include + +#ifdef __GNUG__ +# include +# include +#endif + + +// ------------------------------------------------------------------ +// helper to demangle type names +// ------------------------------------------------------------------ +#ifdef __GNUG__ +std::string demangle(const char* name) +{ + // some arbitrary value to eliminate the compiler warning + int status = -4; + std::unique_ptr res { + abi::__cxa_demangle(name, NULL, NULL, &status), + std::free + }; + return (status==0) ? res.get() : name ; +} +#else +// does nothing if not g++ +std::string demangle(const char* name) { + return name; +} +#endif + +inline std::string print_type() { return ""; } + +template +inline std::string print_type() +{ + return demangle(typeid(T).name()); +} + +template +inline std::string print_type(T&& head, Args&&... tail) +{ + std::string temp = print_type(); + std::cout << temp << std::endl; + return print_type(std::forward(tail)...); +} + + namespace hpx { namespace threads { namespace executors { struct bitmap_storage @@ -51,6 +98,8 @@ namespace hpx { namespace threads { namespace executors int domain = numa_function_(ts...); std::cout << "The numa domain is " << domain << "\n"; + print_type(ts...); + // now we must forward the task on to the correct dispatch function typedef typename util::detail::invoke_deferred_result::type result_type; diff --git a/src/runtime/threads/executors/pool_executor.cpp b/src/runtime/threads/executors/pool_executor.cpp index d6d8d36f4b7e..287f43f331bb 100644 --- a/src/runtime/threads/executors/pool_executor.cpp +++ b/src/runtime/threads/executors/pool_executor.cpp @@ -69,7 +69,7 @@ namespace hpx { namespace threads { namespace executors threads::thread_schedule_hint schedulehint, error_code& ec) { - std::cout << "pool exeutor received hint " << schedulehint << std::endl; + std::cout << "pool executor received hint " << schedulehint << std::endl; // create a new thread thread_init_data data( util::bind(