This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Check contact pair performance smoke stats across OpenMP thread counts."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
METRICS = (
|
||||
"active_count",
|
||||
"search_facets",
|
||||
"search_masters",
|
||||
"search_broad",
|
||||
"search_active",
|
||||
"bvh_nodes",
|
||||
"cache_used",
|
||||
)
|
||||
|
||||
|
||||
def run_case(source_root: Path, executable: Path, threads: int) -> dict[str, int]:
|
||||
env = os.environ.copy()
|
||||
env["OMP_NUM_THREADS"] = str(threads)
|
||||
proc = subprocess.run(
|
||||
[str(executable), "32", "1"],
|
||||
cwd=source_root,
|
||||
env=env,
|
||||
text=True,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
check=False,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
print(proc.stdout, end="")
|
||||
raise SystemExit(
|
||||
f"perf_contact_pair failed for OMP_NUM_THREADS={threads}: "
|
||||
f"exit {proc.returncode}"
|
||||
)
|
||||
return parse_metrics(proc.stdout, threads)
|
||||
|
||||
|
||||
def parse_metrics(output: str, threads: int) -> dict[str, int]:
|
||||
values: dict[str, int] = {}
|
||||
for line in output.splitlines():
|
||||
match = re.match(r"\s*([A-Za-z_]+):\s+([-+]?\d+)\s*$", line)
|
||||
if match and match.group(1) in METRICS:
|
||||
values[match.group(1)] = int(match.group(2))
|
||||
|
||||
missing = [metric for metric in METRICS if metric not in values]
|
||||
if missing:
|
||||
print(output, end="")
|
||||
raise SystemExit(
|
||||
f"missing metrics for OMP_NUM_THREADS={threads}: {', '.join(missing)}"
|
||||
)
|
||||
if values["active_count"] <= 0:
|
||||
raise SystemExit(f"no active contact for OMP_NUM_THREADS={threads}")
|
||||
if values["cache_used"] <= 0:
|
||||
raise SystemExit(f"no BVH cache use for OMP_NUM_THREADS={threads}")
|
||||
return values
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
if len(argv) != 3:
|
||||
print(
|
||||
"usage: check_perf_contact_pair_omp.py <source-root> "
|
||||
"<perf_contact_pair-exe>"
|
||||
)
|
||||
return 2
|
||||
|
||||
source_root = Path(argv[1]).resolve()
|
||||
executable = Path(argv[2]).resolve()
|
||||
serial = run_case(source_root, executable, 1)
|
||||
parallel = run_case(source_root, executable, 4)
|
||||
|
||||
mismatches = [
|
||||
metric
|
||||
for metric in METRICS
|
||||
if serial[metric] != parallel[metric]
|
||||
]
|
||||
if mismatches:
|
||||
print("OpenMP contact performance statistics differ:")
|
||||
for metric in mismatches:
|
||||
print(
|
||||
f" {metric}: OMP=1 {serial[metric]}, "
|
||||
f"OMP=4 {parallel[metric]}"
|
||||
)
|
||||
return 1
|
||||
|
||||
print("perf_contact_pair OpenMP consistency: PASS")
|
||||
for metric in METRICS:
|
||||
print(f" {metric}: {serial[metric]}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv))
|
||||
@@ -18,6 +18,7 @@ def parse_args() -> argparse.Namespace:
|
||||
parser.add_argument("--dynamic-steps", type=int, default=0)
|
||||
parser.add_argument("--output-interval", type=int, default=0)
|
||||
parser.add_argument("--require-contact", action="store_true")
|
||||
parser.add_argument("--require-friction", action="store_true")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
@@ -95,11 +96,39 @@ def check_contact_output(build_dir: Path, case_name: str, step: int) -> None:
|
||||
raise RuntimeError(f"{contact_file} did not record active contact")
|
||||
|
||||
|
||||
def check_friction_output(build_dir: Path, case_name: str, step: int) -> None:
|
||||
contact_file = build_dir / "example_smoke" / case_name / f"contact_{step:08d}.csv"
|
||||
if not contact_file.exists():
|
||||
raise RuntimeError(f"missing contact output: {contact_file}")
|
||||
|
||||
with contact_file.open(newline="", encoding="utf-8") as handle:
|
||||
rows = [row for row in csv.DictReader(handle) if row.get("kind") == "PAIR"]
|
||||
if not rows:
|
||||
raise RuntimeError(f"{contact_file} does not contain contact pair rows")
|
||||
|
||||
max_slip = max(float(row["accumulated_slip"]) for row in rows)
|
||||
max_work = max(float(row["friction_work_total"]) for row in rows)
|
||||
min_work = min(float(row["friction_work_total"]) for row in rows)
|
||||
max_reg = max(float(row["friction_regularization"]) for row in rows)
|
||||
max_ft = max(
|
||||
max(abs(float(row["ftx"])), abs(float(row["fty"])), abs(float(row["ftz"])))
|
||||
for row in rows
|
||||
)
|
||||
if max_reg <= 0.0:
|
||||
raise RuntimeError(f"{contact_file} did not report friction regularization")
|
||||
if max_slip <= 0.0 or max_ft <= 0.0:
|
||||
raise RuntimeError(f"{contact_file} did not record frictional slip")
|
||||
if min_work < -1.0e-12 or max_work <= 0.0:
|
||||
raise RuntimeError(f"{contact_file} did not record positive friction work")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
args = parse_args()
|
||||
_, steps = run_case(args)
|
||||
if args.require_contact:
|
||||
check_contact_output(Path(args.build_dir).resolve(), args.case_name, steps)
|
||||
if args.require_friction:
|
||||
check_friction_output(Path(args.build_dir).resolve(), args.case_name, steps)
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user