diff --git a/cbind/base/psb_c_comm_cbind_impl.f90 b/cbind/base/psb_c_comm_cbind_impl.f90 new file mode 100644 index 00000000..47c3711e --- /dev/null +++ b/cbind/base/psb_c_comm_cbind_impl.f90 @@ -0,0 +1,238 @@ +submodule (psb_c_comm_cbind_mod) psb_c_comm_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + +contains + + module function psb_c_covrl(xh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_ovrl(xp,descp,info) + + res = info + + end function psb_c_covrl + + module function psb_c_covrl_opt(xh,cdh,update,mode) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: update, mode + + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_ovrl(xp,descp,info,update=update,mode=mode) + + res = info + + end function psb_c_covrl_opt + + + module function psb_c_chalo(xh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_halo(xp,descp,info) + + res = info + + end function psb_c_chalo + + module function psb_c_chalo_opt(xh,cdh,tran,data,mode) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: data, mode + character(c_char) :: tran + + + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + character :: ftran + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ftran = tran + call psb_halo(xp,descp,info,data=data,mode=mode,tran=ftran) + + res = info + + end function psb_c_chalo_opt + + + module function psb_c_cvscatter(ng,gx,xh,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + integer(psb_c_lpk_), value :: ng + complex(c_float_complex), target :: gx(*) + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: vp + complex(psb_spk_), pointer :: pgx(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + else + return + end if + + pgx => gx(1:ng) + + call psb_scatter(pgx,vp,descp,info) + res = info + + end function psb_c_cvscatter + + module function psb_c_cvgather_f(v,xh,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + complex(c_float_complex), target :: v(*) + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: vp + complex(psb_spk_), allocatable :: fv(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + else + return + end if + + call psb_gather(fv,vp,descp,info) + res = info + if (res /=0) return + sz = size(fv) + v(1:sz) = fv(1:sz) + end function psb_c_cvgather_f + + module function psb_c_cspgather_f(gah,ah,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_cspmat) :: ah, gah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap, gap + integer(psb_c_ipk_) :: info, sz + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(gah%item)) then + call c_f_pointer(gah%item,gap) + else + return + end if + call psb_gather(gap,ap,descp,info) + res = info + end function psb_c_cspgather_f + +end submodule psb_c_comm_cbind_impl diff --git a/cbind/base/psb_c_psblas_cbind_impl.f90 b/cbind/base/psb_c_psblas_cbind_impl.f90 new file mode 100644 index 00000000..aa558d05 --- /dev/null +++ b/cbind/base/psb_c_psblas_cbind_impl.f90 @@ -0,0 +1,1267 @@ +submodule (psb_c_psblas_cbind_mod) psb_c_psblas_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + +contains + + module function psb_c_cgeaxpby(alpha,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,yh + type(psb_c_descriptor) :: cdh + complex(c_float_complex), value :: alpha,beta + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geaxpby(alpha,xp,beta,yp,descp,info) + + res = info + + end function psb_c_cgeaxpby + + module function psb_c_cgeaxpbyz(alpha,xh,beta,yh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + complex(c_float_complex), value :: alpha,beta + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_geaxpby(alpha,xp,beta,yp,zp,descp,info) + + res = info + + end function psb_c_cgeaxpbyz + + module function psb_c_cgemlt(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_gemlt(xp,yp,descp,info) + + res = info + + end function psb_c_cgemlt + + module function psb_c_cgemlt2(alpha,xh,yh,beta,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,yh, zh + type(psb_c_descriptor) :: cdh + + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + complex(psb_spk_), intent(in), value :: alpha,beta + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gemlt(alpha,xp,yp,beta,zp,descp,info) + + res = info + + end function psb_c_cgemlt2 + + module function psb_c_cgediv(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_gediv(xp,yp,descp,info) + + res = info + + end function psb_c_cgediv + + module function psb_c_cgediv2(xh,yh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gediv(xp,yp,zp,descp,info) + + res = info + + end function psb_c_cgediv2 + + module function psb_c_cgediv_check(xh,yh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,yh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + fflag = flag + call psb_gediv(xp,yp,descp,info,fflag) + + res = info + + end function psb_c_cgediv_check + + module function psb_c_cgediv2_check(xh,yh,zh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + fflag = flag + call psb_gediv(xp,yp,zp,descp,info,fflag) + + res = info + + end function psb_c_cgediv2_check + + module function psb_c_cgeinv(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geinv(xp,yp,descp,info) + + res = info + + end function psb_c_cgeinv + + module function psb_c_cgeinv_check(xh,yh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,yh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + fflag = flag + call psb_geinv(xp,yp,descp,info,fflag) + + res = info + + end function psb_c_cgeinv_check + + module function psb_c_cgeabs(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geabs(xp,yp,descp,info) + + res = info + + end function psb_c_cgeabs + + module function psb_c_cgecmp(xh,ch,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,zp + integer(psb_c_ipk_) :: info + real(c_float_complex), value :: ch + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gecmp(xp,ch,zp,descp,info) + + res = info + + end function psb_c_cgecmp + + module function psb_c_cgecmpmat(ah,bh,tol,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_cspmat) :: ah,bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + real(c_float_complex), value :: tol + logical :: isequal + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call psb_gecmp(ap,bp,tol,descp,isequal,info) + + res = isequal + + end function psb_c_cgecmpmat + + module function psb_c_cgecmpmat_val(ah,val,tol,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + complex(c_float_complex), value :: val + real(c_float_complex), value :: tol + logical :: isequal + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_gecmp(ap,val,tol,descp,isequal,info) + + res = isequal + + end function psb_c_cgecmpmat_val + + module function psb_c_cgeaddconst(xh,bh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cvector) :: xh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,zp + integer(psb_c_ipk_) :: info + real(c_float_complex), value :: bh + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_geaddconst(xp,bh,zp,descp,info) + + res = info + + end function psb_c_cgeaddconst + + + module function psb_c_cgenrm2(xh,cdh) bind(c) result(res) + implicit none + real(c_float_complex) :: res + + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_genrm2(xp,descp,info) + + end function psb_c_cgenrm2 + + module function psb_c_cgenrmi(xh,cdh) bind(c) result(res) + implicit none + real(c_float_complex) :: res + + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + type(psb_c_vect_type) :: yp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geall(yp,descp,info) + call psb_geabs(xp,yp,descp,info) + res = psb_geasum(yp,descp,info) + call psb_gefree(yp,descp,info) + + end function psb_c_cgenrmi + + module function psb_c_cgenrm2_weight(xh,wh,cdh) bind(c) result(res) + implicit none + real(c_float_complex) :: res + + type(psb_c_cvector) :: xh, wh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp, wp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(wh%item)) then + call c_f_pointer(wh%item,wp) + else + return + end if + + res = psb_genrm2(xp,wp,descp,info) + + end function psb_c_cgenrm2_weight + + module function psb_c_cgenrm2_weightmask(xh,wh,idvh,cdh) bind(c) result(res) + implicit none + real(c_float_complex) :: res + + type(psb_c_cvector) :: xh, wh, idvh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp, wp, idvp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(wh%item)) then + call c_f_pointer(wh%item,wp) + else + return + end if + if (c_associated(idvh%item)) then + call c_f_pointer(idvh%item,idvp) + else + return + end if + + res = psb_genrm2(xp,wp,idvp,descp,info) + + end function psb_c_cgenrm2_weightmask + + module function psb_c_cgeamax(xh,cdh) bind(c) result(res) + implicit none + real(c_float_complex) :: res + + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_geamax(xp,descp,info) + + end function psb_c_cgeamax + + + module function psb_c_cgeasum(xh,cdh) bind(c) result(res) + implicit none + real(c_float_complex) :: res + + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_geasum(xp,descp,info) + + end function psb_c_cgeasum + + + module function psb_c_cspnrmi(ah,cdh) bind(c) result(res) + implicit none + real(c_float_complex) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = psb_spnrmi(ap,descp,info) + + end function psb_c_cspnrmi + + module function psb_c_cgedot(xh,yh,cdh) bind(c) result(res) + implicit none + complex(c_float_complex) :: res + + type(psb_c_cvector) :: xh,yh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + res = psb_gedot(xp,yp,descp,info) + + end function psb_c_cgedot + + + module function psb_c_cspmm(alpha,ah,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_cvector) :: xh,yh + type(psb_c_descriptor) :: cdh + complex(c_float_complex), value :: alpha, beta + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_spmm(alpha,ap,xp,beta,yp,descp,info) + + res = info + + end function psb_c_cspmm + + + module function psb_c_cspmm_opt(alpha,ah,xh,beta,yh,cdh,trans,doswap) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_cvector) :: xh,yh + type(psb_c_descriptor) :: cdh + complex(c_float_complex), value :: alpha, beta + character(c_char) :: trans + logical(c_bool), value :: doswap + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp + type(psb_cspmat_type), pointer :: ap + character :: ftrans + logical :: fdoswap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + fdoswap = doswap + ftrans = trans + call psb_spmm(alpha,ap,xp,beta,yp,descp,info,trans=ftrans,doswap=fdoswap) + + res = info + + end function psb_c_cspmm_opt + + + module function psb_c_cspsm(alpha,ah,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_cvector) :: xh,yh + type(psb_c_descriptor) :: cdh + complex(c_float_complex), value :: alpha, beta + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp,yp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_spsm(alpha,ap,xp,beta,yp,descp,info) + + res = info + + end function psb_c_cspsm + + module function psb_c_cnnz(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = psb_nnz(ap,descp,info) + + end function psb_c_cnnz + + module function psb_c_cis_matupd(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_upd() + end function + + module function psb_c_cis_matasb(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_asb() + end function + + module function psb_c_cis_matbld(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_bld() + end function + + module function psb_c_cset_matupd(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_upd() + + res = psb_success_ + end function + + module function psb_c_cset_matasb(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + + res = -1; + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_asb() + + res = psb_success_ + + end function + + module function psb_c_cset_matbld(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_bld() + + res = psb_success_ + end function + + module function psb_c_ccopy_mat(ah,bh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cspmat) :: ah,bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call ap%clone(bp,info) + + res = info + end function + + module function psb_c_cspscal(alpha,ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + complex(c_float_complex), value :: alpha + type(psb_c_cspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%scal(alpha,info) + + res = info + + end function psb_c_cspscal + + module function psb_c_cspscalpid(alpha,ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + complex(c_float_complex), value :: alpha + type(psb_c_cspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%scalpid(alpha,info) + + res = info + + end function psb_c_cspscalpid + + module function psb_c_cspaxpby(alpha,ah,beta,bh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + complex(c_float_complex), value :: alpha + type(psb_c_cspmat) :: ah + complex(c_float_complex), value :: beta + type(psb_c_cspmat) :: bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call ap%spaxpby(alpha,beta,bp,info) + + res = info + end function psb_c_cspaxpby + +end submodule psb_c_psblas_cbind_impl diff --git a/cbind/base/psb_c_serial_cbind_impl.F90 b/cbind/base/psb_c_serial_cbind_impl.F90 new file mode 100644 index 00000000..05330730 --- /dev/null +++ b/cbind/base/psb_c_serial_cbind_impl.F90 @@ -0,0 +1,283 @@ +submodule (psb_c_serial_cbind_mod) psb_c_serial_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + use psb_base_tools_cbind_mod + +contains + + + module function psb_c_cvect_get_nrows(xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_cvector) :: xh + + type(psb_c_vect_type), pointer :: vp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + res = vp%get_nrows() + end if + + end function psb_c_cvect_get_nrows + + module function psb_c_cvect_f_get_cpy(v,xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + complex(c_float_complex) :: v(*) + type(psb_c_cvector) :: xh + + type(psb_c_vect_type), pointer :: vp + complex(psb_spk_), allocatable :: fv(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + fv = vp%get_vect() + sz = size(fv) + v(1:sz) = fv(1:sz) + end if + + end function psb_c_cvect_f_get_cpy + + + module function psb_c_cvect_zero(xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_cvector) :: xh + + type(psb_c_vect_type), pointer :: vp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + call vp%zero() + end if + + end function psb_c_cvect_zero + + module function psb_c_cvect_f_get_pnt(xh) bind(c) result(res) + implicit none + + type(c_ptr) :: res + type(psb_c_cvector) :: xh + + type(psb_c_vect_type), pointer :: vp + + res = c_null_ptr + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + if(vp%is_dev()) call vp%sync() + res = c_loc(vp%v%v) + end if + + end function psb_c_cvect_f_get_pnt + + + module function psb_c_cmat_get_nrows(mh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cspmat) :: mh + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + res = ap%get_nrows() + + end function psb_c_cmat_get_nrows + + + module function psb_c_cmat_get_ncols(mh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_cspmat) :: mh + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + res = ap%get_ncols() + + end function psb_c_cmat_get_ncols + + module function psb_c_cmat_name_print(mh,name) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + character(c_char) :: name(*) + + type(psb_c_cspmat) :: mh + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + character(1024) :: fname + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + call psb_stringc2f(name,fname) + + call ap%print(fname,head='PSBLAS Cbinding Interface') + + end function psb_c_cmat_name_print + + module function psb_c_cvect_set_scal(x,val) bind(c) result(info) + implicit none + + type(psb_c_cvector) :: x + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + complex(c_float_complex), value :: val + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + call xp%set(val) + + info = 0 + + end function psb_c_cvect_set_scal + + module function psb_c_cvect_set_scal_bound(x,val,ifirst,ilast) bind(c) result(info) + implicit none + + type(psb_c_cvector) :: x + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: ifirst, ilast + complex(c_float_complex) :: val + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + call xp%set(val,first=ifirst,last=ilast) + + info = 0 + + end function psb_c_cvect_set_scal_bound + + module function psb_c_cvect_set_vect(x,val,n) bind(c) result(info) + implicit none + type(psb_c_cvector) :: x + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: n + complex(c_float_complex) :: val(*) + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + call xp%set(val(1:n)) + + info = 0 + + end function psb_c_cvect_set_vect + + module function psb_c_cvect_set_entry(x,index,val) bind(c) result(info) + implicit none + + type(psb_c_cvector) :: x + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: index + complex(c_float_complex), value :: val + integer(psb_c_ipk_) :: ixb + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + call xp%set_entry((index+(1-ixb)),val) + info = 0 + + end function psb_c_cvect_set_entry + + module function psb_c_cvect_get_entry(x,index) bind(c) result(res) + implicit none + + type(psb_c_cvector) :: x + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_), value :: index + complex(c_float_complex) :: res + integer(psb_c_ipk_) :: ixb + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + res = xp%get_entry((index+(1-ixb))) + end function psb_c_cvect_get_entry + + module function psb_c_cvect_clone(xh,yh) bind(c) result(info) + implicit none + + integer(psb_c_ipk_) :: info + type(psb_c_cvector) :: xh,yh + + type(psb_c_vect_type), pointer :: xp,yp + + info = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + call xp%clone(yp,info) + + end function psb_c_cvect_clone + +end submodule psb_c_serial_cbind_impl diff --git a/cbind/base/psb_c_tools_cbind_impl.F90 b/cbind/base/psb_c_tools_cbind_impl.F90 new file mode 100644 index 00000000..aa2623ca --- /dev/null +++ b/cbind/base/psb_c_tools_cbind_impl.F90 @@ -0,0 +1,732 @@ +submodule ( psb_c_tools_cbind_mod) psb_c_tools_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_cpenv_mod + use psb_objhandle_mod + use psb_base_tools_cbind_mod +#ifdef PSB_HAVE_CUDA + use psb_cuda_mod +#endif + +contains + + ! Should define geall_opt with DUPL argument + module function psb_c_cgeall(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_cgeall + + module function psb_c_cgeall_remote(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info,bldmode=psb_matbld_remote_,dupl=psb_dupl_add_) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_cgeall_remote + + module function psb_c_cgeall_remote_options(xh,cdh,bldmode,dupl) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: dupl + integer(psb_c_ipk_), value :: bldmode + + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info,bldmode=bldmode,dupl=dupl) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_cgeall_remote_options + + module function psb_c_cgeasb(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info) + res = min(0,info) + + return + end function psb_c_cgeasb + + module function psb_c_cgeasb_options(xh,cdh,dupl) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: dupl + + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info,dupl=dupl) + res = min(0,info) + + return + end function psb_c_cgeasb_options + + module function psb_c_cgeasb_options_format(xh,cdh,dupl,format) bind(c) result(res) + ! Takes into account format argument as a c string, and uses it to call the appropriate psb_geasb + ! with mold argument + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + character(kind=c_char), dimension(*) :: format + integer(psb_c_ipk_), value :: dupl + + ! Local variables + character(len=6) :: fformat + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + ! mold variables +#ifdef PSB_HAVE_CUDA + type(psb_c_vect_cuda), target :: vgpu +#endif + type(psb_c_base_vect_type), target :: vect + class(psb_c_base_vect_type), pointer :: vmold + + ! Select mold based on format + call psb_stringc2f(format,fformat) + + select case (psb_toupper(fformat)) +#ifdef PSB_HAVE_CUDA + case('GPU','DEVICE') + vmold => vgpu +#endif + case('CPU','HOST') + vmold => vect + case default + write(psb_out_unit,*) 'psb_c_cgeasb_options_format: Unknown format ',fformat + vmold => vect + end select + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info,dupl=dupl,mold=vmold) + res = min(0,info) + + return + end function psb_c_cgeasb_options_format + + + module function psb_c_cgefree(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_gefree(xp,descp,info) + res = min(0,info) + deallocate(xp,stat=info) + res = min(0,info) + xh%item = c_null_ptr + + return + end function psb_c_cgefree + + + module function psb_c_cgeins(nz,irw,val,xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: nz + integer(psb_c_lpk_) :: irw(*) + complex(c_float_complex) :: val(*) + type(psb_c_cvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_c_vect_type), pointer :: xp + integer(psb_c_ipk_) :: ixb, info + + res = -1 + info = 0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_geins(nz,irw(1:nz),val(1:nz),& + & xp,descp,info) + else + call psb_geins(nz,(irw(1:nz)+(1-ixb)),val(1:nz),& + & xp,descp,info) + end if + + res = min(0,info) + + return + end function psb_c_cgeins + + module function psb_c_cspall(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + return + end if + allocate(ap) + call psb_spall(ap,descp,info) + mh%item = c_loc(ap) + res = min(0,info) + + return + end function psb_c_cspall + + + module function psb_c_cspall_remote(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + return + end if + allocate(ap) + call psb_spall(ap,descp,info,bldmode=psb_matbld_remote_,dupl=psb_dupl_add_) + mh%item = c_loc(ap) + res = min(0,info) + + return + end function psb_c_cspall_remote + + module function psb_c_cspasb(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + call psb_spasb(ap,descp,info) + res = min(0,info) + return + end function psb_c_cspasb + + module function psb_c_cspfree(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + call psb_spfree(ap,descp,info) + res = min(0,info) + deallocate(ap,stat=info) + mh%item=c_null_ptr + return + end function psb_c_cspfree + + + + + module function psb_c_cspasb_opt(mh,cdh,afmt,upd,dupl) bind(c) result(res) + +#if 0 +#ifdef PSB_HAVE_LIBRSB + use psb_c_rsb_mat_mod +#endif +#endif +#if defined(PSB_HAVE_CUDA) + use psb_cuda_mod +#endif + use psb_ext_mod + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_cspmat) :: mh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: upd,dupl + character(c_char) :: afmt(*) + integer(psb_c_ipk_) :: info,n + character(len=5) :: fafmt + integer(psb_ipk_), parameter :: hksz = 32 + ! mold variables +#if 0 +#ifdef PSB_HAVE_LIBRSB + type(psb_c_rsb_sparse_mat) :: arsb +#endif +#endif + type(psb_c_ell_sparse_mat), target :: aell + type(psb_c_csr_sparse_mat), target :: acsr + type(psb_c_csc_sparse_mat), target :: acsc + type(psb_c_coo_sparse_mat), target :: acoo + type(psb_c_hll_sparse_mat), target :: ahll + type(psb_c_hdia_sparse_mat), target :: ahdia + type(psb_c_dns_sparse_mat), target :: adns +#if defined(PSB_HAVE_CUDA) + type(psb_c_cuda_hlg_sparse_mat), target :: ahlg + type(psb_c_cuda_csrg_sparse_mat), target :: acsrg + type(psb_c_cuda_elg_sparse_mat), target :: aelg +#endif + class(psb_c_base_sparse_mat), pointer :: amold + !Local variables + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + call psb_stringc2f(afmt,fafmt) + + ! Set the mold variable based on afmt + select case (psb_toupper(fafmt)) +#if defined(PSB_HAVE_CUDA) + case('ELG') + amold => aelg + case('HLG') + call psi_set_hksz(hksz) + amold => ahlg + case('CSRG') + amold => acsrg + case('ELL') + amold => aell + case('HLL') + call psi_set_hksz(hksz) + amold => ahll + case('CSR') + amold => acsr + case('CSC') + amold => acsc + case('DNS') + amold => adns + case default + write(*,*) 'Unknown format defaulting to HLG' + amold => ahlg +#else + case('ELL') + amold => aell + case('HLL') + call psi_set_hksz(hksz) + amold => ahll + amold => ahdia + case('CSR') + amold => acsr + case('CSC') + amold => acsc + case('DNS') + amold => adns + case default + write(*,*) 'Unknown format defaulting to CSR' + amold => acsr +#endif + end select + + select case(fafmt) +#if 0 +#ifdef PSB_HAVE_LIBRSB + case('RSB') + call psb_spasb(double_spmat_pool(mh)%item,descriptor_pool(cdh)%item,info,& + & upd=upd,mold=arsb) +#endif +#endif + case('ELL','HLL','CSR','DNS','CSC') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) +#if defined(PSB_HAVE_CUDA) + case('ELG','HLG','CSRG') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) +#endif + case default + write(psb_out_unit,*) 'psb_c_cspasb_opt: Unknown format ',fafmt + call psb_spasb(ap,descp,info,afmt=fafmt,upd=upd,dupl=dupl) + end select + + res = min(0,info) + + return + end function psb_c_cspasb_opt + + + module function psb_c_cspins(nz,irw,icl,val,mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: nz + integer(psb_c_lpk_) :: irw(*), icl(*) + complex(c_float_complex) :: val(*) + type(psb_c_cspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: ixb,info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_spins(nz,irw(1:nz),icl(1:nz),val(1:nz),ap,descp,info) + else + call psb_spins(nz,(irw(1:nz)+(1-ixb)),(icl(1:nz)+(1-ixb)),val(1:nz),ap,descp,info) + end if + res = min(0,info) + return + end function psb_c_cspins + + + module function psb_c_csprn(mh,cdh,clear) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + logical(c_bool), value :: clear + type(psb_c_cspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_cspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + logical :: fclear + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + fclear = clear + call psb_sprn(ap,descp,info,clear=fclear) + res = min(0,info) + + return + end function psb_c_csprn +!!$ +!!$ module function psb_c_cspprint(mh) bind(c) result(res) +!!$ +!!$ implicit none +!!$ integer(psb_c_ipk_) :: res +!!$ integer(psb_c_ipk_), value :: mh +!!$ integer(psb_c_ipk_) :: info +!!$ +!!$ +!!$ res = -1 +!!$ call psb_check_double_spmat_handle(mh,info) +!!$ if (info < 0) return +!!$ +!!$ call psb_csprt(0,double_spmat_pool(mh)%item,head='Debug mat') +!!$ +!!$ res = 0 +!!$ +!!$ return +!!$ end function psb_c_cspprint + + function psb_c_cgetelem(xh,index,cdh) bind(c) result(res) + implicit none + + type(psb_c_cvector) :: xh + integer(psb_c_lpk_), value :: index + type(psb_c_descriptor) :: cdh + complex(c_float_complex) :: res + + type(psb_c_vect_type), pointer :: xp + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + res = psb_getelem(xp,index,descp,info) + else + res = psb_getelem(xp,index+(1-ixb),descp,info) + end if + + return + + end function psb_c_cgetelem + + module function psb_c_csetelem(index,val,xh,cdh) bind(c) result(res) + implicit none + + type(psb_c_cvector) :: xh + integer(psb_c_lpk_), value :: index + type(psb_c_descriptor) :: cdh + complex(c_float_complex), value :: val + integer(psb_c_ipk_) :: res + + type(psb_c_vect_type), pointer :: xp + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_setelem(index,val,xp,descp,info) + else + call psb_setelem(index+(1-ixb),val,xp,descp,info) + end if + res=info + return + + end function psb_c_csetelem + + module function psb_c_cmatgetelem(ah,rowindex,colindex,cdh) bind(c) result(res) + implicit none + + type(psb_c_cspmat) :: ah + integer(psb_c_lpk_), value :: rowindex, colindex + type(psb_c_descriptor) :: cdh + complex(c_float_complex) :: res + type(psb_cspmat_type), pointer :: ap + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + res = psb_getelem(ap,rowindex,colindex,descp,info) + else + res = psb_getelem(ap,rowindex+(1-ixb),colindex+(1-ixb),descp,info) + end if + + return + + end function psb_c_cmatgetelem + +end submodule psb_c_tools_cbind_impl diff --git a/cbind/base/psb_d_comm_cbind_impl.f90 b/cbind/base/psb_d_comm_cbind_impl.f90 new file mode 100644 index 00000000..534f2c03 --- /dev/null +++ b/cbind/base/psb_d_comm_cbind_impl.f90 @@ -0,0 +1,238 @@ +submodule (psb_d_comm_cbind_mod) psb_d_comm_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + +contains + + module function psb_c_dovrl(xh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_ovrl(xp,descp,info) + + res = info + + end function psb_c_dovrl + + module function psb_c_dovrl_opt(xh,cdh,update,mode) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: update, mode + + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_ovrl(xp,descp,info,update=update,mode=mode) + + res = info + + end function psb_c_dovrl_opt + + + module function psb_c_dhalo(xh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_halo(xp,descp,info) + + res = info + + end function psb_c_dhalo + + module function psb_c_dhalo_opt(xh,cdh,tran,data,mode) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: data, mode + character(c_char) :: tran + + + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + character :: ftran + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ftran = tran + call psb_halo(xp,descp,info,data=data,mode=mode,tran=ftran) + + res = info + + end function psb_c_dhalo_opt + + + module function psb_c_dvscatter(ng,gx,xh,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + integer(psb_c_lpk_), value :: ng + real(c_double), target :: gx(*) + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: vp + real(psb_dpk_), pointer :: pgx(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + else + return + end if + + pgx => gx(1:ng) + + call psb_scatter(pgx,vp,descp,info) + res = info + + end function psb_c_dvscatter + + module function psb_c_dvgather_f(v,xh,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + real(c_double), target :: v(*) + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: vp + real(psb_dpk_), allocatable :: fv(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + else + return + end if + + call psb_gather(fv,vp,descp,info) + res = info + if (res /=0) return + sz = size(fv) + v(1:sz) = fv(1:sz) + end function psb_c_dvgather_f + + module function psb_c_dspgather_f(gah,ah,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_dspmat) :: ah, gah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap, gap + integer(psb_c_ipk_) :: info, sz + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(gah%item)) then + call c_f_pointer(gah%item,gap) + else + return + end if + call psb_gather(gap,ap,descp,info) + res = info + end function psb_c_dspgather_f + +end submodule psb_d_comm_cbind_impl diff --git a/cbind/base/psb_d_psblas_cbind_impl.f90 b/cbind/base/psb_d_psblas_cbind_impl.f90 new file mode 100644 index 00000000..7326ed16 --- /dev/null +++ b/cbind/base/psb_d_psblas_cbind_impl.f90 @@ -0,0 +1,1368 @@ +submodule (psb_d_psblas_cbind_mod) psb_d_psblas_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + +contains + + module function psb_c_dgeaxpby(alpha,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + real(c_double), value :: alpha,beta + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geaxpby(alpha,xp,beta,yp,descp,info) + + res = info + + end function psb_c_dgeaxpby + + module function psb_c_dgeaxpbyz(alpha,xh,beta,yh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + real(c_double), value :: alpha,beta + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_geaxpby(alpha,xp,beta,yp,zp,descp,info) + + res = info + + end function psb_c_dgeaxpbyz + + module function psb_c_dgemlt(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_gemlt(xp,yp,descp,info) + + res = info + + end function psb_c_dgemlt + + module function psb_c_dgemlt2(alpha,xh,yh,beta,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,yh, zh + type(psb_c_descriptor) :: cdh + + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + real(psb_dpk_), intent(in), value :: alpha,beta + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gemlt(alpha,xp,yp,beta,zp,descp,info) + + res = info + + end function psb_c_dgemlt2 + + module function psb_c_dgediv(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_gediv(xp,yp,descp,info) + + res = info + + end function psb_c_dgediv + + module function psb_c_dgediv2(xh,yh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gediv(xp,yp,zp,descp,info) + + res = info + + end function psb_c_dgediv2 + + module function psb_c_dgediv_check(xh,yh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + fflag = flag + call psb_gediv(xp,yp,descp,info,fflag) + + res = info + + end function psb_c_dgediv_check + + module function psb_c_dgediv2_check(xh,yh,zh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + fflag = flag + call psb_gediv(xp,yp,zp,descp,info,fflag) + + res = info + + end function psb_c_dgediv2_check + + module function psb_c_dgeinv(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geinv(xp,yp,descp,info) + + res = info + + end function psb_c_dgeinv + + module function psb_c_dgeinv_check(xh,yh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + fflag = flag + call psb_geinv(xp,yp,descp,info,fflag) + + res = info + + end function psb_c_dgeinv_check + + module function psb_c_dgeabs(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geabs(xp,yp,descp,info) + + res = info + + end function psb_c_dgeabs + + module function psb_c_dgecmp(xh,ch,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,zp + integer(psb_c_ipk_) :: info + real(c_double), value :: ch + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gecmp(xp,ch,zp,descp,info) + + res = info + + end function psb_c_dgecmp + + module function psb_c_dgecmpmat(ah,bh,tol,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_dspmat) :: ah,bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + real(c_double), value :: tol + logical :: isequal + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call psb_gecmp(ap,bp,tol,descp,isequal,info) + + res = isequal + + end function psb_c_dgecmpmat + + module function psb_c_dgecmpmat_val(ah,val,tol,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + real(c_double), value :: val + real(c_double), value :: tol + logical :: isequal + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_gecmp(ap,val,tol,descp,isequal,info) + + res = isequal + + end function psb_c_dgecmpmat_val + + module function psb_c_dgeaddconst(xh,bh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: xh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,zp + integer(psb_c_ipk_) :: info + real(c_double), value :: bh + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_geaddconst(xp,bh,zp,descp,info) + + res = info + + end function psb_c_dgeaddconst + + module function psb_c_dmask(ch,xh,mh,t,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dvector) :: ch,xh,mh + type(psb_c_descriptor) :: cdh + logical(c_bool) :: t + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: cp,xp,mp + integer(psb_c_ipk_) :: info + logical :: fp + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ch%item)) then + call c_f_pointer(ch%item,cp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,mp) + else + return + end if + + call psb_mask(cp,xp,mp,fp,descp,info) + + t = fp + res = info + + end function psb_c_dmask + + module function psb_c_dminquotient(xh,yh,cdh) bind(c) result(res) + implicit none + real(psb_dpk_) :: res + + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + res = psb_minquotient(xp,yp,descp,info) + + + end function psb_c_dminquotient + + module function psb_c_dgenrm2(xh,cdh) bind(c) result(res) + implicit none + real(c_double) :: res + + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_genrm2(xp,descp,info) + + end function psb_c_dgenrm2 + + module function psb_c_dgenrmi(xh,cdh) bind(c) result(res) + implicit none + real(c_double) :: res + + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + type(psb_d_vect_type) :: yp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geall(yp,descp,info) + call psb_geabs(xp,yp,descp,info) + res = psb_geasum(yp,descp,info) + call psb_gefree(yp,descp,info) + + end function psb_c_dgenrmi + + module function psb_c_dgenrm2_weight(xh,wh,cdh) bind(c) result(res) + implicit none + real(c_double) :: res + + type(psb_c_dvector) :: xh, wh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp, wp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(wh%item)) then + call c_f_pointer(wh%item,wp) + else + return + end if + + res = psb_genrm2(xp,wp,descp,info) + + end function psb_c_dgenrm2_weight + + module function psb_c_dgenrm2_weightmask(xh,wh,idvh,cdh) bind(c) result(res) + implicit none + real(c_double) :: res + + type(psb_c_dvector) :: xh, wh, idvh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp, wp, idvp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(wh%item)) then + call c_f_pointer(wh%item,wp) + else + return + end if + if (c_associated(idvh%item)) then + call c_f_pointer(idvh%item,idvp) + else + return + end if + + res = psb_genrm2(xp,wp,idvp,descp,info) + + end function psb_c_dgenrm2_weightmask + + module function psb_c_dgeamax(xh,cdh) bind(c) result(res) + implicit none + real(c_double) :: res + + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_geamax(xp,descp,info) + + end function psb_c_dgeamax + + module function psb_c_dgemin(xh,cdh) bind(c) result(res) + implicit none + real(c_double) :: res + + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_gemin(xp,descp,info) + + end function psb_c_dgemin + + module function psb_c_dgeasum(xh,cdh) bind(c) result(res) + implicit none + real(c_double) :: res + + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_geasum(xp,descp,info) + + end function psb_c_dgeasum + + + module function psb_c_dspnrmi(ah,cdh) bind(c) result(res) + implicit none + real(c_double) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = psb_spnrmi(ap,descp,info) + + end function psb_c_dspnrmi + + module function psb_c_dgedot(xh,yh,cdh) bind(c) result(res) + implicit none + real(c_double) :: res + + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + res = psb_gedot(xp,yp,descp,info) + + end function psb_c_dgedot + + + module function psb_c_dspmm(alpha,ah,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + real(c_double), value :: alpha, beta + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_spmm(alpha,ap,xp,beta,yp,descp,info) + + res = info + + end function psb_c_dspmm + + + module function psb_c_dspmm_opt(alpha,ah,xh,beta,yh,cdh,trans,doswap) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + real(c_double), value :: alpha, beta + character(c_char) :: trans + logical(c_bool), value :: doswap + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + type(psb_dspmat_type), pointer :: ap + character :: ftrans + logical :: fdoswap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + fdoswap = doswap + ftrans = trans + call psb_spmm(alpha,ap,xp,beta,yp,descp,info,trans=ftrans,doswap=fdoswap) + + res = info + + end function psb_c_dspmm_opt + + + module function psb_c_dspsm(alpha,ah,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_dvector) :: xh,yh + type(psb_c_descriptor) :: cdh + real(c_double), value :: alpha, beta + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp,yp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_spsm(alpha,ap,xp,beta,yp,descp,info) + + res = info + + end function psb_c_dspsm + + module function psb_c_dnnz(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = psb_nnz(ap,descp,info) + + end function psb_c_dnnz + + module function psb_c_dis_matupd(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_upd() + end function + + module function psb_c_dis_matasb(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_asb() + end function + + module function psb_c_dis_matbld(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_bld() + end function + + module function psb_c_dset_matupd(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_upd() + + res = psb_success_ + end function + + module function psb_c_dset_matasb(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + + res = -1; + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_asb() + + res = psb_success_ + + end function + + module function psb_c_dset_matbld(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_bld() + + res = psb_success_ + end function + + module function psb_c_dcopy_mat(ah,bh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dspmat) :: ah,bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call ap%clone(bp,info) + + res = info + end function + + module function psb_c_dspscal(alpha,ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + real(c_double), value :: alpha + type(psb_c_dspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%scal(alpha,info) + + res = info + + end function psb_c_dspscal + + module function psb_c_dspscalpid(alpha,ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + real(c_double), value :: alpha + type(psb_c_dspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%scalpid(alpha,info) + + res = info + + end function psb_c_dspscalpid + + module function psb_c_dspaxpby(alpha,ah,beta,bh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + real(c_double), value :: alpha + type(psb_c_dspmat) :: ah + real(c_double), value :: beta + type(psb_c_dspmat) :: bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call ap%spaxpby(alpha,beta,bp,info) + + res = info + end function psb_c_dspaxpby + +end submodule psb_d_psblas_cbind_impl diff --git a/cbind/base/psb_d_serial_cbind_impl.F90 b/cbind/base/psb_d_serial_cbind_impl.F90 new file mode 100644 index 00000000..72323d3a --- /dev/null +++ b/cbind/base/psb_d_serial_cbind_impl.F90 @@ -0,0 +1,284 @@ +submodule (psb_d_serial_cbind_mod) psb_d_serial_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + use psb_base_tools_cbind_mod + +contains + + + module function psb_c_dvect_get_nrows(xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_dvector) :: xh + + type(psb_d_vect_type), pointer :: vp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + res = vp%get_nrows() + end if + + end function psb_c_dvect_get_nrows + + module function psb_c_dvect_f_get_cpy(v,xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + real(c_double) :: v(*) + type(psb_c_dvector) :: xh + + type(psb_d_vect_type), pointer :: vp + real(psb_dpk_), allocatable :: fv(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + fv = vp%get_vect() + sz = size(fv) + v(1:sz) = fv(1:sz) + end if + + end function psb_c_dvect_f_get_cpy + + + module function psb_c_dvect_zero(xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_dvector) :: xh + + type(psb_d_vect_type), pointer :: vp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + call vp%zero() + end if + + end function psb_c_dvect_zero + + module function psb_c_dvect_f_get_pnt(xh) bind(c) result(res) + implicit none + + type(c_ptr) :: res + type(psb_c_dvector) :: xh + + type(psb_d_vect_type), pointer :: vp + + res = c_null_ptr + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + if(vp%is_dev()) call vp%sync() + res = c_loc(vp%v%v) + end if + + end function psb_c_dvect_f_get_pnt + + + module function psb_c_dmat_get_nrows(mh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dspmat) :: mh + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + res = ap%get_nrows() + + end function psb_c_dmat_get_nrows + + + module function psb_c_dmat_get_ncols(mh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_dspmat) :: mh + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + res = ap%get_ncols() + + end function psb_c_dmat_get_ncols + + module function psb_c_dmat_name_print(mh,name) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + character(c_char) :: name(*) + + type(psb_c_dspmat) :: mh + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + character(1024) :: fname + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + call psb_stringc2f(name,fname) + + call ap%print(fname,head='PSBLAS Cbinding Interface') + + end function psb_c_dmat_name_print + + module function psb_c_dvect_set_scal(x,val) bind(c) result(info) + implicit none + + type(psb_c_dvector) :: x + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + real(c_double), value :: val + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + write(0,*) 'C_set_scal ',val,size(xp%v%v) + call xp%set(val) + + info = 0 + + end function psb_c_dvect_set_scal + + module function psb_c_dvect_set_scal_bound(x,val,ifirst,ilast) bind(c) result(info) + implicit none + + type(psb_c_dvector) :: x + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: ifirst, ilast + real(c_double) :: val + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + call xp%set(val,first=ifirst,last=ilast) + + info = 0 + + end function psb_c_dvect_set_scal_bound + + module function psb_c_dvect_set_vect(x,val,n) bind(c) result(info) + implicit none + type(psb_c_dvector) :: x + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: n + real(c_double) :: val(*) + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + call xp%set(val(1:n)) + + info = 0 + + end function psb_c_dvect_set_vect + + module function psb_c_dvect_set_entry(x,index,val) bind(c) result(info) + implicit none + + type(psb_c_dvector) :: x + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: index + real(c_double), value :: val + integer(psb_c_ipk_) :: ixb + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + call xp%set_entry((index+(1-ixb)),val) + info = 0 + + end function psb_c_dvect_set_entry + + module function psb_c_dvect_get_entry(x,index) bind(c) result(res) + implicit none + + type(psb_c_dvector) :: x + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_), value :: index + real(c_double) :: res + integer(psb_c_ipk_) :: ixb + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + res = xp%get_entry((index+(1-ixb))) + end function psb_c_dvect_get_entry + + module function psb_c_dvect_clone(xh,yh) bind(c) result(info) + implicit none + + integer(psb_c_ipk_) :: info + type(psb_c_dvector) :: xh,yh + + type(psb_d_vect_type), pointer :: xp,yp + + info = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + call xp%clone(yp,info) + + end function psb_c_dvect_clone + +end submodule psb_d_serial_cbind_impl diff --git a/cbind/base/psb_d_tools_cbind_impl.F90 b/cbind/base/psb_d_tools_cbind_impl.F90 new file mode 100644 index 00000000..6a25faae --- /dev/null +++ b/cbind/base/psb_d_tools_cbind_impl.F90 @@ -0,0 +1,742 @@ +submodule ( psb_d_tools_cbind_mod) psb_d_tools_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_cpenv_mod + use psb_objhandle_mod + use psb_base_tools_cbind_mod +#ifdef PSB_HAVE_CUDA + use psb_cuda_mod +#endif + +contains + + ! Should define geall_opt with DUPL argument + module function psb_c_dgeall(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_dgeall + + module function psb_c_dgeall_remote(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info,bldmode=psb_matbld_remote_,dupl=psb_dupl_add_) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_dgeall_remote + + module function psb_c_dgeall_remote_options(xh,cdh,bldmode,dupl) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: dupl + integer(psb_c_ipk_), value :: bldmode + + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info,bldmode=bldmode,dupl=dupl) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_dgeall_remote_options + + module function psb_c_dgeasb(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info) + res = min(0,info) + + return + end function psb_c_dgeasb + + module function psb_c_dgeasb_options(xh,cdh,dupl) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: dupl + + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info,dupl=dupl) + res = min(0,info) + + return + end function psb_c_dgeasb_options + + module function psb_c_dgeasb_options_format(xh,cdh,dupl,format) bind(c) result(res) + ! Takes into account format argument as a c string, and uses it to call the appropriate psb_geasb + ! with mold argument + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + character(kind=c_char), dimension(*) :: format + integer(psb_c_ipk_), value :: dupl + + ! Local variables + character(len=6) :: fformat + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + ! mold variables +#ifdef PSB_HAVE_CUDA + type(psb_d_vect_cuda), target :: vgpu +#endif + type(psb_d_base_vect_type), target :: vect + class(psb_d_base_vect_type), pointer :: vmold + + ! Select mold based on format + call psb_stringc2f(format,fformat) + + select case (psb_toupper(fformat)) +#ifdef PSB_HAVE_CUDA + case('GPU','DEVICE') + vmold => vgpu +#endif + case('CPU','HOST') + vmold => vect + case default + write(psb_out_unit,*) 'psb_c_dgeasb_options_format: Unknown format ',fformat + vmold => vect + end select + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info,dupl=dupl,mold=vmold) + res = min(0,info) + + return + end function psb_c_dgeasb_options_format + + + module function psb_c_dgefree(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_gefree(xp,descp,info) + res = min(0,info) + deallocate(xp,stat=info) + res = min(0,info) + xh%item = c_null_ptr + + return + end function psb_c_dgefree + + + module function psb_c_dgeins(nz,irw,val,xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: nz + integer(psb_c_lpk_) :: irw(*) + real(c_double) :: val(*) + type(psb_c_dvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: ixb, info + + res = -1 + info = 0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_geins(nz,irw(1:nz),val(1:nz),& + & xp,descp,info) + else + call psb_geins(nz,(irw(1:nz)+(1-ixb)),val(1:nz),& + & xp,descp,info) + end if + + res = min(0,info) + + return + end function psb_c_dgeins + + module function psb_c_dspall(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + return + end if + allocate(ap) + call psb_spall(ap,descp,info) + mh%item = c_loc(ap) + res = min(0,info) + + return + end function psb_c_dspall + + + module function psb_c_dspall_remote(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + return + end if + allocate(ap) + call psb_spall(ap,descp,info,bldmode=psb_matbld_remote_,dupl=psb_dupl_add_) + mh%item = c_loc(ap) + res = min(0,info) + + return + end function psb_c_dspall_remote + + module function psb_c_dspasb(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + call psb_spasb(ap,descp,info) + res = min(0,info) + return + end function psb_c_dspasb + + module function psb_c_dspfree(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + call psb_spfree(ap,descp,info) + res = min(0,info) + deallocate(ap,stat=info) + mh%item=c_null_ptr + return + end function psb_c_dspfree + + + + + module function psb_c_dspasb_opt(mh,cdh,afmt,upd,dupl) bind(c) result(res) + +#if 0 +#ifdef PSB_HAVE_LIBRSB + use psb_d_rsb_mat_mod +#endif +#endif +#if defined(PSB_HAVE_CUDA) + use psb_cuda_mod +#endif + use psb_ext_mod + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_dspmat) :: mh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: upd,dupl + character(c_char) :: afmt(*) + integer(psb_c_ipk_) :: info,n + character(len=5) :: fafmt + integer(psb_ipk_), parameter :: hksz = 32 + ! mold variables +#if 0 +#ifdef PSB_HAVE_LIBRSB + type(psb_d_rsb_sparse_mat) :: arsb +#endif +#endif + type(psb_d_ell_sparse_mat), target :: aell + type(psb_d_csr_sparse_mat), target :: acsr + type(psb_d_csc_sparse_mat), target :: acsc + type(psb_d_coo_sparse_mat), target :: acoo + type(psb_d_hll_sparse_mat), target :: ahll + type(psb_d_hdia_sparse_mat), target :: ahdia + type(psb_d_dns_sparse_mat), target :: adns +#if defined(PSB_HAVE_CUDA) + type(psb_d_cuda_hlg_sparse_mat), target :: ahlg + type(psb_d_cuda_hdiag_sparse_mat), target :: ahdiag + type(psb_d_cuda_csrg_sparse_mat), target :: acsrg + type(psb_d_cuda_elg_sparse_mat), target :: aelg +#endif + class(psb_d_base_sparse_mat), pointer :: amold + !Local variables + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + call psb_stringc2f(afmt,fafmt) + + ! Set the mold variable based on afmt + select case (psb_toupper(fafmt)) +#if defined(PSB_HAVE_CUDA) + case('ELG') + amold => aelg + case('HLG') + call psi_set_hksz(hksz) + amold => ahlg + case('HDIAG') + amold => ahdiag + case('CSRG') + amold => acsrg + case('ELL') + amold => aell + case('HLL') + call psi_set_hksz(hksz) + amold => ahll + case('HDIA') + amold => ahdia + case('CSR') + amold => acsr + case('CSC') + amold => acsc + case('DNS') + amold => adns + case default + write(*,*) 'Unknown format defaulting to HLG' + amold => ahlg +#else + case('ELL') + amold => aell + case('HLL') + call psi_set_hksz(hksz) + amold => ahll + case('HDIA') + amold => ahdia + case('CSR') + amold => acsr + case('CSC') + amold => acsc + case('DNS') + amold => adns + case default + write(*,*) 'Unknown format defaulting to CSR' + amold => acsr +#endif + end select + + select case(fafmt) +#if 0 +#ifdef PSB_HAVE_LIBRSB + case('RSB') + call psb_spasb(double_spmat_pool(mh)%item,descriptor_pool(cdh)%item,info,& + & upd=upd,mold=arsb) +#endif +#endif + case('ELL','HLL','CSR','DNS','CSC') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) + case('HDIA') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) +#if defined(PSB_HAVE_CUDA) + case('ELG','HLG','CSRG') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) + case('HDIAG') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) +#endif + case default + write(psb_out_unit,*) 'psb_c_dspasb_opt: Unknown format ',fafmt + call psb_spasb(ap,descp,info,afmt=fafmt,upd=upd,dupl=dupl) + end select + + res = min(0,info) + + return + end function psb_c_dspasb_opt + + + module function psb_c_dspins(nz,irw,icl,val,mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: nz + integer(psb_c_lpk_) :: irw(*), icl(*) + real(c_double) :: val(*) + type(psb_c_dspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: ixb,info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_spins(nz,irw(1:nz),icl(1:nz),val(1:nz),ap,descp,info) + else + call psb_spins(nz,(irw(1:nz)+(1-ixb)),(icl(1:nz)+(1-ixb)),val(1:nz),ap,descp,info) + end if + res = min(0,info) + return + end function psb_c_dspins + + + module function psb_c_dsprn(mh,cdh,clear) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + logical(c_bool), value :: clear + type(psb_c_dspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_dspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + logical :: fclear + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + fclear = clear + call psb_sprn(ap,descp,info,clear=fclear) + res = min(0,info) + + return + end function psb_c_dsprn +!!$ +!!$ module function psb_c_dspprint(mh) bind(c) result(res) +!!$ +!!$ implicit none +!!$ integer(psb_c_ipk_) :: res +!!$ integer(psb_c_ipk_), value :: mh +!!$ integer(psb_c_ipk_) :: info +!!$ +!!$ +!!$ res = -1 +!!$ call psb_check_double_spmat_handle(mh,info) +!!$ if (info < 0) return +!!$ +!!$ call psb_csprt(0,double_spmat_pool(mh)%item,head='Debug mat') +!!$ +!!$ res = 0 +!!$ +!!$ return +!!$ end function psb_c_dspprint + + function psb_c_dgetelem(xh,index,cdh) bind(c) result(res) + implicit none + + type(psb_c_dvector) :: xh + integer(psb_c_lpk_), value :: index + type(psb_c_descriptor) :: cdh + real(c_double) :: res + + type(psb_d_vect_type), pointer :: xp + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + res = psb_getelem(xp,index,descp,info) + else + res = psb_getelem(xp,index+(1-ixb),descp,info) + end if + + return + + end function psb_c_dgetelem + + module function psb_c_dsetelem(index,val,xh,cdh) bind(c) result(res) + implicit none + + type(psb_c_dvector) :: xh + integer(psb_c_lpk_), value :: index + type(psb_c_descriptor) :: cdh + real(c_double), value :: val + integer(psb_c_ipk_) :: res + + type(psb_d_vect_type), pointer :: xp + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_setelem(index,val,xp,descp,info) + else + call psb_setelem(index+(1-ixb),val,xp,descp,info) + end if + res=info + return + + end function psb_c_dsetelem + + module function psb_c_dmatgetelem(ah,rowindex,colindex,cdh) bind(c) result(res) + implicit none + + type(psb_c_dspmat) :: ah + integer(psb_c_lpk_), value :: rowindex, colindex + type(psb_c_descriptor) :: cdh + real(c_double) :: res + type(psb_dspmat_type), pointer :: ap + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + res = psb_getelem(ap,rowindex,colindex,descp,info) + else + res = psb_getelem(ap,rowindex+(1-ixb),colindex+(1-ixb),descp,info) + end if + + return + + end function psb_c_dmatgetelem + +end submodule psb_d_tools_cbind_impl diff --git a/cbind/base/psb_s_comm_cbind_impl.f90 b/cbind/base/psb_s_comm_cbind_impl.f90 new file mode 100644 index 00000000..cd9c4f9f --- /dev/null +++ b/cbind/base/psb_s_comm_cbind_impl.f90 @@ -0,0 +1,238 @@ +submodule (psb_s_comm_cbind_mod) psb_s_comm_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + +contains + + module function psb_c_sovrl(xh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_ovrl(xp,descp,info) + + res = info + + end function psb_c_sovrl + + module function psb_c_sovrl_opt(xh,cdh,update,mode) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: update, mode + + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_ovrl(xp,descp,info,update=update,mode=mode) + + res = info + + end function psb_c_sovrl_opt + + + module function psb_c_shalo(xh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_halo(xp,descp,info) + + res = info + + end function psb_c_shalo + + module function psb_c_shalo_opt(xh,cdh,tran,data,mode) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: data, mode + character(c_char) :: tran + + + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + character :: ftran + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ftran = tran + call psb_halo(xp,descp,info,data=data,mode=mode,tran=ftran) + + res = info + + end function psb_c_shalo_opt + + + module function psb_c_svscatter(ng,gx,xh,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + integer(psb_c_lpk_), value :: ng + real(c_float), target :: gx(*) + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: vp + real(psb_spk_), pointer :: pgx(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + else + return + end if + + pgx => gx(1:ng) + + call psb_scatter(pgx,vp,descp,info) + res = info + + end function psb_c_svscatter + + module function psb_c_svgather_f(v,xh,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + real(c_float), target :: v(*) + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: vp + real(psb_spk_), allocatable :: fv(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + else + return + end if + + call psb_gather(fv,vp,descp,info) + res = info + if (res /=0) return + sz = size(fv) + v(1:sz) = fv(1:sz) + end function psb_c_svgather_f + + module function psb_c_sspgather_f(gah,ah,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_sspmat) :: ah, gah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap, gap + integer(psb_c_ipk_) :: info, sz + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(gah%item)) then + call c_f_pointer(gah%item,gap) + else + return + end if + call psb_gather(gap,ap,descp,info) + res = info + end function psb_c_sspgather_f + +end submodule psb_s_comm_cbind_impl diff --git a/cbind/base/psb_s_psblas_cbind_impl.f90 b/cbind/base/psb_s_psblas_cbind_impl.f90 new file mode 100644 index 00000000..808ed772 --- /dev/null +++ b/cbind/base/psb_s_psblas_cbind_impl.f90 @@ -0,0 +1,1368 @@ +submodule (psb_s_psblas_cbind_mod) psb_s_psblas_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + +contains + + module function psb_c_sgeaxpby(alpha,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + real(c_float), value :: alpha,beta + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geaxpby(alpha,xp,beta,yp,descp,info) + + res = info + + end function psb_c_sgeaxpby + + module function psb_c_sgeaxpbyz(alpha,xh,beta,yh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + real(c_float), value :: alpha,beta + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_geaxpby(alpha,xp,beta,yp,zp,descp,info) + + res = info + + end function psb_c_sgeaxpbyz + + module function psb_c_sgemlt(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_gemlt(xp,yp,descp,info) + + res = info + + end function psb_c_sgemlt + + module function psb_c_sgemlt2(alpha,xh,yh,beta,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,yh, zh + type(psb_c_descriptor) :: cdh + + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + real(psb_spk_), intent(in), value :: alpha,beta + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gemlt(alpha,xp,yp,beta,zp,descp,info) + + res = info + + end function psb_c_sgemlt2 + + module function psb_c_sgediv(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_gediv(xp,yp,descp,info) + + res = info + + end function psb_c_sgediv + + module function psb_c_sgediv2(xh,yh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gediv(xp,yp,zp,descp,info) + + res = info + + end function psb_c_sgediv2 + + module function psb_c_sgediv_check(xh,yh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + fflag = flag + call psb_gediv(xp,yp,descp,info,fflag) + + res = info + + end function psb_c_sgediv_check + + module function psb_c_sgediv2_check(xh,yh,zh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + fflag = flag + call psb_gediv(xp,yp,zp,descp,info,fflag) + + res = info + + end function psb_c_sgediv2_check + + module function psb_c_sgeinv(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geinv(xp,yp,descp,info) + + res = info + + end function psb_c_sgeinv + + module function psb_c_sgeinv_check(xh,yh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + fflag = flag + call psb_geinv(xp,yp,descp,info,fflag) + + res = info + + end function psb_c_sgeinv_check + + module function psb_c_sgeabs(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geabs(xp,yp,descp,info) + + res = info + + end function psb_c_sgeabs + + module function psb_c_sgecmp(xh,ch,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,zp + integer(psb_c_ipk_) :: info + real(c_float), value :: ch + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gecmp(xp,ch,zp,descp,info) + + res = info + + end function psb_c_sgecmp + + module function psb_c_sgecmpmat(ah,bh,tol,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_sspmat) :: ah,bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + real(c_float), value :: tol + logical :: isequal + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call psb_gecmp(ap,bp,tol,descp,isequal,info) + + res = isequal + + end function psb_c_sgecmpmat + + module function psb_c_sgecmpmat_val(ah,val,tol,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + real(c_float), value :: val + real(c_float), value :: tol + logical :: isequal + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_gecmp(ap,val,tol,descp,isequal,info) + + res = isequal + + end function psb_c_sgecmpmat_val + + module function psb_c_sgeaddconst(xh,bh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: xh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,zp + integer(psb_c_ipk_) :: info + real(c_float), value :: bh + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_geaddconst(xp,bh,zp,descp,info) + + res = info + + end function psb_c_sgeaddconst + + module function psb_c_smask(ch,xh,mh,t,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_svector) :: ch,xh,mh + type(psb_c_descriptor) :: cdh + logical(c_bool) :: t + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: cp,xp,mp + integer(psb_c_ipk_) :: info + logical :: fp + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ch%item)) then + call c_f_pointer(ch%item,cp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,mp) + else + return + end if + + call psb_mask(cp,xp,mp,fp,descp,info) + + t = fp + res = info + + end function psb_c_smask + + module function psb_c_sminquotient(xh,yh,cdh) bind(c) result(res) + implicit none + real(psb_spk_) :: res + + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + res = psb_minquotient(xp,yp,descp,info) + + + end function psb_c_sminquotient + + module function psb_c_sgenrm2(xh,cdh) bind(c) result(res) + implicit none + real(c_float) :: res + + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_genrm2(xp,descp,info) + + end function psb_c_sgenrm2 + + module function psb_c_sgenrmi(xh,cdh) bind(c) result(res) + implicit none + real(c_float) :: res + + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + type(psb_s_vect_type) :: yp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geall(yp,descp,info) + call psb_geabs(xp,yp,descp,info) + res = psb_geasum(yp,descp,info) + call psb_gefree(yp,descp,info) + + end function psb_c_sgenrmi + + module function psb_c_sgenrm2_weight(xh,wh,cdh) bind(c) result(res) + implicit none + real(c_float) :: res + + type(psb_c_svector) :: xh, wh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp, wp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(wh%item)) then + call c_f_pointer(wh%item,wp) + else + return + end if + + res = psb_genrm2(xp,wp,descp,info) + + end function psb_c_sgenrm2_weight + + module function psb_c_sgenrm2_weightmask(xh,wh,idvh,cdh) bind(c) result(res) + implicit none + real(c_float) :: res + + type(psb_c_svector) :: xh, wh, idvh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp, wp, idvp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(wh%item)) then + call c_f_pointer(wh%item,wp) + else + return + end if + if (c_associated(idvh%item)) then + call c_f_pointer(idvh%item,idvp) + else + return + end if + + res = psb_genrm2(xp,wp,idvp,descp,info) + + end function psb_c_sgenrm2_weightmask + + module function psb_c_sgeamax(xh,cdh) bind(c) result(res) + implicit none + real(c_float) :: res + + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_geamax(xp,descp,info) + + end function psb_c_sgeamax + + module function psb_c_sgemin(xh,cdh) bind(c) result(res) + implicit none + real(c_float) :: res + + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_gemin(xp,descp,info) + + end function psb_c_sgemin + + module function psb_c_sgeasum(xh,cdh) bind(c) result(res) + implicit none + real(c_float) :: res + + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_geasum(xp,descp,info) + + end function psb_c_sgeasum + + + module function psb_c_sspnrmi(ah,cdh) bind(c) result(res) + implicit none + real(c_float) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = psb_spnrmi(ap,descp,info) + + end function psb_c_sspnrmi + + module function psb_c_sgedot(xh,yh,cdh) bind(c) result(res) + implicit none + real(c_float) :: res + + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + res = psb_gedot(xp,yp,descp,info) + + end function psb_c_sgedot + + + module function psb_c_sspmm(alpha,ah,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + real(c_float), value :: alpha, beta + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_spmm(alpha,ap,xp,beta,yp,descp,info) + + res = info + + end function psb_c_sspmm + + + module function psb_c_sspmm_opt(alpha,ah,xh,beta,yh,cdh,trans,doswap) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + real(c_float), value :: alpha, beta + character(c_char) :: trans + logical(c_bool), value :: doswap + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + type(psb_sspmat_type), pointer :: ap + character :: ftrans + logical :: fdoswap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + fdoswap = doswap + ftrans = trans + call psb_spmm(alpha,ap,xp,beta,yp,descp,info,trans=ftrans,doswap=fdoswap) + + res = info + + end function psb_c_sspmm_opt + + + module function psb_c_sspsm(alpha,ah,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_svector) :: xh,yh + type(psb_c_descriptor) :: cdh + real(c_float), value :: alpha, beta + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp,yp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_spsm(alpha,ap,xp,beta,yp,descp,info) + + res = info + + end function psb_c_sspsm + + module function psb_c_snnz(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = psb_nnz(ap,descp,info) + + end function psb_c_snnz + + module function psb_c_sis_matupd(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_upd() + end function + + module function psb_c_sis_matasb(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_asb() + end function + + module function psb_c_sis_matbld(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_bld() + end function + + module function psb_c_sset_matupd(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_upd() + + res = psb_success_ + end function + + module function psb_c_sset_matasb(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + + res = -1; + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_asb() + + res = psb_success_ + + end function + + module function psb_c_sset_matbld(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_sspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_bld() + + res = psb_success_ + end function + + module function psb_c_scopy_mat(ah,bh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_sspmat) :: ah,bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call ap%clone(bp,info) + + res = info + end function + + module function psb_c_sspscal(alpha,ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + real(c_float), value :: alpha + type(psb_c_sspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%scal(alpha,info) + + res = info + + end function psb_c_sspscal + + module function psb_c_sspscalpid(alpha,ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + real(c_float), value :: alpha + type(psb_c_sspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%scalpid(alpha,info) + + res = info + + end function psb_c_sspscalpid + + module function psb_c_sspaxpby(alpha,ah,beta,bh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + real(c_float), value :: alpha + type(psb_c_sspmat) :: ah + real(c_float), value :: beta + type(psb_c_sspmat) :: bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call ap%spaxpby(alpha,beta,bp,info) + + res = info + end function psb_c_sspaxpby + +end submodule psb_s_psblas_cbind_impl diff --git a/cbind/base/psb_s_serial_cbind_impl.F90 b/cbind/base/psb_s_serial_cbind_impl.F90 new file mode 100644 index 00000000..a562fec6 --- /dev/null +++ b/cbind/base/psb_s_serial_cbind_impl.F90 @@ -0,0 +1,283 @@ +submodule (psb_s_serial_cbind_mod) psb_s_serial_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + use psb_base_tools_cbind_mod + +contains + + + module function psb_c_svect_get_nrows(xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_svector) :: xh + + type(psb_s_vect_type), pointer :: vp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + res = vp%get_nrows() + end if + + end function psb_c_svect_get_nrows + + module function psb_c_svect_f_get_cpy(v,xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + real(c_float) :: v(*) + type(psb_c_svector) :: xh + + type(psb_s_vect_type), pointer :: vp + real(psb_spk_), allocatable :: fv(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + fv = vp%get_vect() + sz = size(fv) + v(1:sz) = fv(1:sz) + end if + + end function psb_c_svect_f_get_cpy + + + module function psb_c_svect_zero(xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_svector) :: xh + + type(psb_s_vect_type), pointer :: vp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + call vp%zero() + end if + + end function psb_c_svect_zero + + module function psb_c_svect_f_get_pnt(xh) bind(c) result(res) + implicit none + + type(c_ptr) :: res + type(psb_c_svector) :: xh + + type(psb_s_vect_type), pointer :: vp + + res = c_null_ptr + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + if(vp%is_dev()) call vp%sync() + res = c_loc(vp%v%v) + end if + + end function psb_c_svect_f_get_pnt + + + module function psb_c_smat_get_nrows(mh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_sspmat) :: mh + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + res = ap%get_nrows() + + end function psb_c_smat_get_nrows + + + module function psb_c_smat_get_ncols(mh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_sspmat) :: mh + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + res = ap%get_ncols() + + end function psb_c_smat_get_ncols + + module function psb_c_smat_name_print(mh,name) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + character(c_char) :: name(*) + + type(psb_c_sspmat) :: mh + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + character(1024) :: fname + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + call psb_stringc2f(name,fname) + + call ap%print(fname,head='PSBLAS Cbinding Interface') + + end function psb_c_smat_name_print + + module function psb_c_svect_set_scal(x,val) bind(c) result(info) + implicit none + + type(psb_c_svector) :: x + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + real(c_float), value :: val + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + call xp%set(val) + + info = 0 + + end function psb_c_svect_set_scal + + module function psb_c_svect_set_scal_bound(x,val,ifirst,ilast) bind(c) result(info) + implicit none + + type(psb_c_svector) :: x + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: ifirst, ilast + real(c_float) :: val + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + call xp%set(val,first=ifirst,last=ilast) + + info = 0 + + end function psb_c_svect_set_scal_bound + + module function psb_c_svect_set_vect(x,val,n) bind(c) result(info) + implicit none + type(psb_c_svector) :: x + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: n + real(c_float) :: val(*) + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + call xp%set(val(1:n)) + + info = 0 + + end function psb_c_svect_set_vect + + module function psb_c_svect_set_entry(x,index,val) bind(c) result(info) + implicit none + + type(psb_c_svector) :: x + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: index + real(c_float), value :: val + integer(psb_c_ipk_) :: ixb + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + call xp%set_entry((index+(1-ixb)),val) + info = 0 + + end function psb_c_svect_set_entry + + module function psb_c_svect_get_entry(x,index) bind(c) result(res) + implicit none + + type(psb_c_svector) :: x + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_), value :: index + real(c_float) :: res + integer(psb_c_ipk_) :: ixb + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + res = xp%get_entry((index+(1-ixb))) + end function psb_c_svect_get_entry + + module function psb_c_svect_clone(xh,yh) bind(c) result(info) + implicit none + + integer(psb_c_ipk_) :: info + type(psb_c_svector) :: xh,yh + + type(psb_s_vect_type), pointer :: xp,yp + + info = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + call xp%clone(yp,info) + + end function psb_c_svect_clone + +end submodule psb_s_serial_cbind_impl diff --git a/cbind/base/psb_s_tools_cbind_impl.F90 b/cbind/base/psb_s_tools_cbind_impl.F90 new file mode 100644 index 00000000..f7194360 --- /dev/null +++ b/cbind/base/psb_s_tools_cbind_impl.F90 @@ -0,0 +1,742 @@ +submodule ( psb_s_tools_cbind_mod) psb_s_tools_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_cpenv_mod + use psb_objhandle_mod + use psb_base_tools_cbind_mod +#ifdef PSB_HAVE_CUDA + use psb_cuda_mod +#endif + +contains + + ! Should define geall_opt with DUPL argument + module function psb_c_sgeall(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_sgeall + + module function psb_c_sgeall_remote(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info,bldmode=psb_matbld_remote_,dupl=psb_dupl_add_) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_sgeall_remote + + module function psb_c_sgeall_remote_options(xh,cdh,bldmode,dupl) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: dupl + integer(psb_c_ipk_), value :: bldmode + + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info,bldmode=bldmode,dupl=dupl) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_sgeall_remote_options + + module function psb_c_sgeasb(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info) + res = min(0,info) + + return + end function psb_c_sgeasb + + module function psb_c_sgeasb_options(xh,cdh,dupl) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: dupl + + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info,dupl=dupl) + res = min(0,info) + + return + end function psb_c_sgeasb_options + + module function psb_c_sgeasb_options_format(xh,cdh,dupl,format) bind(c) result(res) + ! Takes into account format argument as a c string, and uses it to call the appropriate psb_geasb + ! with mold argument + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + character(kind=c_char), dimension(*) :: format + integer(psb_c_ipk_), value :: dupl + + ! Local variables + character(len=6) :: fformat + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + ! mold variables +#ifdef PSB_HAVE_CUDA + type(psb_s_vect_cuda), target :: vgpu +#endif + type(psb_s_base_vect_type), target :: vect + class(psb_s_base_vect_type), pointer :: vmold + + ! Select mold based on format + call psb_stringc2f(format,fformat) + + select case (psb_toupper(fformat)) +#ifdef PSB_HAVE_CUDA + case('GPU','DEVICE') + vmold => vgpu +#endif + case('CPU','HOST') + vmold => vect + case default + write(psb_out_unit,*) 'psb_c_sgeasb_options_format: Unknown format ',fformat + vmold => vect + end select + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info,dupl=dupl,mold=vmold) + res = min(0,info) + + return + end function psb_c_sgeasb_options_format + + + module function psb_c_sgefree(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_gefree(xp,descp,info) + res = min(0,info) + deallocate(xp,stat=info) + res = min(0,info) + xh%item = c_null_ptr + + return + end function psb_c_sgefree + + + module function psb_c_sgeins(nz,irw,val,xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: nz + integer(psb_c_lpk_) :: irw(*) + real(c_float) :: val(*) + type(psb_c_svector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_s_vect_type), pointer :: xp + integer(psb_c_ipk_) :: ixb, info + + res = -1 + info = 0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_geins(nz,irw(1:nz),val(1:nz),& + & xp,descp,info) + else + call psb_geins(nz,(irw(1:nz)+(1-ixb)),val(1:nz),& + & xp,descp,info) + end if + + res = min(0,info) + + return + end function psb_c_sgeins + + module function psb_c_sspall(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_sspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + return + end if + allocate(ap) + call psb_spall(ap,descp,info) + mh%item = c_loc(ap) + res = min(0,info) + + return + end function psb_c_sspall + + + module function psb_c_sspall_remote(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_sspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + return + end if + allocate(ap) + call psb_spall(ap,descp,info,bldmode=psb_matbld_remote_,dupl=psb_dupl_add_) + mh%item = c_loc(ap) + res = min(0,info) + + return + end function psb_c_sspall_remote + + module function psb_c_sspasb(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_sspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + call psb_spasb(ap,descp,info) + res = min(0,info) + return + end function psb_c_sspasb + + module function psb_c_sspfree(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_sspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + call psb_spfree(ap,descp,info) + res = min(0,info) + deallocate(ap,stat=info) + mh%item=c_null_ptr + return + end function psb_c_sspfree + + + + + module function psb_c_sspasb_opt(mh,cdh,afmt,upd,dupl) bind(c) result(res) + +#if 0 +#ifdef PSB_HAVE_LIBRSB + use psb_s_rsb_mat_mod +#endif +#endif +#if defined(PSB_HAVE_CUDA) + use psb_cuda_mod +#endif + use psb_ext_mod + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_sspmat) :: mh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: upd,dupl + character(c_char) :: afmt(*) + integer(psb_c_ipk_) :: info,n + character(len=5) :: fafmt + integer(psb_ipk_), parameter :: hksz = 32 + ! mold variables +#if 0 +#ifdef PSB_HAVE_LIBRSB + type(psb_s_rsb_sparse_mat) :: arsb +#endif +#endif + type(psb_s_ell_sparse_mat), target :: aell + type(psb_s_csr_sparse_mat), target :: acsr + type(psb_s_csc_sparse_mat), target :: acsc + type(psb_s_coo_sparse_mat), target :: acoo + type(psb_s_hll_sparse_mat), target :: ahll + type(psb_s_hdia_sparse_mat), target :: ahdia + type(psb_s_dns_sparse_mat), target :: adns +#if defined(PSB_HAVE_CUDA) + type(psb_s_cuda_hlg_sparse_mat), target :: ahlg + type(psb_s_cuda_hdiag_sparse_mat), target :: ahdiag + type(psb_s_cuda_csrg_sparse_mat), target :: acsrg + type(psb_s_cuda_elg_sparse_mat), target :: aelg +#endif + class(psb_s_base_sparse_mat), pointer :: amold + !Local variables + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + call psb_stringc2f(afmt,fafmt) + + ! Set the mold variable based on afmt + select case (psb_toupper(fafmt)) +#if defined(PSB_HAVE_CUDA) + case('ELG') + amold => aelg + case('HLG') + call psi_set_hksz(hksz) + amold => ahlg + case('HDIAG') + amold => ahdiag + case('CSRG') + amold => acsrg + case('ELL') + amold => aell + case('HLL') + call psi_set_hksz(hksz) + amold => ahll + case('HDIA') + amold => ahdia + case('CSR') + amold => acsr + case('CSC') + amold => acsc + case('DNS') + amold => adns + case default + write(*,*) 'Unknown format defaulting to HLG' + amold => ahlg +#else + case('ELL') + amold => aell + case('HLL') + call psi_set_hksz(hksz) + amold => ahll + case('HDIA') + amold => ahdia + case('CSR') + amold => acsr + case('CSC') + amold => acsc + case('DNS') + amold => adns + case default + write(*,*) 'Unknown format defaulting to CSR' + amold => acsr +#endif + end select + + select case(fafmt) +#if 0 +#ifdef PSB_HAVE_LIBRSB + case('RSB') + call psb_spasb(double_spmat_pool(mh)%item,descriptor_pool(cdh)%item,info,& + & upd=upd,mold=arsb) +#endif +#endif + case('ELL','HLL','CSR','DNS','CSC') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) + case('HDIA') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) +#if defined(PSB_HAVE_CUDA) + case('ELG','HLG','CSRG') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) + case('HDIAG') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) +#endif + case default + write(psb_out_unit,*) 'psb_c_sspasb_opt: Unknown format ',fafmt + call psb_spasb(ap,descp,info,afmt=fafmt,upd=upd,dupl=dupl) + end select + + res = min(0,info) + + return + end function psb_c_sspasb_opt + + + module function psb_c_sspins(nz,irw,icl,val,mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: nz + integer(psb_c_lpk_) :: irw(*), icl(*) + real(c_float) :: val(*) + type(psb_c_sspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: ixb,info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_spins(nz,irw(1:nz),icl(1:nz),val(1:nz),ap,descp,info) + else + call psb_spins(nz,(irw(1:nz)+(1-ixb)),(icl(1:nz)+(1-ixb)),val(1:nz),ap,descp,info) + end if + res = min(0,info) + return + end function psb_c_sspins + + + module function psb_c_ssprn(mh,cdh,clear) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + logical(c_bool), value :: clear + type(psb_c_sspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_sspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + logical :: fclear + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + fclear = clear + call psb_sprn(ap,descp,info,clear=fclear) + res = min(0,info) + + return + end function psb_c_ssprn +!!$ +!!$ module function psb_c_sspprint(mh) bind(c) result(res) +!!$ +!!$ implicit none +!!$ integer(psb_c_ipk_) :: res +!!$ integer(psb_c_ipk_), value :: mh +!!$ integer(psb_c_ipk_) :: info +!!$ +!!$ +!!$ res = -1 +!!$ call psb_check_double_spmat_handle(mh,info) +!!$ if (info < 0) return +!!$ +!!$ call psb_csprt(0,double_spmat_pool(mh)%item,head='Debug mat') +!!$ +!!$ res = 0 +!!$ +!!$ return +!!$ end function psb_c_sspprint + + function psb_c_sgetelem(xh,index,cdh) bind(c) result(res) + implicit none + + type(psb_c_svector) :: xh + integer(psb_c_lpk_), value :: index + type(psb_c_descriptor) :: cdh + real(c_float) :: res + + type(psb_s_vect_type), pointer :: xp + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + res = psb_getelem(xp,index,descp,info) + else + res = psb_getelem(xp,index+(1-ixb),descp,info) + end if + + return + + end function psb_c_sgetelem + + module function psb_c_ssetelem(index,val,xh,cdh) bind(c) result(res) + implicit none + + type(psb_c_svector) :: xh + integer(psb_c_lpk_), value :: index + type(psb_c_descriptor) :: cdh + real(c_float), value :: val + integer(psb_c_ipk_) :: res + + type(psb_s_vect_type), pointer :: xp + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_setelem(index,val,xp,descp,info) + else + call psb_setelem(index+(1-ixb),val,xp,descp,info) + end if + res=info + return + + end function psb_c_ssetelem + + module function psb_c_smatgetelem(ah,rowindex,colindex,cdh) bind(c) result(res) + implicit none + + type(psb_c_sspmat) :: ah + integer(psb_c_lpk_), value :: rowindex, colindex + type(psb_c_descriptor) :: cdh + real(c_float) :: res + type(psb_sspmat_type), pointer :: ap + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + res = psb_getelem(ap,rowindex,colindex,descp,info) + else + res = psb_getelem(ap,rowindex+(1-ixb),colindex+(1-ixb),descp,info) + end if + + return + + end function psb_c_smatgetelem + +end submodule psb_s_tools_cbind_impl diff --git a/cbind/base/psb_z_comm_cbind_impl.f90 b/cbind/base/psb_z_comm_cbind_impl.f90 new file mode 100644 index 00000000..04392c6a --- /dev/null +++ b/cbind/base/psb_z_comm_cbind_impl.f90 @@ -0,0 +1,238 @@ +submodule (psb_z_comm_cbind_mod) psb_z_comm_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + +contains + + module function psb_c_zovrl(xh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_ovrl(xp,descp,info) + + res = info + + end function psb_c_zovrl + + module function psb_c_zovrl_opt(xh,cdh,update,mode) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: update, mode + + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_ovrl(xp,descp,info,update=update,mode=mode) + + res = info + + end function psb_c_zovrl_opt + + + module function psb_c_zhalo(xh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_halo(xp,descp,info) + + res = info + + end function psb_c_zhalo + + module function psb_c_zhalo_opt(xh,cdh,tran,data,mode) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: data, mode + character(c_char) :: tran + + + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + character :: ftran + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ftran = tran + call psb_halo(xp,descp,info,data=data,mode=mode,tran=ftran) + + res = info + + end function psb_c_zhalo_opt + + + module function psb_c_zvscatter(ng,gx,xh,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + integer(psb_c_lpk_), value :: ng + complex(c_double_complex), target :: gx(*) + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: vp + complex(psb_dpk_), pointer :: pgx(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + else + return + end if + + pgx => gx(1:ng) + + call psb_scatter(pgx,vp,descp,info) + res = info + + end function psb_c_zvscatter + + module function psb_c_zvgather_f(v,xh,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + complex(c_double_complex), target :: v(*) + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: vp + complex(psb_dpk_), allocatable :: fv(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + else + return + end if + + call psb_gather(fv,vp,descp,info) + res = info + if (res /=0) return + sz = size(fv) + v(1:sz) = fv(1:sz) + end function psb_c_zvgather_f + + module function psb_c_zspgather_f(gah,ah,cdh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_zspmat) :: ah, gah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap, gap + integer(psb_c_ipk_) :: info, sz + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(gah%item)) then + call c_f_pointer(gah%item,gap) + else + return + end if + call psb_gather(gap,ap,descp,info) + res = info + end function psb_c_zspgather_f + +end submodule psb_z_comm_cbind_impl diff --git a/cbind/base/psb_z_psblas_cbind_impl.f90 b/cbind/base/psb_z_psblas_cbind_impl.f90 new file mode 100644 index 00000000..366944c4 --- /dev/null +++ b/cbind/base/psb_z_psblas_cbind_impl.f90 @@ -0,0 +1,1267 @@ +submodule (psb_z_psblas_cbind_mod) psb_z_psblas_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + +contains + + module function psb_c_zgeaxpby(alpha,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,yh + type(psb_c_descriptor) :: cdh + complex(c_double_complex), value :: alpha,beta + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geaxpby(alpha,xp,beta,yp,descp,info) + + res = info + + end function psb_c_zgeaxpby + + module function psb_c_zgeaxpbyz(alpha,xh,beta,yh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + complex(c_double_complex), value :: alpha,beta + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_geaxpby(alpha,xp,beta,yp,zp,descp,info) + + res = info + + end function psb_c_zgeaxpbyz + + module function psb_c_zgemlt(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_gemlt(xp,yp,descp,info) + + res = info + + end function psb_c_zgemlt + + module function psb_c_zgemlt2(alpha,xh,yh,beta,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,yh, zh + type(psb_c_descriptor) :: cdh + + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + complex(psb_dpk_), intent(in), value :: alpha,beta + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gemlt(alpha,xp,yp,beta,zp,descp,info) + + res = info + + end function psb_c_zgemlt2 + + module function psb_c_zgediv(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_gediv(xp,yp,descp,info) + + res = info + + end function psb_c_zgediv + + module function psb_c_zgediv2(xh,yh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gediv(xp,yp,zp,descp,info) + + res = info + + end function psb_c_zgediv2 + + module function psb_c_zgediv_check(xh,yh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,yh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + fflag = flag + call psb_gediv(xp,yp,descp,info,fflag) + + res = info + + end function psb_c_zgediv_check + + module function psb_c_zgediv2_check(xh,yh,zh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,yh,zh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp,zp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + fflag = flag + call psb_gediv(xp,yp,zp,descp,info,fflag) + + res = info + + end function psb_c_zgediv2_check + + module function psb_c_zgeinv(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geinv(xp,yp,descp,info) + + res = info + + end function psb_c_zgeinv + + module function psb_c_zgeinv_check(xh,yh,cdh, flag) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,yh + type(psb_c_descriptor) :: cdh + logical(c_bool), value :: flag + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + logical :: fflag + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + fflag = flag + call psb_geinv(xp,yp,descp,info,fflag) + + res = info + + end function psb_c_zgeinv_check + + module function psb_c_zgeabs(xh,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,yh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + + call psb_geabs(xp,yp,descp,info) + + res = info + + end function psb_c_zgeabs + + module function psb_c_zgecmp(xh,ch,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,zp + integer(psb_c_ipk_) :: info + real(c_double_complex), value :: ch + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_gecmp(xp,ch,zp,descp,info) + + res = info + + end function psb_c_zgecmp + + module function psb_c_zgecmpmat(ah,bh,tol,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_zspmat) :: ah,bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + real(c_double_complex), value :: tol + logical :: isequal + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call psb_gecmp(ap,bp,tol,descp,isequal,info) + + res = isequal + + end function psb_c_zgecmpmat + + module function psb_c_zgecmpmat_val(ah,val,tol,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + complex(c_double_complex), value :: val + real(c_double_complex), value :: tol + logical :: isequal + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_gecmp(ap,val,tol,descp,isequal,info) + + res = isequal + + end function psb_c_zgecmpmat_val + + module function psb_c_zgeaddconst(xh,bh,zh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zvector) :: xh,zh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,zp + integer(psb_c_ipk_) :: info + real(c_double_complex), value :: bh + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(zh%item)) then + call c_f_pointer(zh%item,zp) + else + return + end if + + call psb_geaddconst(xp,bh,zp,descp,info) + + res = info + + end function psb_c_zgeaddconst + + + module function psb_c_zgenrm2(xh,cdh) bind(c) result(res) + implicit none + real(c_double_complex) :: res + + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_genrm2(xp,descp,info) + + end function psb_c_zgenrm2 + + module function psb_c_zgenrmi(xh,cdh) bind(c) result(res) + implicit none + real(c_double_complex) :: res + + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + type(psb_z_vect_type) :: yp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geall(yp,descp,info) + call psb_geabs(xp,yp,descp,info) + res = psb_geasum(yp,descp,info) + call psb_gefree(yp,descp,info) + + end function psb_c_zgenrmi + + module function psb_c_zgenrm2_weight(xh,wh,cdh) bind(c) result(res) + implicit none + real(c_double_complex) :: res + + type(psb_c_zvector) :: xh, wh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp, wp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(wh%item)) then + call c_f_pointer(wh%item,wp) + else + return + end if + + res = psb_genrm2(xp,wp,descp,info) + + end function psb_c_zgenrm2_weight + + module function psb_c_zgenrm2_weightmask(xh,wh,idvh,cdh) bind(c) result(res) + implicit none + real(c_double_complex) :: res + + type(psb_c_zvector) :: xh, wh, idvh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp, wp, idvp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(wh%item)) then + call c_f_pointer(wh%item,wp) + else + return + end if + if (c_associated(idvh%item)) then + call c_f_pointer(idvh%item,idvp) + else + return + end if + + res = psb_genrm2(xp,wp,idvp,descp,info) + + end function psb_c_zgenrm2_weightmask + + module function psb_c_zgeamax(xh,cdh) bind(c) result(res) + implicit none + real(c_double_complex) :: res + + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_geamax(xp,descp,info) + + end function psb_c_zgeamax + + + module function psb_c_zgeasum(xh,cdh) bind(c) result(res) + implicit none + real(c_double_complex) :: res + + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1.0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + res = psb_geasum(xp,descp,info) + + end function psb_c_zgeasum + + + module function psb_c_zspnrmi(ah,cdh) bind(c) result(res) + implicit none + real(c_double_complex) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = psb_spnrmi(ap,descp,info) + + end function psb_c_zspnrmi + + module function psb_c_zgedot(xh,yh,cdh) bind(c) result(res) + implicit none + complex(c_double_complex) :: res + + type(psb_c_zvector) :: xh,yh + type(psb_c_descriptor) :: cdh + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp + integer(psb_c_ipk_) :: info + + res = -1.0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + res = psb_gedot(xp,yp,descp,info) + + end function psb_c_zgedot + + + module function psb_c_zspmm(alpha,ah,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_zvector) :: xh,yh + type(psb_c_descriptor) :: cdh + complex(c_double_complex), value :: alpha, beta + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_spmm(alpha,ap,xp,beta,yp,descp,info) + + res = info + + end function psb_c_zspmm + + + module function psb_c_zspmm_opt(alpha,ah,xh,beta,yh,cdh,trans,doswap) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_zvector) :: xh,yh + type(psb_c_descriptor) :: cdh + complex(c_double_complex), value :: alpha, beta + character(c_char) :: trans + logical(c_bool), value :: doswap + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp + type(psb_zspmat_type), pointer :: ap + character :: ftrans + logical :: fdoswap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + fdoswap = doswap + ftrans = trans + call psb_spmm(alpha,ap,xp,beta,yp,descp,info,trans=ftrans,doswap=fdoswap) + + res = info + + end function psb_c_zspmm_opt + + + module function psb_c_zspsm(alpha,ah,xh,beta,yh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_zvector) :: xh,yh + type(psb_c_descriptor) :: cdh + complex(c_double_complex), value :: alpha, beta + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp,yp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call psb_spsm(alpha,ap,xp,beta,yp,descp,info) + + res = info + + end function psb_c_zspsm + + module function psb_c_znnz(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = psb_nnz(ap,descp,info) + + end function psb_c_znnz + + module function psb_c_zis_matupd(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_upd() + end function + + module function psb_c_zis_matasb(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_asb() + end function + + module function psb_c_zis_matbld(ah,cdh) bind(c) result(res) + implicit none + logical(c_bool) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = .false. + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + res = ap%is_bld() + end function + + module function psb_c_zset_matupd(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_upd() + + res = psb_success_ + end function + + module function psb_c_zset_matasb(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + + res = -1; + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_asb() + + res = psb_success_ + + end function + + module function psb_c_zset_matbld(ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%set_bld() + + res = psb_success_ + end function + + module function psb_c_zcopy_mat(ah,bh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zspmat) :: ah,bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call ap%clone(bp,info) + + res = info + end function + + module function psb_c_zspscal(alpha,ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + complex(c_double_complex), value :: alpha + type(psb_c_zspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%scal(alpha,info) + + res = info + + end function psb_c_zspscal + + module function psb_c_zspscalpid(alpha,ah,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + complex(c_double_complex), value :: alpha + type(psb_c_zspmat) :: ah + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + call ap%scalpid(alpha,info) + + res = info + + end function psb_c_zspscalpid + + module function psb_c_zspaxpby(alpha,ah,beta,bh,cdh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + complex(c_double_complex), value :: alpha + type(psb_c_zspmat) :: ah + complex(c_double_complex), value :: beta + type(psb_c_zspmat) :: bh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap,bp + integer(psb_c_ipk_) :: info + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + if (c_associated(bh%item)) then + call c_f_pointer(bh%item,bp) + else + return + end if + + call ap%spaxpby(alpha,beta,bp,info) + + res = info + end function psb_c_zspaxpby + +end submodule psb_z_psblas_cbind_impl diff --git a/cbind/base/psb_z_serial_cbind_impl.F90 b/cbind/base/psb_z_serial_cbind_impl.F90 new file mode 100644 index 00000000..225bc0b7 --- /dev/null +++ b/cbind/base/psb_z_serial_cbind_impl.F90 @@ -0,0 +1,283 @@ +submodule (psb_z_serial_cbind_mod) psb_z_serial_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_objhandle_mod + use psb_base_tools_cbind_mod + +contains + + + module function psb_c_zvect_get_nrows(xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_zvector) :: xh + + type(psb_z_vect_type), pointer :: vp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + res = vp%get_nrows() + end if + + end function psb_c_zvect_get_nrows + + module function psb_c_zvect_f_get_cpy(v,xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + complex(c_double_complex) :: v(*) + type(psb_c_zvector) :: xh + + type(psb_z_vect_type), pointer :: vp + complex(psb_dpk_), allocatable :: fv(:) + integer(psb_c_ipk_) :: info, sz + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + fv = vp%get_vect() + sz = size(fv) + v(1:sz) = fv(1:sz) + end if + + end function psb_c_zvect_f_get_cpy + + + module function psb_c_zvect_zero(xh) bind(c) result(res) + implicit none + + integer(psb_c_ipk_) :: res + type(psb_c_zvector) :: xh + + type(psb_z_vect_type), pointer :: vp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + call vp%zero() + end if + + end function psb_c_zvect_zero + + module function psb_c_zvect_f_get_pnt(xh) bind(c) result(res) + implicit none + + type(c_ptr) :: res + type(psb_c_zvector) :: xh + + type(psb_z_vect_type), pointer :: vp + + res = c_null_ptr + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,vp) + if(vp%is_dev()) call vp%sync() + res = c_loc(vp%v%v) + end if + + end function psb_c_zvect_f_get_pnt + + + module function psb_c_zmat_get_nrows(mh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zspmat) :: mh + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + res = ap%get_nrows() + + end function psb_c_zmat_get_nrows + + + module function psb_c_zmat_get_ncols(mh) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + + type(psb_c_zspmat) :: mh + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + res = ap%get_ncols() + + end function psb_c_zmat_get_ncols + + module function psb_c_zmat_name_print(mh,name) bind(c) result(res) + implicit none + integer(psb_c_ipk_) :: res + character(c_char) :: name(*) + + type(psb_c_zspmat) :: mh + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + character(1024) :: fname + + res = 0 + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + call psb_stringc2f(name,fname) + + call ap%print(fname,head='PSBLAS Cbinding Interface') + + end function psb_c_zmat_name_print + + module function psb_c_zvect_set_scal(x,val) bind(c) result(info) + implicit none + + type(psb_c_zvector) :: x + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + complex(c_double_complex), value :: val + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + call xp%set(val) + + info = 0 + + end function psb_c_zvect_set_scal + + module function psb_c_zvect_set_scal_bound(x,val,ifirst,ilast) bind(c) result(info) + implicit none + + type(psb_c_zvector) :: x + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: ifirst, ilast + complex(c_double_complex) :: val + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + call xp%set(val,first=ifirst,last=ilast) + + info = 0 + + end function psb_c_zvect_set_scal_bound + + module function psb_c_zvect_set_vect(x,val,n) bind(c) result(info) + implicit none + type(psb_c_zvector) :: x + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: n + complex(c_double_complex) :: val(*) + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + call xp%set(val(1:n)) + + info = 0 + + end function psb_c_zvect_set_vect + + module function psb_c_zvect_set_entry(x,index,val) bind(c) result(info) + implicit none + + type(psb_c_zvector) :: x + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + integer(psb_c_ipk_), value :: index + complex(c_double_complex), value :: val + integer(psb_c_ipk_) :: ixb + + info = -1; + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + call xp%set_entry((index+(1-ixb)),val) + info = 0 + + end function psb_c_zvect_set_entry + + module function psb_c_zvect_get_entry(x,index) bind(c) result(res) + implicit none + + type(psb_c_zvector) :: x + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_), value :: index + complex(c_double_complex) :: res + integer(psb_c_ipk_) :: ixb + + if (c_associated(x%item)) then + call c_f_pointer(x%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + res = xp%get_entry((index+(1-ixb))) + end function psb_c_zvect_get_entry + + module function psb_c_zvect_clone(xh,yh) bind(c) result(info) + implicit none + + integer(psb_c_ipk_) :: info + type(psb_c_zvector) :: xh,yh + + type(psb_z_vect_type), pointer :: xp,yp + + info = -1 + + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + if (c_associated(yh%item)) then + call c_f_pointer(yh%item,yp) + else + return + end if + call xp%clone(yp,info) + + end function psb_c_zvect_clone + +end submodule psb_z_serial_cbind_impl diff --git a/cbind/base/psb_z_tools_cbind_impl.F90 b/cbind/base/psb_z_tools_cbind_impl.F90 new file mode 100644 index 00000000..8b55f384 --- /dev/null +++ b/cbind/base/psb_z_tools_cbind_impl.F90 @@ -0,0 +1,732 @@ +submodule ( psb_z_tools_cbind_mod) psb_z_tools_cbind_impl + use iso_c_binding + use psb_base_mod + use psb_cpenv_mod + use psb_objhandle_mod + use psb_base_tools_cbind_mod +#ifdef PSB_HAVE_CUDA + use psb_cuda_mod +#endif + +contains + + ! Should define geall_opt with DUPL argument + module function psb_c_zgeall(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_zgeall + + module function psb_c_zgeall_remote(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info,bldmode=psb_matbld_remote_,dupl=psb_dupl_add_) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_zgeall_remote + + module function psb_c_zgeall_remote_options(xh,cdh,bldmode,dupl) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: dupl + integer(psb_c_ipk_), value :: bldmode + + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + return + end if + allocate(xp) + call psb_geall(xp,descp,info,bldmode=bldmode,dupl=dupl) + xh%item = c_loc(xp) + res = min(0,info) + + return + end function psb_c_zgeall_remote_options + + module function psb_c_zgeasb(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info) + res = min(0,info) + + return + end function psb_c_zgeasb + + module function psb_c_zgeasb_options(xh,cdh,dupl) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: dupl + + + type(psb_desc_type), pointer :: descp + type(psb_d_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info,dupl=dupl) + res = min(0,info) + + return + end function psb_c_zgeasb_options + + module function psb_c_zgeasb_options_format(xh,cdh,dupl,format) bind(c) result(res) + ! Takes into account format argument as a c string, and uses it to call the appropriate psb_geasb + ! with mold argument + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + character(kind=c_char), dimension(*) :: format + integer(psb_c_ipk_), value :: dupl + + ! Local variables + character(len=6) :: fformat + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + ! mold variables +#ifdef PSB_HAVE_CUDA + type(psb_z_vect_cuda), target :: vgpu +#endif + type(psb_z_base_vect_type), target :: vect + class(psb_z_base_vect_type), pointer :: vmold + + ! Select mold based on format + call psb_stringc2f(format,fformat) + + select case (psb_toupper(fformat)) +#ifdef PSB_HAVE_CUDA + case('GPU','DEVICE') + vmold => vgpu +#endif + case('CPU','HOST') + vmold => vect + case default + write(psb_out_unit,*) 'psb_c_zgeasb_options_format: Unknown format ',fformat + vmold => vect + end select + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_geasb(xp,descp,info,dupl=dupl,mold=vmold) + res = min(0,info) + + return + end function psb_c_zgeasb_options_format + + + module function psb_c_zgefree(xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: info + + res = -1 + + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + call psb_gefree(xp,descp,info) + res = min(0,info) + deallocate(xp,stat=info) + res = min(0,info) + xh%item = c_null_ptr + + return + end function psb_c_zgefree + + + module function psb_c_zgeins(nz,irw,val,xh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: nz + integer(psb_c_lpk_) :: irw(*) + complex(c_double_complex) :: val(*) + type(psb_c_zvector) :: xh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_z_vect_type), pointer :: xp + integer(psb_c_ipk_) :: ixb, info + + res = -1 + info = 0 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_geins(nz,irw(1:nz),val(1:nz),& + & xp,descp,info) + else + call psb_geins(nz,(irw(1:nz)+(1-ixb)),val(1:nz),& + & xp,descp,info) + end if + + res = min(0,info) + + return + end function psb_c_zgeins + + module function psb_c_zspall(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + return + end if + allocate(ap) + call psb_spall(ap,descp,info) + mh%item = c_loc(ap) + res = min(0,info) + + return + end function psb_c_zspall + + + module function psb_c_zspall_remote(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + return + end if + allocate(ap) + call psb_spall(ap,descp,info,bldmode=psb_matbld_remote_,dupl=psb_dupl_add_) + mh%item = c_loc(ap) + res = min(0,info) + + return + end function psb_c_zspall_remote + + module function psb_c_zspasb(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + call psb_spasb(ap,descp,info) + res = min(0,info) + return + end function psb_c_zspasb + + module function psb_c_zspfree(mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + call psb_spfree(ap,descp,info) + res = min(0,info) + deallocate(ap,stat=info) + mh%item=c_null_ptr + return + end function psb_c_zspfree + + + + + module function psb_c_zspasb_opt(mh,cdh,afmt,upd,dupl) bind(c) result(res) + +#if 0 +#ifdef PSB_HAVE_LIBRSB + use psb_z_rsb_mat_mod +#endif +#endif +#if defined(PSB_HAVE_CUDA) + use psb_cuda_mod +#endif + use psb_ext_mod + implicit none + integer(psb_c_ipk_) :: res + type(psb_c_zspmat) :: mh + type(psb_c_descriptor) :: cdh + integer(psb_c_ipk_), value :: upd,dupl + character(c_char) :: afmt(*) + integer(psb_c_ipk_) :: info,n + character(len=5) :: fafmt + integer(psb_ipk_), parameter :: hksz = 32 + ! mold variables +#if 0 +#ifdef PSB_HAVE_LIBRSB + type(psb_z_rsb_sparse_mat) :: arsb +#endif +#endif + type(psb_z_ell_sparse_mat), target :: aell + type(psb_z_csr_sparse_mat), target :: acsr + type(psb_z_csc_sparse_mat), target :: acsc + type(psb_z_coo_sparse_mat), target :: acoo + type(psb_z_hll_sparse_mat), target :: ahll + type(psb_z_hdia_sparse_mat), target :: ahdia + type(psb_z_dns_sparse_mat), target :: adns +#if defined(PSB_HAVE_CUDA) + type(psb_z_cuda_hlg_sparse_mat), target :: ahlg + type(psb_z_cuda_csrg_sparse_mat), target :: acsrg + type(psb_z_cuda_elg_sparse_mat), target :: aelg +#endif + class(psb_z_base_sparse_mat), pointer :: amold + !Local variables + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + call psb_stringc2f(afmt,fafmt) + + ! Set the mold variable based on afmt + select case (psb_toupper(fafmt)) +#if defined(PSB_HAVE_CUDA) + case('ELG') + amold => aelg + case('HLG') + call psi_set_hksz(hksz) + amold => ahlg + case('CSRG') + amold => acsrg + case('ELL') + amold => aell + case('HLL') + call psi_set_hksz(hksz) + amold => ahll + case('CSR') + amold => acsr + case('CSC') + amold => acsc + case('DNS') + amold => adns + case default + write(*,*) 'Unknown format defaulting to HLG' + amold => ahlg +#else + case('ELL') + amold => aell + case('HLL') + call psi_set_hksz(hksz) + amold => ahll + amold => ahdia + case('CSR') + amold => acsr + case('CSC') + amold => acsc + case('DNS') + amold => adns + case default + write(*,*) 'Unknown format defaulting to CSR' + amold => acsr +#endif + end select + + select case(fafmt) +#if 0 +#ifdef PSB_HAVE_LIBRSB + case('RSB') + call psb_spasb(double_spmat_pool(mh)%item,descriptor_pool(cdh)%item,info,& + & upd=upd,mold=arsb) +#endif +#endif + case('ELL','HLL','CSR','DNS','CSC') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) +#if defined(PSB_HAVE_CUDA) + case('ELG','HLG','CSRG') + call psb_spasb(ap,descp,info,upd=upd,mold=amold) +#endif + case default + write(psb_out_unit,*) 'psb_c_zspasb_opt: Unknown format ',fafmt + call psb_spasb(ap,descp,info,afmt=fafmt,upd=upd,dupl=dupl) + end select + + res = min(0,info) + + return + end function psb_c_zspasb_opt + + + module function psb_c_zspins(nz,irw,icl,val,mh,cdh) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + integer(psb_c_ipk_), value :: nz + integer(psb_c_lpk_) :: irw(*), icl(*) + complex(c_double_complex) :: val(*) + type(psb_c_zspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: ixb,info,n + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_spins(nz,irw(1:nz),icl(1:nz),val(1:nz),ap,descp,info) + else + call psb_spins(nz,(irw(1:nz)+(1-ixb)),(icl(1:nz)+(1-ixb)),val(1:nz),ap,descp,info) + end if + res = min(0,info) + return + end function psb_c_zspins + + + module function psb_c_zsprn(mh,cdh,clear) bind(c) result(res) + + implicit none + integer(psb_c_ipk_) :: res + logical(c_bool), value :: clear + type(psb_c_zspmat) :: mh + type(psb_c_descriptor) :: cdh + + type(psb_desc_type), pointer :: descp + type(psb_zspmat_type), pointer :: ap + integer(psb_c_ipk_) :: info + logical :: fclear + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(mh%item)) then + call c_f_pointer(mh%item,ap) + else + return + end if + + fclear = clear + call psb_sprn(ap,descp,info,clear=fclear) + res = min(0,info) + + return + end function psb_c_zsprn +!!$ +!!$ module function psb_c_zspprint(mh) bind(c) result(res) +!!$ +!!$ implicit none +!!$ integer(psb_c_ipk_) :: res +!!$ integer(psb_c_ipk_), value :: mh +!!$ integer(psb_c_ipk_) :: info +!!$ +!!$ +!!$ res = -1 +!!$ call psb_check_double_spmat_handle(mh,info) +!!$ if (info < 0) return +!!$ +!!$ call psb_csprt(0,double_spmat_pool(mh)%item,head='Debug mat') +!!$ +!!$ res = 0 +!!$ +!!$ return +!!$ end function psb_c_zspprint + + function psb_c_zgetelem(xh,index,cdh) bind(c) result(res) + implicit none + + type(psb_c_zvector) :: xh + integer(psb_c_lpk_), value :: index + type(psb_c_descriptor) :: cdh + complex(c_double_complex) :: res + + type(psb_z_vect_type), pointer :: xp + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + res = psb_getelem(xp,index,descp,info) + else + res = psb_getelem(xp,index+(1-ixb),descp,info) + end if + + return + + end function psb_c_zgetelem + + module function psb_c_zsetelem(index,val,xh,cdh) bind(c) result(res) + implicit none + + type(psb_c_zvector) :: xh + integer(psb_c_lpk_), value :: index + type(psb_c_descriptor) :: cdh + complex(c_double_complex), value :: val + integer(psb_c_ipk_) :: res + + type(psb_z_vect_type), pointer :: xp + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(xh%item)) then + call c_f_pointer(xh%item,xp) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + call psb_setelem(index,val,xp,descp,info) + else + call psb_setelem(index+(1-ixb),val,xp,descp,info) + end if + res=info + return + + end function psb_c_zsetelem + + module function psb_c_zmatgetelem(ah,rowindex,colindex,cdh) bind(c) result(res) + implicit none + + type(psb_c_zspmat) :: ah + integer(psb_c_lpk_), value :: rowindex, colindex + type(psb_c_descriptor) :: cdh + complex(c_double_complex) :: res + type(psb_zspmat_type), pointer :: ap + type(psb_desc_type), pointer :: descp + integer(psb_c_ipk_) :: info, ixb + + res = -1 + if (c_associated(cdh%item)) then + call c_f_pointer(cdh%item,descp) + else + return + end if + if (c_associated(ah%item)) then + call c_f_pointer(ah%item,ap) + else + return + end if + + ixb = psb_c_get_index_base() + if (ixb == 1) then + res = psb_getelem(ap,rowindex,colindex,descp,info) + else + res = psb_getelem(ap,rowindex+(1-ixb),colindex+(1-ixb),descp,info) + end if + + return + + end function psb_c_zmatgetelem + +end submodule psb_z_tools_cbind_impl