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
Revamp section describing how to fix 1:nthreads() pattern (#137)
* remove section describing the partial fix to 1:nthreads() pattern
* add back in the non-recommended fix, but make it use `maxthreadid`.
* run TLS doc generator
#Unfortunately, this approach is [**generally wrong**](https://julialang.org/blog/2023/07/PSA-dont-use-threadid/). The first issue is that `threadid()`
242
+
#This approach is [**wrong**](https://julialang.org/blog/2023/07/PSA-dont-use-threadid/). The first issue is that `threadid()`
251
243
# doesn't necessarily start at 1 (and thus might return a value `> nthreads()`), in which
252
244
# case `Cs[threadid()]` would be an out-of-bounds access attempt. This might be surprising
253
245
# but is a simple consequence of the ordering of different kinds of Julia threads: If Julia
254
246
# is started with a non-zero number of interactive threads, e.g. `--threads 5,2`, the
255
247
# interactive threads come first (look at `Threads.threadpool.(1:Threads.maxthreadid())`).
248
+
# [Starting in julia v1.12, julia will launch with at one interactive thread](https://github.com/JuliaLang/julia/pull/57087),
249
+
# and so the above code will error by default.
256
250
#
257
251
# But even if we account for this offset there is another, more fundamental problem, namely
258
252
# **task-migration**. By default, all spawned parallel tasks are "non-sticky" and can
@@ -266,31 +260,55 @@ res_nu ≈ res_pt_naive
266
260
# (Note that, in practice, this - most likely 😉 - doesn't happen for the very simple example
267
261
# above, but you can't rely on it!)
268
262
#
269
-
# ### The quick fix (with caveats)
263
+
# ### The quick (and non-recommended) fix
270
264
#
271
265
# A simple solution for the task-migration issue is to opt-out of dynamic scheduling with
272
266
# `scheduler=:static` (or `scheduler=StaticScheduler()`). This scheduler statically
273
267
# assigns tasks to threads upfront without any dynamic rescheduling
274
268
# (the tasks are sticky and won't migrate).
275
269
#
270
+
# We'll also need to switch from `nthreads` to `maxthreadid`, since that can be greater than
0 commit comments