Julia的@spawnat如何在远程工作进程上初始化变量?

时间:2015-05-23 00:40:04

标签: parallel-processing scope julia remote-server

以下是一些输出;我无法完全理解这里发生了什么。具体来说,初始化后变量d,e,f在哪里?它们是否在工人2上动态创建和销毁?

julia> addprocs(1)
1-element Array{Any,1}:
 2

julia> whos()
Base                          Module
Core                          Module
Main                          Module
ans                           1-element Array{Any,1}

julia> fetch(@spawnat 2 whos())
        From worker 2:  Base                          Module
        From worker 2:  Core                          Module
        From worker 2:  Main                          Module

julia> a,b,c= 10,20,30
(10,20,30)

julia> fetch(@spawnat 2 a,b,c = (50,60,70))
(50,60,70)

julia> a,b,c
(10,20,30)

julia> whos()
Base                          Module
Core                          Module
Main                          Module
a                             Int64
ans                           (Int64,Int64,Int64)
b                             Int64
c                             Int64

julia> fetch(@spawnat 2 whos())
        From worker 2:  Base                          Module
        From worker 2:  Core                          Module
        From worker 2:  Main                          Module

julia> fetch(@spawnat 2 d,e,f = (a,b,c))
(10,20,30)

julia> fetch(@spawnat 2 whos())
        From worker 2:  Base                          Module
        From worker 2:  Core                          Module
        From worker 2:  Main                          Module

julia> whos()
Base                          Module
Core                          Module
Main                          Module
a                             Int64
ans                           Nothing
b                             Int64
c                             Int64

julia> versioninfo()
Julia Version 0.3.5
Commit a05f87b* (2015-01-08 22:33 UTC)
Platform Info:
System: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem)
LAPACK: libopenblas
LIBM: libopenlibm
LLVM: libLLVM-3.3

我真正的问题是关于通过@spawnat在远程工作人员上调用函数时的数据移动,即我的理解是

> @spawnat 2 func(a,b,c)

会导致a,b& c从本地移动到远程。如果& c存在于遥远的范围内,运动还会发生吗? a&在我的情况下,c是大型数组,我已经预装了所有工人。 b在调用@spawnat 2 func(a,b,c)之前在本地计算。

这可以用@spawnat完成吗?还有其他解决方法吗?

0 个答案:

没有答案