Parallel processing Julia上的数据移动(并行)

Parallel processing Julia上的数据移动(并行),parallel-processing,julia,Parallel Processing,Julia,我们在count_heads.jl中有一个函数: function count_hands(n) c::Int=0 for i=1:n c+=rand(Bool) end c end 我们以/julia-p2运行julia 我们希望在不同的过程中计算a和b,我们有: julia> @everywhere include("count_hands.jl") julia> a=@spawn count_hands(1000000000)

我们在count_heads.jl中有一个函数:

function count_hands(n)
    c::Int=0
    for i=1:n
        c+=rand(Bool)
    end
    c
end
我们以/julia-p2运行julia 我们希望在不同的过程中计算a和b,我们有:

julia> @everywhere include("count_hands.jl")
julia> a=@spawn count_hands(1000000000)
julia> b=@spawn count_hands(1000000000)
julia> fetch(a)+fetch(b)
1:我们如何确定我们在不同的过程中计算a和b? 我知道我们可以使用@spawnat而不是@spawn,并选择进程数,但我看到了这段代码,我想知道我们如何确定这一点

我们假设这是正确的,它们都是在不同的过程中计算的,每个a和b在不同的过程中计算,然后它们在过程1中相加。是这样吗

我们如何确定我们是在不同的过程中计算a和b

除非您使用@spawnat n并确保NPROC大于或等于n,并且ns不同,否则无法执行此操作

是这样吗

是的,假设您已经使用@spawnat 1进行了一次测试。您可以通过如下方式重写函数来测试这一点:

julia> @everywhere function count_hands(n)
           println("this process is $(myid())")
           c::Int=0
           for i=1:n
               c+=rand(Bool)
           end
           c
       end

julia> a = @spawnat 1 count_hands(1000)
this process is 1
Future(1, 1, 11, Nullable{Any}())

julia> b = @spawnat 2 count_hands(1000)
Future(2, 1, 12, Nullable{Any}())

julia>  From worker 2:  this process is 2
julia>

julia> fetch(a) + fetch(b)
1021