在試圖在簡單程序中混合精度 - 使用實數和雙精度並使用BLAS的ddot例程時,我想出雙精度單元的錯誤輸出。下面的代碼:帶簡單MKL BLAS例程的Fortran雙精度程序
program test
!! adding this statement narrowed the issue down to ddot being considered real(4)
implicit none
integer, parameter :: dp = kind(1.0d0)
!! The following 2 lines were added for the calls to the BLAS routines.
!! This fixed the issue.
real(dp), external :: ddot
real, external :: sdot
real, dimension(3) :: a,b
real(dp), dimension(3) :: d,e
integer :: i
do i = 1,3
a(i) = 1.0*i
b(i) = 3.5*i
d(i) = 1.0d0*i
e(i) = 3.5d0*i
end do
write (*,200) "sdot real(4) = ", sdot(3,a,1,b,1) ! should work and return 49.0
write (*,200) "ddot real(4) = ", ddot(3,a,1,b,1) ! should not work
write (*,200) "sdot real(8) = ", sdot(3,d,1,e,1) ! should not work
write (*,200) "ddot real(8) = ", ddot(3,d,1,e,1) ! should work and return 49.0
200 format(a,f5.2)
end program test
我已經試過兩gfortran和ifort使用MKL BLAS庫如下編譯:
ifort -lmkl_intel_lp64 -lmkl_sequential -lmkl_core
gfortran -lmkl_intel_lp64 -lmkl_sequential -lmkl_core main.f90
輸出是:
sdot real(4) = 49.00
ddot real(4) = 0.00
sdot real(8) = 4.10
ddot real(8) = 0.00
我怎樣才能得到ddot例程正確處理雙精度值?
此外,添加-autodouble標誌(ifort)或-fdefault-real-8(gfortran)標誌使得兩個ddot例程都能正常工作,但sdot例程失敗。
編輯: 我添加了隱式無語句和ddot和sdot函數的兩個類型語句。沒有爲函數調用指定的類型,ddot被隱式輸入爲單精度實數。
對於一個真正廣泛的警告列表+1 – 2011-05-08 06:30:47
這是隱含的無警告,引導我進入解決方案。謝謝。 – Shamster 2011-05-08 07:15:41