From 0b850736f3510bd0c5aaa7e84b7eee026c197fa2 Mon Sep 17 00:00:00 2001 From: Carsten Bauer Date: Mon, 4 Mar 2024 21:39:35 +0100 Subject: [PATCH] update example on docs startpage --- docs/src/index.md | 11 +++++++++++ 1 file changed, 11 insertions(+) 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