Dagger error, parallel computing

When I am using Dagger to run functions parallelly. I got errors. The code is as follows. Can anyone show how to run functions parallelly using Dagger?
Thanks!

addprocs()
using Dagger

function f1(x)
    sleep(2)
    rand()+x
end 

vs = [rand(Int) for i in 1:10];
cks = Any[]
for v in vs
    push!(cks, delayed(f1)(v))
end 

for k in cks
    @show collect(k)
end

Running on Windows 7, 64bit,Julia 0.61, latest Dagger

error:
On worker 2:
UndefVarError: #f1 not defined
deserialize_datatype at .\serialize.jl:973
handle_deserialize at .\serialize.jl:677
deserialize at .\serialize.jl:637
handle_deserialize at .\serialize.jl:684
deserialize at .\serialize.jl:637
#1 at .\serialize.jl:739
ntuple at .\tuple.jl:108
deserialize_tuple at .\serialize.jl:739
handle_deserialize at .\serialize.jl:667
deserialize_msg at .\distributed\messages.jl:98
message_handler_loop at .\distributed\process_messages.jl:161
process_tcp_streams at .\distributed\process_messages.jl:118
#99 at .\event.jl:73
#remotecall_fetch#141(::Array{Any,1}, ::Function, ::Function, ::Base.Distributed.Worker, ::Dagger.Context, ::Vararg{Any,N} where N) at .\distributed\remotecall.jl:354
remotecall_fetch(::Function, ::Base.Distributed.Worker, ::Dagger.Context, ::Vararg{Any,N} where N) at .\distributed\remotecall.jl:346
#remotecall_fetch#144(::Array{Any,1}, ::Function, ::Function, ::Int64, ::Dagger.Context, ::Vararg{Any,N} where N) at .\distributed\remotecall.jl:367
macro expansion at E:\julia-package\v0.6\Dagger\src\compute.jl:332 [inlined]
(::Dagger.##69#70{Dagger.Context,Dagger.OSProc,Int64,#f1,Tuple{Int64},Channel{Any},Bool,Bool,Bool})() at .\event.jl:73

try:

@everywhere function f1(x)
           sleep(2)
           rand()+x
end 

You work with multiple processes here, which involves the pain to make your functions available on all processes.

3 Likes

@sdanisch Thank you so much! It works.