Run benchmarks and output CSV.
()
| 318 | |
| 319 | |
| 320 | def main(): |
| 321 | """Run benchmarks and output CSV.""" |
| 322 | if len(sys.argv) < 2: |
| 323 | print(f"Usage: python {FILENAME} <output.csv>") |
| 324 | sys.exit(1) |
| 325 | |
| 326 | # Handle output CSV path: if simple filename, store in script directory |
| 327 | output_arg = sys.argv[1] |
| 328 | if '/' not in output_arg and '\\' not in output_arg: |
| 329 | # Simple filename, store in script directory |
| 330 | output_csv = SCRIPT_DIR / output_arg |
| 331 | else: |
| 332 | # Path provided, use as-is |
| 333 | output_csv = Path(output_arg) |
| 334 | |
| 335 | output_csv.parent.mkdir(parents=True, exist_ok=True) |
| 336 | |
| 337 | # Solver configurations: (name, setup_function, numberer) |
| 338 | solvers = [ |
| 339 | ("BandSPD", setup_bandspd, "RCM"), |
| 340 | ("UmfPack", setup_umfpack, "Plain"), |
| 341 | ("CuPyCG", setup_cupy_cg, "RCM"), |
| 342 | ] |
| 343 | |
| 344 | # Known problematic solver/mesh factor thresholds that cause segmentation faults or are too large |
| 345 | # Format: solver_name -> mesh_factor limit (skip if mesh_factor >= limit) |
| 346 | SKIP_LIMITS = { |
| 347 | "UmfPack": 14.0, |
| 348 | "BandSPD": 20.0, |
| 349 | } |
| 350 | |
| 351 | # Mesh refinement factors |
| 352 | mesh_factors = [2.0, 4.0, 6.0, 8.0, 10.0, 12.0, 14.0, 16.0, 18.0, 20.0, 22.0, 24.0, 26.0] |
| 353 | |
| 354 | print("\n=== Python Sparse Solver Benchmark ===") |
| 355 | print(f"Comparing: {[s[0] for s in solvers]}") |
| 356 | print(f"Mesh factors: {mesh_factors}") |
| 357 | print(f"Results will be written to: {output_csv}\n") |
| 358 | |
| 359 | with output_csv.open("w", newline="") as csvfile: |
| 360 | writer = csv.writer(csvfile) |
| 361 | writer.writerow(CSV_HEADER) |
| 362 | |
| 363 | for mesh_factor in mesh_factors: |
| 364 | mesh_size, counts = counts_from_mesh_factor(mesh_factor) |
| 365 | mesh_info_printed = False |
| 366 | |
| 367 | for solver_name, solver_setup, numberer in solvers: |
| 368 | # Skip if mesh_factor exceeds the limit for this solver |
| 369 | limit = SKIP_LIMITS.get(solver_name, float('inf')) |
| 370 | if mesh_factor >= limit: |
| 371 | # Write skipped row |
| 372 | writer.writerow(( |
| 373 | solver_name, |
| 374 | mesh_factor, |
| 375 | mesh_size, |
| 376 | -1, # num_elements |
| 377 | -1, # num_nodes |
no test coverage detected