Skip to content

Commit c0eec21

Browse files
authored
docs: Clarify limitations of Datadeps (#606)
1 parent 3901581 commit c0eec21

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/src/datadeps.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,34 @@ runs sequentially. This means that the structure of the program doesn't have to
9898
change in order to use Dagger for parallelization, which can make applying
9999
Dagger to existing algorithms quite effortless.
100100

101+
## Limitations
102+
103+
It's important to be aware of a key limitation when working with `Dagger.spawn_datadeps`. Operations that involve explicit synchronization or fetching results of other Dagger tasks, such as `fetch`, `wait`, or `@sync`, cannot be used directly inside a `spawn_datadeps` block.
104+
105+
The `spawn_datadeps` region is designed to manage data dependencies automatically based on the `In`, `Out`, and `InOut` annotations. Introducing explicit synchronization primitives can interfere with this mechanism and lead to unexpected behavior or errors.
106+
107+
**Example of what NOT to do:**
108+
109+
```julia
110+
Dagger.spawn_datadeps() do
111+
# Incorrect: Using fetch inside spawn_datadeps
112+
task1 = Dagger.@spawn my_func1!(InOut(A))
113+
result1 = fetch(task1) # This will not work as expected
114+
115+
# Incorrect: Using wait inside spawn_datadeps
116+
task2 = Dagger.@spawn my_func2!(InOut(B))
117+
wait(task2) # This will also lead to issues
118+
119+
# Incorrect: Using @sync inside spawn_datadeps
120+
@sync begin
121+
Dagger.@spawn my_func3!(InOut(C))
122+
Dagger.@spawn my_func4!(InOut(D))
123+
end
124+
end
125+
```
126+
127+
If you need to synchronize or fetch results, these operations should be performed outside the `spawn_datadeps` block. The primary purpose of `spawn_datadeps` is to define a region where data dependencies for mutable operations are automatically managed.
128+
101129
## Aliasing Support
102130

103131
Datadeps is smart enough to detect when two arguments from different tasks

0 commit comments

Comments
 (0)