Fortran Coder

查看: 2448|回复: 3
打印 上一主题 下一主题

[数学库] linux中gfortran如何调用MKL

[复制链接]

16

帖子

7

主题

0

精华

入门

F 币
66 元
贡献
36 点
跳转到指定楼层
楼主
发表于 2022-7-11 21:25:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 Neo123 于 2022-7-11 21:27 编辑

[Fortran] 纯文本查看 复制代码
!===============================================================================
! Copyright 2004-2020 Intel Corporation.
!
! This software and the related documents are Intel copyrighted  materials,  and
! your use of  them is  governed by the  express license  under which  they were
! provided to you (License).  Unless the License provides otherwise, you may not
! use, modify, copy, publish, distribute,  disclose or transmit this software or
! the related documents without Intel's prior written permission.
!
! This software and the related documents  are provided as  is,  with no express
! or implied  warranties,  other  than those  that are  expressly stated  in the
! License.
!===============================================================================

!   Content : Intel(R) Math Kernel Library (Intel(R) MKL) DSS Fortran-90 example
!
!*******************************************************************************
!--------------------------------------------------------------------------
!
! Example program for solving a symmetric positive definite system of
! equations.
!
!--------------------------------------------------------------------------
INCLUDE 'mkl_dss.f90' ! Include the standard DSS "header file."
PROGRAM solver_f90_test
    use mkl_dss
    IMPLICIT NONE
    INTEGER, PARAMETER :: dp = KIND(1.0D0)
    INTEGER :: error
    INTEGER :: i
    INTEGER, PARAMETER :: bufLen = 20
! Define the data arrays and the solution and rhs vectors.
    INTEGER, ALLOCATABLE :: columns( : )
    INTEGER :: nCols
    INTEGER :: nNonZeros
    INTEGER :: nRhs
    INTEGER :: nRows
    REAL(KIND=DP), ALLOCATABLE :: rhs( : )
    INTEGER, ALLOCATABLE :: rowIndex( : )
    REAL(KIND=DP), ALLOCATABLE :: solution( : )
    REAL(KIND=DP), ALLOCATABLE :: values( : )
    TYPE(MKL_DSS_HANDLE) :: handle ! Allocate storage for the solver handle.
    REAL(KIND=DP),ALLOCATABLE::statOUt( : )
    CHARACTER*15 statIn
    INTEGER perm(1)
    INTEGER buff(bufLen)
! Set the problem to be solved.
    nRows = 5
    nCols = 5
    nNonZeros = 9
    nRhs = 1
    perm(1) = 0
    ALLOCATE(rowIndex(nRows + 1))
    rowIndex = (/ 1, 6, 7, 8, 9, 10 /)
    ALLOCATE( columns( nNonZeros ) )
    columns = (/ 1, 2, 3, 4, 5, 2, 3, 4, 5 /)
    ALLOCATE(values(nNonZeros))
    values = (/ 9.0_DP, 1.5_DP, 6.0_DP, 0.75_DP, 3.0_DP, 0.5_DP, 12.0_DP, &
              0.625_DP, 16.0_DP /)
    ALLOCATE(rhs(nRows))
    rhs = (/ 1.0_DP, 2.0_DP, 3.0_DP, 4.0_DP, 5.0_DP /)
! Initialize the solver.
    error = DSS_CREATE(handle, MKL_DSS_DEFAULTS)
    IF (error /= MKL_DSS_SUCCESS) GOTO 999
! Define the non-zero structure of the matrix.
    error = DSS_DEFINE_STRUCTURE(handle, MKL_DSS_SYMMETRIC, rowIndex, nRows, &
                                 nCols, columns, nNonZeros)
    IF (error /= MKL_DSS_SUCCESS) GOTO 999
! Reorder the matrix.
    error = DSS_REORDER(handle, MKL_DSS_DEFAULTS, perm)
    IF (error /= MKL_DSS_SUCCESS) GOTO 999
! Factor the matrix.
    error = DSS_FACTOR_REAL(handle, MKL_DSS_DEFAULTS, values)
    IF (error /= MKL_DSS_SUCCESS) GOTO 999
! Allocate the solution vector and solve the problem.
    ALLOCATE(solution(nRows))
    error = DSS_SOLVE_REAL(handle, MKL_DSS_DEFAULTS, rhs, nRhs, solution)
    IF (error /= MKL_DSS_SUCCESS) GOTO 999
