Skip to content

Commit 38b7f08

Browse files
authored
Issue with OGGM multiprocessing fixed (#46)
* Multiprocessing fixed for OGGM * Bug fixed
1 parent b654e78 commit 38b7f08

File tree

4 files changed

+37
-57
lines changed

4 files changed

+37
-57
lines changed

src/parameters/OGGMparameters.jl

+5-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

2-
struct OGGMparameters <: AbstractParameters
2+
export oggm_config
3+
4+
struct OGGMparameters <: AbstractParameters
35
working_dir::String
46
paths::Union{PyDict, Nothing}
57
params::Union{PyDict, Nothing}
@@ -41,26 +43,6 @@ function OGGMparameters(;
4143
)
4244

4345
@assert ((ice_thickness_source == "Millan22") || (ice_thickness_source == "Farinotti19")) "Wrong ice thickness source! Should be either `Millan22` or `Farinotti19`."
44-
# initialize OGGM configuration
45-
cfg.initialize()
46-
47-
if isnothing(paths) && !test
48-
paths = PyDict(cfg."PATHS") # OGGM PATHS
49-
paths["working_dir"] = working_dir # Choose own custom path for the OGGM data
50-
end
51-
if isnothing(params) && !test
52-
params = PyDict(cfg."PARAMS")
53-
params["hydro_month_nh"]=1
54-
params["dl_verify"] = false
55-
params["continue_on_error"] = true # avoid stopping when a task fails for a glacier (e.g. lack of data)
56-
57-
# Multiprocessing
58-
params["use_multiprocessing"] = multiprocessing # Let's use multiprocessing for OGGM
59-
if multiprocessing
60-
params["mp_processes"] = workers
61-
end
62-
63-
end
6446

6547
# Build the OGGM parameters and configuration
6648
OGGM_parameters = OGGMparameters(working_dir, paths, params,
@@ -83,7 +65,7 @@ Configures the basic paths and parameters for OGGM.
8365
function oggm_config(working_dir=joinpath(homedir(), "OGGM/OGGM_data"); oggm_processes=1)
8466
@eval begin
8567
@everywhere begin
86-
@eval ODINN begin
68+
@eval Sleipnir begin
8769
cfg.initialize() # initialize OGGM configuration
8870

8971
PATHS = PyDict(cfg."PATHS") # OGGM PATHS
@@ -102,12 +84,8 @@ function oggm_config(working_dir=joinpath(homedir(), "OGGM/OGGM_data"); oggm_pro
10284

10385

10486

105-
end # @eval ODINN
87+
end # @eval Sleipnir
10688
end # @everywhere
10789
end # @eval
10890

109-
@eval ODINN begin
110-
111-
end # @eval ODINN
112-
11391
end

src/parameters/Parameters.jl

+11-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ function Parameters(;
3535
OGGM::OGGMparameters = OGGMparameters()
3636
)
3737

38-
# Build the parameters based on all the subtypes of parameters
39-
parameters = Parameters(physical, simulation, OGGM,
40-
nothing,nothing, nothing)
41-
42-
return parameters
38+
# Build the parameters based on all the subtypes of parameters
39+
parameters = Parameters(physical, simulation, OGGM,
40+
nothing,nothing, nothing)
41+
42+
if parameters.simulation.multiprocessing
43+
enable_multiprocessing(parameters.simulation.workers)
44+
end
45+
46+
oggm_config(OGGM.working_dir; oggm_processes=OGGM.workers)
47+
48+
return parameters
4349
end
4450

4551
Base.:(==)(a::Parameters, b::Parameters) = a.physical == b.physical && a.simulation == b.simulation && a.OGGM == b.OGGM &&

src/parameters/SimulationParameters.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function SimulationParameters(;
6262

6363
if !ispath(working_dir)
6464
mkpath(joinpath(working_dir, "data"))
65-
end
65+
end
6666

6767
return simulation_parameters
6868
end

src/setup/config.jl

+20-24
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,26 @@ function clean()
4343
exit()
4444
end
4545

46-
# """
47-
# Initialize_ODINN(processes, python_path)
46+
function enable_multiprocessing(procs::Int)
47+
if procs > 0
48+
if nprocs() < procs
49+
@eval begin
50+
addprocs($procs - nprocs(); exeflags="--project")
51+
println("Number of cores: ", nprocs())
52+
println("Number of workers: ", nworkers())
53+
@everywhere using Sleipnir
54+
end # @eval
55+
elseif nprocs() != procs && procs == 1
56+
@eval begin
57+
rmprocs(workers(), waitfor=0)
58+
println("Number of cores: ", nprocs())
59+
println("Number of workers: ", nworkers())
60+
end # @eval
61+
end
62+
end
63+
return nworkers()
64+
end
65+
4866

49-
# Initializes ODINN by configuring PyCall based on a given Python path. It also configures multiprocessing
50-
# for a given number of processes.
51-
# """
52-
# function enable_multiprocessing(procs::Int)
53-
# if procs > 0
54-
# if nprocs() < procs
55-
# @eval begin
56-
# addprocs($procs - nprocs(); exeflags="--project")
57-
# println("Number of cores: ", nprocs())
58-
# println("Number of workers: ", nworkers())
59-
# @everywhere using ODINN
60-
# end # @eval
61-
# elseif nprocs() != procs && procs == 1
62-
# @eval begin
63-
# rmprocs(workers(), waitfor=0)
64-
# println("Number of cores: ", nprocs())
65-
# println("Number of workers: ", nworkers())
66-
# end # @eval
67-
# end
68-
# end
69-
# return nworkers()
70-
# end
7167

7268
include("helper_utilities.jl")

0 commit comments

Comments
 (0)