Using Shared Arrays

parallel

#1
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


#2

You probably shouldn’t tag user questions as Development. That’s one way to incur the wrath of the gods.


#3

Yup changed that…btw any idea on why is sequential code behaving differently from parallel code?


#4

Have you made sure each process reads and write disjoint segments of the array? Without the code for _accumulate, I can’t say for certain, but seems probable that you aren’t writing to independent pieces of it? (and avoiding reading from it?)


#5

Thanks!! I was not writing in independent segments and probably that was causing collision.