[英]Can we do a parallel operation for Quantum Monte Carlo method in julia?
This is my main code of parallel operation:这是我并行操作的主要代码:
using Distributed
using SharedArrays
nprocs()
addprocs(7)
Now, I need to store a variable about time:现在,我需要存储一个关于时间的变量:
variable = SharedArray{ComplexF64, 3}(Dim, steps, paths)
Note that "steps" and "paths" denote time series and total number of trajectories, respectively.请注意,“步骤”和“路径”分别表示时间序列和轨迹总数。 However, if i define this variable, i will meet with the out of memory probelm because Dim=10000, steps=600, and paths=1000, though i can use multiple kernels to achieve parallel operation.但是,如果我定义这个变量,我会遇到 out of memory 问题,因为 Dim=10000,steps=600,paths=1000,尽管我可以使用多个内核来实现并行操作。 The code of parallel operation can be written as并行操作的代码可以写成
@sync @distributed for path=1:paths
...
variable[:,:,path] = matrix_var
end
Actually, this variable is not my final result, and the result is其实这个变量并不是我最终的结果,结果是
final_var = sum(variable, dim=3)
, which represents the summation of all trajectories. ,代表所有轨迹的总和。
Thus, I want to deal with the out of memory problem and simultaneously use parallel operation.因此,我想处理out of memory的问题,同时使用并行运算。 If i cast away the dimension of "paths" when i define this variable, the out of memory problem will vanish, but parallel operation becomes invaild.如果我在定义这个变量的时候去掉了“路径”的维度,out of memory 的问题就消失了,但是并行运算就无效了。 I hope that there are a solution to overcome it.我希望有一个解决方案来克服它。
Seems that for each value of path you should create the variable
locally rather than on huge array.似乎对于路径的每个值,您应该在本地而不是在巨大的数组上创建variable
。 Your code might look more or less like this:您的代码可能看起来或多或少像这样:
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.