Skip to content

Replace GSL Bessel I_n with fortnum (1/5) - #29

Draft
krystophny wants to merge 4 commits into
mainfrom
drop-gsl-fortnum-bessel
Draft

Replace GSL Bessel I_n with fortnum (1/5)#29
krystophny wants to merge 4 commits into
mainfrom
drop-gsl-fortnum-bessel

Conversation

@krystophny

@krystophny krystophny commented Jun 14, 2026

Copy link
Copy Markdown
Member

Merge order

Stack sequence: #29 -> #30 -> #31 -> #32 -> #33.

Each PR is now based on main individually, so its diff is cumulative against main and shares code with its stack neighbors. Merge in the sequence above. Once a predecessor merges into main, the next PR rebases onto it and its diff shrinks to its own increment.


First in a five-PR stack migrating MEPHIT off GSL (and FFTW) onto the fortnum numerical core. Merged in order, the stack composes to the full migration; this PR wires fortnum via CMake FetchContent and moves the modified-Bessel call site in mephit_pert.

Dependency removed: the gsl_sf_bessel_In_array C binding. fortnum's bessel_in_array fills I_0..I_nmax in one pass; the orders |m|-1, |m|, |m|+1 are recovered with the symmetry I_{-n}(x) = I_n(x), so pol_mode = 0 maps order -1 to I_1. fortnum is declared with FetchContent at the pinned tag 92de6e9, guarded by if(NOT TARGET fortnum) because libneo also pulls it in transitively. The fortnum include dir is added for the C/C++ sources and the fortnum target is linked. GSL stays linked until the remaining call sites move over in the later PRs of this stack.

Verification

Configure and build the shared library at this tip (out-of-source build):

$ cmake -S . -B build -G Ninja
...
-- Configuring done (9.6s)
-- Generating done (0.1s)
$ cmake --build build --target mephit
[7/7] Linking CXX shared library lib/libmephit.so

fortnum is pinned at the required tag:

$ git -C build/_deps/fortnum-src rev-parse HEAD
92de6e949a772cfffc73bb5295fe5e2b056b9c18

The GSL Bessel symbol is gone and fortnum's routine is now linked:

$ nm -DC build/lib/libmephit.so | grep -i 'gsl_sf_bessel\|bessel_in_array'
0000000000110740 T __fortnum_special_bessel_MOD_bessel_in_array

Note: the .x executables do not link at this tip, and they also do not link on main: find_package(FFTW) is never called, so the FFTW_LIBRARIES link variable is empty and the FFTW symbols pulled in by src/fftw3.f90 are unresolved at the executable link step. PR 4 of this stack removes that FFTW usage and the executables link. The shared library, the verifiable artifact for this aspect, builds.

Note: fortnum pin updated to current main (92de6e9) after a fortnum history rewrite; old shas no longer resolve.

Drop the gsl_sf_bessel_In_array C binding in mephit_pert and compute the
modified Bessel functions through fortnum's bessel_in_array. fortnum fills
I_0..I_nmax in one pass, so the orders |m|-1, |m|, |m|+1 are recovered with
the symmetry I_{-n}(x) = I_n(x); for pol_mode = 0 the order -1 maps to I_1.

Wire fortnum via CMake FetchContent at the pinned tag, guarded so a build that
also pulls fortnum transitively through libneo does not declare the target
twice. Add the fortnum include directory for the C/C++ sources and link the
fortnum target. GSL stays linked until the remaining call sites move over.
@krystophny
krystophny marked this pull request as draft June 14, 2026 07: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