title: julia @parallel for loop does not update array
body: <p>I am new to julia and to get started I wanted to port some numpy code to julia and hoped to get some nice performance increase. So far not to my satisfaction.</p>
  
  <p>This is the function I want to compute</p>
  
  <pre><code>function s(x_list, r_list)
      result_list = zeros(size(x_list,1))
      for i = 1:size(x_list,1)
          dotprods = r_list * x_list[i,:]'
          expcall  = exp(im * dotprods)
          sumprod  = sum(expcall) * sum(conj(expcall))
          result_list[i] = sumprod
      end
      return result_list
  end
  </code></pre>
  
  <p>with data input that looks like</p>
  
  <pre><code>v = rand(3)
  r = rand(6000,3)
  x = linspace(1.0, 2.0, 300) * (v./sqrt(sumabs2(v)))'
  </code></pre>
  
  <p>for this function and the given input, <code>@time s(x,r)</code> gives me</p>
  
  <pre><code>0.110619 seconds (3.60 k allocations: 96.256 MB, 8.47% gc time)
  </code></pre>
  
  <p>For this case, numpy does the same job in ~70ms, so I'm not very happy! Now if I do a <code>@parallel for</code> loop with <code>julia -p 2</code>:</p>
  
  <pre><code>function s(x_list, r_list)
      result_list = SharedArray(Float64, size(x_list,1))
      @parallel for i = 1:size(x_list,1)
          dotprods = r_list * x_list[i,:]'
          expcall  = exp(im * dotprods)
          sumprod  = sum(expcall) * sum(conj(expcall))
          result_list[i] = sumprod
      end
      return result_list
  end
  </code></pre>
  
  <p>the problem is that</p>
  
  <pre><code>result_list[i] = sumprod
  </code></pre>
  
  <p>doesn't get updated and I get the list of zeros returned from the array initialization. What am I doing wrong here? 
  Further attempts to increase speed also did not show any benefit, e.g.</p>
  
  <pre><code>@vectorize_2arg Array{Float64,2} s
  </code></pre>
  
  <p>and declaring types </p>
  
  <pre><code>function s{T&lt;:Float64}(x_list::Array{T,2}, r_list::Array{T,2}) 
  </code></pre>
  
  <p>But now, starting the same <code>@parallel for</code> loop in a session with just one thread (no <code>-p2</code>, just <code>julia</code>) the array does get updated and <code>@time s(x,r)</code> tells me</p>
  
  <pre><code>0.000040 seconds (36 allocations: 4.047 KB)
  </code></pre>
  
  <p>which is actually impossible for the function and input given! Is this a bug? </p>
  
  <p>Any help is very appreciated!</p>