Skip to content

perf(waves): vectorise the wave component sum - #92

Merged
SMI-Lab-Inha merged 2 commits into
devfrom
perf/wave-component-cost
Nov 7, 2026
Merged

SMI-Lab-Inha merged 2 commits into
devfrom
perf/wave-component-cost

Conversation

@SMI-Lab-Inha

Copy link
Copy Markdown
Owner

Summary

Wave kinematics took 70-80 % of a step on a long elevation record: a 4,200 s record cut at 3.6 rad/s keeps about 2,400 components, summed at each node and step. This keeps the exact sum and makes it generate well; spectral seas, wave trains and spread seas share the gain.

  • GNU Fortran did not vectorise the sine, cosine and exponential at all. Block kernels now take the quadrant and exponent from the bits of the rounded value, with near-minimax polynomials (2.26 ulp for sine and cosine, 1.30 ulp for the exponential, against quadruple precision).
  • Sums run in 64 interleaved lanes, added pairwise in a fixed order, so they stay independent of the thread count.
  • Components past the first 1024 no longer have their sine and cosine evaluated twice, and the depth ratios take one division.

Rejected on measurement: splitting the time factor (no gain for moving nodes), recursive phasors (they act on a term that costs almost nothing) and a kinematics grid (an approximation for at most 2x now that the wave share is about 50 %).

Speed

298 nodes, 2,406 components, dtM 0.1, per step:

Build Step ms Wave ms Wave share 1 h run
ifx, release flags 7.85 → 5.0 5.6 → 2.55 71 → 51 % 4.7 → 3.0 min
gfortran AVX2 22.6 → 7.2 18.0 → 3.6 80 → 50 % 13.6 → 4.3 min
gfortran x86-64 21.8 → 9.3 17.4 → 5.5 80 → 59 % 13.1 → 5.6 min

Result changes (round-off)

All 53 decks in examples/ plus moordynC_wavekin/chain_wavekin7_currents1.dat against the base:

  • 4,200 s benchmark: largest output difference 2e-4 N, print resolution, no drift.
  • 11 of the 14 wave decks are text-identical at printed precision.
  • lazy_wave_bend_stiffener: 3e-7 of range.
  • lazy_wave_vessel_rao: 2.1e-3 of range, one decaying spike at 46.8 s; that deck runs at a relative tolerance of 1e-4, and at 1e-11 the difference is 6e-7.
  • als_volturnus_line_break_time and _tension: 1e-7 of range until about 800 s, then the free post-break drift diverges, as it did with the AVX2 change (up to 0.17 of range on AnchTen2; peaks agree to 4 digits, std to 4e-4).

Checks

  • Bit-identical at 1 and 4 threads. The kernels hold no state, so restarts are unaffected. FMA stays off; no per-step allocation.
  • New test wave_component_sum compares against a direct quadruple-precision sum across heights, four depths and 1 to 5,156 components.
  • CTest 360 of 360 on the default kernel and with OPENBLAS_CORETYPE=Prescott; pytest passes; no new compiler warnings.

The CHANGELOG entry lands with the release batch.

The wave kinematics of a long elevation record sum thousands of
components at every node and step. GNU Fortran kept the block sine,
cosine and exponential scalar (their integer conversion and floating
MERGE blocked the vectoriser), every build summed in running scalars,
and components past the first 1024 had their phase factors evaluated
twice.

The block kernels now take the quadrant and exponent from the bits of
the rounded value, use near-minimax polynomials in Estrin's scheme, and
vectorise under GNU Fortran and ifx alike; their errors fall to 2.3 ulp
(sine, cosine) and 1.3 ulp (exponential) against quadruple precision.
The sums of CD_Component_Wave_Kinematics and CD_Sea_Kinematics run in
64 interleaved lanes added up pairwise, in an order fixed by the source;
the depth ratios take one division, a block with an underflowing
exponential forms the lower exponential in the block kernel, and the
phase factors of up to 4096 components are kept for the velocity sums.
Each sum stays a function of its arguments alone: no state, and the same
bits at any thread count.

On a 298-node finite-EI line in a 4,200 s record of 2,406 components
the wave sum falls from 6.0 to 3.0 ms per step with the release flags,
and from 18 to 3.6 ms in a GNU AVX2 build. Results change at round-off.

The new wave_component_sum test holds the sum to a direct quadruple
precision reference across heights, depths and record lengths.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
@SMI-Lab-Inha

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: 🔄 Running

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-11-07T12:36:31.888220Z c8464d6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 CableDyn | 🛠️ Build #35718707 | 📁 Comparing c8464d6 against latest (3d04008)

  🔍 Preview build  

2 files changed
± file_formats.html
± theory.html

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: c8464d61bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@SMI-Lab-Inha
SMI-Lab-Inha merged commit ba90a42 into dev Nov 7, 2026
21 checks passed
@SMI-Lab-Inha
SMI-Lab-Inha deleted the perf/wave-component-cost branch November 7, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant