如何调用一个函数使用remotecall_fetch(朱莉娅 - 平行)
问题描述:
我想在过程2.运行一个简单的功能,所以我这样定义的函数:如何调用一个函数使用remotecall_fetch(朱莉娅 - 平行)
julia> f(x,y) = x+y
f (generic function with 1 method)
,然后我想要做的过程2 ,但我得到了它的错误:
julia> remotecall_fetch(f,2,1,1)
ERROR: On worker 2:
UndefVarError: #f not defined
deserialize_datatype at ./serialize.jl:969
handle_deserialize at ./serialize.jl:674
deserialize at ./serialize.jl:634
handle_deserialize at ./serialize.jl:681
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
Stacktrace:
[1] #remotecall_fetch#141(::Array{Any,1}, ::Function, ::Function, ::Base.Distributed.Worker, ::Int64, ::Vararg{Int64,N} where N) at ./distributed/remotecall.jl:354
[2] remotecall_fetch(::Function, ::Base.Distributed.Worker, ::Int64, ::Vararg{Int64,N} where N) at ./distributed/remotecall.jl:346
[3] #remotecall_fetch#144(::Array{Any,1}, ::Function, ::Function, ::Int64, ::Int64, ::Vararg{Int64,N} where N) at ./distributed/remotecall.jl:367
[4] remotecall_fetch(::Function, ::Int64, ::Int64, ::Vararg{Int64,N} where N) at ./distributed/remotecall.jl:367
我知道我们可以这样定义函数:
julia> @everywhere f(x,y)=x+y
,然后我们可以得到的资源ULT:
julia> remotecall_fetch(f,2,3,4)
7
其实我也不知道我怎么可以Include
或using
定义我的功能在所有的过程或其中的一部分。
答
@everywhere
是正确的宏使用。对于模块,只需执行@everywhere using MyModule
,模块MyModule
中的所有导出函数将可供所有工作进程使用。