Created
May 17, 2017 16:52
-
-
Save taeguk/24ae06a5018c8917d2586f888667cd46 to your computer and use it in GitHub Desktop.
b.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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