如何在 julia 中定义远程调用?

How to define remote calls in julia?

请指导定义远程调用函数:

日志:

[root@srvr0 ~]# julia -p 4
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.4 (2021-11-19)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> 

julia> using Distributed;

julia> r = remotecall(2, ones, 2, 2)
ERROR: MethodError: no method matching remotecall(::Int64, ::typeof(ones), ::Int64, ::Int64)
Closest candidates are:
  remotecall(::Any, ::Distributed.LocalProcess, ::Any...; kwargs...) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/remotecall.jl:357
  remotecall(::Any, ::Distributed.Worker, ::Any...; kwargs...) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/remotecall.jl:363
  remotecall(::Any, ::Integer, ::Any...; kwargs...) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Distributed/src/remotecall.jl:376
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

julia> fetch(r)
ERROR: UndefVarError: r not defined
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

正如错误消息中的类型签名(“最接近的候选者”)所示,工作进程必须是调用的第二个参数。因此,您调用的函数 ones 在本例中是第一个参数。

julia> using Distributed

julia> r = remotecall(ones, 2, 2, 2)
Future(2, 1, 5, nothing)

julia> fetch(r)
2×2 Matrix{Float64}:
 1.0  1.0
 1.0  1.0