julia> betweenness = SharedArray{Float64}(n_v);
julia> @time for s in reverse(vs)
if degree(g,s) > 0 # this might be 1?
state = dijkstra_shortest_paths(g, s; allpaths=true)
if endpoints
_accumulate_endpoints!(betweenness, state, g, s)
else
_accumulate_basic!(betweenness, state, g, s)
end
end
end
133.344839 seconds (95.12 M allocations: 15.006 GiB, 1.41% gc time)
julia> betweenness2 = SharedArray{Float64}(n_v);
julia> @time for s in vs
if degree(g,s) > 0 # this might be 1?
state = dijkstra_shortest_paths(g, s; allpaths=true)
if endpoints
_accumulate_endpoints!(betweenness2, state, g, s)
else
_accumulate_basic!(betweenness2, state, g, s)
end
end
end
131.878554 seconds (95.12 M allocations: 15.006 GiB, 1.38% gc time)
julia> betweenness2 == betweenness
false
julia> sum(betweenness2-betweenness)
4.890762284048833e-8
julia> betweennessp = SharedArray{Float64}(n_v);
julia> @time @sync @parallel for s in vs
if degree(g,s) > 0 # this might be 1?
state = dijkstra_shortest_paths(g, s; allpaths=true)
if endpoints
_accumulate_endpoints!(betweennessp, state, g, s)
else
_accumulate_basic!(betweennessp, state, g, s)
end
end
end
75.195969 seconds (334.83 k allocations: 22.154 MiB, 0.01% gc time)
julia> sum(betweennessp-betweenness)
-888.7666665875818
I am trying to parallelise a loop. Whenever I run loop sequentially and add to shared array the difference in two successive runs is almost insignificant which is justified. But when i run the same loop in parallel and add to the shared array i get significant difference with answer in previous cases. Can anyone please explain this / point out error