Unable to run this old code. Distributed. Arrays

I was browsing 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

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.

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:

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

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

2 Likes

You are really fast.
Thank you.

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

@parallel is now @distributed:

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.
1 Like