@@ -95,8 +95,9 @@ function benchmark_algorithms(matrix_sizes, algorithms, alg_names, eltypes;
95
95
# Initialize results DataFrame
96
96
results_data = []
97
97
98
- # Track algorithms that have timed out (per element type)
99
- timed_out_algorithms = Dict {String, Set{String}} () # eltype => Set of algorithm names
98
+ # Track algorithms that have exceeded maxtime (per element type and size)
99
+ # Structure: eltype => algorithm_name => max_size_tested
100
+ blocked_algorithms = Dict {String, Dict{String, Int}} () # eltype => Dict(algorithm_name => max_size)
100
101
101
102
# Calculate total number of benchmarks for progress bar
102
103
total_benchmarks = 0
@@ -112,8 +113,8 @@ function benchmark_algorithms(matrix_sizes, algorithms, alg_names, eltypes;
112
113
113
114
try
114
115
for eltype in eltypes
115
- # Initialize timed out set for this element type
116
- timed_out_algorithms [string (eltype)] = Set {String} ()
116
+ # Initialize blocked algorithms dict for this element type
117
+ blocked_algorithms [string (eltype)] = Dict {String, Int } ()
117
118
118
119
# Filter algorithms for this element type
119
120
compatible_algs, compatible_names = filter_compatible_algorithms (algorithms, alg_names, eltype)
@@ -143,32 +144,35 @@ function benchmark_algorithms(matrix_sizes, algorithms, alg_names, eltypes;
143
144
end
144
145
145
146
for (alg, name) in zip (compatible_algs, compatible_names)
146
- # Skip this algorithm if it has already timed out for this element type
147
- if name in timed_out_algorithms[string (eltype)]
148
- # Still need to update progress bar
149
- ProgressMeter. next! (progress)
150
- # Record as skipped due to previous timeout
151
- push! (results_data,
152
- (
153
- size = n,
154
- algorithm = name,
155
- eltype = string (eltype),
156
- gflops = NaN ,
157
- success = false ,
158
- error = " Skipped: timed out on smaller matrix"
159
- ))
160
- continue
147
+ # Skip this algorithm if it has exceeded maxtime for a smaller or equal size matrix
148
+ if haskey (blocked_algorithms[string (eltype)], name)
149
+ max_allowed_size = blocked_algorithms[string (eltype)][name]
150
+ if n > max_allowed_size
151
+ # Still need to update progress bar
152
+ ProgressMeter. next! (progress)
153
+ # Record as skipped due to exceeding maxtime on smaller matrix
154
+ push! (results_data,
155
+ (
156
+ size = n,
157
+ algorithm = name,
158
+ eltype = string (eltype),
159
+ gflops = NaN ,
160
+ success = false ,
161
+ error = " Skipped: exceeded maxtime on size $max_allowed_size matrix"
162
+ ))
163
+ continue
164
+ end
161
165
end
162
166
163
167
# Update progress description
164
168
ProgressMeter. update! (progress,
165
169
desc= " Benchmarking $name on $(n) ×$(n) $eltype matrix: " )
166
170
167
- gflops = NaN # Use NaN for timed out runs
171
+ gflops = NaN # Use NaN for failed/ timed out runs
168
172
success = true
169
173
error_msg = " "
170
174
passed_correctness = true
171
- timed_out = false
175
+ exceeded_maxtime = false
172
176
173
177
try
174
178
# Create the linear problem for this test
@@ -179,69 +183,25 @@ function benchmark_algorithms(matrix_sizes, algorithms, alg_names, eltypes;
179
183
# Time the warmup run and correctness check
180
184
start_time = time ()
181
185
182
- # Warmup run and correctness check with simple timeout
186
+ # Warmup run and correctness check - no interruption, just timing
183
187
warmup_sol = nothing
184
- timed_out_flag = false
185
188
186
- # Try to run with a timeout - simpler approach without async
187
- try
188
- # Create a task for the solve
189
- done_channel = Channel (1 )
190
- error_channel = Channel (1 )
191
-
192
- warmup_task = @async begin
193
- try
194
- result = solve (prob, alg)
195
- put! (done_channel, result)
196
- catch e
197
- put! (error_channel, e)
198
- end
199
- end
200
-
201
- # Wait for completion or timeout
202
- timeout_occurred = false
203
- result = nothing
204
-
205
- # Use timedwait which is more reliable than manual polling
206
- wait_result = timedwait (() -> istaskdone (warmup_task), maxtime)
207
-
208
- if wait_result === :timed_out
209
- timeout_occurred = true
210
- timed_out_flag = true
211
- # Don't try to kill the task - just mark it as timed out
212
- # The task will continue running in background but we move on
213
- else
214
- # Task completed - get the result
215
- if isready (done_channel)
216
- warmup_sol = take! (done_channel)
217
- elseif isready (error_channel)
218
- throw (take! (error_channel))
219
- end
220
- end
221
-
222
- # Close channels to prevent resource leaks
223
- close (done_channel)
224
- close (error_channel)
225
-
226
- catch e
227
- # If an error occurred during solve, re-throw it
228
- if ! timed_out_flag
229
- throw (e)
230
- end
231
- end
189
+ # Simply run the solve and measure time
190
+ warmup_sol = solve (prob, alg)
191
+ elapsed_time = time () - start_time
232
192
233
- if timed_out_flag
234
- # Task timed out
235
- timed_out = true
236
- # Add to timed out set so it's skipped for larger matrices
237
- push! (timed_out_algorithms[string (eltype)], name)
238
- @warn " Algorithm $name timed out (exceeded $(maxtime) s) for size $n , eltype $eltype . Will skip for larger matrices."
193
+ # Check if we exceeded maxtime
194
+ if elapsed_time > maxtime
195
+ exceeded_maxtime = true
196
+ # Block this algorithm for larger matrices
197
+ # Store the last size that was allowed to complete
198
+ blocked_algorithms[string (eltype)][name] = n
199
+ @warn " Algorithm $name exceeded maxtime ($(round (elapsed_time, digits= 2 )) s > $(maxtime) s) for size $n , eltype $eltype . Will skip for larger matrices."
239
200
success = false
240
- error_msg = " Timed out (exceeded $(maxtime ) s)"
201
+ error_msg = " Exceeded maxtime ( $( round (elapsed_time, digits = 2 ) ) s)"
241
202
gflops = NaN
242
203
else
243
- # Successful completion
244
- elapsed_time = time () - start_time
204
+ # Successful completion within time limit
245
205
246
206
# Check correctness if reference solution is available
247
207
if check_correctness && reference_solution != = nothing
@@ -259,8 +219,8 @@ function benchmark_algorithms(matrix_sizes, algorithms, alg_names, eltypes;
259
219
end
260
220
end
261
221
262
- # Only benchmark if correctness check passed and we have time remaining
263
- if passed_correctness && ! timed_out
222
+ # Only benchmark if correctness check passed and we didn't exceed maxtime
223
+ if passed_correctness && ! exceeded_maxtime
264
224
# Check if we have enough time remaining for benchmarking
265
225
# Allow at least 2x the warmup time for benchmarking
266
226
remaining_time = maxtime - elapsed_time
0 commit comments