BLAS daxpy没有添加任何东西,y没有变化

时间:2017-03-23 19:43:33

标签: fortran blas

我遇到以下问题:

我正在尝试使用BLAS子程序,但是在使用它们时,它们似乎没有工作/覆盖解决方案,例如,如果我尝试添加两个向量a和{{ 1}}并使用

运行一个函数
b

然后program test real(kind=8), dimension(:), allocatable :: a,b integer ::n print*, "input n, a, b" read*, n allocate(a(n), b(n)) read*, a, b print*, a print*, b call daxpy(n,1,a,1,b,1) print*, a print*, b deallocate(a, b) end program test 两次都出现非零值。

我假设子程序计算b然后将其覆盖为a+b

我尝试过使用b而没有任何BLAS调用,而且工作正常。

1 个答案:

答案 0 :(得分:0)

我认为你需要将双精度文字(或变量)传递给“alpha”(对于daxpy):

program test
    implicit none
    integer, parameter :: dp = kind(0.0d0)  ! for blas
    real(dp), dimension(:), allocatable :: a, b
    integer :: n
    n = 2
    allocate( a(n), b(n) )
    a = 1.0d0   ! or 1.0_dp
    b = 2.0d0
    print *, "b = ", b

      call daxpy( n, 1,     a, 1, b, 1 )   ! case (1)
    ! call daxpy( n, 1.0d0, a, 1, b, 1 )   ! case (2)
                    !^^^^
    print *, "b = ", b
    deallocate( a, b )
end program

Case (1):  // the second "b" usually gives more garbage data like 1.06E+160
 b =    2.0000000000000000        2.0000000000000000     
 b =    2.0000000000000000        2.0000000000000000 

Case (2):
 b =    2.0000000000000000        2.0000000000000000
 b =    3.0000000000000000        3.0000000000000000

如果我们为BLAS包含一些接口文件(例如,从MKL包含目录获取的mkl_blas.fi)

program test
    implicit none
    include 'mkl_blas.fi'
    ...

案例(1)给出了(多一点)显式消息的错误:

test.f90:13:38:

     call daxpy( n, 1,     a, 1, b, 1 )
                                      1
Error: Type mismatch in argument 'da' at (1); passed INTEGER(4) to REAL(8)