From f114eeec7759ff5f9c55bf8f3d768d89998dcf48 Mon Sep 17 00:00:00 2001 From: Francesco Minnocci Date: Thu, 28 Sep 2023 20:13:21 +0200 Subject: [PATCH] Add ClusterManagers --- solve.jl | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/solve.jl b/solve.jl index 597ee90..51cadde 100644 --- a/solve.jl +++ b/solve.jl @@ -2,6 +2,7 @@ using TypedPolynomials using LinearAlgebra using Distributed +using ClusterManagers # Local dependencies include("random_poly.jl") @@ -18,36 +19,36 @@ using .AdaptStep using .Plot # Launch worker processes -num_cores = parse(Int, ENV["SLURM_CPUS_PER_TASK"]) -addprocs(num_cores) +addprocs(SlurmManager(40), N=20, t="01:00:00")) + +function compute_root(H, r, maxsteps) + t = 1.0 + step_size = 0.01 + x0 = r + m = 0 + steps = 0 + + while t > 0 && steps < maxsteps + x0 = en_step(H, x0, t, step_size) + (m, step_size) = adapt_step(H, x0, t, step_size, m) + t -= step_size + steps += 1 + end + return (x0, steps) +end # Main homotopy continuation loop -function solve(F, (G, roots) = start_system(F), maxsteps = 1000) +function solve(F, (G, roots) = start_system(F)) H=homotopy(F,G) - solutions = [] - step_array = [] @distributed for r in roots - t = 1.0 - step_size = 0.01 - x0 = r - m = 0 - steps = 0 - - while t > 0 && steps < maxsteps - x0 = en_step(H, x0, t, step_size) - (m, step_size) = adapt_step(H, x0, t, step_size, m) - t -= step_size - steps += 1 - end - push!(solutions, x0) - push!(step_array, steps) + (solutions, step_array) = compute_root(H, r, maxsteps = 1000) end # Gather results from worker processes - solutions = fetch(solutions) - step_array = fetch(step_array) - return (solutions, step_array) + sols = fetch(solutions) + steps = fetch(step_array) + return (sols, steps) end # Input polynomial systems