[UPDATE] Modified tests to supèport GPU SpMV computing, Moreover dinstinct routine for persistant is now present in psi_dswpadata

communication_v2
Stack-1 3 weeks ago
parent 75d86864b0
commit be6f27069a

File diff suppressed because it is too large Load Diff

@ -30,11 +30,6 @@ module psb_comm_neighbor_impl_mod
logical :: persistent_request_ready = .false.
logical :: persistent_in_flight = .false.
integer(psb_ipk_) :: persistent_buffer_size = 0
integer(psb_ipk_) :: diag_init_calls = 0
integer(psb_ipk_) :: diag_start_calls = 0
integer(psb_ipk_) :: diag_ineighbor_calls = 0
integer(psb_ipk_) :: diag_wait_calls = 0
integer(psb_ipk_) :: diag_buffer_reallocs = 0
contains
procedure, pass :: init => psb_comm_neighbor_init
procedure, pass :: free => neighbor_topology_free
@ -398,11 +393,6 @@ contains
this%persistent_request_ready = .false.
this%persistent_in_flight = .false.
this%persistent_buffer_size = 0
this%diag_init_calls = 0
this%diag_start_calls = 0
this%diag_ineighbor_calls = 0
this%diag_wait_calls = 0
this%diag_buffer_reallocs = 0
call this%free(info)
end subroutine psb_comm_neighbor_destroy
@ -440,16 +430,6 @@ contains
this%persistent_request_ready = .false.
this%persistent_in_flight = .false.
this%persistent_buffer_size = 0
this%diag_init_calls = 0
this%diag_start_calls = 0
this%diag_ineighbor_calls = 0
this%diag_wait_calls = 0
this%diag_buffer_reallocs = 0
this%diag_init_calls = 0
this%diag_start_calls = 0
this%diag_ineighbor_calls = 0
this%diag_wait_calls = 0
this%diag_buffer_reallocs = 0
end subroutine psb_comm_neighbor_init

@ -4,8 +4,8 @@ MODDIR=$(INSTALLDIR)/modules/
include $(INCDIR)/Make.inc.psblas
LIBDIR=$(INSTALLDIR)/lib/
PSBLAS_LIB= -L$(LIBDIR) -lpsb_util -lpsb_linsolve -lpsb_prec -lpsb_base
LDLIBS=$(PSBLDLIBS)
PSBLAS_LIB= -L$(LIBDIR) $(LCUDA) -lpsb_util -lpsb_linsolve -lpsb_prec -lpsb_base -lpsb_cuda -lpsb_ext
LDLIBS=$(PSBGPULDLIBS)
FINCLUDES=$(FMFLAG)$(MODDIR) $(FMFLAG).
@ -24,7 +24,7 @@ runsd:
(if test ! -d runs ; then mkdir runs; fi)
psb_comm_cg_test.o: $(PROGSRC)
$(FC) $(FCOPT) $(FINCLUDES) $(FDEFINES) -c $(PROGSRC) -o $@
$(FC) $(FCOPT) $(FINCLUDES) $(FDEFINES) $(FCUDEFINES) -c $(PROGSRC) -o $@
$(EXE): $(TOBJS)
$(FLINK) $(LOPT) $(TOBJS) -o $(EXE) $(PSBLAS_LIB) $(LDLIBS)

