@ -10,8 +10,16 @@ module psbn_d_base_mat_mod
procedure , pass ( a ) :: d_base_cssv
procedure , pass ( a ) :: d_base_cssm
generic , public :: cssm = > d_base_cssm , d_base_cssv
procedure , pass ( a ) :: d_scals
procedure , pass ( a ) :: d_scal
generic , public :: scal = > d_scals , d_scal
procedure , pass ( a ) :: get_diag
procedure , pass ( a ) :: csnmi
procedure , pass ( a ) :: csput
procedure , pass ( a ) :: d_csgetrow
procedure , pass ( a ) :: d_csgetblk
generic , public :: csget = > d_csgetrow , d_csgetblk
procedure , pass ( a ) :: csclip
procedure , pass ( a ) :: cp_to_coo
procedure , pass ( a ) :: cp_from_coo
procedure , pass ( a ) :: cp_to_fmt
@ -21,9 +29,12 @@ module psbn_d_base_mat_mod
procedure , pass ( a ) :: mv_to_fmt
procedure , pass ( a ) :: mv_from_fmt
end type psbn_d_base_sparse_mat
private :: d_base_csmv , d_base_csmm , d_base_cssv , d_base_cssm , &
& csnmi , csput , cp_to_coo , cp_from_coo , cp_to_fmt , cp_from_fmt , &
& mv_to_coo , mv_from_coo , mv_to_fmt , mv_from_fmt
& d_scals , d_scal , csnmi , csput , d_csgetrow , d_csgetblk , &
& cp_to_coo , cp_from_coo , cp_to_fmt , cp_from_fmt , &
& mv_to_coo , mv_from_coo , mv_to_fmt , mv_from_fmt , &
& get_diag , csclip
type , extends ( psbn_d_base_sparse_mat ) :: psbn_d_coo_sparse_mat
@ -41,8 +52,11 @@ module psbn_d_base_mat_mod
procedure , pass ( a ) :: d_base_csmv = > d_coo_csmv
procedure , pass ( a ) :: d_base_cssm = > d_coo_cssm
procedure , pass ( a ) :: d_base_cssv = > d_coo_cssv
procedure , pass ( a ) :: d_scals = > d_coo_scals
procedure , pass ( a ) :: d_scal = > d_coo_scal
procedure , pass ( a ) :: csnmi = > d_coo_csnmi
procedure , pass ( a ) :: csput = > d_coo_csput
procedure , pass ( a ) :: get_diag = > d_coo_get_diag
procedure , pass ( a ) :: reallocate_nz = > d_coo_reallocate_nz
procedure , pass ( a ) :: allocate_mnnz = > d_coo_allocate_mnnz
procedure , pass ( a ) :: cp_to_coo = > d_cp_coo_to_coo
@ -55,16 +69,23 @@ module psbn_d_base_mat_mod
procedure , pass ( a ) :: mv_from_fmt = > d_mv_coo_from_fmt
procedure , pass ( a ) :: fix = > d_fix_coo
procedure , pass ( a ) :: free = > d_coo_free
procedure , pass ( a ) :: trim = > d_coo_trim
procedure , pass ( a ) :: d_csgetrow = > d_coo_csgetrow
procedure , pass ( a ) :: d_csgetblk = > d_coo_csgetblk
procedure , pass ( a ) :: csclip = > d_coo_csclip
procedure , pass ( a ) :: print = > d_coo_print
procedure , pass ( a ) :: get_fmt = > d_coo_get_fmt
end type psbn_d_coo_sparse_mat
private :: d_coo_get_nzeros , d_coo_set_nzeros , &
private :: d_coo_get_nzeros , d_coo_set_nzeros , d_coo_get_diag , &
& d_coo_csmm , d_coo_csmv , d_coo_cssm , d_coo_cssv , d_coo_csnmi , &
& d_coo_csput , d_coo_reallocate_nz , d_coo_allocate_mnnz , &
& d_fix_coo , d_coo_free , d_coo_print , d_coo_get_fmt , &
& d_cp_coo_to_coo , d_cp_coo_from_coo , &
& d_cp_coo_to_fmt , d_cp_coo_from_fmt
& d_cp_coo_to_fmt , d_cp_coo_from_fmt , &
& d_coo_scals , d_coo_scal , d_coo_csgetrow , d_coo_csgetblk , &
& d_coo_csclip
interface
@ -175,12 +196,33 @@ module psbn_d_base_mat_mod
import psbn_d_coo_sparse_mat
class ( psbn_d_coo_sparse_mat ) , intent ( inout ) :: a
real ( psb_dpk_ ) , intent ( in ) :: val ( : )
integer , intent ( in ) :: nz , ia ( : ) , ja ( : ) , imin , imax , jmin , jmax
integer , intent ( in ) :: nz , ia ( : ) , ja ( : ) , &
& imin , imax , jmin , jmax
integer , intent ( out ) :: info
integer , intent ( in ) , optional :: gtl ( : )
end subroutine d_coo_csput_impl
end interface
interface
subroutine d_coo_csgetrow_impl ( imin , imax , a , nz , ia , ja , val , info , &
& jmin , jmax , iren , append , nzin , rscale , cscale )
use psb_const_mod
import psbn_d_coo_sparse_mat
implicit none
class ( psbn_d_coo_sparse_mat ) , intent ( in ) :: a
integer , intent ( in ) :: imin , imax
integer , intent ( out ) :: nz
integer , allocatable , intent ( inout ) :: ia ( : ) , ja ( : )
real ( psb_dpk_ ) , allocatable , intent ( inout ) :: val ( : )
integer , intent ( out ) :: info
logical , intent ( in ) , optional :: append
integer , intent ( in ) , optional :: iren ( : )
integer , intent ( in ) , optional :: jmin , jmax , nzin
logical , intent ( in ) , optional :: rscale , cscale
end subroutine d_coo_csgetrow_impl
end interface
interface d_coo_cssm_impl
subroutine d_coo_cssv_impl ( alpha , a , x , beta , y , info , trans )
use psb_const_mod
@ -490,6 +532,108 @@ contains
end subroutine csput
subroutine d_csgetrow ( imin , imax , a , nz , ia , ja , val , info , &
& jmin , jmax , iren , append , nzin , rscale , cscale )
! Output is always in COO format
use psb_error_mod
use psb_const_mod
implicit none
class ( psbn_d_base_sparse_mat ) , intent ( in ) :: a
integer , intent ( in ) :: imin , imax
integer , intent ( out ) :: nz
integer , allocatable , intent ( inout ) :: ia ( : ) , ja ( : )
real ( psb_dpk_ ) , allocatable , intent ( inout ) :: val ( : )
integer , intent ( out ) :: info
logical , intent ( in ) , optional :: append
integer , intent ( in ) , optional :: iren ( : )
integer , intent ( in ) , optional :: jmin , jmax , nzin
logical , intent ( in ) , optional :: rscale , cscale
Integer :: err_act
character ( len = 20 ) :: name = 'csget'
logical , parameter :: debug = . false .
call psb_get_erraction ( err_act )
! This is the base version . If we get here
! it means the derived class is incomplete ,
! so we throw an error .
info = 700
call psb_errpush ( info , name , a_err = a % get_fmt ( ) )
if ( err_act / = psb_act_ret_ ) then
call psb_error ( )
end if
return
end subroutine d_csgetrow
subroutine d_csgetblk ( imin , imax , a , b , info , &
& jmin , jmax , iren , append , rscale , cscale )
! Output is always in COO format
use psb_error_mod
use psb_const_mod
implicit none
class ( psbn_d_base_sparse_mat ) , intent ( in ) :: a
class ( psbn_d_coo_sparse_mat ) , intent ( inout ) :: b
integer , intent ( in ) :: imin , imax
integer , intent ( out ) :: info
logical , intent ( in ) , optional :: append
integer , intent ( in ) , optional :: iren ( : )
integer , intent ( in ) , optional :: jmin , jmax
logical , intent ( in ) , optional :: rscale , cscale
Integer :: err_act
character ( len = 20 ) :: name = 'csget'
logical , parameter :: debug = . false .
call psb_get_erraction ( err_act )
! This is the base version . If we get here
! it means the derived class is incomplete ,
! so we throw an error .
info = 700
call psb_errpush ( info , name , a_err = a % get_fmt ( ) )
if ( err_act / = psb_act_ret_ ) then
call psb_error ( )
end if
return
end subroutine d_csgetblk
subroutine csclip ( a , b , info , &
& imin , imax , jmin , jmax , rscale , cscale )
! Output is always in COO format
use psb_error_mod
use psb_const_mod
implicit none
class ( psbn_d_base_sparse_mat ) , intent ( in ) :: a
class ( psbn_d_coo_sparse_mat ) , intent ( out ) :: b
integer , intent ( out ) :: info
integer , intent ( in ) , optional :: imin , imax , jmin , jmax
logical , intent ( in ) , optional :: rscale , cscale
Integer :: err_act
character ( len = 20 ) :: name = 'csclip'
logical , parameter :: debug = . false .
call psb_get_erraction ( err_act )
! This is the base version . If we get here
! it means the derived class is incomplete ,
! so we throw an error .
info = 700
call psb_errpush ( info , name , a_err = a % get_fmt ( ) )
if ( err_act / = psb_act_ret_ ) then
call psb_error ( )
end if
return
end subroutine csclip
! == == == == == == == == == == == == == == == == == ==
!
!
@ -610,9 +754,61 @@ contains
end if
return
end subroutine d_base_cssv
subroutine d_scals ( d , a , info )
use psb_error_mod
implicit none
class ( psbn_d_base_sparse_mat ) , intent ( in ) :: a
real ( psb_dpk_ ) , intent ( in ) :: d
integer , intent ( out ) :: info
Integer :: err_act
character ( len = 20 ) :: name = 'd_scals'
logical , parameter :: debug = . false .
call psb_get_erraction ( err_act )
! This is the base version . If we get here
! it means the derived class is incomplete ,
! so we throw an error .
info = 700
call psb_errpush ( info , name , a_err = a % get_fmt ( ) )
if ( err_act / = psb_act_ret_ ) then
call psb_error ( )
end if
return
end subroutine d_scals
subroutine d_scal ( d , a , info )
use psb_error_mod
implicit none
class ( psbn_d_base_sparse_mat ) , intent ( in ) :: a
real ( psb_dpk_ ) , intent ( in ) :: d ( : )
integer , intent ( out ) :: info
Integer :: err_act
character ( len = 20 ) :: name = 'd_scal'
logical , parameter :: debug = . false .
call psb_get_erraction ( err_act )
! This is the base version . If we get here
! it means the derived class is incomplete ,
! so we throw an error .
info = 700
call psb_errpush ( info , name , a_err = a % get_fmt ( ) )
if ( err_act / = psb_act_ret_ ) then
call psb_error ( )
end if
return
end subroutine d_scal
function csnmi ( a ) result ( res )
use psb_error_mod
use psb_const_mod
@ -640,6 +836,33 @@ contains
end function csnmi
subroutine get_diag ( a , d , info )
use psb_error_mod
use psb_const_mod
implicit none
class ( psbn_d_base_sparse_mat ) , intent ( in ) :: a
real ( psb_dpk_ ) , intent ( out ) :: d ( : )
integer , intent ( out ) :: info
Integer :: err_act
character ( len = 20 ) :: name = 'get_diag'
logical , parameter :: debug = . false .
call psb_get_erraction ( err_act )
! This is the base version . If we get here
! it means the derived class is incomplete ,
! so we throw an error .
info = 700
call psb_errpush ( info , name , a_err = a % get_fmt ( ) )
if ( err_act / = psb_act_ret_ ) then
call psb_error ( )
end if
return
end subroutine get_diag
@ -1125,6 +1348,242 @@ contains
end subroutine d_coo_csput
subroutine d_coo_csgetrow ( imin , imax , a , nz , ia , ja , val , info , &
& jmin , jmax , iren , append , nzin , rscale , cscale )
! Output is always in COO format
use psb_error_mod
use psb_const_mod
implicit none
class ( psbn_d_coo_sparse_mat ) , intent ( in ) :: a
integer , intent ( in ) :: imin , imax
integer , intent ( out ) :: nz
integer , allocatable , intent ( inout ) :: ia ( : ) , ja ( : )
real ( psb_dpk_ ) , allocatable , intent ( inout ) :: val ( : )
integer , intent ( out ) :: info
logical , intent ( in ) , optional :: append
integer , intent ( in ) , optional :: iren ( : )
integer , intent ( in ) , optional :: jmin , jmax , nzin
logical , intent ( in ) , optional :: rscale , cscale
Integer :: err_act
character ( len = 20 ) :: name = 'csget'
logical , parameter :: debug = . false .
call psb_erractionsave ( err_act )
info = 0
call d_coo_csgetrow_impl ( imin , imax , a , nz , ia , ja , val , info , &
& jmin , jmax , iren , append , nzin , rscale , cscale )
if ( info / = 0 ) go to 9999
call psb_erractionrestore ( err_act )
return
9999 continue
call psb_erractionrestore ( err_act )
if ( err_act == psb_act_abort_ ) then
call psb_error ( )
return
end if
return
end subroutine d_coo_csgetrow
subroutine d_coo_csgetblk ( imin , imax , a , b , info , &
& jmin , jmax , iren , append , rscale , cscale )
! Output is always in COO format
use psb_error_mod
use psb_const_mod
implicit none
class ( psbn_d_coo_sparse_mat ) , intent ( in ) :: a
class ( psbn_d_coo_sparse_mat ) , intent ( inout ) :: b
integer , intent ( in ) :: imin , imax
integer , intent ( out ) :: info
logical , intent ( in ) , optional :: append
integer , intent ( in ) , optional :: iren ( : )
integer , intent ( in ) , optional :: jmin , jmax
logical , intent ( in ) , optional :: rscale , cscale
Integer :: err_act , nzin , nzout
character ( len = 20 ) :: name = 'csget'
logical :: append_
logical , parameter :: debug = . false .
call psb_erractionsave ( err_act )
info = 0
if ( present ( append ) ) then
append_ = append
else
append_ = . false .
endif
if ( append_ ) then
nzin = a % get_nzeros ( )
else
nzin = 0
endif
call a % csget ( imin , imax , nzout , b % ia , b % ja , b % val , info , &
& jmin = jmin , jmax = jmax , iren = iren , append = append_ , &
& nzin = nzin , rscale = rscale , cscale = cscale )
if ( info / = 0 ) go to 9999
call b % set_nzeros ( nzin + nzout )
call b % fix ( info )
if ( info / = 0 ) go to 9999
call psb_erractionrestore ( err_act )
return
9999 continue
call psb_erractionrestore ( err_act )
if ( err_act == psb_act_abort_ ) then
call psb_error ( )
return
end if
return
end subroutine d_coo_csgetblk
subroutine d_coo_csclip ( a , b , info , &
& imin , imax , jmin , jmax , rscale , cscale )
! Output is always in COO format
use psb_error_mod
use psb_const_mod
implicit none
class ( psbn_d_coo_sparse_mat ) , intent ( in ) :: a
class ( psbn_d_coo_sparse_mat ) , intent ( out ) :: b
integer , intent ( out ) :: info
integer , intent ( in ) , optional :: imin , imax , jmin , jmax
logical , intent ( in ) , optional :: rscale , cscale
Integer :: err_act , nzin , nzout , imin_ , imax_ , jmin_ , jmax_ , mb , nb
character ( len = 20 ) :: name = 'csget'
logical :: rscale_ , cscale_
logical , parameter :: debug = . false .
call psb_erractionsave ( err_act )
info = 0
nzin = 0
if ( present ( imin ) ) then
imin_ = imin
else
imin_ = 1
end if
if ( present ( imax ) ) then
imax_ = imax
else
imax_ = a % get_nrows ( )
end if
if ( present ( jmin ) ) then
jmin_ = jmin
else
jmin_ = 1
end if
if ( present ( jmax ) ) then
jmax_ = jmax
else
jmax_ = a % get_ncols ( )
end if
if ( present ( rscale ) ) then
rscale_ = rscale
else
rscale_ = . true .
end if
if ( present ( cscale ) ) then
cscale_ = cscale
else
cscale_ = . true .
end if
if ( rscale_ ) then
mb = imax_ - imin_ + 1
else
mb = a % get_nrows ( ) ! Should this be imax_ ? ?
endif
if ( cscale_ ) then
nb = jmax_ - jmin_ + 1
else
nb = a % get_ncols ( ) ! Should this be jmax_ ? ?
endif
call b % allocate ( mb , nb )
call a % csget ( imin_ , imax_ , nzout , b % ia , b % ja , b % val , info , &
& jmin = jmin_ , jmax = jmax_ , append = . false . , &
& nzin = nzin , rscale = rscale_ , cscale = cscale_ )
if ( info / = 0 ) go to 9999
call b % set_nzeros ( nzin + nzout )
call b % fix ( info )
if ( info / = 0 ) go to 9999
call psb_erractionrestore ( err_act )
return
9999 continue
call psb_erractionrestore ( err_act )
if ( err_act == psb_act_abort_ ) then
call psb_error ( )
return
end if
return
end subroutine d_coo_csclip
! ! $
! ! $ subroutine d_coo_csget ( irw , a , nz , ia , ja , val , info , iren , lrw , append , nzin )
! ! $ ! Output is always in COO format
! ! $ use psb_error_mod
! ! $ use psb_const_mod
! ! $ implicit none
! ! $
! ! $ class ( psbn_d_coo_sparse_mat ) , intent ( inout ) :: a
! ! $ integer , intent ( in ) :: irw
! ! $ integer , intent ( out ) :: nz
! ! $ integer , allocatable , intent ( inout ) :: ia ( : ) , ja ( : )
! ! $ real ( psb_dpk_ ) , allocatable , intent ( inout ) :: val ( : )
! ! $ integer , intent ( out ) :: info
! ! $ logical , intent ( in ) , optional :: append
! ! $ integer , intent ( in ) , optional :: iren ( : )
! ! $ integer , intent ( in ) , optional :: lrw , nzin
! ! $ Integer :: err_act
! ! $ character ( len = 20 ) :: name = 'csget'
! ! $ logical , parameter :: debug = . false .
! ! $
! ! $ call psb_erractionsave ( err_act )
! ! $ info = 0
! ! $
! ! $ call d_coo_csget_impl ( irw , a , nz , ia , ja , val , info , iren , lrw , append , nzin )
! ! $ if ( info / = 0 ) go to 9999
! ! $
! ! $ call psb_erractionrestore ( err_act )
! ! $ return
! ! $
! ! $ 9999 continue
! ! $ call psb_erractionrestore ( err_act )
! ! $
! ! $ if ( err_act == psb_act_abort_ ) then
! ! $ call psb_error ( )
! ! $ return
! ! $ end if
! ! $ return
! ! $
! ! $ end subroutine d_coo_csget
! ! $
subroutine d_coo_free ( a )
implicit none
@ -1141,6 +1600,38 @@ contains
end subroutine d_coo_free
subroutine d_coo_trim ( a )
use psb_realloc_mod
use psb_error_mod
implicit none
class ( psbn_d_coo_sparse_mat ) , intent ( inout ) :: a
Integer :: err_act , info , nz
character ( len = 20 ) :: name = 'trim'
logical , parameter :: debug = . false .
call psb_erractionsave ( err_act )
info = 0
nz = a % get_nzeros ( )
if ( info == 0 ) call psb_realloc ( nz , a % ia , info )
if ( info == 0 ) call psb_realloc ( nz , a % ja , info )
if ( info == 0 ) call psb_realloc ( nz , a % val , info )
if ( info / = 0 ) go to 9999
call psb_erractionrestore ( err_act )
return
9999 continue
call psb_erractionrestore ( err_act )
if ( err_act == psb_act_abort_ ) then
call psb_error ( )
return
end if
return
end subroutine d_coo_trim
subroutine d_coo_allocate_mnnz ( m , n , a , nz )
use psb_error_mod
use psb_realloc_mod
@ -1275,6 +1766,7 @@ contains
! == == == == == == == == == == == == == == == == == ==
!
!
@ -1494,6 +1986,122 @@ contains
end function d_coo_csnmi
subroutine d_coo_get_diag ( a , d , info )
use psb_error_mod
use psb_const_mod
implicit none
class ( psbn_d_coo_sparse_mat ) , intent ( in ) :: a
real ( psb_dpk_ ) , intent ( out ) :: d ( : )
integer , intent ( out ) :: info
Integer :: err_act , mnm , i , j
character ( len = 20 ) :: name = 'get_diag'
logical , parameter :: debug = . false .
info = 0
call psb_erractionsave ( err_act )
mnm = min ( a % get_nrows ( ) , a % get_ncols ( ) )
if ( size ( d ) < mnm ) then
info = 35
call psb_errpush ( info , name , i_err = ( / 2 , size ( d ) , 0 , 0 , 0 / ) )
go to 9999
end if
d ( : ) = dzero
do i = 1 , a % get_nzeros ( )
j = a % ia ( i )
if ( ( j == a % ja ( i ) ) . and . ( j < = mnm ) . and . ( j > 0 ) ) then
d ( j ) = a % val ( i )
endif
enddo
call psb_erractionrestore ( err_act )
return
9999 continue
call psb_erractionrestore ( err_act )
if ( err_act == psb_act_abort_ ) then
call psb_error ( )
return
end if
return
end subroutine d_coo_get_diag
subroutine d_coo_scal ( d , a , info )
use psb_error_mod
use psb_const_mod
implicit none
class ( psbn_d_coo_sparse_mat ) , intent ( inout ) :: a
real ( psb_dpk_ ) , intent ( in ) :: d ( : )
integer , intent ( out ) :: info
Integer :: err_act , mnm , i , j , m
character ( len = 20 ) :: name = 'scal'
logical , parameter :: debug = . false .
info = 0
call psb_erractionsave ( err_act )
m = a % get_nrows ( )
if ( size ( d ) < m ) then
info = 35
call psb_errpush ( info , name , i_err = ( / 2 , size ( d ) , 0 , 0 , 0 / ) )
go to 9999
end if
do i = 1 , a % get_nzeros ( )
j = a % ia ( i )
a % val ( i ) = a % val ( i ) * d ( j )
enddo
call psb_erractionrestore ( err_act )
return
9999 continue
call psb_erractionrestore ( err_act )
if ( err_act == psb_act_abort_ ) then
call psb_error ( )
return
end if
return
end subroutine d_coo_scal
subroutine d_coo_scals ( d , a , info )
use psb_error_mod
use psb_const_mod
implicit none
class ( psbn_d_coo_sparse_mat ) , intent ( inout ) :: a
real ( psb_dpk_ ) , intent ( in ) :: d
integer , intent ( out ) :: info
Integer :: err_act , mnm , i , j , m
character ( len = 20 ) :: name = 'scal'
logical , parameter :: debug = . false .
info = 0
call psb_erractionsave ( err_act )
do i = 1 , a % get_nzeros ( )
a % val ( i ) = a % val ( i ) * d
enddo
call psb_erractionrestore ( err_act )
return
9999 continue
call psb_erractionrestore ( err_act )
if ( err_act == psb_act_abort_ ) then
call psb_error ( )
return
end if
return
end subroutine d_coo_scals
end module psbn_d_base_mat_mod