peraro / finiteflow

Multivariate functional reconstruction using finite fields and dataflow graphs.
MIT License
42 stars 5 forks source link

Flint and Ubuntu 24.04 #6

Open jodavies opened 2 months ago

jodavies commented 2 months ago

Hi,

Since upgrading to Ubuntu 24.04, I have problems loading FiniteFlow in Mathematica (I tested v13.3 and v14.1).

CMake finds the Mathematica installation and things seem to compile properly. I build using cmake -DCMAKE_INSTALL_PREFIX=$HOME/software . so I end up with /home/josh/software/lib/libfflow.so and /home/josh/.Wolfram/SystemFiles/LibraryResources/Linux-x86-64/fflowmlink.so after make install.

In Mathematica though, I get:

<< FiniteFlow`
LibraryFunction::load: The library /home/josh/.Wolfram/SystemFiles/LibraryResources/Linux-x86-64/fflowmlink.so cannot be loaded.
LibraryFunction::libload: The function fflowml_default_nthreads was not loaded from the file /home/josh/.Wolfram/SystemFiles/LibraryResources/Linux-x86-64/fflowmlink.so.
LibraryFunction::libload: The function fflowml_graph_new was not loaded from the file /home/josh/.Wolfram/SystemFiles/LibraryResources/Linux-x86-64/fflowmlink.so.
LibraryFunction::libload: The function fflowml_graph_dummy was not loaded from the file /home/josh/.Wolfram/SystemFiles/LibraryResources/Linux-x86-64/fflowmlink.so.
General::stop: Further output of LibraryFunction::libload will be suppressed during this calculation.

This seems related to the version of Flint which FiniteFlow is linked to. Ubuntu 24.04's package is 3.0.1. If I link against https://github.com/peraro/flint-finiteflow-dep then things work OK.

Is FiniteFlow supposed to be compatible with Flint 3? Mathematica also links against its own libflint these days, which I think is also 2.x. I don't know if the version mismatch there can cause problems.

Thanks, Josh.

peraro commented 1 month ago

Hi, thanks for reporting this. Can you try

make tests
./testcapi

to see if it's a Mathematica problem or something else?

If that works, please try

LD_DEBUG=libs math -script ./mathlink/tests.m

and report here any error/warning you find.

I tested it with both Flint 2.x and Flint 3. I don't know if flint-finiteflow-dep can cause conflicts with Mathematica, so far I haven't had any report about this.

jodavies commented 1 month ago

The capi test runs fine. The relevant line from trying to run mathlink/tests.m looks to be:

     432095: /lib/x86_64-linux-gnu/libflint.so.18: error: symbol lookup error: undefined symbol: __gmpn_modexact_1_odd (fatal)

 LibraryFunction::load: The library /home/josh/.Wolfram/SystemFiles/LibraryResources/Linux-x86-64/fflowmlink.so cannot be loaded.

This symbol is present in /lib/x86_64-linux-gnu/libgmp.so however.

Edit: I don't think /lib/x86_64-linux-gnu/libgmp.so gets loaded, but rather /usr/local/Wolfram/Wolfram/14.1/SystemFiles/Kernel/Binaries/Linux-x86-64/../../../Libraries/Linux-x86-64/libgmp.so.10. This contains

__gmpn_modexact_1c_odd
__gmpn_modexact_1c_odd_init
__gmpn_modexact_1c_odd_x86_64
__gmpn_modexact_1_odd_x86_64
peraro commented 1 month ago

It looks like there may be some conflict between the GMP library used to compile flint and the one that is loaded when Mathematica is running. I am not sure why it only happens with the latest flint and not with flint-finiteflow-dep. If it doesn't cause issues you could try using the latter, until this is solved.

What happens if you try using

export LD_LIBRARY_PATH="/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH"

before running the Mathematica test?

Also, are you able to tell which GMP library is loaded when ./testcapi is run?

jodavies commented 1 month ago

testcapi uses /lib/x86_64-linux-gnu/libgmp.so.10, it doesn't know anything about Mathematica's libraries. Setting the library path before launching Mathematica doesn't help, presumably it is programmed to look for its own bundled libraries first.

Certainly I can use flint-finiteflow-dep. This works because it does not contain __gmpn_modexact_1_odd and so Mathematica's libgmp is fine.

Mathematica's libgmp contains lots of symbols which look like they are optimized for specific architectures, and due to this some symbols in Ubuntu's libgmp are "missing" in Mathematica's.