Devectorize.jl
Devectorize.jl copied to clipboard
Devectorize and Parallel Computing
Hi everyone,
I am having trouble getting @devec to work with parallelized code. I am not sure what I am doing wrong. Here is a MWE:
addprocs(2 - 1)
using Devectorize
@everywhere begin
using Devectorize
function parallel_computation_example(N::Int64)
a = ones(N)
b = 2*ones(N)
c = -1*ones(N)
@devec r = sum(exp(a + b) .* sum(c))
return r
end
end
output = SharedArray(Float64, 10)
@sync @parallel for is = 1:10
output[is] = parallel_computation_example(is)
end
output
If I comment out the first line (addprocs), everything works fine and the code produces some output
10-element SharedArray{Float64,1}:
-20.0855
-80.3421
-180.77
-321.369
-502.138
-723.079
-984.191
-1285.47
-1626.93
-2008.55
However, if I try to parallelize the loop, I get the following error:
ERROR: LoadError: On worker 2:
UndefVarError: @devec not defined
in eval at .\boot.jl:234
in eval_ew_expr at .\multi.jl:1981
in #647 at .\multi.jl:1421
in run_work_thunk at .\multi.jl:1001
in macro expansion at .\multi.jl:1421 [inlined]
in #646 at .\event.jl:68
in #remotecall_fetch#628(::Array{Any,1}, ::Function, ::Function, ::Base.Worker, ::Expr, ::Vararg{Expr,N}) at .\multi.jl:1070
in remotecall_fetch(::Function, ::Base.Worker, ::Expr, ::Vararg{Expr,N}) at .\multi.jl:1062
in #remotecall_fetch#631(::Array{Any,1}, ::Function, ::Function, ::Int64, ::Expr, ::Vararg{Expr,N}) at .\multi.jl:1080
in remotecall_fetch(::Function, ::Int64, ::Expr, ::Vararg{Expr,N}) at .\multi.jl:1080
in (::##17#19)() at .\multi.jl:1967
in sync_end() at .\task.jl:311
in macro expansion; at .\multi.jl:1977 [inlined]
in anonymous at .\<missing>:?
in include_from_node1(::String) at .\loading.jl:488
This is an error that I would get if I had not told the second worker what the Devectorize package was. But I did include it after @everywhere
. Am I missing something obvious? Thanks in advance.