Multithreading in Agents.jl

I agree with @nilshg that it’s impossible to really know what the issue is that you’re having, but note that

@time for i in 1:160000
         aa[i] .= [1, 1, 1, 1] 
       end

could be

@time for i in 1:160000
         aa[i] .= (1, 1, 1, 1)
       end

which will get rid of them.

julia> function ex1(aa)
       for i in 1:160000
       aa[i] .= [1, 1, 1, 1]
       end
       end
ex1 (generic function with 1 method)

julia> function ex2(aa)
       for i in 1:160000
       aa[i] .= (1, 1, 1, 1)
       end
       end
ex2 (generic function with 1 method)

julia> using BenchmarkTools

julia> @benchmark ex1($aa)
BenchmarkTools.Trial: 842 samples with 1 evaluation.
 Range (min … max):  3.575 ms … 161.583 ms  ┊ GC (min … max):  0.00% … 93.63%
 Time  (median):     5.540 ms               ┊ GC (median):     0.00%
 Time  (mean ± σ):   5.918 ms ±   5.723 ms  ┊ GC (mean ± σ):  11.47% ± 12.36%

   █▃▁
  ▆███▆▄▃▃▃▃▂▃▂▃▃▃▄▃▄▅▄▅▅▄▅▄▄▄▄▅▅▄▃▃▃▂▂▂▂▂▃▂▁▂▂▂▂▂▂▂▁▁▂▁▁▁▁▂▂ ▃
  3.58 ms         Histogram: frequency by time        12.1 ms <

 Memory estimate: 14.65 MiB, allocs estimate: 160000.

julia> @benchmark ex2($aa)
BenchmarkTools.Trial: 5279 samples with 1 evaluation.
 Range (min … max):  717.100 μs …   2.393 ms  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     869.900 μs               ┊ GC (median):    0.00%
 Time  (mean ± σ):   937.408 μs ± 195.761 μs  ┊ GC (mean ± σ):  0.00% ± 0.00%

     ▃▇█▄▁▂▂ ▁
  ▁▃▆█████████▇▆▅▅▅▄▃▃▃▃▄▃▃▃▃▃▂▂▃▂▂▂▂▂▂▂▂▂▂▂▂▁▁▂▂▁▁▁▂▁▁▁▁▁▁▁▁▁▁ ▃
  717 μs           Histogram: frequency by time         1.63 ms <

 Memory estimate: 0 bytes, allocs estimate: 0.
2 Likes