使用CUDA FORTRAN中的cusparseDgtsv函数的运行时错误

时间:2019-06-27 18:26:26

标签: cuda fortran nvidia pgi-accelerator

我一直在测试cusparse函数GTSV,以便在涉及解决许多TDMA的研究项目中使用它。我已经试用了涉及cusparse函数的CUDA FORTRAN示例代码。一切都很好,但是我发现输出有问题。因此,我检查了操作状态,并在输出中看到了这一点:

  

PGI $ ./test_cuda_cusparse.exe    创建cusparseCreate_status:   CUSPARSE_STATUS_SUCCESS
  Dgtsv状态:CUSPARSE_STATUS_INVALID_VALUE

     

解决方案是:SOL(1):1.000000000000000 SOL(2):2.000000000000000 SOL(3):3.000000000000000   SOL(4):4.000000000000000 SOL(5):5.000000000000000 SOL(6):6.000000000000000 SOL(7):7.000000000000000 SOL(8):8.000000000000000   SOL(9):9.000000000000000 SOL(10):10.00000000000000 SOL(11):11.00000000000000 SOL(12):12.00000000000000 SOL(13):13.00000000000000   SOL(14):14.00000000000000 SOL(15):
  15.00000000000000 SOL(16):16.00000000000000 SOL(17):15.00000000000000 SOL(18):14.00000000000000   SOL(19):13.00000000000000 SOL(20):
  12.00000000000000 SOL(21):11.00000000000000 SOL(22):10.00000000000000 SOL(23):9.000000000000000   SOL(24):8.000000000000000 SOL(25):
  7.000000000000000 SOL(26):6.000000000000000 SOL(27):5.000000000000000 SOL(28):4.000000000000000   SOL(29):3.000000000000000 SOL(30):
  2.000000000000000 SOL(31):1.000000000000000

现在,我搜索了此错误,并且据我所知,我已经满足避免该错误的所有标准,即:

  

CUSPARSE_STATUS_INVALID_VALUE =传递了无效的参数(m <3,   n <0)。

我的M和N是: m = 31且n = 1 我已经在代码中插入了所有所需的细节,包括预期的输出(作为注释):

 !********** cuda_tdma.cuf ************!

PROGRAM TDMA

    use iso_C_binding
    use cudafor
    use cusparse
    implicit none

    !    atri - sub-diagonal (means it is the diagonal below the main diagonal)
    !    btri - the main diagonal
    !    ctri - sup-diagonal (means it is the diagonal above the main diagonal)
    !    dtri - right part
    !    npts - number of equations

    integer npts,i,istat
    parameter (npts=31)
    real(8),dimension(npts) :: atri,btri,ctri,dtri
    integer(4)  cusparseCreate_status
    type(cusparseHandle) :: handle 
    integer(4) :: m, n, ldb
    real(8), device, dimension(npts) :: dl,d,du,B

    !***** TEST VALUES INITIALIZATION *****!

    atri       = 1.0    
    atri(1)    = 0.0

    btri       = 2.0

    ctri       = 1.0
    ctri(npts) = 0.0

    do i=1,16           !***** dtri = transpose of (1,2,3,4,....16,15,14,13,12,....1) *****!
    dtri(i)=i
    dtri(32-i)=i    
    enddo   

    !atri(1)=0  
    !atri(2)=-1
    !atri(3)=-1
    !btri(1)=3
    !btri(2)=3
    !btri(3)=3
    !ctri(1)=-1
    !ctri(2)=-1
    !ctri(3)=0
    !dtri(1)=-1
    !dtri(2)=7
    !dtri(3)=7

    !***** memcpy() HtoD *****!

    dl  = atri
    d   = btri
    du  = ctri
    B   = dtri
    m   = npts
    n   = 1
    ldb = 1

    !**** cusparse_create and check ****!

    cusparseCreate_status = cusparseCreate(handle) 

    print*,'CREATE cusparseCreate_status: '
    if(cusparseCreate_status.eq.CUSPARSE_STATUS_SUCCESS) print*,'CUSPARSE_STATUS_SUCCESS'
    if(cusparseCreate_status.eq.CUSPARSE_STATUS_NOT_INITIALIZED) print*,'CUSPARSE_STATUS_NOT_INITIALIZED'
    if(cusparseCreate_status.eq.CUSPARSE_STATUS_ALLOC_FAILED) print*,'CUSPARSE_STATUS_ALLOC_FAILED'
    if(cusparseCreate_status.eq.CUSPARSE_STATUS_ARCH_MISMATCH) print*,'CUSPARSE_STATUS_ARCH_MISMATCHED'

    !***** Calling Dgtsv and checking the output Status *****!

    istat = cusparseDgtsv(handle,m,n,dl,d,du,B,ldb)

    print*,'Dgtsv STATUS: '
    if(istat.eq.CUSPARSE_STATUS_SUCCESS) print*,'CUSPARSE_STATUS_SUCCESS'
    if(istat.eq.CUSPARSE_STATUS_NOT_INITIALIZED) print*,'CUSPARSE_STATUS_NOT_INITIALIZED'
    if(istat.eq.CUSPARSE_STATUS_ALLOC_FAILED) print*,'CUSPARSE_STATUS_ALLOC_FAILED'
    if(istat.eq.CUSPARSE_STATUS_INVALID_VALUE) print*,'CUSPARSE_STATUS_INVALID_VALUE'
    if(istat.eq.CUSPARSE_STATUS_ARCH_MISMATCH) print*,'CUSPARSE_STATUS_ARCH_MISMATCHED'
    if(istat.eq.CUSPARSE_STATUS_EXECUTION_FAILED) print*,'CUSPARSE_STATUS_EXECUTION_FAILED'
    if(istat.eq.CUSPARSE_STATUS_INTERNAL_ERROR) print*,'CUSPARSE_STATUS_INTERNAL_ERROR'

    !***** memcpy() DtoH *****!

    dtri = B

    !***** Printing solution *****!

    print*,'The solution is: '          !***** Expexted Solution = transpose of (0,1,0,2,0,3,...,0,8,0,7,0,6,...,0,1,0)
    do i=1,npts
        print*,'SOL(',i,'):',dtri(i)
    end do

 END PROGRAM TDMA

为什么输出错误?

0 个答案:

没有答案