DrTimothyAldenDavis / SuiteSparse

The official SuiteSparse library: a suite of sparse matrix algorithms authored or co-authored by Tim Davis, Texas A&M University.
https://people.engr.tamu.edu/davis/suitesparse.html
Other
1.15k stars 259 forks source link

Linking SuiteSparse to Mathematica via LibraryLink #317

Closed jruizvid closed 1 year ago

jruizvid commented 1 year ago

I am trying to make some of the functions of SuiteSparse available in Mathematica. I am stuck and thought I would ask for feedback, although this forum is probably not thought for that.

My question right now is: what are the library files that SuiteSparseQR_C_factorize depends on? The details are in stackexchange

I can use SuiteSparseQR normally compiling with gcc, but in LibraryLink of Mathematica I need to import the libraries in a explicit way (or at least that worked using cholmod).

Thanks!

mmuetzel commented 1 year ago

Fwiw, I see the following dependencies for the spqr library on Windows:

$ ntldd -R /mingw64/bin/libspqr.dll | grep -v -e "WINDOWS" -e "not found"
        libcholmod.dll => C:\msys64\mingw64\bin\libcholmod.dll (0x000002097eaf0000)
         libamd.dll => C:\msys64\mingw64\bin\libamd.dll (0x000002097ea50000)
         libcamd.dll => C:\msys64\mingw64\bin\libcamd.dll (0x0000020900000000)
         libccolamd.dll => C:\msys64\mingw64\bin\libccolamd.dll (0x0000020900000000)
         libcolamd.dll => C:\msys64\mingw64\bin\libcolamd.dll (0x0000020900000000)
         libgomp-1.dll => C:\msys64\mingw64\bin\libgomp-1.dll (0x0000020900000000)
          libwinpthread-1.dll => C:\msys64\mingw64\bin\libwinpthread-1.dll (0x0000020900070000)
        libsuitesparseconfig.dll => C:\msys64\mingw64\bin\libsuitesparseconfig.dll (0x000002097ea60000)
        libgcc_s_seh-1.dll => C:\msys64\mingw64\bin\libgcc_s_seh-1.dll (0x0000020900050000)
        libopenblas.dll => C:\msys64\mingw64\bin\libopenblas.dll (0x00000209008d0000)
         libgfortran-5.dll => C:\msys64\mingw64\bin\libgfortran-5.dll (0x0000020900000000)
          libquadmath-0.dll => C:\msys64\mingw64\bin\libquadmath-0.dll (0x0000020900320000)

There might be similar tools for your platform.

jruizvid commented 1 year ago

Thank you for the feedback. It's good to know these tools exist.

I managed to link SuiteSparse and Mathematica. The solution was much more simple: saving the matrix into a text file and executing the C++ code of SuiteSparseQR from inside Mathematica. It is extremely fast and you keep all your input and output within Mathematica.

All my code is posted here for anyone interested.

Thank you to the people involved in SuiteSparse, it is incredibly useful for my research.

DrTimothyAldenDavis commented 1 year ago

I can't be of much help since I'm not familiar with Mathematica. Writing to a text file is one solution but it has its drawbacks -- it is a lot slower than it should be (most of the time will be spent writing the file and then reading it in), and it might introduce numerical inaccuracies (if the matrix market file is not written in full precision).

SuiteSparse libraries all work with 64-bit integers, or 32-bit (most libraries have both variants). SuiteSparseQR only has a 64-bit variant but a 32-bit version with 'int32_t' integers as its index type is in progress.