调用BLAS函数 [英] Calling BLAS functions
问题描述
这是一个简单的程序
PROGRAM MAIN
implicit none
integer, PARAMETER :: N=10
real*8 :: A(N)
real*8 :: x=0.1D0
integer :: i=1
Do i=1,N
A(i)=i
end do
call dscal(N,x, A, 1)
x=dasum(N,A,1)
END PROGRAM MAIN
我用命令编译
gfortran test.f90 -o test -O1 -I /usr/include/ -L /usr/lib -lblas
虽然我调用子例程dscal
没问题,但是函数dasum
While I have no problem calling the subroutine dscal
I get the following error for the function dasum
test.f90:15.2:
x=dasum(N,A,1)
1
Error: Function 'dasum' at (1) has no IMPLICIT type
我应该包括一个定义BLAS功能的文件吗?
Should I include a certain file to define the BLAS functions?
推荐答案
对于函数,您需要手动指定返回值(如果感觉很豪华,还可以选择external
):
For functions, you need to manually specify the return value (and if you are feeling posh, optionally an external
):
real*8,external :: dasum
此外,请不要使用real*8
.它不符合标准,不便于移植并且令人困惑.而是使用kind
参数定义精度,例如:
Additionally, please don't use real*8
. It is not Standard-conforming, not portable and quite confusing. Instead use the kind
parameter to define the precision, e.g.:
real(kind=kind(1.d0))
之类的.如果可以使用ISO_Fortran_env module
,请使用其常量REAL32
和REAL64
.
or the like. If you can use the ISO_Fortran_env module
, use its constants REAL32
and REAL64
.
这篇关于调用BLAS函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!