Migrate off GSL onto fortnum - #28
Closed
krystophny wants to merge 1 commit into
Closed
Conversation
Replace every GSL numerical routine with the fortnum core. Consumers now
depend on fortnum directly rather than on the GSL/FGSL stack.
Fortran (src/mephit_pert.f90): drop the bind(C) interface to
gsl_sf_bessel_In_array and call fortnum_special bessel_in_array in
kilca_vacuum_fourier. fortnum fills I_n(0:nmax), so the order |pol_mode|-1
needed for the radial Bessel sum (which is -1 when pol_mode = 0) is recovered
through the symmetry I_{-n}(x) = I_n(x). Call-site results are unchanged.
C: hyper1F1.c uses fortnum_integrate_qag (key 21, the former GSL_INTEG_GAUSS21)
for the 1F1 quadrature, threading the quad_params through the C ABI context
pointer, and fortnum_levin_u_accel for the Kummer-series acceleration. The
quadrature integrand now relies on float.h for DBL_EPSILON, formerly pulled in
transitively by the GSL headers. mephit_fem.c builds the unit-interval
Gauss-Legendre rule with fortnum_gauss_legendre_ab. The GSL error-handler
plumbing (gsl_errno_msg, gsl_set_error_handler) is removed from mephit_util and
mephit_run; fortnum routines report status through return codes.
Build: drop find_package(GSL) and the FGSL pickup, fetch fortnum via
FetchContent (git@github.com:lazy-fortran/fortnum.git, GIT_TAG main) guarded by
NOT TARGET fortnum so a transitive pull through libneo does not redeclare the
target, link the fortnum target, and add its include directory for the C/C++
sources. FFTW and the netlib zeroin/d1mach routines are untouched; they were
never GSL.
Supersedes #26.
Closed
Member
Author
|
This monolithic migration is superseded by an atomic, stacked re-cut off main, with the FFTW migration added. One PR per dependency or concern, each individually reviewable; merged in order they compose to the full migration:
The stack tip builds clean: libmephit.so plus all three executables link, with zero GSL, FFTW, AMOS, and SLATEC symbols in the library and no GSL or FFTW dynamic dependency in the binaries. fortnum's own suite (68 tests) passes at tag a7faa3c. PRs 1 to 3 are drafts because their tips do not link the executables standalone (the empty FFTW_LIBRARIES link, also broken on main, is fixed in PR 4). Leaving this PR open for a human to close. |
Member
Author
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.
Migrate MEPHIT off GSL onto fortnum, the single numerical core. Consumers depend
on fortnum directly (not the libneo math-kit). This supersedes the
libneo-routed PR #26.
What changed
Fortran (
src/mephit_pert.f90)bind(C)interface togsl_sf_bessel_In_arrayand callfortnum_specialbessel_in_arrayinkilca_vacuum_fourier.I_n(0:nmax), so the order|pol_mode|-1(which is-1whenpol_mode = 0) is recovered viaI_{-n}(x) = I_n(x). Call-site values areunchanged.
C
hyper1F1.c:gsl_integration_qag(ruleGSL_INTEG_GAUSS21) becomesfortnum_integrate_qag(..., key=21, ..., ctx=&qp), threading the quadratureparameters through the C ABI context pointer;
gsl_sum_levin_u_*becomesfortnum_levin_u_accel. Adds#include <float.h>forDBL_EPSILON,formerly pulled in transitively by the GSL headers.
mephit_fem.c:gsl_integration_glfixed_*becomesfortnum_gauss_legendre_ab(order, 0.0, 1.0, ...).mephit_util.c/mephit_run.c: remove the GSL error-handler plumbing(
gsl_errno_msg,gsl_set_error_handler); fortnum reports status via returncodes.
Build
find_package(GSL)and the FGSL pickup fromCMakeLists.txt/cmake/SetupCODE.cmake.FetchContentfromgit@github.com:lazy-fortran/fortnum.git(
GIT_TAG main), guarded byif(NOT TARGET fortnum)so a transitive pullthrough libneo does not redeclare the target. Link the
fortnumtarget; add${fortnum_SOURCE_DIR}/includeto the C/C++ include path forfortnum.h.FFTW (
src/fftw3.f90) and the netlibzeroin/d1machroutines are not GSLand are untouched. GSL is fully removed: no
find_package(GSL), noGSL::gsl,no
gsl/*includes, nogsl_symbols inlibmephit.so.This migration required forwarding an opaque user context through fortnum's
callback-driven C ABI (the header documented it as forwarded but the wrappers
hardcoded NULL). Fixed upstream in fortnum
(lazy-fortran/fortnum@dc277b5) and verified there before consuming it here.
Verification
GSL fully removed from the source and the linked library:
Full CMake configure (fortnum fetched over SSH, no GSL):
Full build (library + all executables), green:
Numerical equivalence of the migrated routines:
1F1(1;b;z) via the fortnum QAG path vs an independent Kummer-series reference
(
b = 2 + 0.5i,z = 0.3 - 0.2i):Bessel index logic in
kilca_vacuum_fouriervs scipyiv, including thepol_mode = 0case that needsI_{-1} = I_1:5-point Gauss-Legendre on [0,1] from
fortnum_gauss_legendre_abintegrates1, x, x^2 exactly (matching the former GSL glfixed rule):
Upstream fortnum test suite after the ctx-ABI fix, including the C smoke test:
Supersedes #26.