Skip to content

Commit a0e39a9

Browse files
committedNov 25, 2024
Update test_bmark.jl
using spwan instead of threads
1 parent 083b88e commit a0e39a9

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed
 

‎src/bmark_solvers.jl

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,22 @@ Any keyword argument accepted by `solve_problems`
2222
A Dict{Symbol, AbstractExecutionStats} of statistics.
2323
"""
2424
function bmark_solvers(solvers::Dict{Symbol, <:Any}, args...; kwargs...)
25+
tasks = Vector{Task}(undef, length(solvers))
26+
names = Vector{Symbol}(undef, length(solvers))
27+
idx = 0
28+
for (name, solver) in solvers
29+
idx += 1
30+
names[idx] = name
31+
tasks[idx] = Threads.@spawn begin
32+
@info "running solver $name"
33+
solve_problems(solver, name, args...; kwargs...)
34+
end
35+
end
36+
2537
stats = Dict{Symbol, DataFrame}()
26-
# Initialize the lock for thread-safe updates
27-
my_lock = ReentrantLock()
28-
key_array = collect(keys(solvers)) # Convert keys to an array for indexing
29-
30-
Threads.@threads for i in eachindex(key_array)
31-
name = key_array[i]
32-
solver = solvers[name]
33-
@info "Running solver $name on thread $(Threads.threadid())"
34-
result = solve_problems(solver, name, args...; kwargs...)
35-
# Ensure thread-safe access to `stats`
36-
lock(my_lock) do
37-
stats[name] = result
38-
end
38+
for i in 1:length(tasks)
39+
result = fetch(tasks[i])
40+
stats[names[i]] = result
3941
end
4042
return stats
4143
end

‎test/test_bmark.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function test_bmark()
9797
]
9898
callable = CallableSolver()
9999
solvers = Dict(
100-
:dummy => dummy_solver,
100+
:dummy_1 => dummy_solver,
101101
:callable => callable,
102102
:dummy_solver_specific =>
103103
nlp -> dummy_solver(

0 commit comments

Comments
 (0)