@@ -22,20 +22,22 @@ Any keyword argument accepted by `solve_problems`
22
22
A Dict{Symbol, AbstractExecutionStats} of statistics.
23
23
"""
24
24
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
+
25
37
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
39
41
end
40
42
return stats
41
43
end
0 commit comments