@ -1,5 +1,8 @@
program psb_comm_cg_test
use psb_base_mod
#ifdef PSB_HAVE_CUDA
use psb_cuda_mod
#endif
use psb_prec_mod
use psb_linsolve_mod
use psb_comm_factory_mod
@ -14,8 +17,14 @@ program psb_comm_cg_test
type(psb_desc_type) :: desc_a
type(psb_d_vect_type) :: b, x
type(psb_dprec_type) :: prec
integer(psb_ipk_) :: info, iam, np
#ifdef PSB_HAVE_CUDA
type(psb_d_vect_cuda) :: vmold
type(psb_i_vect_cuda) :: imold
type(psb_d_cuda_hlg_sparse_mat), target :: ahlg
class(psb_d_base_sparse_mat), pointer :: agmold
#endif
integer(psb_ipk_) :: info, my_rank, np
integer(psb_ipk_) :: desc_me, desc_np
integer(psb_ipk_) :: idim, itmax, itrace, istop, iter
integer(psb_ipk_) :: scheme_idx, prec_idx, rep, nrep, nwarm
@ -35,7 +44,9 @@ program psb_comm_cg_test
character(len=20) :: prec_name(n_precs)
character(len=5) :: afmt
character(len=256) :: arg
character(len=16) :: gpu_arg
logical :: setup_done
logical :: use_gpu
info = psb_success_
afmt = 'CSR'
@ -47,6 +58,11 @@ program psb_comm_cg_test
itrace = -1
istop = 2
eps = 1.d-6
#ifdef PSB_HAVE_CUDA
use_gpu = .true.
#else
use_gpu = .false.
#endif
scheme_type = (/ psb_comm_isend_irecv_, psb_comm_ineighbor_alltoallv_, &
& psb_comm_persistent_ineighbor_alltoallv_ /)
scheme_name(1) = 'isend_irecv'
@ -89,15 +105,31 @@ program psb_comm_cg_test
info = psb_success_
end if
end if
call parse_gpu_arg(use_gpu, info)
if (info /= psb_success_) then
write(psb_err_unit,'("Invalid value for --gpu option. Use --gpu=TRUE or --gpu=FALSE")')
stop 1
end if
! call psb_set_debug_level(psb_debug_ext_)
! call probe_ieee('before psb_init')
call psb_init(ctxt)
#ifdef PSB_HAVE_CUDA
if (use_gpu) call psb_cuda_init(ctxt)
#endif
! call probe_ieee('after psb_init')
call clear_ieee_flags()
! call probe_ieee('after clear_ieee_flags')
call psb_info(ctxt, iam, np)
call psb_info(ctxt, my_rank, np)
#ifndef PSB_HAVE_CUDA
if (use_gpu .and. my_rank == psb_root_) then
write(psb_out_unit,'("Warning: --gpu=TRUE requested but this executable was built without CUDA support. Running on CPU.")')
end if
use_gpu = .false.
#endif
allocate(setup_time(n_precs,n_schemes,nrep), solve_time(n_precs,n_schemes,nrep), &
& total_time(n_precs,n_schemes,nrep), final_error(n_precs,n_schemes,nrep), &
@ -107,7 +139,7 @@ program psb_comm_cg_test
& comm_set_time(n_precs,n_schemes,nrep), krylov_time(n_precs,n_schemes,nrep), stat=info)
if (info /= psb_success_) stop 1
if (iam == psb_root_) then
if (my_rank == psb_root_) then
write(psb_out_unit,*) 'Welcome to PSBLAS version: ', psb_version_string_
write(psb_out_unit,*) 'This is the comm/cg test program'
write(psb_out_unit,'("Grid dimensions : ",i4," x ",i4," x ",i4)') idim,idim,idim
@ -117,18 +149,32 @@ program psb_comm_cg_test
write(psb_out_unit,'("Max iterations (CG) : ",i0)') itmax
write(psb_out_unit,'("Repetitions : ",i0)') nrep
write(psb_out_unit,'("Warmup solves : ",i0)') nwarm
write(psb_out_unit,'("GPU enabled : ",l1)') use_gpu
write(psb_out_unit,'(" ")')
write(psb_out_unit,'("Usage: ./psb_comm_cg_test [idim] [nrep] [nwarm] [itmax]")')
write(psb_out_unit,'("Usage: ./psb_comm_cg_test [idim] [nrep] [nwarm] [itmax] [--gpu=TRUE|FALSE]")')
write(psb_out_unit,'(" ")')
end if
call psb_barrier(ctxt)
t_start = psb_wtime()
! call probe_ieee('before psb_d_gen_pde3d')
call psb_d_gen_pde3d(ctxt,idim,a,b,x,desc_a,afmt,info)
! call probe_ieee('after psb_d_gen_pde3d')
if (info /= psb_success_) goto 9999
#ifdef PSB_HAVE_CUDA
if (use_gpu) then
agmold => ahlg
call a%cscnv(info,mold=agmold)
if (info /= psb_success_) goto 9999
call desc_a%cnv(mold=imold)
if (info /= psb_success_) goto 9999
call psb_geasb(x,desc_a,info,mold=vmold)
if (info /= psb_success_) goto 9999
call psb_geasb(b,desc_a,info,mold=vmold)
if (info /= psb_success_) goto 9999
end if
#endif
do prec_idx = 1, n_precs
do scheme_idx = 1, n_schemes
do rep = 1, nrep
@ -206,31 +252,20 @@ program psb_comm_cg_test
final_error(prec_idx,scheme_idx,rep) = err
solve_info(prec_idx,scheme_idx,rep) = info
if (iam == psb_root_) then
select type(ch => x%v%comm_handle)
type is(psb_comm_neighbor_handle)
write(psb_out_unit,'("DIAG_COMM scheme=",a,", prec=",a,", rep=",i0)') &
& trim(scheme_name(scheme_idx)), trim(prec_name(prec_idx)), rep
write(psb_out_unit,'("DIAG_COMM counters: init=",i0,", start=",i0,", ineighbor=",i0,", wait=",i0,", realloc=",i0)') &
& ch%diag_init_calls, ch%diag_start_calls, ch%diag_ineighbor_calls, &
& ch%diag_wait_calls, ch%diag_buffer_reallocs
write(psb_out_unit,'("DIAG_COMM state: ready=",l1,", bsz=",i0)') &
& ch%persistent_request_ready, ch%persistent_buffer_size
class default
continue
end select
end if
if (info /= psb_success_) goto 9999
end do
end do
end do
if (iam == psb_root_) then
if (my_rank == psb_root_) then
write(psb_out_unit,'(" ")')
write(psb_out_unit,'(100("="))')
write(psb_out_unit,'("CG TIMING STATISTICS - FINAL RESULTS TABLE")')
write(psb_out_unit,'(100("="))')
write(psb_out_unit,'("Legend:")')
write(psb_out_unit,'(" - Each phase time for one repetition is reduced with max across MPI ranks.")')
write(psb_out_unit,'(" - Minimum/Average/Maximum/Std Dev are computed across repetitions.")')
write(psb_out_unit,'(" - KrylovPerIter = KrylovSolve/iterations; TotalPerIter = TotalTime/iterations.")')
do prec_idx = 1, n_precs
write(psb_out_unit,'(" ")')
@ -307,6 +342,10 @@ program psb_comm_cg_test
& prec_init_time,prec_bld_time,comm_set_time,krylov_time, &
& krylov_it_time,total_it_time)
#ifdef PSB_HAVE_CUDA
if (use_gpu) call psb_cuda_exit()
#endif
call psb_exit(ctxt)
stop
@ -449,6 +488,32 @@ contains
call ieee_set_flag(ieee_underflow, .false.)
end subroutine clear_ieee_flags
subroutine parse_gpu_arg(use_gpu, info)
logical, intent(inout) :: use_gpu
integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_) :: i, argc
character(len=256) :: carg, uarg, val
info = psb_success_
argc = command_argument_count()
do i = 1, argc
call get_command_argument(i,carg)
uarg = psb_toupper(trim(carg))
if (index(uarg,'--GPU=') == 1) then
val = psb_toupper(adjustl(carg(7:len_trim(carg))))
select case (trim(val))
case ('TRUE','T','1','YES','Y','ON')
use_gpu = .true.
case ('FALSE','F','0','NO','N','OFF')
use_gpu = .false.
case default
info = psb_err_internal_error_
return
end select
end if
end do
end subroutine parse_gpu_arg
subroutine psb_d_gen_pde3d(ctxt,idim,a,bv,xv,desc_a,afmt,info)
implicit none
integer(psb_ipk_), intent(in) :: idim
@ -464,7 +529,7 @@ contains
integer(psb_lpk_) :: m,n,glob_row
integer(psb_ipk_) :: nnz,nlr,i,ii,ib,k
integer(psb_ipk_) :: ix,iy,iz
integer(psb_ipk_) :: np, iam, nr, nt
integer(psb_ipk_) :: np, my_rank, nr, nt
integer(psb_ipk_) :: icoeff
integer(psb_lpk_), allocatable :: irow(:),icol(:),myidx(:)
real(psb_dpk_), allocatable :: val(:)
@ -477,7 +542,7 @@ contains
name = 'create_matrix'
call psb_erractionsave(err_act)
call psb_info(ctxt, iam, np)
call psb_info(ctxt, my_rank, np)
if (idim <= 0) then
info = psb_err_internal_error_
@ -489,9 +554,9 @@ contains
call psb_errpush(info,name,a_err='invalid context: np <= 0')
goto 9999
end if
if (iam < 0) then
if (my_rank < 0) then
info = psb_err_context_error_
call psb_errpush(info,name,a_err='invalid context: iam < 0')
call psb_errpush(info,name,a_err='invalid context: my_rank < 0')
goto 9999
end if
@ -528,14 +593,14 @@ contains
call psb_errpush(info,name,a_err='invalid local nnz estimate: nnz <= 0')
goto 9999
end if
if(iam == psb_root_) write(psb_out_unit,'("Generating Matrix (size=",i0,")...")')n
if(my_rank == psb_root_) write(psb_out_unit,'("Generating Matrix (size=",i0,")...")')n
nt = (m+np-1)/np
nr = max(0,min(nt,m-(iam*nt)))
nr = max(0,min(nt,m-(my_rank*nt)))
nt = nr
call psb_sum(ctxt,nt)
if (nt /= m) then
write(psb_err_unit,*) iam, 'Initialization error ',nr,nt,m
write(psb_err_unit,*) my_rank, 'Initialization error ',nr,nt,m
info = -1
call psb_barrier(ctxt)
call psb_abort(ctxt)
@ -661,7 +726,7 @@ contains
! call probe_ieee('after psb_spins')
if(info /= psb_success_) then
write(psb_err_unit,'("INSERT FAIL rank=",i0,", call=psb_spins, ii=",i0,", ib=",i0,", icoeff=",i0)') &
iam, ii, ib, icoeff
my_rank, ii, ib, icoeff
write(psb_err_unit,'(" glob_row=",i0,", ix=",i0,", iy=",i0,", iz=",i0)') glob_row, ix, iy, iz
exit
end if
@ -669,7 +734,7 @@ contains
! call probe_ieee('after psb_geins bv')
if(info /= psb_success_) then
write(psb_err_unit,'("INSERT FAIL rank=",i0,", call=psb_geins bv, ii=",i0,", ib=",i0,", icoeff=",i0)') &
iam, ii, ib, icoeff
my_rank, ii, ib, icoeff
write(psb_err_unit,'(" glob_row=",i0,", ix=",i0,", iy=",i0,", iz=",i0)') glob_row, ix, iy, iz
exit
end if
@ -678,7 +743,7 @@ contains
! call probe_ieee('after psb_geins xv')
if(info /= psb_success_) then
write(psb_err_unit,'("INSERT FAIL rank=",i0,", call=psb_geins xv, ii=",i0,", ib=",i0,", icoeff=",i0)') &
iam, ii, ib, icoeff
my_rank, ii, ib, icoeff
write(psb_err_unit,'(" glob_row=",i0,", ix=",i0,", iy=",i0,", iz=",i0)') glob_row, ix, iy, iz
exit
end if
@ -730,7 +795,7 @@ contains
call psb_amx(ctxt,tgen)
call psb_amx(ctxt,tasb)
call psb_amx(ctxt,ttot)
if(iam == psb_root_) then
if(my_rank == psb_root_) then
tmpfmt = a%get_fmt()
write(psb_out_unit,'("The matrix has been generated and assembled in ",a3," format.")') tmpfmt
write(psb_out_unit,'("-allocation time : ",es12.5)') talc

