Reputation: 2801
How can I multiply two matrices by Lapack package for Fortran? I use gfortran compiler in ubuntu. My code which doesn't work is:
program main
integer, parameter :: n = 10
double precision :: alpha = 1.0, beta = 0.0
real, dimension(10,10) :: a
do i1 = 1,n
do j1 = 1,n
a(i1,j1) = j1 + (i1-1)*n
end do
end do
call cpu_time(start)
call DGEMM('N', 'N', n, n, n, alpha, a, n, a, n, beta, a, n)
call cpu_time(end)
print *, end - start
end program main
I used:
gfortran 0.f90 -llapack
It returned:
/tmp/ccPy78g5.o: In function `MAIN__':
0.f90:(.text+0x110): undefined reference to `dgemm_'
collect2: ld returned 1 exit status
Upvotes: 3
Views: 8298
Reputation: 3330
The error message means, that your compiler (gfortran) cannot find lapack
or rather dgemm
. Please make sure, that lapack is in your path. Alternatively (I assume you are using Ubuntu Linux) you could try -lblas
instead (after installing it, of course - afaik ubuntu follows a different naming convention):
gfortran 0.f90 -lblas -llapack
Edit
Alternatively, you may pass the path to the library directly as an argument. By default, gfortran will look in `/usr/local/lib/``for the specified libraries. If the library is located somewhere else, you may instead use something like
gfortran 0.f90 /path/to/my/library.a
Upvotes: 3