I’m running into performance problems when my multithreaded code allocates heavily, so I’m trying to use let bindings to avoid reallocating large arrays, but I don’t see any way to make the bindings thread-local.
For example, I don’t think the following is thread-safe:
const rngs = ntuple(Random.MersenneTwister, Threads.nthreads()) let a = zeros(10^6) global function f() rand!(rngs[Threads.threadid()], a) sum(a) end end Threads.@threads for _ in 1:100 f() end