@ -1,18 +0,0 @@
17 Number of entries below this
CG Iterative method BICGSTAB CGS BICG BICGSTABL RGMRES FCG CGR RICHARDSON
NONE Preconditioner NONE DIAG BJAC
CSR Storage format for matrix A: CSR COO
100 Domain size (actual system is this**3 in pde3d)
3 Partition: 1 BLOCK 3 3D
2 Stopping criterion 1 2
0200 MAXIT
10 ITRACE
002 IRST restart for RGMRES and BiCGSTABL
INVK Block Solver ILU,ILUT,INVK,INVT,AINV
NONE If ILU : MILU or NONE otherwise ignored
NONE Scaling if ILUT: NONE, MAXVAL otherwise ignored
0 Level of fill for forward factorization
1 Level of fill for inverse factorization (only INVK,INVT)
1E-1 Threshold for forward factorization
1E-1 Threshold for inverse factorization (Only INVK, INVT)
LLK Orthogonalization algorithm (only AINV)

@ -6,12 +6,12 @@ include $(INCDIR)/Make.inc.psblas
# Libraries used
#
LIBDIR=$(INSTALLDIR)/lib/
PSBLAS_LIB= -L$(LIBDIR) -lpsb_util -lpsb_linsolve -lpsb_prec -lpsb_base
LDLIBS=$(PSBLDLIBS)
PSBLAS_LIB= -L$(LIBDIR) -lpsb_util -lpsb_linsolve -lpsb_prec -lpsb_cuda -lpsb_ext -lpsb_base
LDLIBS=$(PSBGPULDLIBS)
FINCLUDES=$(FMFLAG)$(MODDIR) $(FMFLAG).
TOBJS=psb_spmv_overlap_test.o spmv_overlap.o
TOBJS=psb_spmv_test.o
EXEDIR=./runs
@ -20,13 +20,16 @@ all: runsd spmv_overlap
runsd:
(if test ! -d runs ; then mkdir runs; fi)
psb_spmv_test.o: psb_spmv_test.f90
$(FC) $(FCOPT) -cpp $(FINCLUDES) $(FDEFINES) $(FCUDEFINES) -c $< -o $@
spmv_overlap: $(TOBJS)
$(FLINK) $(LOPT) $(TOBJS) -o spmv_overlap $(PSBLAS_LIB) $(LDLIBS)
/bin/mv spmv_overlap $(EXEDIR)
/bin/cp -f $(EXEDIR)/spmv_overlap $(EXEDIR)/psb_spmv_overlap_test
/bin/cp -f $(EXEDIR)/spmv_overlap $(EXEDIR)/psb_spmv_kernel
clean:
/bin/rm -f $(TOBJS) $(TOBJS_API) *$(.mod) $(EXEDIR)/spmv_overlap $(EXEDIR)/psb_spmv_overlap_test
/bin/rm -f $(TOBJS) $(TOBJS_API) *$(.mod) $(EXEDIR)/spmv_overlap $(EXEDIR)/psb_spmv_kernel
lib:
(cd ../../; make library)

