Parallel processing @everywhere是否不在主机上加载函数?
我制作了一个模块,在核心数量上有一个if条件。如果芯数大于1,则路线平行;否则,它将按照下面代码中所示的串行路径运行Parallel processing @everywhere是否不在主机上加载函数?,parallel-processing,julia,Parallel Processing,Julia,我制作了一个模块,在核心数量上有一个if条件。如果芯数大于1,则路线平行;否则,它将按照下面代码中所示的串行路径运行 module mymodule import Pkg using Distributed if nworkers() > 1 @everywhere using Pkg @everywhere Pkg.activate(".") @everywhere Pkg.instantiate() @everywhere using CSV
module mymodule
import Pkg
using Distributed
if nworkers() > 1
@everywhere using Pkg
@everywhere Pkg.activate(".")
@everywhere Pkg.instantiate()
@everywhere using CSV
@everywhere include("src/myfuncs.jl")
function func()
df=CSV.read(file);
.......
end
else
using Pkg
Pkg.activate(".")
Pkg.instantiate()
using CSV
include("src/myfuncs.jl")
function func()
df=CSV.read(file);
.......
end
end
end #mymodule
1) 当我实例化一个Julia会话时,例如,Julia-p8
我得到一个错误,说error:UndefVarError:CSV not defined
。另一方面,当会话被简单地实例化为julia
时,没有错误。Project.toml和Master.toml文件比src
高一级。在使用@everyone
之前,我是否必须加载主机,例如
include("src/myfuncs.jl")
@everywhere include("src/myfuncs.jl")
2) 此外,我发现当程序执行串行路由时,它找不到myfunc.jl
文件,因为它已经在src
文件夹中(查找src/src/myfunc.jl
),这种行为让我感到困惑
有人能在这里分享他们的想法吗?@everywhere
在所有工人和主人身上执行。然而:
Pkg之前使用
修改代码以运行。激活
@everywhere Pkg.instantiate()
实现什么,但可以肯定的是,您现在正在做的事情并不好(您必须确保它不会在群集节点的多个副本中运行)希望有帮助 你的建议很有帮助。然而,这个问题仍然困扰着我<代码>包括(“myfuncs.jl”)@everywhere include(“src/myfuncs.jl”)-只有这样做才有效,是什么解释了这种行为?这与编译竞争问题完全相同。您希望先编译代码,然后再使用它。在您的问题中,您还为
myfuncs.jl
和src/myfuncs.jl
使用了不同的位置-通常情况下,除非您执行从进程的自定义启动或某些进程更改其主文件夹位置(例如通过cd
功能),否则情况不应如此我没有为myfuncs.jl
和src/myfuncs.jl
使用不同的位置。我之所以“被迫”使用它,是因为正如您所提到的,看起来有些进程正在更改其主文件夹位置(我不明白为什么会发生这种情况?),此外,您建议不根据工作人员的数量来分离代码的建议已经实现,现在运行良好。谢谢关于文件夹-除非在启动从属进程之前在主进程上执行cd
,否则我从未观察到它们发生变化。
using Distributed
@everywhere using Distributed
using CSV
@everywhere using CSV