Skip to content

Commit

Permalink
update example on docs startpage
Browse files Browse the repository at this point in the history
  • Loading branch information
carstenbauer committed Mar 4, 2024
1 parent d44af6f commit 0b85073
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 0b85073

Please sign in to comment.