File diff suppressed because it is too large Load Diff

@ -0,0 +1,694 @@
!> Test program for overlapping communication and computation with psb_spmm.
!!
!! This benchmark compares two equivalent SpMV paths:
!! 1. Serialized halo exchange + compute
!! 2. Overlapped psb_spmm(..., doswap=.true.)
!!
module psb_spmv_overlap_test
use psb_base_mod
use psb_util_mod
use psb_comm_factory_mod, only: psb_comm_set
use psb_comm_schemes_mod, only: psb_comm_isend_irecv_, psb_comm_ineighbor_alltoallv_, &
& psb_comm_persistent_ineighbor_alltoallv_
use psb_comm_neighbor_impl_mod, only: psb_comm_neighbor_handle
#ifdef PSB_HAVE_CUDA
use psb_cuda_mod
#endif
implicit none
interface
function d_func_3d(x,y,z) result(val)
import :: psb_dpk_
real(psb_dpk_), intent(in) :: x,y,z
real(psb_dpk_) :: val
end function d_func_3d
end interface
contains
function d_null_func_3d(x,y,z) result(val)
real(psb_dpk_), intent(in) :: x,y,z
real(psb_dpk_) :: val
val = dzero
end function d_null_func_3d
!
! functions parametrizing the differential equation
!
!
! Note: b1, b2 and b3 are the coefficients of the first
! derivative of the unknown function. The default
! we apply here is to have them zero, so that the resulting
! matrix is symmetric/hermitian and suitable for
! testing with CG and FCG.
! When testing methods for non-hermitian matrices you can
! change the B1/B2/B3 functions to e.g. done/sqrt((3*done))
!
function b1(x,y,z)
use psb_base_mod, only : psb_dpk_, done, dzero
implicit none
real(psb_dpk_) :: b1
real(psb_dpk_), intent(in) :: x,y,z
b1=dzero
end function b1
function b2(x,y,z)
use psb_base_mod, only : psb_dpk_, done, dzero
implicit none
real(psb_dpk_) :: b2
real(psb_dpk_), intent(in) :: x,y,z
b2=dzero
end function b2
function b3(x,y,z)
use psb_base_mod, only : psb_dpk_, done, dzero
implicit none
real(psb_dpk_) :: b3
real(psb_dpk_), intent(in) :: x,y,z
b3=dzero
end function b3
function c(x,y,z)
use psb_base_mod, only : psb_dpk_, done, dzero
implicit none
real(psb_dpk_) :: c
real(psb_dpk_), intent(in) :: x,y,z
c=dzero
end function c
function a1(x,y,z)
use psb_base_mod, only : psb_dpk_, done, dzero
implicit none
real(psb_dpk_) :: a1
real(psb_dpk_), intent(in) :: x,y,z
a1=done/80
end function a1
function a2(x,y,z)
use psb_base_mod, only : psb_dpk_, done, dzero
implicit none
real(psb_dpk_) :: a2
real(psb_dpk_), intent(in) :: x,y,z
a2=done/80
end function a2
function a3(x,y,z)
use psb_base_mod, only : psb_dpk_, done, dzero
implicit none
real(psb_dpk_) :: a3
real(psb_dpk_), intent(in) :: x,y,z
a3=done/80
end function a3
function g(x,y,z)
use psb_base_mod, only : psb_dpk_, done, dzero
implicit none
real(psb_dpk_) :: g
real(psb_dpk_), intent(in) :: x,y,z
g = dzero
if (x == done) then
g = done
else if (x == dzero) then
g = exp(y**2-z**2)
end if
end function g
!
! subroutine to allocate and fill in the coefficient matrix and
! the rhs.
!
subroutine psb_d_gen_pde3d(ctxt,idim,a,bv,xv,desc_a,afmt,info,&
& f,amold,vmold,imold,partition,nrl,iv,tnd)
use psb_base_mod
use psb_util_mod
!
! Discretizes the partial differential equation
!
! a1 dd(u) a2 dd(u) a3 dd(u) b1 d(u) b2 d(u) b3 d(u)
! - ------ - ------ - ------ + ----- + ------ + ------ + c u = f
! dxdx dydy dzdz dx dy dz
!
! with Dirichlet boundary conditions
! u = g
!
! on the unit cube 0<=x,y,z<=1.
!
!
! Note that if b1=b2=b3=c=0., the PDE is the Laplace equation.
!
implicit none
integer(psb_ipk_) :: idim
type(psb_dspmat_type) :: a
type(psb_d_vect_type) :: xv,bv
type(psb_desc_type) :: desc_a
type(psb_ctxt_type) :: ctxt
integer(psb_ipk_) :: info
character(len=*) :: afmt
procedure(d_func_3d), optional :: f
class(psb_d_base_sparse_mat), optional :: amold
class(psb_d_base_vect_type), optional :: vmold
class(psb_i_base_vect_type), optional :: imold
integer(psb_ipk_), optional :: partition, nrl,iv(:)
logical, optional :: tnd
! Local variables.
integer(psb_ipk_), parameter :: nb=20
type(psb_d_csc_sparse_mat) :: acsc
type(psb_d_coo_sparse_mat) :: acoo
type(psb_d_csr_sparse_mat) :: acsr
real(psb_dpk_) :: zt(nb),x,y,z
integer(psb_ipk_) :: nnz,nr,nlr,i,j,ii,ib,k, partition_
integer(psb_lpk_) :: m,n,glob_row,nt
integer(psb_ipk_) :: ix,iy,iz,ia,indx_owner
! For 3D partition
! Note: integer control variables going directly into an MPI call
! must be 4 bytes, i.e. psb_mpk_
integer(psb_mpk_) :: npdims(3), npp, minfo
integer(psb_ipk_) :: npx,npy,npz, iamx,iamy,iamz,mynx,myny,mynz
integer(psb_ipk_), allocatable :: bndx(:),bndy(:),bndz(:)
! Process grid
integer(psb_ipk_) :: np, iam, nth
integer(psb_ipk_) :: icoeff
integer(psb_lpk_), allocatable :: irow(:),icol(:),myidx(:)
real(psb_dpk_), allocatable :: val(:)
! deltah dimension of each grid cell
! deltat discretization time
real(psb_dpk_) :: deltah, sqdeltah, deltah2
real(psb_dpk_), parameter :: rhs=dzero,one=done,zero=dzero
real(psb_dpk_) :: t0, t1, t2, t3, tasb, talc, ttot, tgen, tcdasb
integer(psb_ipk_) :: err_act
procedure(d_func_3d), pointer :: f_
logical :: tnd_
character(len=20) :: name, ch_err,tmpfmt
info = psb_success_
name = 'create_matrix'
call psb_erractionsave(err_act)
call psb_info(ctxt, iam, np)
if (present(f)) then
f_ => f
else
f_ => d_null_func_3d
end if
deltah = done/(idim+1)
sqdeltah = deltah*deltah
deltah2 = (2*done)* deltah
if (present(partition)) then
if ((1<= partition).and.(partition <= 3)) then
partition_ = partition
else
write(*,*) 'Invalid partition choice ',partition,' defaulting to 3'
partition_ = 3
end if
else
partition_ = 3
end if
tnd_ = .false.
if (present(tnd)) tnd_ = tnd
! initialize array descriptor and sparse matrix storage. provide an
! estimate of the number of non zeroes
m = (1_psb_lpk_*idim)*idim*idim
n = m
nnz = ((n*7)/(np))
if(iam == psb_root_) write(psb_out_unit,'("Generating Matrix (size=",i0,")...")')n
t0 = psb_wtime()
select case(partition_)
case(1)
! A BLOCK partition
if (present(nrl)) then
nr = nrl
else
!
! Using a simple BLOCK distribution.
!
nt = (m+np-1)/np
nr = max(0,min(nt,m-(iam*nt)))
end if
nt = nr
call psb_sum(ctxt,nt)
if (nt /= m) then
write(psb_err_unit,*) iam, 'Initialization error ',nr,nt,m
info = -1
call psb_barrier(ctxt)
call psb_abort(ctxt)
return
end if
!
! First example of use of CDALL: specify for each process a number of
! contiguous rows
!
call psb_cdall(ctxt,desc_a,info,nl=nr)
myidx = desc_a%get_global_indices()
nlr = size(myidx)
case(2)
! A partition defined by the user through IV
if (present(iv)) then
if (size(iv) /= m) then
write(psb_err_unit,*) iam, 'Initialization error: wrong IV size',size(iv),m
info = -1
call psb_barrier(ctxt)
call psb_abort(ctxt)
return
end if
else
write(psb_err_unit,*) iam, 'Initialization error: IV not present'
info = -1
call psb_barrier(ctxt)
call psb_abort(ctxt)
return
end if
!
! Second example of use of CDALL: specify for each row the
! process that owns it
!
call psb_cdall(ctxt,desc_a,info,vg=iv)
myidx = desc_a%get_global_indices()
nlr = size(myidx)
case(3)
! A 3-dimensional partition
! A nifty MPI function will split the process list
npdims = 0
call mpi_dims_create(np,3,npdims,info)
npx = npdims(1)
npy = npdims(2)
npz = npdims(3)
allocate(bndx(0:npx),bndy(0:npy),bndz(0:npz))
! We can reuse idx2ijk for process indices as well.
call idx2ijk(iamx,iamy,iamz,iam,npx,npy,npz,base=0)
! Now let's split the 3D cube in hexahedra
call dist1Didx(bndx,idim,npx)
mynx = bndx(iamx+1)-bndx(iamx)
call dist1Didx(bndy,idim,npy)
myny = bndy(iamy+1)-bndy(iamy)
call dist1Didx(bndz,idim,npz)
mynz = bndz(iamz+1)-bndz(iamz)
! How many indices do I own?
nlr = mynx*myny*mynz
allocate(myidx(nlr))
! Now, let's generate the list of indices I own
nr = 0
do i=bndx(iamx),bndx(iamx+1)-1
do j=bndy(iamy),bndy(iamy+1)-1
do k=bndz(iamz),bndz(iamz+1)-1
nr = nr + 1
call ijk2idx(myidx(nr),i,j,k,idim,idim,idim)
end do
end do
end do
if (nr /= nlr) then
write(psb_err_unit,*) iam,iamx,iamy,iamz, 'Initialization error: NR vs NLR ',&
& nr,nlr,mynx,myny,mynz
info = -1
call psb_barrier(ctxt)
call psb_abort(ctxt)
end if
!
! Third example of use of CDALL: specify for each process
! the set of global indices it owns.
!
call psb_cdall(ctxt,desc_a,info,vl=myidx)
case default
write(psb_err_unit,*) iam, 'Initialization error: should not get here'
info = -1
call psb_barrier(ctxt)
call psb_abort(ctxt)
return
end select
if (info == psb_success_) call psb_spall(a,desc_a,info,nnz=nnz)
! define rhs from boundary conditions; also build initial guess
if (info == psb_success_) call psb_geall(xv,desc_a,info)
if (info == psb_success_) call psb_geall(bv,desc_a,info)
call psb_barrier(ctxt)
talc = psb_wtime()-t0
if (info /= psb_success_) then
info=psb_err_from_subroutine_
ch_err='allocation rout.'
call psb_errpush(info,name,a_err=ch_err)
goto 9999
end if
! we build an auxiliary matrix consisting of one row at a
! time; just a small matrix. might be extended to generate
! a bunch of rows per call.
!
allocate(val(20*nb),irow(20*nb),&
&icol(20*nb),stat=info)
if (info /= psb_success_ ) then
info=psb_err_alloc_dealloc_
call psb_errpush(info,name)
goto 9999
endif
! loop over rows belonging to current process in a block
! distribution.
call psb_barrier(ctxt)
t1 = psb_wtime()
do ii=1, nlr,nb
ib = min(nb,nlr-ii+1)
icoeff = 1
do k=1,ib
i=ii+k-1
! local matrix pointer
glob_row=myidx(i)
! compute gridpoint coordinates
call idx2ijk(ix,iy,iz,glob_row,idim,idim,idim)
! x, y, z coordinates
x = (ix-1)*deltah
y = (iy-1)*deltah
z = (iz-1)*deltah
zt(k) = f_(x,y,z)
! internal point: build discretization
!
! term depending on (x-1,y,z)
!
val(icoeff) = -a1(x,y,z)/sqdeltah-b1(x,y,z)/deltah2
if (ix == 1) then
zt(k) = g(dzero,y,z)*(-val(icoeff)) + zt(k)
else
call ijk2idx(icol(icoeff),ix-1,iy,iz,idim,idim,idim)
irow(icoeff) = glob_row
icoeff = icoeff+1
endif
! term depending on (x,y-1,z)
val(icoeff) = -a2(x,y,z)/sqdeltah-b2(x,y,z)/deltah2
if (iy == 1) then
zt(k) = g(x,dzero,z)*(-val(icoeff)) + zt(k)
else
call ijk2idx(icol(icoeff),ix,iy-1,iz,idim,idim,idim)
irow(icoeff) = glob_row
icoeff = icoeff+1
endif
! term depending on (x,y,z-1)
val(icoeff)=-a3(x,y,z)/sqdeltah-b3(x,y,z)/deltah2
if (iz == 1) then
zt(k) = g(x,y,dzero)*(-val(icoeff)) + zt(k)
else
call ijk2idx(icol(icoeff),ix,iy,iz-1,idim,idim,idim)
irow(icoeff) = glob_row
icoeff = icoeff+1
endif
! term depending on (x,y,z)
val(icoeff)=(2*done)*(a1(x,y,z)+a2(x,y,z)+a3(x,y,z))/sqdeltah &
& + c(x,y,z)
call ijk2idx(icol(icoeff),ix,iy,iz,idim,idim,idim)
irow(icoeff) = glob_row
icoeff = icoeff+1
! term depending on (x,y,z+1)
val(icoeff)=-a3(x,y,z)/sqdeltah+b3(x,y,z)/deltah2
if (iz == idim) then
zt(k) = g(x,y,done)*(-val(icoeff)) + zt(k)
else
call ijk2idx(icol(icoeff),ix,iy,iz+1,idim,idim,idim)
irow(icoeff) = glob_row
icoeff = icoeff+1
endif
! term depending on (x,y+1,z)
val(icoeff)=-a2(x,y,z)/sqdeltah+b2(x,y,z)/deltah2
if (iy == idim) then
zt(k) = g(x,done,z)*(-val(icoeff)) + zt(k)
else
call ijk2idx(icol(icoeff),ix,iy+1,iz,idim,idim,idim)
irow(icoeff) = glob_row
icoeff = icoeff+1
endif
! term depending on (x+1,y,z)
val(icoeff)=-a1(x,y,z)/sqdeltah+b1(x,y,z)/deltah2
if (ix==idim) then
zt(k) = g(done,y,z)*(-val(icoeff)) + zt(k)
else
call ijk2idx(icol(icoeff),ix+1,iy,iz,idim,idim,idim)
irow(icoeff) = glob_row
icoeff = icoeff+1
endif
end do
call psb_spins(icoeff-1,irow,icol,val,a,desc_a,info)
if(info /= psb_success_) exit
call psb_geins(ib,myidx(ii:ii+ib-1),zt(1:ib),bv,desc_a,info)
if(info /= psb_success_) exit
zt(:)=dzero
call psb_geins(ib,myidx(ii:ii+ib-1),zt(1:ib),xv,desc_a,info)
if(info /= psb_success_) exit
end do
tgen = psb_wtime()-t1
if(info /= psb_success_) then
info=psb_err_from_subroutine_
ch_err='insert rout.'
call psb_errpush(info,name,a_err=ch_err)
goto 9999
end if
deallocate(val,irow,icol)
call psb_barrier(ctxt)
t1 = psb_wtime()
if (present(imold)) then
call psb_cdasb(desc_a,info,mold=imold)
else
call psb_cdasb(desc_a,info)
end if
tcdasb = psb_wtime()-t1
call psb_barrier(ctxt)
t1 = psb_wtime()
if (info == psb_success_) then
if (present(amold)) then
call psb_spasb(a,desc_a,info,mold=amold)
else
call psb_spasb(a,desc_a,info,afmt=afmt)
end if
end if
call psb_barrier(ctxt)
if(info /= psb_success_) then
info=psb_err_from_subroutine_
ch_err='asb rout.'
call psb_errpush(info,name,a_err=ch_err)
goto 9999
end if
if (info == psb_success_) then
if (present(vmold)) then
call psb_geasb(xv,desc_a,info,mold=vmold)
if (info == psb_success_) call psb_geasb(bv,desc_a,info,mold=vmold)
else
call psb_geasb(xv,desc_a,info)
if (info == psb_success_) call psb_geasb(bv,desc_a,info)
end if
end if
if(info /= psb_success_) then
info=psb_err_from_subroutine_
ch_err='asb rout.'
call psb_errpush(info,name,a_err=ch_err)
goto 9999
end if
tasb = psb_wtime()-t1
call psb_barrier(ctxt)
ttot = psb_wtime() - t0
call psb_amx(ctxt,talc)
call psb_amx(ctxt,tgen)
call psb_amx(ctxt,tasb)
call psb_amx(ctxt,ttot)
if(iam == psb_root_) then
tmpfmt = a%get_fmt()
write(psb_out_unit,'("The matrix has been generated and assembled in ",a3," format.")')&
& tmpfmt
write(psb_out_unit,'("-allocation time : ",es12.5)') talc
write(psb_out_unit,'("-coeff. gen. time : ",es12.5)') tgen
write(psb_out_unit,'("-desc asbly time : ",es12.5)') tcdasb
write(psb_out_unit,'("- mat asbly time : ",es12.5)') tasb
write(psb_out_unit,'("-total time : ",es12.5)') ttot
end if
call psb_erractionrestore(err_act)
return
9999 call psb_error_handler(ctxt,err_act)
return
end subroutine psb_d_gen_pde3d
subroutine run_spmv_kernel(ctxt,use_gpu)
use psb_base_mod
#ifdef PSB_HAVE_CUDA
use psb_cuda_mod
#endif
implicit none
type(psb_ctxt_type), intent(in) :: ctxt
logical, intent(in) :: use_gpu
type(psb_dspmat_type) :: a
type(psb_d_vect_type) :: x, y
type(psb_desc_type) :: desc_a
character(len=5) :: afmt
character(len=64) :: env_buf
integer(psb_ipk_) :: my_rank, np, info, err_act
integer(psb_ipk_) :: idim, times, i, n_global
integer :: env_len, env_status, ios
real(psb_dpk_) :: alpha, beta, t0, t1, dt, avg_t
#ifdef PSB_HAVE_CUDA
type(psb_d_vect_cuda) :: vmold
type(psb_i_vect_cuda) :: imold
type(psb_d_cuda_hlg_sparse_mat), target :: ahlg
class(psb_d_base_sparse_mat), pointer :: agmold
#endif
info = psb_success_
afmt = 'CSR'
idim = 10
times = 100
alpha = done
beta = dzero
call psb_erractionsave(err_act)
call psb_info(ctxt, my_rank, np)
call get_environment_variable('IDIM', env_buf, length=env_len, status=env_status)
if ((env_status == 0) .and. (env_len > 0)) then
read(env_buf(1:env_len), *, iostat=ios) idim
if ((ios /= 0) .or. (idim < 2)) idim = 10
end if
call get_environment_variable('TIMES', env_buf, length=env_len, status=env_status)
if ((env_status == 0) .and. (env_len > 0)) then
read(env_buf(1:env_len), *, iostat=ios) times
if ((ios /= 0) .or. (times < 1)) times = 100
end if
n_global = idim * idim * idim
call psb_barrier(ctxt)
call psb_d_gen_pde3d(ctxt,idim,a,y,x,desc_a,afmt,info)
if (info /= psb_success_) goto 9999
#ifdef PSB_HAVE_CUDA
if (use_gpu) then
agmold => ahlg
call a%cscnv(info,mold=agmold)
if (info /= psb_success_) goto 9999
call desc_a%cnv(mold=imold)
if (info /= psb_success_) goto 9999
call psb_geasb(x,desc_a,info,mold=vmold)
if (info /= psb_success_) goto 9999
call psb_geasb(y,desc_a,info,mold=vmold)
if (info /= psb_success_) goto 9999
end if
#endif
! warm-up
call psb_spmm(alpha, a, x, beta, y, desc_a, info, doswap=.false.)
if (info /= psb_success_) goto 9999
call psb_barrier(ctxt)
t0 = psb_wtime()
do i = 1, times
call psb_spmm(alpha, a, x, beta, y, desc_a, info, doswap=.false.)
if (info /= psb_success_) exit
end do
t1 = psb_wtime()
if (info /= psb_success_) goto 9999
dt = t1 - t0
call psb_amx(ctxt, dt)
avg_t = dt / real(times, psb_dpk_)
if (my_rank == psb_root_) then
write(psb_out_unit,'(/,"SpMV benchmark (no overlap)")')
write(psb_out_unit,'(" idim : ",i0)') idim
write(psb_out_unit,'(" global unknowns : ",i0)') n_global
write(psb_out_unit,'(" repetitions : ",i0)') times
write(psb_out_unit,'(" total time [s] : ",es12.5)') dt
write(psb_out_unit,'(" avg time [s] : ",es12.5)') avg_t
end if
call psb_gefree(y, desc_a, info)
call psb_gefree(x, desc_a, info)
call psb_spfree(a, desc_a, info)
call psb_cdfree(desc_a, info)
call psb_erractionrestore(err_act)
return
9999 call psb_error(ctxt)
call psb_error_handler(ctxt, err_act)
end subroutine run_spmv_kernel
end module psb_spmv_overlap_test
program psb_spmv_kernel
use psb_spmv_overlap_test
use psb_base_mod
#ifdef PSB_HAVE_CUDA
use psb_cuda_mod
#endif
implicit none
type(psb_ctxt_type) :: ctxt
logical :: use_gpu
integer(psb_ipk_) :: my_rank, np, k
character(len=256) :: arg
call psb_init(ctxt)
call psb_info(ctxt, my_rank, np)
#ifdef PSB_HAVE_CUDA
use_gpu = .true.
#else
use_gpu = .false.
#endif
do k = 1, command_argument_count()
call get_command_argument(k, arg)
if (index(psb_toupper(trim(arg)), '--GPU=') == 1) then
select case (psb_toupper(adjustl(arg(7:len_trim(arg)))))
case ('TRUE','T','1','YES','Y','ON')
use_gpu = .true.
case ('FALSE','F','0','NO','N','OFF')
use_gpu = .false.
end select
end if
end do
#ifdef PSB_HAVE_CUDA
if (use_gpu) call psb_cuda_init(ctxt)
#else
use_gpu = .false.
#endif
if (my_rank == psb_root_) then
write(psb_out_unit,*) 'Welcome to PSBLAS version: ', psb_version_string_
write(psb_out_unit,*) 'This is the psb_spmv_kernel sample program'
write(psb_out_unit,'("GPU enabled : ",l1)') use_gpu
end if
call run_spmv_kernel(ctxt,use_gpu)
#ifdef PSB_HAVE_CUDA
if (use_gpu) call psb_cuda_exit()
#endif
call psb_exit(ctxt)
end program psb_spmv_kernel

@ -1,28 +0,0 @@
program main
use psb_spmv_overlap_test
use psb_base_mod
implicit none
integer(psb_ipk_) :: my_rank, np
integer(psb_ipk_) :: k, h
type(psb_ctxt_type) :: ctxt
call psb_init(ctxt)
call psb_info(ctxt, my_rank, np)
if (my_rank == psb_root_) then
write(psb_out_unit,*) 'Welcome to PSBLAS version: ', psb_version_string_
write(psb_out_unit,*) 'This is the psb_spmv_overlap_test sample program'
end if
call psb_barrier(ctxt)
call psb_spmv_overlap_kernel(ctxt)
call psb_exit(ctxt)
end program main
Loading…
Cancel
Save