Julia:无法使用“使用”包设置并行化

问题描述 投票:0回答:1

我在为并行化设置代码方面遇到了很大的麻烦。当我尝试通过运行以下代码来“声明”我在工作程序中使用的软件包时:

#--------------------------------#
#         Initialization         #
#--------------------------------#

# Packages
#using Distributed

using QuantEcon, Optim, Distributions, DelimitedFiles, ExcelReaders
using ProgressMeter, BenchmarkTools, DataFrames, Combinatorics
using LinearAlgebra, Statistics, Random, StatsBase
using BlackBoxOptim, Distributed

# Number of cores/workers
addprocs(2)

@everywhere begin
    using Pkg; Pkg.activate(".")  # required
    using QuantEcon, Optim, Distributions, DelimitedFiles, ExcelReaders
    using ProgressMeter, BenchmarkTools, DataFrames, Combinatorics
    using LinearAlgebra, Statistics, Random, StatsBase
    using BlackBoxOptim, Distributed
end

# Set Directory

cd("XXX\\julia_codes")

我收到以下错误:

<strong>On worker 2:</strong>

<strong>ArgumentError: Package QuantEcon not found in current path:
- Run `import Pkg; Pkg.add("QuantEcon")` to install the QuantEcon package.

require at .\loading.jl:823
top-level scope at XXX\julia_codes\4-Simulations.jl:26
eval at .\boot.jl:328
#116 at C:\Users\julia\AppData\Local\Julia-1.1.1\share\julia\stdlib\v1.1\Distributed\src\process_messages.jl:276
run_work_thunk at C:\Users\julia\AppData\Local\Julia-1.1.1\share\julia\stdlib\v1.1\Distributed\src\process_messages.jl:56
run_work_thunk at C:\Users\julia\AppData\Local\Julia-1.1.1\share\julia\stdlib\v1.1\Distributed\src\process_messages.jl:65
#102 at .\task.jl:259
#remotecall_wait#154(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::Distributed.Worker, ::Module, ::Vararg{Any,N} where N) at C:\Users\julia\AppData\Local\Julia-1.1.1\share\julia\stdlib\v1.1\Distributed\src\remotecall.jl:421
remotecall_wait(::Function, ::Distributed.Worker, ::Module, ::Vararg{Any,N} where N) at C:\Users\julia\AppData\Local\Julia-1.1.1\share\julia\stdlib\v1.1\Distributed\src\remotecall.jl:412
#remotecall_wait#157(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Function, ::Int64, ::Module, ::Vararg{Any,N} where N) at C:\Users\julia\AppData\Local\Julia-1.1.1\share\julia\stdlib\v1.1\Distributed\src\remotecall.jl:433
remotecall_wait(::Function, ::Int64, ::Module, ::Vararg{Any,N} where N) at C:\Users\julia\AppData\Local\Julia-1.1.1\share\julia\stdlib\v1.1\Distributed\src\remotecall.jl:433
(::getfield(Distributed, Symbol("##161#163")){Module,Expr})() at .\task.jl:259

...and 7 more exception(s).</strong>

in top-level scope at [stdlib\v1.1\Distributed\src\macros.jl:183](#)

in remotecall_eval at [stdlib\v1.1\Distributed\src\macros.jl:199](#)

in macro expansion at [base\task.jl:245](#)

in sync_end at [base\task.jl:226](#)

通常的解决方案:

https://discourse.julialang.org/t/packages-and-workers/14072/9

https://discourse.julialang.org/t/understanding-everywhere-and-environments/27438

似乎也没有帮助。

parallel-processing julia
1个回答
0
投票

我遇到了同样的问题,但是注释中的建议-删除Pkg.activate(".")解决了它!

通常,以下对我有用:

using Distributed addprocs(12) @everywhere begin ...all using statements... end

我正在运行Julia版本1.0.5

© www.soinside.com 2019 - 2024. All rights reserved.