# Mean function does not work in parallel calculations

hi, i want to calculate mean with @distributed. it is my code.

``````Using SharedArrays , Distributed , Statistics
@everywhere using SharedArrays
t=zeros(120,100,8)+zeros(120,100,8)*im
s=convert(SharedArray,t)
function test()
@time @distributed for (i ,j) in collect(Iterators.product ( 1:100,1:8))
x=rand(200,120)+rand(200,120)*im
y=rand(200,120)+rand(200,120)*im
z=x.*conj(y)
s[:,i , j ]= (mean( z, dims=1))
end
return s
end
@time zz=test()
``
My result zz is zero why? When I remove @distributed of my code everything is OK.
I need use @distributed to reach speed up.``````

Package Statistics needs to be used everywhere.
(your code is a bit difficult to read and has some errors, so I repost it with the solution)

``````using Distributed

@everywhere using SharedArrays, Statistics

t=zeros(120,100,8)+zeros(120,100,8)*im
s=convert(SharedArray,t)

function test()
@time @distributed for (i ,j) in collect(Iterators.product( 1:100,1:8))
x=rand(200,120)+rand(200,120)*im
y=rand(200,120)+rand(200,120)*im
z=x.*conj(y)
s[:,i , j ]= (mean( z, dims=1))
end
return s
end

@time zz=test();
``````

Remark I forgot yesterday:
But, if you do it like this, you will not get good performance result, because in the distributed case every worker has to do nearly the same work like before the single worker in the not distributed case. You distribute nearly the same workload as before on 5 workers so nearly quintupling the work.

Wrong.