You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+164-1Lines changed: 164 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -413,6 +413,8 @@ Note that `@batch` defaults to using up to one thread per physical core, instead
413
413
is because [LoopVectorization.jl](https://github.com/JuliaSIMD/LoopVectorization.jl) currently only uses up to 1 thread per physical core, and switching the number of
414
414
threads incurs some overhead. See the docstring on `@batch` (i.e., `?@batch` in a Julia REPL) for some more discussion.
415
415
416
+
## Local per-thread storage
417
+
416
418
You also can define local storage for each thread, providing a vector containing each of the local storages at the end.
417
419
418
420
```julia
@@ -446,4 +448,165 @@ julia> let
446
448
end
447
449
448
450
Float16[83.0, 90.0, 27.0, 65.0]
449
-
```
451
+
```
452
+
453
+
## Disabling Polyester threads
454
+
455
+
When running many repetitions of a Polyester-multithreaded function (e.g. in an embarrassingly parallel problem that repeatedly executes a small already Polyester-multithreaded function), it can be beneficial to disable Polyester (the inner multithreaded loop) and multithread only at the outer level (e.g. with `Base.Threads`). This can be done with the `disable_polyester_threads` context manager. In the expandable section below you can see examples with benchmarks.
456
+
457
+
It is best to call `disable_polyester_threads` only once, before any `@thread` uses happen, to avoid overhead. E.g. best to do it as:
458
+
```julia
459
+
disable_polyester_threads() do
460
+
@threadsfor i in1:n
461
+
f()
462
+
end
463
+
end
464
+
```
465
+
instead of doing it in the following unnecessarily slow manner:
466
+
```julia
467
+
@threadsfor i in1:n # DO NOT DO THIS
468
+
disable_polyester_threads() do# IT HAS UNNECESSARY OVERHEAD
469
+
f()
470
+
end
471
+
end
472
+
```
473
+
474
+
475
+
<details>
476
+
<summary>Benchmarks of nested multi-threading with Polyester</summary>
477
+
478
+
```julia
479
+
# Big inner problem, repeated only a few times
480
+
481
+
y =rand(10000000,4);
482
+
x =rand(size(y)...);
483
+
484
+
@btimeinner($x,$y,1) # 73.319 ms (0 allocations: 0 bytes)
485
+
@btimeinner_polyester($x,$y,1) # 8.936 ms (0 allocations: 0 bytes)
486
+
@btimeinner_thread($x,$y,1) # 11.206 ms (49 allocations: 4.56 KiB)
487
+
488
+
@btimesequential_sequential($x,$y) # 274.926 ms (0 allocations: 0 bytes)
489
+
@btimesequential_polyester($x,$y) # 36.963 ms (0 allocations: 0 bytes)
490
+
@btimesequential_thread($x,$y) # 49.373 ms (196 allocations: 18.25 KiB)
491
+
492
+
@btimethreads_of_polyester($x,$y) # 78.828 ms (58 allocations: 4.84 KiB)
493
+
# the following is a purposefully suboptimal way to disable threads
494
+
@btimethreads_of_polyester_inner_disable($x,$y) # 70.182 ms (47 allocations: 4.50 KiB)
495
+
# the following is a good way to disable threads (the disable call happening once in the outer scope)
0 commit comments