Use binary search for the S(alpha,beta) interval lookup in thermr#401
Open
ramic-k wants to merge 1 commit into
Open
Use binary search for the S(alpha,beta) interval lookup in thermr#401ramic-k wants to merge 1 commit into
ramic-k wants to merge 1 commit into
Conversation
sig() located the bracketing alpha and beta intervals with linear scans on every evaluation. For modern tabulations with hundreds to thousands of grid points the scans dominate THERMR runtime (~70% of profile samples on a 399x5001-point law). Replace both scans with binary searches that select exactly the same interval (first i with value < grid(i+1), saturating at n-1). Output is bit-for-bit identical; THERMR time on large TSL tapes drops severalfold.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
sig()located the bracketing α and β intervals with linear scans onevery evaluation:
For modern fine-grid tabulations these scans dominate THERMR runtime:
profiling a coherent-crystal evaluation with a 399 α × 5001 β law put
~70% of all samples inside the two scan loops. This PR replaces both
with binary searches that select exactly the same interval (the
first
iwithvalue < grid(i+1), saturating atn-1), making thelookup O(log n) per evaluation.
Effect
(ia, ib)pair isthe same for every query, including the equality and saturation edge
cases, so all downstream arithmetic is unchanged. Verified by byte
comparison of full RECONR/BROADR/THERMR/ACER output chains on three
different TSL tapes (incoherent and coherent laws, 399×400 to
399×5001 grids).
performance-neutral (and the suite results are identical with and
without it; same pass/fail sets on macOS/arm64).
39 to 23 minutes at -O0 (the scans shrink from ~70% of samples to a
negligible share; remaining time is interpolation and quadrature).
Large-grid tapes need
nwscrenlarged to fit — that is independentof this change.
No new dependencies, no interface changes; the two loop replacements
and two scratch integers are the entire diff.