diff --git a/.ergo/plans.jsonl b/.ergo/plans.jsonl index 42f7719..fc55958 100644 --- a/.ergo/plans.jsonl +++ b/.ergo/plans.jsonl @@ -324,3 +324,39 @@ {"type":"state","ts":"2026-05-10T04:24:19.571118Z","data":{"id":"6RCV3S","state":"doing","ts":"2026-05-10T04:24:19.571118Z"}} {"type":"result","ts":"2026-05-10T04:28:23.977868Z","data":{"task_id":"6RCV3S","summary":"Fixed MB04QC TRANQ=N path; strict Fortran differential and combined parity batch pass.","path":"tests/python/test_mb04qc.py","sha256_at_attach":"96e0d8b7ff4c2854b310dbf585349a9a645e545ca626325677ee9c919a895550","mtime_at_attach":"2026-05-10T04:27:58.743315138Z","git_commit_at_attach":"984b015bf393e4666b5aff924bb3830b2717c073","ts":"2026-05-10T04:28:23.977868Z"}} {"type":"state","ts":"2026-05-10T04:28:23.980356Z","data":{"id":"6RCV3S","state":"done","ts":"2026-05-10T04:28:23.980356Z"}} +{"type":"new_epic","ts":"2026-05-11T00:06:30.339617Z","data":{"id":"ODU564","uuid":"d594fdb1-f877-4fc5-a92f-d6db19b3ff3c","epic_id":"","state":"todo","title":"Improve C11 Lyapunov benchmark-generator performance","body":"## Scope\n- Improve C11 speed for benchmark cases where the Fortran reference is faster, based on `benchmark_c_vs_fortran_report.md` generated 2026-05-10.\n- Primary targets are `BB04AD` and `BB03AD` group-4 Lyapunov benchmark generators, especially examples 4.1 and 4.2.\n- Keep numerical outputs and wrapper behavior unchanged.\n\n## Non-goals\n- Do not change public Python APIs.\n- Do not optimize solver routines (`SB02MD`, `SB02OD`, `SB03MD`, `SB03OD`) in this epic unless profiling shows the generator changes are no longer the bottleneck.\n- Do not commit generated benchmark reports unless they are intentionally used as documentation or PR evidence.\n\n## Key Decisions And Assumptions\n- Start from the measured worst gaps: `BB04AD ex4.2 n=30` at 2.59x Fortran advantage, `BB04AD ex4.1 n=20` at 2.51x, and `BB03AD ex4.2 n=30` at 2.25x.\n- Prioritize algorithm-preserving micro-optimizations: replacing repeated `pow()` calls in inner loops with recurrence/precomputed scale vectors, reducing avoidable full-matrix initialization, and preserving column-major access.\n- Performance claims must compare against a saved pre-change baseline from the same machine and build mode.\n\nUnresolved questions: none","created_at":"2026-05-11T00:06:30.339617Z"}} +{"type":"new_task","ts":"2026-05-11T00:06:30.339653Z","data":{"id":"LRPA6F","uuid":"b0eb7fa7-dfc7-4885-b21e-6d73cf656939","epic_id":"ODU564","state":"todo","title":"spike: profile BB03AD and BB04AD Fortran-faster cases","body":"## Goal\n- Establish a clean baseline and identify the hottest operations in the C11 paths where Fortran is faster.\n- Produce enough evidence to choose the first code optimization without guessing.\n\n## Context\n- Use the fresh benchmark build pattern already proven locally: `build-bench-c` with `-Dbuild_benchmarks=true` and the Fortran reference in `SLICOT-Reference/build_bench`.\n- Measured slow rows are concentrated in `BB03AD` and `BB04AD`, not the Riccati or descriptor generator rows.\n\n## Acceptance Criteria\n- Capture baseline timings for `bb03ad` and `bb04ad` from `scripts/benchmark_c_vs_fortran.py` or direct native executables.\n- Identify whether repeated `pow()` scaling, full-matrix initialization, BLAS call overhead, or another source dominates `ex4.1`/`ex4.2`.\n- Update the dependent optimization tasks with any changed target if profiling disproves the initial `pow()` hypothesis.\n\n## Validation Gates\n- `.venv/bin/meson setup build-bench-c -Dbuild_benchmarks=true --wipe`\n- `.venv/bin/meson compile -C build-bench-c`\n- `.venv/bin/python scripts/benchmark_c_vs_fortran.py --c-build-dir build-bench-c --output benchmark_c_vs_fortran_report.md -r bb03ad bb04ad`","created_at":"2026-05-11T00:06:30.339653Z"}} +{"type":"new_task","ts":"2026-05-11T00:06:30.339657Z","data":{"id":"JZW4XW","uuid":"60bc77c2-62e8-4eee-beb5-6cc95fcac4bc","epic_id":"ODU564","state":"todo","title":"Optimize BB04AD group-4 scaling paths","body":"## Goal\n- Reduce runtime for `BB04AD` examples 4.1 and 4.2 without changing numerical outputs.\n- Target the worst measured Fortran advantage first, then confirm there is no regression in examples 4.3 and 4.4.\n\n## Context\n- Current measured worst rows include `BB04AD ex4.2 n=30` where C11 was 31.03 us and Fortran was 12.00 us, and `BB04AD ex4.1 n=20` where C11 was 16.06 us and Fortran was 6.40 us.\n- Likely first patch is replacing repeated `pow(dpar[1], i-j)` and related per-element exponentiation with recurrence or precomputed scale vectors in `src/BB/bb04ad.c`.\n\n## Acceptance Criteria\n- `BB04AD ex4.1` and `ex4.2` preserve existing Python test outputs and residual properties.\n- Native `bb04ad` benchmark improves the worst targeted rows by at least 20% versus the spike baseline, or the task records evidence that the attempted optimization is not the limiting factor.\n- No `bb04ad` group-4 benchmark row regresses by more than 5% versus baseline unless explained by benchmark noise from repeated runs.\n\n## Validation Gates\n- `uv pip install .`\n- `.venv/bin/pytest tests/python/test_bb04ad.py -v`\n- `.venv/bin/meson compile -C build-bench-c`\n- `build-bench-c/benchmarks/bench_bb04ad`\n- `.venv/bin/python scripts/benchmark_c_vs_fortran.py --c-build-dir build-bench-c --output benchmark_c_vs_fortran_report.md -r bb04ad`","created_at":"2026-05-11T00:06:30.339657Z"}} +{"type":"new_task","ts":"2026-05-11T00:06:30.33966Z","data":{"id":"GRPONV","uuid":"134d70e6-c679-4de0-90d0-2f986dded064","epic_id":"ODU564","state":"todo","title":"Optimize BB03AD group-4 scaling paths","body":"## Goal\n- Reduce runtime for `BB03AD` examples 4.1 and 4.2 while preserving CTLEX outputs.\n- Keep the optimization independent from `BB04AD` unless a shared helper is clearly justified by measured duplication.\n\n## Context\n- Current measured worst rows include `BB03AD ex4.2 n=30` where C11 was 31.89 us and Fortran was 14.20 us, and `BB03AD ex4.1 n=30` where C11 was 83.07 us and Fortran was 38.80 us.\n- Likely first patch is removing repeated `pow()` calls in nested matrix scaling loops in `src/BB/bb03ad.c`.\n\n## Acceptance Criteria\n- `BB03AD ex4.1` and `ex4.2` preserve existing Python test outputs and residual properties.\n- Native `bb03ad` benchmark improves the worst targeted rows by at least 20% versus the spike baseline, or records evidence that another bottleneck must be targeted next.\n- No `bb03ad` group-4 benchmark row regresses by more than 5% versus baseline unless explained by benchmark noise from repeated runs.\n\n## Validation Gates\n- `uv pip install .`\n- `.venv/bin/pytest tests/python/test_bb03ad.py -v`\n- `.venv/bin/meson compile -C build-bench-c`\n- `build-bench-c/benchmarks/bench_bb03ad`\n- `.venv/bin/python scripts/benchmark_c_vs_fortran.py --c-build-dir build-bench-c --output benchmark_c_vs_fortran_report.md -r bb03ad`","created_at":"2026-05-11T00:06:30.33966Z"}} +{"type":"new_task","ts":"2026-05-11T00:06:30.339663Z","data":{"id":"V2VCHD","uuid":"c77192c4-5cd5-4d21-a037-2ba9fd5483c8","epic_id":"ODU564","state":"todo","title":"Add focused performance-report support for Fortran-faster rows","body":"## Goal\n- Make it easy to see remaining C11 slowdowns after each optimization pass.\n- Reduce manual parsing of `benchmark_c_vs_fortran_report.md` when deciding whether more speed work is needed.\n\n## Context\n- The current report has the raw data needed, but it does not directly summarize rows where Fortran is faster or rank them by Fortran advantage.\n- This task should improve the existing benchmark script or report output, not add a separate throwaway parser.\n\n## Acceptance Criteria\n- The generated benchmark report includes a section listing rows where Fortran is faster, sorted by largest Fortran advantage.\n- The section includes routine, dataset, size, C11 time, Fortran time, speed ratio, and absolute delta.\n- Existing report content remains intact and full comparisons still run with the documented command.\n\n## Validation Gates\n- `.venv/bin/python scripts/benchmark_c_vs_fortran.py --c-build-dir build-bench-c --output benchmark_c_vs_fortran_report.md -r bb03ad bb04ad`\n- `rg -n \"Fortran Faster|BB04AD|BB03AD\" benchmark_c_vs_fortran_report.md`","created_at":"2026-05-11T00:06:30.339663Z"}} +{"type":"new_task","ts":"2026-05-11T00:06:30.339665Z","data":{"id":"HKA3XF","uuid":"1eabfc79-66b8-4420-a691-43a3e301a051","epic_id":"ODU564","state":"todo","title":"Verify optimized Lyapunov generator performance end-to-end","body":"## Goal\n- Run the final benchmark comparison and decide whether the C11 Lyapunov generator speed issue is closed.\n- Collect the validation evidence needed for a PR or follow-up optimization tasks.\n\n## Context\n- This task depends on both code optimization slices and the improved reporting so the final result can be judged from generated evidence.\n\n## Acceptance Criteria\n- Full `bb03ad`/`bb04ad` C-vs-Fortran report is regenerated after optimization.\n- All targeted Python behavior tests pass after reinstalling the package.\n- If any `BB03AD` or `BB04AD` row remains more than 1.5x slower than Fortran, create a concrete follow-up ergo task with the measured row and suspected cause; otherwise mark the epic ready for implementation review.\n\n## Validation Gates\n- `uv pip install .`\n- `.venv/bin/pytest tests/python/test_bb03ad.py tests/python/test_bb04ad.py -v`\n- `.venv/bin/meson compile -C build-bench-c`\n- `.venv/bin/python scripts/benchmark_c_vs_fortran.py --c-build-dir build-bench-c --output benchmark_c_vs_fortran_report.md -r bb03ad bb04ad`\n- `git status --short`","created_at":"2026-05-11T00:06:30.339665Z"}} +{"type":"link","ts":"2026-05-11T00:06:30.339669Z","data":{"from_id":"JZW4XW","to_id":"LRPA6F","type":"depends"}} +{"type":"link","ts":"2026-05-11T00:06:30.339671Z","data":{"from_id":"GRPONV","to_id":"LRPA6F","type":"depends"}} +{"type":"link","ts":"2026-05-11T00:06:30.339671Z","data":{"from_id":"V2VCHD","to_id":"LRPA6F","type":"depends"}} +{"type":"link","ts":"2026-05-11T00:06:30.339674Z","data":{"from_id":"HKA3XF","to_id":"JZW4XW","type":"depends"}} +{"type":"link","ts":"2026-05-11T00:06:30.339674Z","data":{"from_id":"HKA3XF","to_id":"GRPONV","type":"depends"}} +{"type":"link","ts":"2026-05-11T00:06:30.339675Z","data":{"from_id":"HKA3XF","to_id":"V2VCHD","type":"depends"}} +{"type":"claim","ts":"2026-05-11T00:09:11.054592Z","data":{"id":"LRPA6F","agent_id":"gpt-5@codex","ts":"2026-05-11T00:09:11.054592Z"}} +{"type":"state","ts":"2026-05-11T00:09:11.054592Z","data":{"id":"LRPA6F","state":"doing","ts":"2026-05-11T00:09:11.054592Z"}} +{"type":"result","ts":"2026-05-11T00:11:15.478278Z","data":{"task_id":"LRPA6F","summary":"Baseline shows BB04AD ex4.1/ex4.2 as the remaining target; BB03AD no longer needs first-pass optimization.","path":"benchmark_c_vs_fortran_report.md","sha256_at_attach":"76d613b1690257aa50c4d91b0ef5b810bece9cc06d9356e87e777d423edde90b","mtime_at_attach":"2026-05-11T00:10:34.279902094Z","git_commit_at_attach":"295fbb9bb91a525662b65827840dc991b43f5c3b","ts":"2026-05-11T00:11:15.478278Z"}} +{"type":"body","ts":"2026-05-11T00:11:15.481036Z","data":{"id":"LRPA6F","body":"## Goal\n- Establish a clean baseline and identify the hottest operations in the C11 paths where Fortran is faster.\n- Produce enough evidence to choose the first code optimization without guessing.\n\n## Result\n- Rebuilt `build-bench-c` with `-Dbuild_benchmarks=true` and regenerated `benchmark_c_vs_fortran_report.md` for `bb03ad bb04ad`.\n- Clean rerun changed the target: `BB03AD` group-4 rows are faster than Fortran or roughly tied, so the stale BB03AD slowdown should not be optimized first.\n- Remaining focused slowdown is `BB04AD` examples 4.1 and 4.2: at `n=50`, ex4.1 is 46.99 us C11 vs 35.70 us F77 (0.76x), and ex4.2 is 43.77 us C11 vs 32.40 us F77 (0.74x).\n- Code inspection points to repeated nested `pow(dpar[1], ...)` scaling in `src/BB/bb04ad.c` examples 4.1/4.2 as the first target. The adjacent BB04AD examples without this exact nested scaling are faster or close in the same report, so full-matrix initialization and BLAS wrappers are not the first bottleneck to attack.\n\n## Validation Gates\n- `.venv/bin/meson setup build-bench-c -Dbuild_benchmarks=true --wipe`\n- `.venv/bin/meson compile -C build-bench-c`\n- `.venv/bin/python scripts/benchmark_c_vs_fortran.py --c-build-dir build-bench-c --output benchmark_c_vs_fortran_report.md -r bb03ad bb04ad`\n","ts":"2026-05-11T00:11:15.481036Z"}} +{"type":"state","ts":"2026-05-11T00:11:15.481036Z","data":{"id":"LRPA6F","state":"done","ts":"2026-05-11T00:11:15.481036Z"}} +{"type":"result","ts":"2026-05-11T00:11:23.043066Z","data":{"task_id":"GRPONV","summary":"Canceled: clean benchmark rerun no longer shows BB03AD as a Fortran-faster target.","path":"benchmark_c_vs_fortran_report.md","sha256_at_attach":"76d613b1690257aa50c4d91b0ef5b810bece9cc06d9356e87e777d423edde90b","mtime_at_attach":"2026-05-11T00:10:34.279902094Z","git_commit_at_attach":"295fbb9bb91a525662b65827840dc991b43f5c3b","ts":"2026-05-11T00:11:23.043066Z"}} +{"type":"body","ts":"2026-05-11T00:11:23.046001Z","data":{"id":"GRPONV","body":"## Goal\n- No longer optimize BB03AD as part of this epic unless a future stable benchmark again shows a real C11 slowdown.\n\n## Context\n- The profiling spike `LRPA6F` rebuilt `build-bench-c` and regenerated `benchmark_c_vs_fortran_report.md` for `bb03ad bb04ad`.\n- Current BB03AD target rows are not slower than Fortran in the clean rerun: ex4.1 n=50 is 72.57 us C11 vs 156.30 us F77, and ex4.2 n=50 is 26.85 us C11 vs 28.40 us F77.\n- The original BB03AD slowdown numbers were stale or noisy relative to the clean build rerun.\n\n## Outcome\n- Canceled by spike evidence. Keep future effort focused on BB04AD unless new benchmark evidence reopens BB03AD.\n\n## Validation Gates\n- Covered by `LRPA6F`: `.venv/bin/python scripts/benchmark_c_vs_fortran.py --c-build-dir build-bench-c --output benchmark_c_vs_fortran_report.md -r bb03ad bb04ad`\n","ts":"2026-05-11T00:11:23.046001Z"}} +{"type":"state","ts":"2026-05-11T00:11:23.046001Z","data":{"id":"GRPONV","state":"canceled","ts":"2026-05-11T00:11:23.046001Z"}} +{"type":"body","ts":"2026-05-11T00:11:34.632302Z","data":{"id":"JZW4XW","body":"## Goal\n- Reduce runtime for `BB04AD` examples 4.1 and 4.2 without changing numerical outputs.\n- Target the measured Fortran advantage first, then confirm there is no regression in examples 4.3 and 4.4.\n\n## Context\n- Spike `LRPA6F` rebuilt `build-bench-c` and regenerated `benchmark_c_vs_fortran_report.md`.\n- Current measured slow rows are `BB04AD` ex4.1/ex4.2 at larger sizes: ex4.1 n=50 is 46.99 us C11 vs 35.70 us F77 (0.76x), and ex4.2 n=50 is 43.77 us C11 vs 32.40 us F77 (0.74x).\n- First patch target remains replacing repeated `pow(dpar[1], j)` and `pow(dpar[1], i-j)` in the nested scaling loops in `src/BB/bb04ad.c` examples 4.1/4.2 with recurrence or precomputed scale vectors. Adjacent BB04AD rows without this nested scaling are faster or close, so do not start with broad initialization or BLAS wrapper changes.\n\n## Acceptance Criteria\n- `BB04AD` ex4.1 and ex4.2 preserve existing Python test outputs and residual properties.\n- Native `bb04ad` benchmark improves ex4.1/ex4.2 at n=50 by at least 15% versus the spike baseline, or records evidence that the attempted optimization is not the limiting factor.\n- No `bb04ad` group-4 benchmark row regresses by more than 5% versus baseline unless explained by benchmark noise from repeated runs.\n\n## Validation Gates\n- `uv pip install .`\n- `.venv/bin/pytest tests/python/test_bb04ad.py -v`\n- `.venv/bin/meson compile -C build-bench-c`\n- `build-bench-c/benchmarks/bench_bb04ad`\n- `.venv/bin/python scripts/benchmark_c_vs_fortran.py --c-build-dir build-bench-c --output benchmark_c_vs_fortran_report.md -r bb04ad`\n","ts":"2026-05-11T00:11:34.632302Z"}} +{"type":"claim","ts":"2026-05-11T00:11:43.668521Z","data":{"id":"JZW4XW","agent_id":"gpt-5@codex","ts":"2026-05-11T00:11:43.668521Z"}} +{"type":"state","ts":"2026-05-11T00:11:43.668521Z","data":{"id":"JZW4XW","state":"doing","ts":"2026-05-11T00:11:43.668521Z"}} +{"type":"result","ts":"2026-05-11T00:13:13.77647Z","data":{"task_id":"JZW4XW","summary":"Optimized BB04AD ex4.1/ex4.2 scaling loops; target rows now faster than Fortran.","path":"src/BB/bb04ad.c","sha256_at_attach":"f1d9f3e7349cf70c6ea3c998fdd254a747ec9e1af05d7ba6df124705271ba7cf","mtime_at_attach":"2026-05-11T00:11:56.547955339Z","git_commit_at_attach":"8dcaab95a1b5f215d0713b486c1ca2c3dda1222f","ts":"2026-05-11T00:13:13.77647Z"}} +{"type":"body","ts":"2026-05-11T00:13:13.779048Z","data":{"id":"JZW4XW","body":"## Goal\n- Reduce runtime for `BB04AD` examples 4.1 and 4.2 without changing numerical outputs.\n- Target the measured Fortran advantage first, then confirm there is no regression in examples 4.3 and 4.4.\n\n## Result\n- Replaced repeated `pow()` exponentiation in BB04AD examples 4.1 and 4.2 with recurrence-based scaling in `src/BB/bb04ad.c`.\n- Commit: `8dcaab9 perf: optimize BB04AD scaling loops`.\n- Native `bench_bb04ad` after the patch: ex4.1 n=50 = 8.21 us and ex4.2 n=50 = 6.62 us, versus spike baselines of 46.99 us and 43.77 us.\n- C-vs-Fortran report after the patch: ex4.1 n=50 = 8.97 us C11 vs 24.50 us F77, and ex4.2 n=50 = 7.25 us C11 vs 22.20 us F77.\n- Adjacent examples 4.3 and 4.4 remain faster or close in the generated report.\n\n## Validation Gates\n- `uv pip install .`\n- `.venv/bin/pytest tests/python/test_bb04ad.py -v` (15 passed)\n- `.venv/bin/meson compile -C build-bench-c`\n- `build-bench-c/benchmarks/bench_bb04ad`\n- `.venv/bin/python scripts/benchmark_c_vs_fortran.py --c-build-dir build-bench-c --output benchmark_c_vs_fortran_report.md -r bb04ad`\n","ts":"2026-05-11T00:13:13.779048Z"}} +{"type":"state","ts":"2026-05-11T00:13:13.779048Z","data":{"id":"JZW4XW","state":"done","ts":"2026-05-11T00:13:13.779048Z"}} +{"type":"claim","ts":"2026-05-11T00:13:23.678076Z","data":{"id":"V2VCHD","agent_id":"gpt-5@codex","ts":"2026-05-11T00:13:23.678076Z"}} +{"type":"state","ts":"2026-05-11T00:13:23.678076Z","data":{"id":"V2VCHD","state":"doing","ts":"2026-05-11T00:13:23.678076Z"}} +{"type":"result","ts":"2026-05-11T00:14:39.76577Z","data":{"task_id":"V2VCHD","summary":"Added sorted Fortran-faster report section with unit coverage.","path":"scripts/benchmark_c_vs_fortran.py","sha256_at_attach":"fc2f0a6895af3b543674910ea44896ab674787d53aa632fbdace4d99b3eae5bb","mtime_at_attach":"2026-05-11T00:14:01.682231665Z","git_commit_at_attach":"cca77d92b979c0d4d3a5fbe330a576cdeffcd834","ts":"2026-05-11T00:14:39.76577Z"}} +{"type":"body","ts":"2026-05-11T00:14:39.76842Z","data":{"id":"V2VCHD","body":"## Goal\n- Make it easy to see remaining C11 slowdowns after each optimization pass.\n- Reduce manual parsing of `benchmark_c_vs_fortran_report.md` when deciding whether more speed work is needed.\n\n## Result\n- Added `## Fortran Faster Rows` to `scripts/benchmark_c_vs_fortran.py`.\n- The section sorts rows by largest Fortran advantage and includes routine, dataset, size, C11 time, F77 time, F77/C11 ratio, and absolute delta.\n- Added persistent coverage in `tests/python/test_benchmark_report.py`.\n- Commit: `cca77d9 bench: report Fortran-faster rows`.\n\n## Validation Gates\n- `.venv/bin/pytest tests/python/test_benchmark_report.py -v` (2 passed)\n- `.venv/bin/python scripts/benchmark_c_vs_fortran.py --c-build-dir build-bench-c --output benchmark_c_vs_fortran_report.md -r bb03ad bb04ad`\n- `rg -n \"Fortran Faster|BB04AD|BB03AD\" benchmark_c_vs_fortran_report.md`\n","ts":"2026-05-11T00:14:39.76842Z"}} +{"type":"state","ts":"2026-05-11T00:14:39.76842Z","data":{"id":"V2VCHD","state":"done","ts":"2026-05-11T00:14:39.76842Z"}} +{"type":"claim","ts":"2026-05-11T00:14:50.007474Z","data":{"id":"HKA3XF","agent_id":"gpt-5@codex","ts":"2026-05-11T00:14:50.007474Z"}} +{"type":"state","ts":"2026-05-11T00:14:50.007474Z","data":{"id":"HKA3XF","state":"doing","ts":"2026-05-11T00:14:50.007474Z"}} +{"type":"result","ts":"2026-05-11T00:15:38.967907Z","data":{"task_id":"HKA3XF","summary":"Final bb03ad/bb04ad report shows no row more than 1.5x slower than Fortran.","path":"benchmark_c_vs_fortran_report.md","sha256_at_attach":"be1164009b3b0151c7c9b584b48c0f98a9ec1d6cb36fac98f76a659735246aba","mtime_at_attach":"2026-05-11T00:15:20.784333433Z","git_commit_at_attach":"cca77d92b979c0d4d3a5fbe330a576cdeffcd834","ts":"2026-05-11T00:15:38.967907Z"}} +{"type":"body","ts":"2026-05-11T00:15:38.97072Z","data":{"id":"HKA3XF","body":"## Goal\n- Run the final benchmark comparison and decide whether the C11 Lyapunov generator speed issue is closed.\n- Collect validation evidence for implementation review.\n\n## Result\n- Reinstalled the package after optimization and reran targeted BB03AD/BB04AD behavior tests.\n- Regenerated the combined `bb03ad bb04ad` C-vs-Fortran report after the BB04AD optimization and report-section work.\n- The generated `## Fortran Faster Rows` section shows only BB04AD ex4.4 rows at 1.11x, 1.07x, and 1.06x Fortran advantage, so no row remains more than 1.5x slower than Fortran and no follow-up task is required by this gate.\n\n## Validation Gates\n- `uv pip install .`\n- `.venv/bin/pytest tests/python/test_bb03ad.py tests/python/test_bb04ad.py -v` (30 passed)\n- `.venv/bin/meson compile -C build-bench-c`\n- `.venv/bin/python scripts/benchmark_c_vs_fortran.py --c-build-dir build-bench-c --output benchmark_c_vs_fortran_report.md -r bb03ad bb04ad`\n- `git status --short` checked; only `.ergo/plans.jsonl` and generated `benchmark_c_vs_fortran_report.md` remain outside code commits.\n","ts":"2026-05-11T00:15:38.97072Z"}} +{"type":"state","ts":"2026-05-11T00:15:38.97072Z","data":{"id":"HKA3XF","state":"done","ts":"2026-05-11T00:15:38.97072Z"}} diff --git a/scripts/benchmark_c_vs_fortran.py b/scripts/benchmark_c_vs_fortran.py index cad4e56..29cd85e 100755 --- a/scripts/benchmark_c_vs_fortran.py +++ b/scripts/benchmark_c_vs_fortran.py @@ -1136,6 +1136,31 @@ def generate_markdown_report( lines.append("*No comparison data available*") lines.append("") + # Fortran-faster rows + lines.append("## Fortran Faster Rows") + lines.append("") + if comparisons: + fortran_faster = sorted( + (c for c in comparisons if c.speedup < 1.0), + key=lambda c: c.c_mean_us / c.f_mean_us if c.f_mean_us > 0 else float("inf"), + reverse=True, + ) + if fortran_faster: + lines.append("| Routine | Dataset | N | C11 (μs) | F77 (μs) | F77 Advantage | Delta (μs) |") + lines.append("|---------|---------|---|----------|----------|---------------|------------|") + for c in fortran_faster: + ratio = c.c_mean_us / c.f_mean_us if c.f_mean_us > 0 else float("inf") + delta = c.c_mean_us - c.f_mean_us + lines.append( + f"| {c.routine.upper()} | {c.dataset} | {c.n} | {c.c_mean_us:.2f} | " + f"{c.f_mean_us:.2f} | {ratio:.2f}x | {delta:.2f} |" + ) + else: + lines.append("*No rows where Fortran is faster.*") + else: + lines.append("*No comparison data available.*") + lines.append("") + # System Information lines.append("## System Configuration") lines.append("") diff --git a/src/BB/bb04ad.c b/src/BB/bb04ad.c index ed82cba..cfad3a8 100644 --- a/src/BB/bb04ad.c +++ b/src/BB/bb04ad.c @@ -97,10 +97,11 @@ void bb04ad(const char* def, const i32* nr, f64* dpar, i32* ipar, SLC_DLASET("A", m, n, &neg_twobyn, &b_diag, b, &ldb); SLC_DLASET("A", n, n, &dbl0, &dbl0, x, &ldx); + temp = ONE; for (i = 0; i < *n; i++) { - temp = pow(dpar[0], (f64)i); a[i + i * lda] = (temp - ONE) / (temp + ONE); dwork[i] = ONE; + temp *= dpar[0]; } SLC_DGEMV("T", n, n, &dbl1, a, &lda, dwork, &int1, &dbl0, &dwork[*n], &int1); @@ -109,12 +110,16 @@ void bb04ad(const char* def, const i32* nr, f64* dpar, i32* ipar, SLC_DGEMV("N", n, n, &dbl1, a, &lda, dwork, &int1, &dbl0, &dwork[*n], &int1); SLC_DGER(n, n, &neg_twobyn, &dwork[*n], &int1, dwork, &int1, a, &lda); + f64 col_scale = ONE; for (j = 0; j < *n; j++) { - b[0 + j * ldb] = b[0 + j * ldb] / pow(dpar[1], (f64)j); + b[0 + j * ldb] = b[0 + j * ldb] * col_scale; + f64 row_scale = col_scale; for (i = 0; i < *n; i++) { - a[i + j * lda] = a[i + j * lda] * pow(dpar[1], (f64)(i - j)); + a[i + j * lda] = a[i + j * lda] * row_scale; + row_scale *= dpar[1]; } dwork[j] = ONE - TWO * (j % 2); + col_scale /= dpar[1]; } SLC_DGEMV("T", n, n, &dbl1, a, &lda, dwork, &int1, &dbl0, &dwork[*n], &int1); @@ -174,12 +179,16 @@ void bb04ad(const char* def, const i32* nr, f64* dpar, i32* ipar, SLC_DGEMV("N", n, n, &dbl1, a, &lda, dwork, &int1, &dbl0, &dwork[*n], &int1); SLC_DGER(n, n, &neg_twobyn, &dwork[*n], &int1, dwork, &int1, a, &lda); + f64 col_scale = ONE; for (j = 0; j < *n; j++) { - b[0 + j * ldb] = b[0 + j * ldb] / pow(dpar[1], (f64)j); + b[0 + j * ldb] = b[0 + j * ldb] * col_scale; + f64 row_scale = col_scale; for (i = 0; i < *n; i++) { - a[i + j * lda] = a[i + j * lda] * pow(dpar[1], (f64)(i - j)); + a[i + j * lda] = a[i + j * lda] * row_scale; + row_scale *= dpar[1]; } dwork[j] = ONE - TWO * (j % 2); + col_scale /= dpar[1]; } SLC_DGEMV("T", n, n, &dbl1, a, &lda, dwork, &int1, &dbl0, &dwork[*n], &int1); diff --git a/tests/python/test_benchmark_report.py b/tests/python/test_benchmark_report.py new file mode 100644 index 0000000..00357e7 --- /dev/null +++ b/tests/python/test_benchmark_report.py @@ -0,0 +1,41 @@ +import importlib.util +from pathlib import Path + + +def load_benchmark_module(): + script_path = Path(__file__).resolve().parents[2] / "scripts" / "benchmark_c_vs_fortran.py" + spec = importlib.util.spec_from_file_location("benchmark_c_vs_fortran", script_path) + module = importlib.util.module_from_spec(spec) + assert spec.loader is not None + spec.loader.exec_module(module) + return module + + +def test_report_lists_fortran_faster_rows_sorted_by_advantage(): + bench = load_benchmark_module() + comparisons = [ + bench.ComparisonResult("bb04ad", "ex4.1", 50, 40.0, 20.0, 0.5, 0.1, 0.1, 0, 0), + bench.ComparisonResult("bb03ad", "ex4.2", 30, 12.0, 10.0, 0.833333, 0.1, 0.1, 0, 0), + bench.ComparisonResult("bb04ad", "ex4.3", 20, 2.0, 4.0, 2.0, 0.1, 0.1, 0, 0), + ] + + report = bench.generate_markdown_report([], [], comparisons, {}) + + assert "## Fortran Faster Rows" in report + assert "| Routine | Dataset | N | C11 (μs) | F77 (μs) | F77 Advantage | Delta (μs) |" in report + first = report.index("| BB04AD | ex4.1 | 50 | 40.00 | 20.00 | 2.00x | 20.00 |") + second = report.index("| BB03AD | ex4.2 | 30 | 12.00 | 10.00 | 1.20x | 2.00 |") + assert first < second + assert "| BB04AD | ex4.3 | 20 |" not in report + + +def test_report_states_when_no_fortran_rows_are_faster(): + bench = load_benchmark_module() + comparisons = [ + bench.ComparisonResult("bb04ad", "ex4.1", 50, 8.0, 20.0, 2.5, 0.1, 0.1, 0, 0), + ] + + report = bench.generate_markdown_report([], [], comparisons, {}) + + assert "## Fortran Faster Rows" in report + assert "*No rows where Fortran is faster.*" in report