Skip to content

Commit a9e21e0

Browse files
committed
docs: update code snippets to be 'simple' Julia snippets and add output examples
1 parent aeb4b2d commit a9e21e0

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

docs/src/task-spawning.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ delayed(+; single=1)(1, 2)
224224
## Changing the thread occupancy
225225

226226
One of the supported [`Sch.ThunkOptions`](@ref) is the `occupancy` keyword.
227+
This keyword can be used to communicate that a task is not expected to fully saturate a CPU core (e.g. due to being IO-bound).
227228
The basic usage looks like this:
228229

229230
```julia
@@ -232,7 +233,7 @@ Dagger.@spawn occupancy=Dict(Dagger.ThreadProc=>0) fn
232233

233234
Consider the following function definitions:
234235

235-
```@example sleep
236+
```julia
236237
using Dagger
237238

238239
function inner()
@@ -252,23 +253,40 @@ function outer_low_occupancy()
252253
Dagger.@spawn occupancy=Dict(Dagger.ThreadProc => 0) inner()
253254
end
254255
end
255-
nothing #hide
256256
```
257257

258258
When running the first outer function N times in parallel, you should see parallelization until all threads are blocked:
259259

260-
```@example sleep
261-
fetch.([Dagger.@spawn outer_full_occupancy() for _ in 1:1]); # hide
260+
```julia
262261
for N in [1, 2, 4, 8, 16]
263262
@time fetch.([Dagger.@spawn outer_full_occupancy() for _ in 1:N])
264263
end
265264
```
266265

266+
The results from the above code snippet should look similar to this (the timings will be influenced by your specific machine):
267+
268+
```text
269+
0.124829 seconds (44.27 k allocations: 3.055 MiB, 12.61% compilation time)
270+
0.104652 seconds (14.80 k allocations: 1.081 MiB)
271+
0.110588 seconds (28.94 k allocations: 2.138 MiB, 4.91% compilation time)
272+
0.208937 seconds (47.53 k allocations: 2.932 MiB)
273+
0.527545 seconds (79.35 k allocations: 4.384 MiB, 0.64% compilation time)
274+
```
275+
267276
Whereas running the outer function that communicates a low occupancy (`outer_low_occupancy`) should run fully in parallel:
268277

269-
```@example sleep
270-
fetch.([Dagger.@spawn outer_low_occupancy() for _ in 1:1]); # hide
278+
```julia
271279
for N in [1, 2, 4, 8, 16]
272280
@time fetch.([Dagger.@spawn outer_low_occupancy() for _ in 1:N])
273281
end
274282
```
283+
284+
In comparison, the `outer_low_occupancy` snippet should show results like this:
285+
286+
```text
287+
0.120686 seconds (44.38 k allocations: 3.070 MiB, 13.00% compilation time)
288+
0.105665 seconds (15.40 k allocations: 1.072 MiB)
289+
0.107495 seconds (28.56 k allocations: 1.940 MiB)
290+
0.109904 seconds (55.03 k allocations: 3.631 MiB)
291+
0.117239 seconds (87.95 k allocations: 5.372 MiB)
292+
```

0 commit comments

Comments
 (0)