-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add SimpleBarrier to tools * barrier but hardcoded ntasks * barrier(n) where n is given or deduced from set ntasks=... + some tests * few more tests * changelog entry (experimental) * drop atbarrier(n) * drop unneccessary comments * update warning in docstring * add OhMyThreads.Experimental and move barrier macro there * require explicit loading of atbarrier * docstring update
- Loading branch information
1 parent
9c772fe
commit af51162
Showing
10 changed files
with
212 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
```@meta | ||
CollapsedDocStrings = true | ||
``` | ||
|
||
# Experimental | ||
|
||
!!! warning | ||
**Everything on this page is experimental and might changed or dropped at any point!** | ||
|
||
## References | ||
|
||
```@autodocs | ||
Modules = [OhMyThreads, OhMyThreads.Experimental] | ||
Public = false | ||
Pages = ["OhMyThreads.jl", "experimental.jl"] | ||
``` |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Experimental | ||
|
||
""" | ||
@barrier | ||
This can be used inside a `@tasks for ... end` to synchronize `n` parallel tasks. | ||
Specifically, a task can only pass the `@barrier` if `n-1` other tasks have reached it | ||
as well. The value of `n` is determined from `@set ntasks=...`, which | ||
is required if one wants to use `@barrier`. | ||
Because this feature is experimental, it is required to load `@barrier` explicitly, e.g. via | ||
`using OhMyThreads.Experimental: @barrier`. | ||
**WARNING:** It is the responsibility of the user to ensure that the right number of tasks | ||
actually reach the barrier. Otherwise, a **deadlock** can occur. In partictular, if the | ||
number of iterations is not a multiple of `n`, the last few iterations (remainder) will be | ||
run by less than `n` tasks which will never be able to pass a `@barrier`. | ||
## Example | ||
```julia | ||
using OhMyThreads: @tasks | ||
# works | ||
@tasks for i in 1:20 | ||
@set ntasks = 20 | ||
sleep(i * 0.2) | ||
println(i, ": before") | ||
@barrier | ||
println(i, ": after") | ||
end | ||
# wrong - deadlock! | ||
@tasks for i in 1:22 # ntasks % niterations != 0 | ||
@set ntasks = 20 | ||
println(i, ": before") | ||
@barrier | ||
println(i, ": after") | ||
end | ||
``` | ||
""" | ||
macro barrier(args...) | ||
error("The @barrier macro may only be used inside of a @tasks block.") | ||
end | ||
|
||
end # Experimental |
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
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
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
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