Skip to content

Commit 2764b76

Browse files
quildtidewolthomjpsamaroo
authored
Warn in docs about sync on inner loops (#550)
Co-authored-by: Wolf Thomsen <[email protected]> Co-authored-by: Julian Samaroo <[email protected]>
1 parent 1f15a50 commit 2764b76

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

docs/src/use-cases/parallel-nested-loops.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ end
7171
```
7272

7373
In this code we have job interdependence. Firstly, we are calculating the
74-
standard deviation `σ` and than we are using that value in the function `f`.
75-
Since `Dagger.@spawn` yields an `DTask` rather than actual values, we need
74+
standard deviation `σ`, and then we are using that value in the function `f`.
75+
Since `Dagger.@spawn` yields a `DTask` rather than actual values, we need
7676
to use the `fetch` function to obtain those values. In this example, the value
7777
fetching is performed once all computations are completed (note that `@sync`
7878
preceding the loop forces the loop to wait for all jobs to complete). Also,
@@ -84,3 +84,9 @@ The above use case scenario has been tested by running `julia -t 8` (or with
8484
`JULIA_NUM_THREADS=8` as environment variable). The `Threads.@threads` code
8585
takes 1.8 seconds to run, while the Dagger code, which is also one line
8686
shorter, runs around 0.9 seconds, resulting in a 2x speedup.
87+
88+
!!! warning
89+
Annotating an inner loop with `@sync` will block the outer loop from
90+
iterating until the inner `@sync` loop is fully completed, negating some
91+
potential parallelism. `@sync` should only be applied to the outermost loop
92+
before a `fetch`.

0 commit comments

Comments
 (0)