-
I used
@code_warntype
oncompute_pair_interaction!
and got no type issues. I also did the same for a simplified version where I removed allfor
loops andif
statements (basically chose oneparticle
and oneneighbor
and computed the force instead of looping over all of them).@code_warntype
didn’t output anything bad. I’m not entirely sure this means my code is type-stable because there was an incident in the past where@code_warntype
came back fine but it turned out that there was a statement likeone_of_many_structs_grouped_under_abstract_type.shared_field
that needed to be rewritten as....shared_field::Float64
in order to have performant code. -
@use_threads
is a macro that becomesThreads.@threads
iflj.multithreaded
istrue
; otherwise it becomes a normalfor
loop without threads (see post). With three threads, this gives about a x2 boost to speed compare to a single thread. Note that if I replace@use_threads lj.multithreaded
withThreads.@threads
, the performance is nearly identical. -
There are about 17 allocations (2.7 KiB) per function call. 16 of those allocations comes from the threading regardless if I use
@use_threads
orThreads.@threads
. I haven’t quite found where that remaining allocation comes from, though it seems insignificant. Is it possible for@time
or@btime
to miss some allocations in a function?
Edit: I will try Duane_Wilson’s suggestion with Setfield and see if switching all my structs to immutable has any effect.