Page 1 of 1

How to use CULA CUDA Device Platform

PostPosted: Tue Nov 11, 2014 12:14 am
by zhouzhen
Now I want to solve the liner function Ax=b by the platform of CUDA Device.
status = culaSparseSetCudaDevicePlatform didn't work well,while
status = culaSparseSetCudaPlatform was fine.

The following is about of the code(didn't work well). I will be very thankful if you can help me.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! CULA Example: Iterative System Solver Using Fortran Interface
!

program cula_iterative_system_solve_fortran

use cudafor
use cula_sparse_type
use cula_sparse
use, intrinsic :: iso_c_binding

implicit none

! library handle
type(culaSparseHandle) :: handle

! configuration options
type(culaSparseConfig) :: config
type(culaSparseCudadeviceOptions) :: platformOpts
type(culaSparseCsrOptions) :: formatOpts
type(culaSparseCgOptions) :: solverOpts
type(culaSparsejacobiOptions) :: precondOpts

! results
type(culaSparseResult) :: res
type(culaSparseResult),device :: d_res

double precision, dimension(:), allocatable :: an
double precision, dimension(:), allocatable :: x
double precision, dimension(:), allocatable :: b

integer, dimension(:), allocatable :: rowptr
integer, dimension(:), allocatable :: colind
!!!!!!!!!!!! device
real*8,device, allocatable :: d_an(:)
double precision,device, dimension(:), allocatable :: d_x
double precision,device, dimension(:), allocatable :: d_b

integer, device,dimension(:), allocatable :: d_rowptr
integer,device, dimension(:), allocatable :: d_colind
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
integer n
integer nnz

integer status
integer i, idx

character*512 :: buf
integer, parameter :: bufsize = 512

! n = 8388608
n=177310
! nnz=8000000
nnz = (n-2)*3 + 2*2
open(4,file='date.dat')
open(5,file='d.dat')
print *, '-----------------------------------------------'
print *, 'Creating a test matrix...'
print *, '-----------------------------------------------'

print *, 'n =', n
print *, 'nnz =', nnz
print *

! allocate matrix
allocate(an(nnz))
allocate(rowPtr(n+1))
allocate(colInd(nnz))

allocate(d_an(nnz))
allocate(d_rowPtr(n+1))
allocate(d_colInd(nnz))

! allocate vectors
allocate(b(n))
allocate(x(n))
allocate(d_b(n))
allocate(d_x(n))


! fill matrix with simple tridiagonal system
idx = 1
do 10 i=1, n

b(i) = 5.0

rowPtr(i) = idx

! subdiagonal
if(i .gt. 1) then
colInd(idx) = i-1
an(idx) = 1.0
idx = idx + 1
endif

! diagonal
colInd(idx) = i
an(idx) = 10.0
idx = idx + 1

! superdiagonal
if( i .lt. n ) then
colInd(idx) = i+1
an(idx) = 1.0
idx = idx + 1
endif
! write(4,*) an(idx),colInd(idx)
10 continue

rowPtr(n+1) = idx

do i=1,nnz
write(4,*) an(i),colInd(i)
end do
do i=1,n+1
write(5,*) rowptr(i)
end do

d_an=an
d_colInd=colInd
d_rowptr=rowPtr
d_x=x
d_b=b

print *, '-----------------------------------------------'
print *, 'Configuring solver...'
print *, '-----------------------------------------------'

! create library handle
status = culaSparseCreate(handle)

! initalize configuration and change some defaults
status = culaSparseConfigInit(handle, config)
config%relativeTolerance = 1e-9
config%maxIterations = 500

! print the configuration string
status = culaSparseGetConfigString(handle, config, buf, bufsize)
print *, buf

! initilize cuda platform and set indexing
status = culaSparseCudadeviceOptionsInit(handle, platformOpts)

! initialize csr options
status = culaSparseCsrOptionsInit(handle, formatOpts)
formatOpts%indexing = 1

! initilize cg solver options
status = culaSparseCgOptionsInit(handle, solverOpts)

! initialize jacobi preconditioner
status = culaSparsejacobiOptionsInit(handle, precondOpts)
! status = culaSparsefainvOptionsInit(handle, precondOpts)

print *, '-----------------------------------------------'
print *, 'Running solver...'
print *, '-----------------------------------------------'

! run solver
status = culaSparseCudadeviceDcsrCgjacobi(handle, config, platformOpts,&
formatOpts, &
solverOpts, precondOpts, n, nnz,d_an, d_rowPtr, d_colInd, d_x, d_b, d_res)
res=d_res
! get status string summary
status = culaSparseGetLastStatusString(handle, buf, bufsize)
print *, buf
print *

print *, '-----------------------------------------------'
print *, 'Solver results...'
print *, '-----------------------------------------------'

! print the result string
status = culaSparseGetResultString(handle, res, buf, bufsize)
print *, buf

end
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
The compiling result is "PGF90-S-0155-Could not resolve generic procedure culasparsecudadevicedcsrcgjacobi (iterativeSystemSolveFortran.cuf: 160)
0 inform, 0 warnings, 1 severes, 0 fatal for cula_iterative_system_solve_fortran"!