I'm new in using Julia and after some courses about numeric analysis programming became a hobby of mine. I ran some tests with all my cores and did the same with threads to compare. I noticed that doing heavier computation went better with the threaded loop than with the process, But it was about the same when it came to addition. (operations were randomly selected for example) After some research its all kinda vague and I ultimately want some perspective from someone that is using the same language if it matters at all.
Some technical info: 8 physical cores, julia added vector of 16 after addprocs() and nthreads() is 16
using Distributed
addprocs()
@everywhere using SharedArrays;
@everywhere using BenchmarkTools;
function test(lim)
r = zeros(Int64(lim / 16),Threads.nthreads())
Threads.@threads for i in eachindex(r)
r[Threads.threadid()] = (BigInt(i)^7 +5)%7;
end
return sum(r)
end
@btime test(10^4) # 1.178 ms (240079 allocations: 3.98 MiB)
@everywhere function test2(lim)
a = SharedArray{Int64}(lim);
@sync @distributed for i=1:lim
a[i] = (BigInt(i)^7 +5)%7;
end
return sum(a)
end
@btime test2(10^4) # 3.796 ms (4413 allocations: 189.02 KiB)