! Print Out the determinant of the matrix (no statistics for a diagonal matrix)
    IF(nRows < nNonZeros) THEN
       ALLOCATE(statOut(5))
       statIn = 'determinant'
       call mkl_cvt_to_null_terminated_str(buff,bufLen,statIn)
       error = DSS_STATISTICS(handle, MKL_DSS_DEFAULTS, buff, statOut)
       IF (error /= MKL_DSS_SUCCESS) GOTO 999
       WRITE(*,"('pow of determinant is '(5F10.3))") (statOut(1))
       WRITE(*,"('base of determinant is '(5F10.3))") (statOut(2))
       WRITE(*,"('Determinant is '(5F10.3))") ((10**statOut(1))*statOut(2))
    END IF
! Deallocate solver storage and various local arrays.
    error = DSS_DELETE(handle, MKL_DSS_DEFAULTS)
    IF (error /= MKL_DSS_SUCCESS) GOTO 999
    IF (ALLOCATED(rowIndex)) DEALLOCATE(rowIndex)
    IF (ALLOCATED(columns )) DEALLOCATE(columns)
    IF (ALLOCATED(values )) DEALLOCATE(values)
    IF (ALLOCATED(rhs)) DEALLOCATE(rhs)
    IF (ALLOCATED(statOut)) DEALLOCATE(statOut)
! Print the solution vector, deallocate it and exit
    WRITE(*,"('Solution Array: '(5F10.3))") (solution(i), i = 1, nCols)
    IF (ALLOCATED(solution)) DEALLOCATE(solution)
    GOTO 1000
! Print an error message and exit
999 WRITE(*,*) "Solver returned error code ", error
    STOP 1
1000 CONTINUE
END PROGRAM solver_f90_test
请教各位大佬,附件dss_sym_f90.f90为mkl的一个例子。想通过gfortan调用MKL编译这个例子,但一直报错。gfortran的编译选项如下所示(根据intel ineAPI Math Kernel Library Link Line Advisor得到的),但是链接报错,不知道怎么回事?
/usr/bin/ld: CMakeFiles/Anura3D_2021.dir/dss_sym_f90.f90.o: in function `MAIN__':
dss_sym_f90.f90:(.text+0xd6c): undefined reference to `dss_create_'
/usr/bin/ld: dss_sym_f90.f90:(.text+0xdc4): undefined reference to `dss_define_structure_'
/usr/bin/ld: dss_sym_f90.f90:(.text+0xdfc): undefined reference to `dss_reorder_'
/usr/bin/ld: dss_sym_f90.f90:(.text+0xe30): undefined reference to `dss_factor_real_d__'
/usr/bin/ld: dss_sym_f90.f90:(.text+0xffd): undefined reference to `dss_solve_real_d__'
/usr/bin/ld: dss_sym_f90.f90:(.text+0x1174): undefined reference to `mkl_cvt_to_null_terminated_str_'
/usr/bin/ld: dss_sym_f90.f90:(.text+0x1195): undefined reference to `dss_statistics_'
/usr/bin/ld: dss_sym_f90.f90:(.text+0x13dc): undefined reference to `dss_delete_'
collect2: error: ld returned 1 exit status


[Fortran] 纯文本查看 复制代码
add_definitions(" -m64 \
 -I'${CMAKE_LIBRARY_PATH}/include' \
 -L'${CMAKE_LIBRARY_PATH}/lib/intel64' \
  -Wl,--start-group ${CMAKE_LIBRARY_PATH}/lib/intel64/libmkl_gf_ilp64.a ${CMAKE_LIBRARY_PATH}/lib/intel64/libmkl_sequential.a ${CMAKE_LIBRARY_PATH}/lib/intel64/libmkl_core.a ${CMAKE_LIBRARY_PATH}/lib/intel64/libmkl_blacs_openmpi_ilp64.a -Wl,--end-group -lpthread -lm")


分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

44

帖子

4

主题

0

精华

熟手

F 币
179 元
贡献
90 点
沙发
发表于 2022-7-12 16:03:27 | 只看该作者
我上次遇到过类似许多未定义的错误(undefined reference) ,最后发现是路径错误。你的这个dss_sym_f90.f90.o很奇怪,如果是dss_sym_f90.f90编译后的object文件,后缀是dss_sym_f90.o。我感觉是你make的时候文件名弄错了。

16

帖子

7

主题

0

精华

入门

F 币
66 元
贡献
36 点
板凳
 楼主| 发表于 2022-7-13 18:19:34 | 只看该作者
zjk0112 发表于 2022-7-12 16:03
我上次遇到过类似许多未定义的错误(undefined reference) ,最后发现是路径错误。你的这个dss_sym_f90.f90. ...

我也是路径不对

44

帖子

4

主题

0

精华

熟手

F 币
179 元
贡献
90 点
地板
发表于 2022-7-15 16:51:09 | 只看该作者
Neo123 发表于 2022-7-13 18:19
我也是路径不对

问题解决了就好
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-12-24 21:10

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表