【发布时间】:2016-03-25 14:26:05
【问题描述】:
我需要在 Fortran 中制作一个点积。我可以使用 Fortran 的内部函数 dot_product 或使用 OpenBLAS 的 ddot。问题是ddot 速度较慢。这是我的代码:
使用 BLAS:
program VectorBLAS
! time VectorBlas.e = 0.30s
implicit none
double precision, dimension(3) :: b
double precision :: result
double precision, external :: ddot
integer, parameter :: LargeInt_K = selected_int_kind (18)
integer (kind=LargeInt_K) :: I
DO I = 1, 10000000
b(:) = 3
result = ddot(3, b, 1, b, 1)
END DO
end program VectorBLAS
与dot_product
program VectorModule
! time VectorModule.e = 0.19s
implicit none
double precision, dimension (3) :: b
double precision :: result
integer, parameter :: LargeInt_K = selected_int_kind (18)
integer (kind=LargeInt_K) :: I
DO I = 1, 10000000
b(:) = 3
result = dot_product(b, b)
END DO
end program VectorModule
这两个代码编译使用:
gfortran file_name.f90 -lblas -o file_name.e
我做错了什么? BLAS不是必须更快吗?
【问题讨论】: