MCPcopy Create free account
hub / github.com/OpenSees/OpenSees / main

Function main

EXAMPLES/SolverBenchmark/benchmark_python_sparse_eigen.py:356–517  ·  view source on GitHub ↗

Run benchmarks and output CSV.

()

Source from the content-addressed store, hash-verified

354
355
356def main():
357 """Run benchmarks and output CSV."""
358 if len(sys.argv) < 2:
359 print(f"Usage: python {FILENAME} <output.csv>")
360 sys.exit(1)
361
362 # Handle output CSV path: if simple filename, store in script directory
363 output_arg = sys.argv[1]
364 if '/' not in output_arg and '\\' not in output_arg:
365 # Simple filename, store in script directory
366 output_csv = SCRIPT_DIR / output_arg
367 else:
368 # Path provided, use as-is
369 output_csv = Path(output_arg)
370
371 output_csv.parent.mkdir(parents=True, exist_ok=True)
372
373 # Solver configurations: (name, run_function)
374 solvers = [
375 ("genBandArpack", run_gen_band_arpack),
376 ("fullGenLapack", run_full_gen_lapack),
377 ("SciPyEigsh", run_scipy_eigsh),
378 ]
379
380 # Known problematic solver/mesh factor thresholds that cause segmentation faults or are too large
381 # Format: solver_name -> mesh_factor limit (skip if mesh_factor >= limit)
382 SKIP_LIMITS = {
383 "fullGenLapack": 4.0,
384 }
385
386 # Mesh refinement factors
387 mesh_factors = [1.0, 2.0, 3.0, 4.0]
388
389 print("\n=== Python Sparse Eigen Solver Benchmark ===")
390 print(f"Comparing: {[s[0] for s in solvers]}")
391 print(f"Mesh factors: {mesh_factors}")
392 print(f"Results will be written to: {output_csv}\n")
393
394 with output_csv.open("w", newline="") as csvfile:
395 writer = csv.writer(csvfile)
396 writer.writerow(CSV_HEADER)
397
398 for mesh_factor in mesh_factors:
399 mesh_size, counts = counts_from_mesh_factor(mesh_factor)
400 mesh_info_printed = False
401
402 for solver_name, solver_run in solvers:
403 # Skip if mesh_factor exceeds the limit for this solver
404 limit = SKIP_LIMITS.get(solver_name, float('inf'))
405 if mesh_factor >= limit:
406 # Write skipped row
407 writer.writerow((
408 solver_name,
409 mesh_factor,
410 mesh_size,
411 -1, # num_elements
412 -1, # num_nodes
413 -1, # num_equations

Calls 6

printFunction · 0.85
counts_from_mesh_factorFunction · 0.70
run_benchmarkFunction · 0.70
openMethod · 0.45
getMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected