@@ -224,6 +224,7 @@ delayed(+; single=1)(1, 2)
224
224
## Changing the thread occupancy
225
225
226
226
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).
227
228
The basic usage looks like this:
228
229
229
230
``` julia
@@ -232,7 +233,7 @@ Dagger.@spawn occupancy=Dict(Dagger.ThreadProc=>0) fn
232
233
233
234
Consider the following function definitions:
234
235
235
- ``` @example sleep
236
+ ``` julia
236
237
using Dagger
237
238
238
239
function inner ()
@@ -252,23 +253,40 @@ function outer_low_occupancy()
252
253
Dagger. @spawn occupancy= Dict (Dagger. ThreadProc => 0 ) inner ()
253
254
end
254
255
end
255
- nothing #hide
256
256
```
257
257
258
258
When running the first outer function N times in parallel, you should see parallelization until all threads are blocked:
259
259
260
- ``` @example sleep
261
- fetch.([Dagger.@spawn outer_full_occupancy() for _ in 1:1]); # hide
260
+ ``` julia
262
261
for N in [1 , 2 , 4 , 8 , 16 ]
263
262
@time fetch .([Dagger. @spawn outer_full_occupancy () for _ in 1 : N])
264
263
end
265
264
```
266
265
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
+
267
276
Whereas running the outer function that communicates a low occupancy (` outer_low_occupancy ` ) should run fully in parallel:
268
277
269
- ``` @example sleep
270
- fetch.([Dagger.@spawn outer_low_occupancy() for _ in 1:1]); # hide
278
+ ``` julia
271
279
for N in [1 , 2 , 4 , 8 , 16 ]
272
280
@time fetch .([Dagger. @spawn outer_low_occupancy () for _ in 1 : N])
273
281
end
274
282
```
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