Hi!
I’m starting to port some (painfully slow) Python code to Fortran for work.
I will need the LAPACK and MINUIT libraries for linalg operations and least-squares minimization respectively.
Does anybody know how to best build and link LAPACK and MINUIT to an existing/new FPM project?
Both the source code for LAPACK and MINUIT are up on Github so I imagine the linking/building process to be at least straightforward if not trivial with FPM… just wondering if anyone has previous experience?
Thanks! Happy (soon-to-be) new year’s!
Abe
Hi Abe. Welcome to the Discourse. It’s pretty common for LAPACK to already be installed on many systems, and many system package managers have it available to easily install. If not there should be some installation instructions in the repository. I’m not familiar with MINUIT, but presumably it will have some installation instructions somewhere in its repository too. For linking an fpm package to external libraries, start with this section of the docs. Just make sure they are installed in a commonly searched location or that location is included in your LD_LIBRARY_PATH
environment variable.
Hi! Thanks for the answer EF!
Indeed linking LAPACK to the existing project is as easy as making sure that LAPACK is installed via the package manager or otherwise (DNF/YUM in my case on RHEL).
I.e.:
sudo dnf install lapack
And addding the line in fpm.toml
[build]
link = ["blas", "lapack"]
Next I want to add the Minuit dependency from my forked version on Github but I haven’t had much success- I also checked out the documentation on linking dependencies from source control.
The documentation is not super explicit on what FPM expects in the repo in order for it to link the local project to some files on GH.
Concretely: what is necessary in order for FPM to recognize, build and link dependencies from a directory up on GH?
For completeness, the github repo of Minuit is here.
As MINUIT is not an fpm package, you cannot list it as a dependency. However, as it’s open source, you could fork it and make an fpm package with what looks like some easy rearranging of the files.
MINUIT is an old Fortran-77 package, and its structure is quite simple. The commands to build the library using Gfortran in Linux are
gfortran -finit-local-zero -fno-automatic -c *.F
ar rcs libminuit.a *.o
There are two versions of a test program (and input data) in the Minuit PDF manual. To build and run the program (copy-paste from PDF into file pgm.f
) and use the commands
gfortran -finit-local-zero -fno-automatic pgm.f libminuit.a
./a.out
The output file contains the following ASCII contour plot, which for some of us can induce nostalgia when viewed:
** 11 **CONTOUR 1.000 2.000
**********
Y-AXIS: PARAMETER 2: Imag(X)
X=0
0.2513 3 222222222 33 44
0.2327 222 : *22 33 44
0.2141 22 : * 22 3 4
0.1954 22 11 * 2 33
0.1768 2 1111111* 22 33
0.1581 22 1 : 1* 2 3
0.1395 2 11 : 11 22 33
0.1209 2 1 0000 11 22 33
0.1022 2 1 00: 00*11 22 3
0.8360E-01 2 1 00: 00 1 22
0.6496E-01 2 11 0: 0 11 22
0.4633E-01 22 1 00 0 11 2
0.2769E-01 *2***11*00000***1****22**
0.9054E-02 -22---111-------1----22--
-0.9583E-02 22 111 * 111 2
-0.2822E-01 222 : 11111 22 3
-0.4686E-01 3 222: * 222 33
-0.6549E-01 33 2222 * 2222 33
-0.8413E-01 333 : 222222 33
-0.1028 333 : * 333 4
-0.1214 33333 * 33333 44
-0.1400 44 :3333333 444
-0.1587 444 : * 444 5
-0.1773 44444: * 44444 55
-0.1959 444444444 555
I I I