0

I need some help regarding installation of LAPACK ( for Fortran 95) on a Fedora machine.

I am writing this post after having tried all answers posted to pertinent queries in this forum.

I tried two different options:

METHOD 1

I directly downloaded the lapack95.a library from here (http://www.netlib.org/lapack95/, file named lapack95_linux_redhat.tgz. After unzipping, I could get file lapack95.a

After looking for some answers on how to link and use libraries, I wrote a trial code and saved in file try.f90 and then did the following

gfortran -c try.f90

gfortran -o try try.o -L/(name of directory where lapack95.a
                          was present. I put it in the same directory
                          as try.f90)/ -llapack95

( The fortran file try.f90 and lapack95.a were in the same directory)

I got the following error:

/usr/bin/ld: cannot find -llapack95
collect2: error: ld returned 1 exit status

I searched on internet and found here (https://forums.fedoraforum.org/archive/index.php/t-248227.html) that we need to install lapack-devel. I did that and had the same outcome.

Method 2

I also tried running the above command (in Method 1) but without space between / and -llapack95 , i.e. as :

gfortran -o try try.o -L/(name of directory where lapack95.a 
                          was present I put it in the same directory
                         as try.f90)/-llapack95

and received the following error:

try.o: In function `MAIN__':
try.f90:(.text+0xdb): undefined reference to `sgesv_'
collect2: error: ld returned 1 exit status

Method 3

After having no success, I thought may it's not good idea to use the lapack95.a downloaded directly. I should build it from the original files.

I realized that may be I need to install lapack95 through proper means following which from the same link http://www.netlib.org/lapack95

I downloaded the file lapack95.tgz and followed the instructions in readme file.( which said just to run make file in SRC)

I made some changes as :

FC1      = f95 -fixed  to 

FC1      = f95 

and

OPTS0    = -u -V -dcfuns -dusty -ieee=full 

to

OPTS0    = -u -V 

( as suggested on https://www.reddit.com/r/linux4noobs/comments/7tgmb9/fortran_library_netlib_lapack95_installation_error/)

I expected that the library will be created in /usr/lib/ or usr/local/lib as LAPACK3 but couldn't find it.

Infact there was an error ( and thus could not have any .a file )

f95 -free -c -u -V - -I./../lapack95_modules f77_lapack_double.f90 f95: error: -E or -x required when input is from standard input make: *** [../make.inc:45: f77_lapack_double.o] Error 1

I am not sure if any of my method is fine. I expected Method 1 to work as I am linking the library locally but failure in all 3 cases.

Kindly suggest. Thanks

d'kar
  • 1
  • 1
  • Welcome. Please take the Welcome [tour] to find out how to use this site. Use the provided formatting tools to make your question more readable (you can [edit] your question). Also, by using the [tag:fortran] tag, you can get more viewers knowledgeable about Fortran. If you tried answers from this site, you should link them, so that you are not just told you should use it. – Vladimir F Героям слава Oct 14 '18 at 16:39
  • *"It seem to work but with some warnings."* So what is the problem now? Does it work or not? Which warnings? – Vladimir F Героям слава Oct 14 '18 at 16:45
  • @VladimirF [1/2] I meant that I was able to compile the code to build it but I just did the same process and there seems to be a problem. It shows the error: f95 -free -c -u -V - -I./../lapack95_modules la_auxmod.f90 f95: error: -E or -x required when input is from standard input f951: Warning: Nonexistent include directory ‘./../lapack95_modules’ [-Wmissing-include-dirs] I copied the directory 'lapack95_modules' which I obtained from other link ( lapack95_linux_redhat.tgz) and then ran the command make double – d'kar Oct 14 '18 at 17:01
  • @VladimirF [2/2] but got the error: f95 -free -c -u -V - -I./../lapack95_modules f77_lapack_double.f90 f95: error: -E or -x required when input is from standard input make: *** [../make.inc:45: f77_lapack_double.o] Error 1 – d'kar Oct 14 '18 at 17:04
  • @deewakar, you need to walk before you run. What to the -u -V do and why are you using them? – evets Oct 14 '18 at 17:14
  • @evets I just followed the procedure as given in Read Me file to install lapack. While I initially thought it could be straight forward by linking it directly during compilation (as mentioned above , method 1) it seems this is not. As I am not too much aware of this, I came here looking for some help. Thanks – d'kar Oct 14 '18 at 17:18
  • @d'kar, Please read the documentation that comes with your compiler. It would have been helpful in your original post to show us the exactly command line and the name of the generated library. You said you had a `lapack95.a` file for the library when you built Netlib's lapack95. Is that the actual filename? If so, then `gfortran ... -llapack95` will cause gfortran to look for a file named `liblapack95.a`. – evets Oct 14 '18 at 18:16
  • @evets Hello, I have edited my original post to be more clear. Apologies for before. Thanks – d'kar Oct 14 '18 at 18:40

1 Answers1

0

Lapack library is a very useful tool to conduct matrix operations in a fast way. On the linux machine, it is very simple to install lapack with the build-in tools: dnf/yum or apt-get [2]. On my Fedora desktop, installation is like this:

sudo dnf install lapack64-devel.x86_64

Here is a small example on how to use lapack lib. The source code is to solve linear equations as linear_eqs.f [3].

    Program LinearEquations
c solving the matrix equation A*x=b using LAPACK
    Implicit none
c declarations, notice single precision
    Real*4 A(3,3), b(3)
    integer i, j, pivot(3), ok
c define matrix A
    A(1,1)=3.1
    A(1,2)=1.3
    A(1,3)=-5.7
    A(2,1)=1.0
    A(2,2)=-6.9
    A(2,3)=5.8
    A(3,1)=3.4
    A(3,2)=7.2
    A(3,3)=-8.8
c define vector b, make b a matrix and you can solve multiple
c equations with the same A but different b
    b(1)=-1.3
    b(2)=-0.1
    b(3)=1.8
c find the solution using the LAPACK routine SGESV
    call SGESV(3, 1, A, 3, pivot, b, 3, ok)
c
c parameters in the order as they appear in the function call
c    order of matrix A, number of right hand sides (b), matrix A,
c    leading dimension of A, array that records pivoting, 
c    result vector b on entry, x on exit, leading dimension of b
c    return value   
c   
c print the vector x
    do i=1, 3
       write(*,*) b(i)
    end do
    end

In this code, one lapack function 'sgesv()' is used. To execute this file, run the below command:

gfortran linear_eqs.f -llapack -o lineqs.out
./lineqs.out

The outputs will be:

1.00000024    
1.00000036    
1.00000036 

Reference

[1] https://github.com/fxcoudert/gfortran-for-macOS/releases

[2] BLAS, ATLAS, LAPACK Shared library minimal example

[3] http://physics.oregonstate.edu/~landaur/nacphy/lapack/codes/linear-f.html

DocNan
  • 11