Skip to content

Instantly share code, notes, and snippets.

@taeguk
Created May 17, 2017 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taeguk/24ae06a5018c8917d2586f888667cd46 to your computer and use it in GitHub Desktop.
Save taeguk/24ae06a5018c8917d2586f888667cd46 to your computer and use it in GitHub Desktop.
b.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);
for (int i = 0; i < 1000000000; ++i) int j = i*i;
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)
);
}
@taeguk
Copy link
Author

taeguk commented May 17, 2017

fibonacci_serial(10) == 55,elapsed time:,10867,[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

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