Hi there,
I have recently read the blog post about changes in @threads behavior from version 1.8 onwards: PSA: Thread-local state is no longer recommended, and I am unsure if I do need to change up code that I wrote for a previous Julia version.
- In my current code, I have multiple functions that use @threads without using the stated threadid, but I am using preallocated buffers that are filled during a loop.
- I dont care at which index that buffer is filled.
- The function inside the @threads loop mutates my arguments, but again I do not care in which order the arguments are getting mutated.
All my code has the following form:
Nchains = 96
# Nthreads == 8
Niterations = 10
T = 1000
for idx in 1:T
buffer_argument1 = [BufferArgument1() for 1:Nchains]
buffer_argument2 = [BufferArgument2() for 1:Nchains]
buffer_output = [BufferOutput() for 1:Nchains]
Base.Threads.@threads for Nchain in Base.OneTo(Nchains)
for iter in 1:10
buffer_output[Nchain] = func1!(buffer_argument1[Nchain], buffer_argument2[Nchain])
end
end
compute_some_summary_statistics(buffer_output)
end
Do I need to change @threads to a version working with @spawn, or is this safe going forward? I tried to find the solution for this based on the multiple open questions already on discourse, but am still unsure about the solution.