我想运行一个并行的for循环。我需要我的每个流程都可以访问2个大字典,gene_dict
并且transcript_dict
。这是我首先尝试的
@everywhere( function EM ... end )
generefs = [ @spawnat i genes for i in 2:nprocs()]
dict1refs = [ @spawnat i gene_dict for i in 2:nprocs()]
dict2refs = [ @spawnat i transcript_dict for i in 2:nprocs()]
result = @parallel (vcat) for i in 1:length(genes)
EM(genes[i], gene_dict, transcript_dict)
end
但是我在所有进程上都遇到了以下错误(不仅是5个):
exception on 5: ERROR: genes not defined
in anonymous at no file:1514
in anonymous at multi.jl:1364
in anonymous at multi.jl:820
in run_work_thunk at multi.jl:593
in run_work_thunk at multi.jl:602
in anonymous at task.jl:6
UndefVarError(:genes)
我以为@spawnat
会将我需要的三个数据结构移到所有流程中。我的第一个想法可能是此操作需要一段时间,并且并行for循环尝试在数据传输完成之前运行。
数据移动@spawnat
但不绑定到与主节点上名称相同的变量。而是将数据保存在工作程序上相当隐蔽的Dict
名称中Base.PGRP
。要访问值,你就必须fetch
在RemoteRef
这你的情况会是这样,比如s
result = @parallel (vcat) for i in 1:length(genes) EM(fetch(genes[i]), fetch(gene_dict[i]), fetch(transcript_dict[i])) end
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句