【发布时间】:2018-07-03 08:57:06
【问题描述】:
我正在尝试并行运行一个 for 循环,其中包括并行尝试一个时代模型。以下是代码:
function init_population(pop :: _population)
addprocs(16)
@sync @parallel for i in 1:pop.size
@everywhere ran=sample(1:202,10,replace=false)
@everywhere w=get_weights(ran) ####keras model
@everywhere gg=_genotype(ran,w) ### composite type
@everywhere m,v=get_mean_variance(gg) ####func doing calculation
@everywhere pp=_phenotype(m,v) ### composite type
@everywhere fitn=get_fitness(pp) ####func doing calculation
@everywhere new_guy = _individual(gg,pp,fitn) ### composite type
@everywhere push!(pop.individuals, new_guy)
end
return pop
end
我得到的错误 ::
ERROR: LoadError: UndefVarError: sample not defined
eval at ./boot.jl:235
eval_ew_expr at ./distributed/macros.jl:116 [inlined]
#135 at ./distributed/remotecall.jl:319
run_work_thunk at ./distributed/process_messages.jl:56
#remotecall_fetch#140 at ./distributed/remotecall.jl:344
remotecall_fetch at ./distributed/remotecall.jl:344
#remotecall_fetch#144 at ./distributed/remotecall.jl:372
remotecall_fetch at ./distributed/remotecall.jl:372
#33 at ./distributed/macros.jl:102
#remotecall_fetch#140(::Array{Any,1}, ::Function, ::Function, ::Base.Distributed.LocalProcess, ::Expr, ::Vararg{Expr,N} where N) at ./distributed/remotecall.jl:345
remotecall_fetch(::Function, ::Base.Distributed.LocalProcess, ::Expr, ::Vararg{Expr,N} where N) at ./distributed/remotecall.jl:344
#remotecall_fetch#144(::Array{Any,1}, ::Function, ::Function, ::Int64, ::Expr, ::Vararg{Expr,N} where N) at ./distributed/remotecall.jl:372
remotecall_fetch(::Function, ::Int64, ::Expr, ::Vararg{Expr,N} where N) at ./distributed/remotecall.jl:372
(::##73#75)() at ./distributed/macros.jl:102
Stacktrace:
[1] sync_end() at ./task.jl:287
[2] macro expansion at ./distributed/macros.jl:112 [inlined]
[3] evolutionary_loop(::_population) at ./untitled-75c3e04a7f530386f03caa1b6d061e62:372
[4] include_string(::String, ::String) at ./loading.jl:522
[5] include_string(::Module, ::String, ::String) at /Users/yash/.julia/v0.6/Compat/src/Compat.jl:88
[6] (::Atom.##112#116{String,String})() at /Users/yash/.julia/v0.6/Atom/src/eval.jl:109
[7] withpath(::Atom.##112#116{String,String}, ::Void) at /Users/yash/.julia/v0.6/CodeTools/src/utils.jl:30
[8] withpath(::Function, ::String) at /Users/yash/.julia/v0.6/Atom/src/eval.jl:38
[9] hideprompt(::Atom.##111#115{String,String}) at /Users/yash/.julia/v0.6/Atom/src/repl.jl:67
[10] macro expansion at /Users/yash/.julia/v0.6/Atom/src/eval.jl:106 [inlined]
[11] (::Atom.##110#114{Dict{String,Any}})() at ./task.jl:80
while loading untitled-75c3e04a7f530386f03caa1b6d061e62, in expression starting on line 395
我不确定如何进行远程呼叫以及它是如何工作的。我基本上是在 16 个进程中运行 for 循环 .pop.size=100 ......我需要在同一个数组上运行它们。
非常感谢任何帮助
【问题讨论】: