diff --git a/docs/src/index.md b/docs/src/index.md index 51f02a80..91ae22bb 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -16,6 +16,7 @@ to add the package to your Julia environment. ```julia using OhMyThreads +# Variant 1: function API function mc_parallel(N; kw...) M = tmapreduce(+, 1:N; kw...) do i rand()^2 + rand()^2 < 1.0 @@ -24,6 +25,16 @@ function mc_parallel(N; kw...) return pi end +# Variant 2: macro API +function mc_parallel_macro(N) + M = @tasks for i in 1:N + @set reducer=+ + rand()^2 + rand()^2 < 1.0 + end + pi = 4 * M / N + return pi +end + N = 100_000_000 mc_parallel(N) # gives, e.g., 3.14159924