I’ve been trying to better undertstand how to find allocations in my code, and I stumbled on this simple MWE which either exposes some limitation of @allocated, or (more likely) a limitation of my understanding.
function test()
a = @allocated begin
end
if a>0
println(a)
error(" Found an allocation?")
end
end
With nothing in the begin/end block, no allocations should be done, and so the function should just finish without an error. This is the case if I just run it on a single thread.
for _ in 1:10000
test()
end
But now doing the same thing in a threaded loop behaves differently (it returns the error message):
Threads.@threads for _ in 1:10000
test()
end
Am I doing something dumb here?
I’m using Julia Version 1.5.2 (2020-09-23):
Commit 539f3ce943 (2020-09-23 23:17 UTC)
Platform Info:
OS: macOS (x86_64-apple-darwin18.7.0)
CPU: Intel(R) Core(TM) i7-8700B CPU @ 3.20GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-9.0.1 (ORCJIT, skylake)
Environment:
JULIA_NUM_THREADS = 12