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
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 example benchmarks.
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
+
456
474
457
475
<details>
458
476
<summary>Benchmarks of nested multi-threading with Polyester</summary>
@@ -472,7 +490,9 @@ x = rand(size(y)...);
472
490
@btimesequential_thread($x,$y) # 49.373 ms (196 allocations: 18.25 KiB)
473
491
474
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
475
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