Stream: helpdesk (published)

Topic: ✔ Necessity of `@inbounds` when using `Threads.@threads`?


view this post on Zulip Júlio Hoffimann (Jul 04 2025 at 14:50):

Does it make sense to use both macros in a loop?

Threads.@threads @inbounds for i in 1:n
end

view this post on Zulip Mason Protter (Jul 04 2025 at 15:35):

I mean, if you know that stuff is actually inbounds, then yes, using both can make sense and give performance improvements.

But generally it's a bad idea to put @inbounds on an entire loop body. I prefer to only apply it to specific indexing calls so I can more easily reason about it

view this post on Zulip Notification Bot (Jul 04 2025 at 15:36):

Júlio Hoffimann has marked this topic as resolved.

view this post on Zulip Mosè Giordano (Jul 04 2025 at 18:29):

https://github.com/JuliaLang/julia/pull/41893

view this post on Zulip Júlio Hoffimann (Jul 04 2025 at 18:33):

Good to know. Thanks for sharing.


Last updated: Jul 22 2025 at 04:56 UTC