代码之家  ›  专栏  ›  技术社区  ›  Fazeleh

如何使用remotecall\u fetch(Julia-并行)调用函数

  •  0
  • Fazeleh  · 技术社区  · 9 年前

    julia> f(x,y) = x+y
    f (generic function with 1 method)
    

    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
    

    julia> remotecall_fetch(f,2,3,4)
    7
    

    实际上,我不知道如何定义所有进程或其中一些进程中的函数 Include using

    1 回复  |  直到 9 年前
        1
  •  4
  •   sbromberger    9 年前

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