繁体   English   中英

julia中的量子蒙特卡洛方法能否并行运算?

[英]Can we do a parallel operation for Quantum Monte Carlo method in julia?

这是我并行操作的主要代码:

using Distributed
using SharedArrays
nprocs()
addprocs(7)

现在,我需要存储一个关于时间的变量:

variable = SharedArray{ComplexF64, 3}(Dim, steps, paths)

请注意,“步骤”和“路径”分别表示时间序列和轨迹总数。 但是,如果我定义这个变量,我会遇到 out of memory 问题,因为 Dim=10000,steps=600,paths=1000,尽管我可以使用多个内核来实现并行操作。 并行操作的代码可以写成

@sync @distributed for path=1:paths
                       ...
                       variable[:,:,path] = matrix_var
end

其实这个变量并不是我最终的结果,结果是

final_var = sum(variable, dim=3)

,代表所有轨迹的总和。

因此,我想处理out of memory的问题,同时使用并行运算。 如果我在定义这个变量的时候去掉了“路径”的维度,out of memory 的问题就消失了,但是并行运算就无效了。 我希望有一个解决方案来克服它。

似乎对于路径的每个值,您应该在本地而不是在巨大的数组上创建variable 您的代码可能看起来或多或少像这样:

final_vars = @distributed (append!) for path=1:paths
    #create local variable for a single step
    locvariable =  Array{ComplexF64, 2}(undef, Dim, steps)
    # at any time locvariable is at most in nprocs() copies
    # load data to locvariable specific to path and do your job
    final_var = sum(locvariable, dim=2)
    [final_var]   # in this way you will get a vector of arrays
end 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM