I want to run a code using parallel computing, which it works fine for serial computing
@everywhere function relay_basis(alpha,delta,name::String,n) #n is the number of sources for 1 relay we have 2 sources
chi = fill(sqrt(0.06), n) # the parameter chi
phi = im*tanh.(chi)
omega = 1.0 / prod(cosh.(chi))^2
syms, op = qrelay_op(n, phi, alpha, delta)
op_a, op_ab, mat, coef = op_mat(op)
op_q2 = [syms.apH[1], syms.apV[1], syms.bpH[end], syms.bpV[end]]
op_q1 = [syms.apH[2:end]..., syms.apV[2:end]..., syms.bpH[1:end-1]..., syms.bpV[1:end-1]...]
mask_q1 = [op in op_q1 for op in op_a];
mask_q2 = [op in op_q2 for op in op_a];
qq = [x in syms.apH || x in syms.bpV ? 1 : 0 for x in op_a]
pdet0 = pdet_maker(0.04, 1e-5)
qrs = QRelaySampler(mat, coef, omega, pdet0)
targetcache=Dict{Vector{Int}, Float64}()
target(x::Vector)= log(qrs.prob(qq, x, mask_q1) * qrs.prob(x)) #the target function of MCMC
Iteration=100_000
burnin=1000
samples=Iteration+burnin
step=25
save_iter=burnin:step:samples
dist= qrs.psetproposal #the proposal distribution
selected=[]
Q = []
current_x = zeros(length(qq))
@time @distributed (+) for i= 2:samples #from this line the MCMC algorithm starts
proposed_x= rand(dist(current_x))
prop_proposed= pdf(dist(current_x), proposed_x)
prop_current= pdf(dist(proposed_x), current_x)
C=prop_current/ prop_proposed
A= min(1,C * exp(target(proposed_x) - target( current_x)))
if rand() < A
if i in save_iter
push!(selected, proposed_x)
push!(Q, qrs.prob(qq, proposed_x, mask_q2))
end
current_x = proposed_x
end
end
return selected, Q
end
when i call the function:
@distributed (+) for i = 0:12
beta = i*pi/12
name = string(i)
selected, Q = relay_basis(pi/4, beta, name,2)
println("beta:", beta)
push!(prob,Q)
df=DataFrame(selected=selected)
end
i get this following error:
On worker 2:
MethodError: no method matching +(::Nothing, ::Array{Float64,1})
Closest candidates are:
+(::Any, ::Any, !Matched::Any, !Matched::Any...) at operators.jl:529
+(!Matched::PyCall.PyObject, ::Any) at C:\Users\Administrator\.julia\packages\PyCall\zqDXB\src\pyoperators.jl:13
+(!Matched::MutableArithmetics.Zero, ::Any) at C:\Users\Administrator\.julia\packages\MutableArithmetics\DcLoq\src\rewrite.jl:52
...
#6 at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\Distributed\src\macros.jl:272
#143 at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\Distributed\src\remotecall.jl:339 [inlined]
run_work_thunk at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\Distributed\src\process_messages.jl:79
#remotecall_fetch#148 at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\Distributed\src\remotecall.jl:364 [inlined]
remotecall_fetch at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\Distributed\src\remotecall.jl:364 [inlined]
#remotecall_fetch#152 at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\Distributed\src\remotecall.jl:406 [inlined]
remotecall_fetch at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\Distributed\src\remotecall.jl:406 [inlined]
#165 at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\Distributed\src\macros.jl:252
Stacktrace:
[1] try_yieldto(::typeof(Base.ensure_rescheduled), ::Base.RefValue{Task}) at .\task.jl:517
[2] wait() at .\task.jl:592
[3] wait(::Base.GenericCondition{Base.Threads.SpinLock}) at .\condition.jl:104
[4] wait(::Task) at .\task.jl:191
[5] fetch at .\task.jl:211 [inlined]
[6] iterate at .\generator.jl:47 [inlined]
[7] collect(::Base.Generator{Array{Task,1},typeof(fetch)}) at .\array.jl:606
[8] preduce(::Function, ::Function, ::UnitRange{Int64}) at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\Distributed\src\macros.jl:256
[9] top-level scope at In[5]:1
i tried to make some changes but i get always the same error