Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMAKE: merge LAPACK_LIBRARIES and BLAS_LIBRARIES #14

Merged
merged 1 commit into from
Nov 3, 2021
Merged

CMAKE: merge LAPACK_LIBRARIES and BLAS_LIBRARIES #14

merged 1 commit into from
Nov 3, 2021

Conversation

band-a-prend
Copy link
Contributor

This patch merge LAPACK_LIBRARIES and BLAS_LIBRARIES lists
with removing of duplicates and replacing ";" with " "
within list to provide proper linking via scifor.pc pkgconfig.

Tested against lapack and openblas system libraries (cmake configuration output of SF compilation lines:).

Using lapack
initial:
-L${libdir} -lscifor /usr/lib64/liblapack.so;/usr/lib64/libblas.so /usr/lib64/libblas.so
patched:
-L${libdir} -lscifor /usr/lib64/liblapack.so /usr/lib64/libblas.so

Using openblas
initial:
-L${libdir} -lscifor /usr/lib64/libopenblas.so;/usr/lib64/libopenblas.so /usr/lib64/libopenblas.so
patched:
-L${libdir} -lscifor /usr/lib64/libopenblas.so

Related issue: https://github.com/QcmPlab/SciFortran/issues/4#issuecomment-736931796

TESTING:
The patched system installed SciFortran was tested for lapack/openblas with quick example:

! inv_triang_matrix.f90 
program inv_test

    use scifor
    implicit none

    real(8), dimension(3, 3) :: A, A_copy
    A = reshape([ 2.0d0, 0.0d0, 0.0d0, 0.0d0, 5.0d0, 0.0d0, 0.0d0, 0.0d0, 8.0d0 ], shape(A))
    write (*, '(3f8.3)' ) A
    A_copy = A

   call inv_triang(A)
   print *, "---------------------------"
   write (*, '(3f8.3)' ) A
   print *, "---------------------------"
   write (*, '(3f8.3)' ) A*A_copy

end program inv_test

! Output:

!   2.000   0.000   0.000
!   0.000   5.000   0.000
!   0.000   0.000   8.000
! ---------------------------
!   0.500   0.000   0.000
!  -0.000   0.200   0.000
!  -0.000  -0.000   0.125
! ---------------------------
!   1.000   0.000   0.000
!  -0.000   1.000   0.000
!  -0.000  -0.000   1.000

Result was compared with python implementation (in fortran case matrix is transpose but it's no matter for triang matrix):

# matrix_inv.py 
from scipy import linalg
import numpy as np

b = np.array([[2., 0., 0.], [0., 5., 0.], [0., 0., 8.]])
print(b)
print('---------------------------')
print(linalg.inv(b))
#[[ 0.5    0.    -0.   ]
# [ 0.     0.2   -0.   ]
# [ 0.     0.     0.125]]
print('---------------------------')
print(np.dot(b, linalg.inv(b)))
#[[1. 0. 0.]
# [0. 1. 0.]
# [0. 0. 1.]]

This patch merge LAPACK_LIBRARIES and BLAS_LIBRARIES lists
with removing of duplicates and replacing ";" with " "
within list to provide proper linking via scifor.pc pkgconfig.

Tested against lapack and openblas system libraries.

Using lapack
initial: "SF compilation lines: -L${libdir} -lscifor /usr/lib64/liblapack.so;/usr/lib64/libblas.so /usr/lib64/libblas.so"
patched: "SF compilation lines: -L${libdir} -lscifor /usr/lib64/liblapack.so /usr/lib64/libblas.so"

Using openblas
initial: "SF compilation lines: -L${libdir} -lscifor /usr/lib64/libopenblas.so;/usr/lib64/libopenblas.so /usr/lib64/libopenblas.so"
patched: "SF compilation lines: -L${libdir} -lscifor /usr/lib64/libopenblas.so"

Related issue: https://github.com/QcmPlab/SciFortran/issues/4#issuecomment-736931796

Signed-off-by: Sergey Torokhov <torokhov-s-a@yandex.ru>
@band-a-prend
Copy link
Contributor Author

band-a-prend commented Nov 3, 2021

I.e. in my case cmake LAPACK_LIBRARIES additionally returns blas implementation library too, but I can't find the proof of that in cmake documentation.

Therefore the separate BLAS_LIBRARIES isn't dropped here.

@aamaricci aamaricci merged commit 7724110 into aamaricci:master Nov 3, 2021
@aamaricci
Copy link
Owner

Thanks.
I merged this in the master branch.
Indeed, this patch solve a long standing issue...

Note that BLAS and LAPACK libraries are basically found together within CMake macro.

@band-a-prend band-a-prend deleted the cmake-lapack branch November 3, 2021 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants