Create a gist now

Instantly share code, notes, and snippets.

@taeguk /a.cpp
Created May 17, 2017

What would you like to do?
a.cpp
hpx::future<std::uint64_t> fibonacci(std::uint64_t n, std::string prefix)
{
if (n < 2) return hpx::make_ready_future(n);
if (n < threshold) return hpx::make_ready_future(fibonacci_serial(n));
auto new_prefix = prefix + "->" + std::to_string(n);
std::cout << "[Debug] " << new_prefix << std::endl;
hpx::future<std::uint64_t> lhs_future = hpx::async(&fibonacci, n-1, new_prefix);
hpx::future<std::uint64_t> rhs_future = fibonacci(n - 2, new_prefix);
if (n == 10)
auto aaarhs_future = fibonacci(n - 3, "X" + new_prefix);
return
hpx::dataflow(
hpx::util::unwrapped(
[](std::uint64_t lhs, std::uint64_t rhs)
{
return lhs + rhs;
})
, std::move(lhs_future), std::move(rhs_future)
);
}
Owner

taeguk commented May 17, 2017

fibonacci_serial(10) == 55,elapsed time:,11169,[s]
[Debug] ->10
[Debug] ->10->8
[Debug] ->10->8->6
[Debug] ->10->8->6->4
[Debug] ->10->8->6->4->2
[Debug] X->10->7
[Debug] X->10->7->5
[Debug] X->10->7->5->3
[Debug] ->10->9
[Debug] ->10->9->7
[Debug] ->10->9->7->5
[Debug] ->10->9->7->5->3
[Debug] ->10->8->7
[Debug] ->10->8->7->5
[Debug] ->10->8->7->5->3
[Debug] ->10->8->6->5
[Debug] ->10->8->6->5->3
[Debug] ->10->8->6->4->3
[Debug] X->10->7->6
[Debug] X->10->7->6->4
[Debug] X->10->7->6->4->2
[Debug] X->10->7->5->4
[Debug] X->10->7->5->4->2
[Debug] X->10->7->5->3->2
[Debug] ->10->9->8
[Debug] ->10->9->8->6
[Debug] ->10->9->8->6->4
[Debug] ->10->9->8->6->4->2
[Debug] ->10->9->7->6
[Debug] ->10->9->7->6->4
[Debug] ->10->9->7->6->4->2
[Debug] ->10->9->7->5->4
[Debug] ->10->9->7->5->4->2
[Debug] ->10->9->7->5->3->2
[Debug] ->10->8->7->6
[Debug] ->10->8->7->6->4
[Debug] ->10->8->7->6->4->2
[Debug] ->10->8->7->5->4
[Debug] ->10->8->7->5->4->2
[Debug] ->10->8->7->5->3->2
[Debug] ->10->8->6->5->4
[Debug] ->10->8->6->5->4->2
[Debug] ->10->8->6->5->3->2
[Debug] ->10->8->6->4->3->2
[Debug] X->10->7->6->5
[Debug] X->10->7->6->5->3
[Debug] X->10->7->6->4->3
[Debug] X->10->7->5->4->3
[Debug] ->10->9->8->7
[Debug] ->10->9->8->7->5
[Debug] ->10->9->8->7->5->3
[Debug] ->10->9->8->6->5
[Debug] ->10->9->8->6->5->3
[Debug] ->10->9->8->6->4->3
[Debug] ->10->9->7->6->5
[Debug] ->10->9->7->6->5->3
[Debug] ->10->9->7->6->4->3
[Debug] ->10->9->7->5->4->3
[Debug] ->10->8->7->6->5
[Debug] ->10->8->7->6->5->3
[Debug] ->10->8->7->6->4->3
[Debug] ->10->8->7->5->4->3
[Debug] ->10->8->6->5->4->3
[Debug] X->10->7->6->5->4
[Debug] X->10->7->6->5->4->2
[Debug] X->10->7->6->5->3->2
[Debug] X->10->7->6->4->3->2
[Debug] X->10->7->5->4->3->2
[Debug] ->10->9->8->7->6
[Debug] ->10->9->8->7->6->4
[Debug] ->10->9->8->7->6->4->2
[Debug] ->10->9->8->7->5->4
[Debug] ->10->9->8->7->5->4->2
[Debug] ->10->9->8->7->5->3->2
[Debug] ->10->9->8->6->5->4
[Debug] ->10->9->8->6->5->4->2
[Debug] ->10->9->8->6->5->3->2
[Debug] ->10->9->8->6->4->3->2
[Debug] ->10->9->7->6->5->4
[Debug] ->10->9->7->6->5->4->2
[Debug] ->10->9->7->6->5->3->2
[Debug] ->10->9->7->6->4->3->2
[Debug] ->10->9->7->5->4->3->2
[Debug] ->10->8->7->6->5->4
[Debug] ->10->8->7->6->5->4->2
[Debug] ->10->8->7->6->5->3->2
[Debug] ->10->8->7->6->4->3->2
[Debug] ->10->8->7->5->4->3->2
[Debug] ->10->8->6->5->4->3->2
[Debug] X->10->7->6->5->4->3
[Debug] ->10->9->8->7->6->5
[Debug] ->10->9->8->7->6->5->3
[Debug] ->10->9->8->7->6->4->3
[Debug] ->10->9->8->7->5->4->3
[Debug] ->10->9->8->6->5->4->3
[Debug] ->10->9->7->6->5->4->3
[Debug] ->10->8->7->6->5->4->3
[Debug] X->10->7->6->5->4->3->2
[Debug] ->10->9->8->7->6->5->4
[Debug] ->10->9->8->7->6->5->4->2
[Debug] ->10->9->8->7->6->5->3->2
[Debug] ->10->9->8->7->6->4->3->2
[Debug] ->10->9->8->7->5->4->3->2
[Debug] ->10->9->8->6->5->4->3->2
[Debug] ->10->9->7->6->5->4->3->2
[Debug] ->10->8->7->6->5->4->3->2
[Debug] ->10->9->8->7->6->5->4->3
[Debug] ->10->9->8->7->6->5->4->3->2
fibonacci_await(10) == 55,elapsed time:,163745764,[s]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment