Groups 126 of 99+ julia-users › SharedArray returns unexpected empty values 6 posts by 2 authors Fred Mar 26 Hi, I did this simple code to try to understand how shared arrays work. Unfortunately my shared array c is always empty : Here I know the size of the final array c because it is a very simple example, but is it possible to create an empty shared array and push the results inside using push function ? Thank you very much for your comments ! addprocs 2 a rand 8 b rand 8 convert SharedArray,a convert SharedArray,b c SharedArray Float64,8 everywhere function prod x,y z x y return z end parallel for i 1:10 c i prod a i , b i end println c result : 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 : Yichao Yu Mar 26 On Sat, Mar 26, 2016 at 3:46 PM, Fred fred.so... gmail.com wrote: Hi, I did this simple code to try to understand how shared arrays work. Unfortunately my shared array c is always empty : Here I know the size of the final array c because it is a very simple example, but is it possible to create an empty shared array and push the results inside using push function ? Thank you very much for your comments ! addprocs 2 a rand 8 b rand 8 convert SharedArray,a convert SharedArray,b c SharedArray Float64,8 everywhere function prod x,y z x y return z end parallel for i 1:10 c i prod a i , b i end http: julia.readthedocs.org en latest stdlib parallel Base. sync You also have a oob access btw. Fred Mar 26 Thank you for your answer ! I did the following change : sync parallel for i 1:8 c i prod a i , b i end and now I obtain a result : 0.18576241230332016,0.23210296820071408,0.2741188848763749,0.6734257301922404, 0.4961438140080696,0.06445466347639998,0.07932590741374389,0.32153039018331936 I hope everything is correct : Fred Mar 26 I compared the speed of the parallel loop : it is 10 times slower with 4 cpus than the simple loop : time sync parallel for i 1:800000 c i prod a i , b i end println c time for i 1:800000 c i prod a i , b i end 0.728079 seconds 391.50 k allocations: 16.659 MB 0.091947 seconds 4.80 M allocations: 73.240 MB, 5.67 gc time Yichao Yu Mar 26 On Sat, Mar 26, 2016 at 5:14 PM, Fred fred.so... gmail.com wrote: I compared the speed of the parallel loop : it is 10 times slower with 4 cpus than the simple loop : parallel use multiple processes and the synchronization is very high compare to the super cheap operations in each loop. Don't use it for simple code like this. threads will likely be more suitable but there are a lot of work on both frontend and backend for it to be more usable. Fred Mar 26 Thank you ! I will try on a more complex example ;