Skip to content

Commit 2e2e1b9

Browse files
committed
Allow parallel parametrization computations
1 parent e333753 commit 2e2e1b9

2 files changed

Lines changed: 53 additions & 6 deletions

File tree

src/algorithms/solvers.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ function _core_msolve(
187187
la_option::Int=2, # linear algebra option
188188
get_param::Int=1, # get rational parametrization
189189
info_level::Int=0, # info level for print outs
190-
precision::Int=32 # precision of the solution set
190+
precision::Int=32, # precision of the solution set
191+
worker_pool::Union{Nothing,AbstractWorkerPool}=nothing, # worker pool for parallel computation
191192
)
192193

193194
F = I.gens
@@ -207,9 +208,14 @@ function _core_msolve(
207208
# convert Singular ideal to flattened arrays of ints
208209
lens, cfs, exps, nr_gens = _convert_to_msolve(F)
209210

210-
jl_len, jl_vnames, jl_cf_lf, jl_cf, jl_sols_num, jl_sols_den =
211-
_core_msolve_array(lens, cfs, exps, variable_names, field_char;
212-
initial_hts, nr_thrds, max_nr_pairs, la_option, get_param, info_level, precision)
211+
run_core_array = () -> _core_msolve_array(lens, cfs, exps, variable_names, field_char;
212+
initial_hts, nr_thrds, max_nr_pairs, la_option, get_param, info_level, precision)
213+
214+
jl_len, jl_vnames, jl_cf_lf, jl_cf, jl_sols_num, jl_sols_den = if isnothing(worker_pool)
215+
run_core_array()
216+
else
217+
remotecall_fetch(run_core_array, worker_pool)
218+
end
213219

214220
# convert to julia array, also give memory management to julia
215221
jl_ld = Int32(length(jl_len))
@@ -490,7 +496,8 @@ function real_solutions(
490496
la_option::Int=2, # linear algebra option
491497
info_level::Int=0, # info level for print outs
492498
precision::Int=32, # precision of the solution set
493-
interval::Bool=false # return real solutions as intervals
499+
interval::Bool=false, # return real solutions as intervals
500+
worker_pool::Union{Nothing,AbstractWorkerPool}=nothing, # worker pool for parallel computation
494501
)
495502

496503
isdefined(I, :real_sols) ||
@@ -500,7 +507,8 @@ function real_solutions(
500507
max_nr_pairs = max_nr_pairs,
501508
la_option = la_option,
502509
info_level = info_level,
503-
precision = precision)
510+
precision = precision,
511+
worker_pool = worker_pool)
504512

505513
if interval
506514
return I.inter_sols

test/algorithms/solvers.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Distributed
2+
13
@testset "Algorithms -> Solvers" begin
24
R, (x1,x2,x3,x4) = polynomial_ring(QQ,["x1","x2","x3","x4"], internal_ordering=:degrevlex)
35
I = Ideal([x1 + 2*x2 + 2*x3 + 2*x4 - 1,
@@ -122,3 +124,40 @@ end
122124
@test (res_len, res_vnames, res_cf_lf, res_cf, res_sols_num, res_sols_den) == AlgebraicSolving._core_msolve_array(
123125
lens, cfs, exps, variable_names, field_char; get_param=2)
124126
end
127+
128+
@testset "Algorithms -> Solvers with workers" begin
129+
R, (x, y) = polynomial_ring(QQ, ["x", "y"])
130+
131+
F1 = [x - 1, y + 2, R(0)]
132+
H1 = Vector{QQFieldElem}[
133+
[1, -2]
134+
]
135+
136+
F2 = [x^2 - 1, y]
137+
H2 = Vector{QQFieldElem}[
138+
[-1, 0],
139+
[1, 0]
140+
]
141+
142+
F3 = [x^2 - 1, y^2]
143+
H3 = H2
144+
145+
nb_tests = 42
146+
F = [F1, F2, F3]
147+
G = Vector{Vector{Vector{QQFieldElem}}}(undef, nb_tests)
148+
H = [H1, H2, H3]
149+
150+
nb_workers = 2
151+
worker_ids = addprocs(nb_workers; exeflags="--project=$(Base.active_project())")
152+
@everywhere worker_ids using AlgebraicSolving
153+
worker_pool = WorkerPool(worker_ids)
154+
155+
Threads.@threads for i in 1:nb_tests
156+
G[i] = real_solutions(Ideal(F[i%3+1]), worker_pool=worker_pool)
157+
end
158+
for i in 1:nb_tests
159+
@test issetequal(G[i], H[i%3+1])
160+
end
161+
162+
rmprocs(worker_ids)
163+
end

0 commit comments

Comments
 (0)