Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Julia 如何从for循环中@everywhere include(iter)_Julia - Fatal编程技术网

Julia 如何从for循环中@everywhere include(iter)

Julia 如何从for循环中@everywhere include(iter),julia,Julia,假设我有一个这样的函数 function paths(loc) if loc[end] == "/" loc = loc[1:end-1] end [string(loc, script) for script in ["/s1.jl", "/s2.jl", "/s3.jl"]] end 我想这样做: for p in paths("/some/path") @everywhere include(p) end 我得到一个错误

假设我有一个这样的函数

function paths(loc)
    if loc[end] == "/"
       loc = loc[1:end-1]    
    end
    [string(loc, script) for script in 
     ["/s1.jl", "/s2.jl", "/s3.jl"]]
end
我想这样做:

for p in paths("/some/path")
    @everywhere include(p)
end
我得到一个错误:

ERROR: UndefVarError: p not defined
eval(::Module, ::Any) at ./boot.jl:235
eval_ew_expr at ./distributed/macros.jl:116 [inlined]
(::Base.Distributed.##135#136{Base.Distributed.#eval_ew_expr,Tuple{Expr},Array{Any,1}})() at ./distributed/remotecall.jl:314
run_work_thunk(::Base.Distributed.##135#136{Base.Distributed.#eval_ew_expr,Tuple{Expr},Array{Any,1}}, ::Bool) at ./distributed/process_messages.jl:56
#remotecall_fetch#140(::Array{Any,1}, ::Function, ::Function, ::Base.Distributed.LocalProcess, ::Expr, ::Vararg{Expr,N} where N) at ./distributed/remotecall.jl:339
remotecall_fetch(::Function, ::Base.Distributed.LocalProcess, ::Expr, ::Vararg{Expr,N} where N) at ./distributed/remotecall.jl:339
#remotecall_fetch#144(::Array{Any,1}, ::Function, ::Function, ::Int64, ::Expr, ::Vararg{Expr,N} where N) at ./distributed/remotecall.jl:367
remotecall_fetch(::Function, ::Int64, ::Expr, ::Vararg{Expr,N} where N) at ./distributed/remotecall.jl:367
(::##189#191)() 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:340
remotecall_fetch(::Function, ::Base.Distributed.LocalProcess, ::Expr, ::Vararg{Expr,N} where N) at ./distributed/remotecall.jl:339
#remotecall_fetch#144(::Array{Any,1}, ::Function, ::Function, ::Int64, ::Expr, ::Vararg{Expr,N} where N) at ./distributed/remotecall.jl:367
remotecall_fetch(::Function, ::Int64, ::Expr, ::Vararg{Expr,N} where N) at ./distributed/remotecall.jl:367
(::##189#191)() at ./distributed/macros.jl:102
Stacktrace:
 [1] sync_end() at ./task.jl:287
 [2] macro expansion at ./distributed/macros.jl:112 [inlined]
 [3] macro expansion at ./REPL[33]:2 [inlined]
 [4] anonymous at ./<missing>:?
ERROR:UndefVarError:p未定义
eval(::模块,::任意)在./boot.jl:235
eval_ew_expr at./distributed/macros.jl:116[内联]
(::Base.Distributed.##135#136{Base.Distributed.#eval_ew_expr,Tuple{expr},Array{Any,1}})在./Distributed/remotecall.jl:314
在./Distributed/process(消息处理)处运行(work)thunk(::Base.Distributed.#135#136{Base.Distributed.#eval#ew)expr,Tuple{expr},Array{Any 1},::Bool
#remotecall_fetch#140(::数组{Any,1},::函数,::Base.Distributed.LocalProcess,::Expr,::Vararg{Expr,N},其中N)at./Distributed/remotecall.jl:339
remotecall_fetch(::Function,::Base.Distributed.LocalProcess,::Expr,::Vararg{Expr,N}其中N)at./Distributed/remotecall.jl:339
#remotecall_fetch#144(::数组{Any,1},::函数,::函数,::Int64,::Expr,::Vararg{Expr,N},其中N)at./distributed/remotecall.jl:367
remotecall_fetch(::Function,::Int64,::Expr,::Vararg{Expr,N}其中N)at./distributed/remotecall.jl:367
(::##189#191)在./distributed/macros.jl:102
#remotecall_fetch#140(::数组{Any,1},::函数,::Base.Distributed.LocalProcess,::Expr,::Vararg{Expr,N},其中N)at./Distributed/remotecall.jl:340
remotecall_fetch(::Function,::Base.Distributed.LocalProcess,::Expr,::Vararg{Expr,N}其中N)at./Distributed/remotecall.jl:339
#remotecall_fetch#144(::数组{Any,1},::函数,::函数,::Int64,::Expr,::Vararg{Expr,N},其中N)at./distributed/remotecall.jl:367
remotecall_fetch(::Function,::Int64,::Expr,::Vararg{Expr,N}其中N)at./distributed/remotecall.jl:367
(::##189#191)在./distributed/macros.jl:102
堆栈跟踪:
[1] sync_end()位于./task.jl:287
[2] 宏扩展位于./distributed/macros.jl:112[内联]
[3] 宏扩展在./REPL[33]:2[内联]
[4] 匿名地址:/?

问题是,如果这是可能的,我如何让它工作

@everywhere include(p)
替换为
@everywhere include($p)
$
是插值,它将表达式参数中的
p
符号与其值替换为
@everywhere

@everywhere include(p)
替换为
@everywhere include($p)
$
是插值,它将表达式参数中的
p
符号与其值替换为
@everywhere
。嘿@DanGetz,你可以发布与答案相同的内容:-),这样它就不会在没有答案的问题中可见。@RahulLakhanpal