Skip to content

Commit

Permalink
Debugging async continuation problem
Browse files Browse the repository at this point in the history
  • Loading branch information
biddisco committed Oct 19, 2017
1 parent fded032 commit 5764067
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 5 deletions.
21 changes: 17 additions & 4 deletions examples/resource_partitioner/guided_pool_test.cpp
Expand Up @@ -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<decltype(&async_guided)>;
// create an executor using that hint type
hpx::threads::executors::guided_pool_executor<hint_type1> 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<void> 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<int, double, const std::string &>;
Expand All @@ -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<double>;
// create an executor using the numa hint type
hpx::threads::executors::guided_pool_executor<hint_type3> 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<double> &&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();

Expand Down
49 changes: 49 additions & 0 deletions hpx/runtime/threads/executors/guided_pool_executor.hpp
Expand Up @@ -20,6 +20,53 @@

#include <hpx/config/warnings_prefix.hpp>

//
#include <typeinfo>

#ifdef __GNUG__
# include <cstdlib>
# include <cxxabi.h>
#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<char, void(*)(void*)> 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 <class T>
inline std::string print_type()
{
return demangle(typeid(T).name());
}

template<typename T, typename... Args>
inline std::string print_type(T&& head, Args&&... tail)
{
std::string temp = print_type<T>();
std::cout << temp << std::endl;
return print_type(std::forward<Args>(tail)...);
}


namespace hpx { namespace threads { namespace executors
{
struct bitmap_storage
Expand Down Expand Up @@ -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<F, Ts...>::type
result_type;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/threads/executors/pool_executor.cpp
Expand Up @@ -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(
Expand Down

0 comments on commit 5764067

Please sign in to comment.