Skip to content

perf(hermite): evaluate each element kernel once for load and tangent (bit-identical) - #119

Merged
SMI-Lab-Inha merged 2 commits into
devfrom
perf/hermite-fused
Nov 8, 2026
Merged

SMI-Lab-Inha merged 2 commits into
devfrom
perf/hermite-fused

Conversation

@SMI-Lab-Inha

Copy link
Copy Markdown
Owner

Where a tangent follows the residual at the same state, the finite-EI dynamic step now evaluates each element kernel once for both. Each kernel already computes its load with the same statements whether or not it also returns its tangent.

Change

  • evaluate_tangent_element: gains an optional forces(12,6) output with the structural, damping, drag, VIV and Froude–Krylov loads from the call that forms the tangent blocks.

  • assemble_residual(stash_tangent):

    • It runs the kernels once, in the tangent path's OpenMP loop (same threshold and thread cap).
    • It adds the loads to R serially, in the element and phase order of the residual-only assembly.
    • It keeps the element tangent blocks.
  • assemble_residual(use_stash):

    • A tangent-only assembly scatters the kept blocks only when the configuration, velocity and time match the keeping evaluation bit for bit.
    • Everything else is unchanged: the scatter order, the non-element terms (attachments, buoyancy, contact, end connections, torsion and twist) and the error checks.
    • Any other evaluation drops the kept blocks.
  • Error behaviour: if a kernel fails in a keeping pass, that pass recomputes the residual the plain way and keeps nothing. Errors and messages stay identical.

  • Where blocks are kept:

    • at the predictor, when the previous step solved;
    • at the modified-Newton and cross-step refresh;
    • in full Newton at the first line-search trial, while this step has built fewer line-search tangents than the previous one.

    These choices decide only where kernels run, never a result.

Evidence

All 54 examples are bit-identical to the base, comparing every output byte for byte, in each of these runs:

  • one thread;
  • OMP_NUM_THREADS=4, compared with the one-thread outputs;
  • a stress build that keeps and uses blocks everywhere;
  • every deck with modified_newton True.

Timings, median of 5, one thread:

deck before after
lazy_wave_vessel_rao 11.86 s 11.23 s (−5.3 %)
lazy_wave_vessel_motion 5.12 s 4.78 s (−6.6 %)
buoy_clamped_cable 2.02 s 1.89 s (−6.4 %)
lazy_wave_bend_stiffener 7.52 s 7.17 s (−4.6 %)

Tests

  • Release CTest: 366/366 on the default and Prescott kernels.
  • Non-slow tier at four threads: 349/349.
  • Debug -fcheck=all: 366/366.
  • Build and format: no warnings; fprettify clean.
  • Docs: doc/cli.rst now says that kept kernel time is counted as residual time in CABLEDYN_PROFILE.

… and tangent

The first Newton iteration of a finite-EI dynamic step assembles its tangent at the predictor,
the state its residual evaluation has just assembled, so every element kernel ran twice there.
The predictor evaluation now runs each kernel once for its load and its tangent
(evaluate_tangent_element with forces, in the same threshold-gated OpenMP loop as the tangent
assembly), adds the loads to the residual serially in the element and phase order of the
residual-only assembly, and keeps the element tangent blocks. The tangent assembly that follows
at bitwise the same configuration, velocity and time scatters those blocks instead of
evaluating the kernels again; every other assembly drops them. The refresh evaluation of
modified Newton and cross-step reuse, which its tangent also follows, does the same.

Every kernel forms its load by the same statements with or without its tangent, so the
residual is bit-for-bit that of the residual-only assembly, and the scattered blocks are those
the tangent assembly would evaluate. If an element evaluation fails (a tangent can overflow
where the load stays finite), the evaluation assembles the residual-only way and keeps
nothing, so every result and message is unchanged. A step that converges at its predictor
needs no tangent: the next predictor then evaluates residual-only.

Signed-off-by: Jae Hoon Seo <jaehoon.seo@inha.ac.kr>
An accepted line-search trial that the iteration goes on from assembles its tangent at the
trial's own state, which the trial's residual evaluation has just assembled. In full Newton
the full step (the first trial) of a line search now keeps its element tangents while the step's
line searches have assembled fewer tangents than those of the previous step, and the
line-search tangent assembly scatters them. The predictor keeps its element tangents when the
previous step made a solve, in place of a flag that recorded whether it converged at its
predictor.

These rules only choose where the element kernels run: kept tangents are used only at bitwise
the state they were evaluated at, so every result is unchanged. A trial that is rejected or
converges keeps tangents that are not used.

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 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-08T13:16:46.938161Z 098f8d6 Manual request
ℹ️ 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 #35732897 | 📁 Comparing 098f8d6 against latest (e8f88f5)

  🔍 Preview build  

6 files changed · ± 6 modified

± Modified

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 098f8d644b

ℹ️ 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 9582feb into dev Nov 8, 2026
16 checks passed
@SMI-Lab-Inha
SMI-Lab-Inha deleted the perf/hermite-fused branch November 9, 2026 08:56
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