Parallel processing 如何使用remotecall_fetch(Julia-parallel)调用函数

Parallel processing 如何使用remotecall_fetch(Julia-parallel)调用函数,parallel-processing,julia,Parallel Processing,Julia,我想在进程2上运行一个简单的函数。所以我定义了如下函数: julia> f(x,y) = x+y f (generic function with 1 method) julia> @everywhere f(x,y)=x+y 然后我想在进程2上执行此操作,但出现了一个错误: julia> remotecall_fetch(f,2,1,1) ERROR: On worker 2: UndefVarError: #f not defined deserialize_datat

我想在进程2上运行一个简单的函数。所以我定义了如下函数:

julia> f(x,y) = x+y
f (generic function with 1 method)
julia> @everywhere f(x,y)=x+y
然后我想在进程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> f(x,y) = x+y
f (generic function with 1 method)
julia> @everywhere f(x,y)=x+y
然后我们可以得到结果:

julia> remotecall_fetch(f,2,3,4)
7
实际上,我不知道如何通过
Include
使用


.

@everywhere
是正确使用的宏。对于模块,只需使用MyModule执行
@everywhere,模块
MyModule
中的所有导出函数将可用于所有工作进程。

@everywhere
是正确的宏。对于模块,只需使用MyModule在任何地方执行
,模块
MyModule
中导出的所有函数将可用于所有工作进程