# Unable to run this old code. Distributed. Arrays

**URL:** <https://discourse.julialang.org/t/unable-to-run-this-old-code-distributed-arrays/18035>\
**Category:** New to Julia\
**Created:** [November 26, 2018, 8:22pm UTC](https://discourse.julialang.org/t/unable-to-run-this-old-code-distributed-arrays/18035 "2018-11-26T20:22:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [November 26, 2018, 8:22pm UTC](https://discourse.julialang.org/t/unable-to-run-this-old-code-distributed-arrays/18035/1 "2018-11-26T20:22:20Z")

</div>

I was browsing [codegolf.stackexchange.com](http://codegolf.stackexchange.com) searching for tips and Julia examples and found this code:  
[fastest code - How Slow Is Python Really (Part II)? - Code Golf Stack Exchange](https://codegolf.stackexchange.com/questions/26371/how-slow-is-python-really-part-ii)

```julia
function pleadingzerocounts(; n = 8, m = 8, iters = 1000)
  @parallel (+) for S = 1:2^(8+8-1)
    leading_counts = zeros(Int, m)
    F = Array(Int, n)
    for i = 1:iters
      flag = 0
      while flag == 0
        for i = 1:n
          v = (1-(rand(Int8)&3))%2
          @inbounds F[i] = v
          flag += v & 1
        end
      end
      for j = 1:m
        sum = 0
        for i = 1:n
          @inbounds sum += S & (1 << (j + i - 2)) > 0 ? F[i] : -F[i]
        end
        sum == 0 ?
          (leading_counts[j] += 1) :
          break
      end
    end
    leading_counts
  end
end

function main()
  # Warm up the JIT
  pleadingzerocounts()
  # Then go for real
  println(@time pleadingzerocounts())
end

```

I’m unable to run it on my computer without errors.

```julia
ERROR: MethodError: no method matching Array(::Type{Int64}, ::Int64)
Closest candidates are:
  Array(::LinearAlgebra.UniformScaling, ::Integer, ::Integer) at C:\Program Files\Julia-1.0.2\share\julia\stdlib\v1.0\LinearAlgebra\src\uniformscaling.jl:330
macro expansion at .\REPL[8]:4 [inlined]
...

```

What I’ve already tried:  
`using Distributed`  
`addprocs(4)`  
Used `@distributed` instead of `@parallel`  
Changed `Int` within `Array` definition and `zero` to `Int64` and other alternatives.  
Changed` Array(Int, n)` to `Array{Int, n}`.  
Something strange for me is that `(+)` symbol. What is it?

But I’m still getting this errors:

```julia
ERROR: MethodError: no method matching setindex!(::Type{Array{Int64,8}}, ::Int64, ::Int64)
macro expansion at .\REPL[6]:10 [inlined]
(::getfield(Main, Symbol("##7#8")){Int64,Int64,Int64})(::typeof(+), ::UnitRange{Int64}, ::Int64, ::Int64) at C:\Program Files\Julia-1.0.2\share\julia\stdlib\v1.0\Distributed\src\macros.jl:276
143 at C:\Program Files\Julia-1.0.2\share\julia\stdlib\v1.0\Distributed\src\remotecall.jl:339 [inlined]
run_work_thunk(::getfield(Distributed, Symbol("##143#144")){getfield(Main, Symbol("##7#8")){Int64,Int64,Int64},Tuple{typeof(+),UnitRange{Int64},Int64,Int64},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}}, ::Bool) at C:\Program Files\Julia-1.0.2\share\julia\stdlib\v1.0\Distributed\src\process_messages.jl:56
remotecall_fetch#148(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::Distributed.LocalProcess, ::Function, ::Vararg{Any,N} where N) at C:\Program Files\Julia-1.0.2\share\julia\stdlib\v1.0\Distributed\src\remotecall.jl:364
remotecall_fetch(::Function, ::Distributed.LocalProcess, ::Function, ::Vararg{Any,N} where N) at C:\Program Files\Julia-1.0.2\share\julia\stdlib\v1.0\Distributed\src\remotecall.jl:364
remotecall_fetch#152(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::Int64, ::Function, ::Vararg{Any,N} where N) at C:\Program Files\Julia-1.0.2\share\julia\stdlib\v1.0\Distributed\src\remotecall.jl:406
remotecall_fetch at C:\Program Files\Julia-1.0.2\share\julia\stdlib\v1.0\Distributed\src\remotecall.jl:406 [inlined]
(::getfield(Distributed, Symbol("##167#168")){typeof(+),getfield(Main, Symbol("##7#8")){Int64,Int64,Int64},UnitRange{Int64},Array{UnitRange{Int64},1},Int64,Int64})() at C:\Program Files\Julia-1.0.2\share\julia\stdlib\v1.0\Distributed\src\macros.jl:259

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 26, 2018, 8:24pm UTC](https://discourse.julialang.org/t/unable-to-run-this-old-code-distributed-arrays/18035/2 "2018-11-26T20:24:04Z")

</div>

Change `Array(Int, n)` to `Array{Int}(undef, n)`, or just `zeros(Int, n)` or `fill(0, n)`.

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [November 26, 2018, 8:26pm UTC](https://discourse.julialang.org/t/unable-to-run-this-old-code-distributed-arrays/18035/3 "2018-11-26T20:26:20Z")

</div>

> [@kristoffer.carlsson](#):
>
> Array{Int}(undef, n)

You are really fast.  
Thank you.

And what’s the meaning of that “(+)” ?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 26, 2018, 8:42pm UTC](https://discourse.julialang.org/t/unable-to-run-this-old-code-distributed-arrays/18035/4 "2018-11-26T20:42:41Z")

</div>

`@parallel` is now `@distributed`:

```julia
help?> @distributed
  @distributed

  A distributed memory, parallel for loop of the form :

  @distributed [reducer] for var = range
      body
  end

  The specified range is partitioned and locally executed across all workers. In case an optional reducer function is specified, @distributed performs local reductions on each worker
  with a final reduction on the calling process.

```
