2017-08-15 198 views
2

我有一個問題,將lapack鏈接到Fortran示例程序。這裏是example.f95從英特爾MKL鏈接LAPACK與gfortran

Program LinearEquations 
! solving the matrix equation A*x=b using LAPACK 
Implicit none 

! declarations 
double precision :: A(3,3), b(3) 
integer :: i, pivot(3), ok 

! matrix A 
A(1,:)=(/3, 1, 3/) 
A(2,:)=(/1, 5, 9/) 
A(3,:)=(/2, 6, 5/) 

! vector b 
b(:)=(/-1, 3, -3/) 
!b(:)=(/2, 2, 9/) 

! find the solution using the LAPACK routine DGESV 
call DGESV(3, 1, A, 3, pivot, b, 3, ok) 

! print the solution x 
do i=1, 3 
    write(*,9) i, b(i) 
end do 

9 format('x[', i1, ']= ', f5.2) 
end program LinearEquations 

這裏我已經安裝了庫

/opt/intel/compilers_and_libraries_2017.4.196/linux/mkl/lib/intel64_lin/libmkl_lapack95_ilp64.a

我使用gfortran編譯程序的程序:

gfortran -o example example.f95 -L/opt/intel/compilers_and_libraries_2017.4.196/linux/mkl/lib/intel64_lin/libmkl_lapack95_ilp64.a

它抱怨

/tmp/ccWtxMFP.o: In function `MAIN__': 
example.f95:(.text+0xf0): undefined reference to `dgesv_' 
collect2: error: ld returned 1 exit status 

有人可以幫我解決這個問題嗎?非常感謝

+1

您似乎使用默認的32位整數,同時指定需要64位整數的庫。請參閱英特爾®mkl鏈接顧問程序小程序以獲取一整套所需的庫。 – tim18

+0

我試過ia32,但它不起作用。 – Vlada

+1

正如您發現的那樣,閱讀文檔比通過反覆試驗更容易。 – tim18

回答

1

有兩種類型的鏈接:

  • 靜態鏈接:您與靜態庫鏈接程序。

    例如:gfortran program.f90 /path-to-lib/libmy.a -o program.x

  • 動態鏈接:你的共享庫鏈接程序:

    例如:gfortran program.f90 -L/path-to-lib -lmy -o program.x

    與libmy.so鏈接程序。對於靜態鏈接

    -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_gf_lp64.a ${MKLROOT}/lib/intel64/libmkl_sequential.a ${MKLROOT}/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -lm -ldl

根據MKL Advisor你應該使用這個。或:

-L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_gf_lp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl

動態鏈接。

其中${MKLROOT}是MKL的路徑。

+0

是的,現在它工作,我用錯了鏈接。當我使用你的建議時,一切正常。非常感謝你。 – Vlada

相關問題