Created
June 5, 2019 00:31
-
-
Save bicycle1885/e3be8a4e0d543c488f2f752eed2b08fa to your computer and use it in GitHub Desktop.
Parallel execution
This file contains hidden or 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
| macro par(expr) | |
| thunk = esc(:(()->($expr))) | |
| quote | |
| local task = Task($thunk) | |
| task.sticky = false | |
| schedule(task) | |
| task | |
| end | |
| end | |
| function fib(n) | |
| if n ≤ 1 | |
| return 1 | |
| else | |
| return fib(n-1) + fib(n-2) | |
| end | |
| end | |
| fetch(@par fib(3)) # compile | |
| const N = 40 | |
| const N_TASKS = 128 | |
| println("Sequential:") | |
| @time [fib(N) for _ in 1:N_TASKS] | |
| println("Parallel:") | |
| @time fetch.([@par fib(N) for _ in 1:N_TASKS]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.