Added vector/scalar comparison routine

This commit is contained in:
cirdans-home
2019-11-28 11:32:37 +01:00
parent d4fc54e75a
commit fcbe0d620a
20 changed files with 462 additions and 5 deletions
+1
View File
@@ -479,4 +479,5 @@ module psb_c_psblas_mod
end subroutine psb_cinv_vect_check
end interface
end module psb_c_psblas_mod
+12
View File
@@ -479,4 +479,16 @@ module psb_d_psblas_mod
end subroutine psb_dinv_vect_check
end interface
interface psb_gecmp
subroutine psb_dcmp_vect(x,c,z,desc_a,info)
import :: psb_desc_type, psb_ipk_, &
& psb_d_vect_type, psb_dpk_
type(psb_d_vect_type), intent (inout) :: x
type(psb_d_vect_type), intent (inout) :: z
real(psb_dpk_), intent(in) :: c
type(psb_desc_type), intent (in) :: desc_a
integer(psb_ipk_), intent(out) :: info
end subroutine psb_dcmp_vect
end interface
end module psb_d_psblas_mod
+12
View File
@@ -479,4 +479,16 @@ module psb_s_psblas_mod
end subroutine psb_sinv_vect_check
end interface
interface psb_gecmp
subroutine psb_scmp_vect(x,c,z,desc_a,info)
import :: psb_desc_type, psb_ipk_, &
& psb_s_vect_type, psb_spk_
type(psb_s_vect_type), intent (inout) :: x
type(psb_s_vect_type), intent (inout) :: z
real(psb_spk_), intent(in) :: c
type(psb_desc_type), intent (in) :: desc_a
integer(psb_ipk_), intent(out) :: info
end subroutine psb_scmp_vect
end interface
end module psb_s_psblas_mod
+1
View File
@@ -479,4 +479,5 @@ module psb_z_psblas_mod
end subroutine psb_zinv_vect_check
end interface
end module psb_z_psblas_mod
+1 -2
View File
@@ -187,6 +187,7 @@ module psb_c_base_vect_mod
procedure, pass(x) :: amax => c_base_amax
procedure, pass(x) :: asum => c_base_asum
end type psb_c_base_vect_type
public :: psb_c_base_vect
@@ -1401,8 +1402,6 @@ contains
end subroutine c_base_inv_a2_check
!
! Simple scaling
!
+6
View File
@@ -135,6 +135,11 @@ module psb_c_vect_mod
& c_vect_absval2, c_vect_nrm2, c_vect_amax, c_vect_asum
! @NOTCPLXS@
! @NOTINTS@
! private :: c_vect_cmp_a2, c_vect_cmp_v2
! @NOTINTE@
! @NOTCPLXE@
class(psb_c_base_vect_type), allocatable, target,&
& save, private :: psb_c_base_vect_default
@@ -855,6 +860,7 @@ contains
end subroutine c_vect_inv_a2_check
subroutine c_vect_scal(alpha, x)
use psi_serial_mod
implicit none
@@ -187,6 +187,13 @@ module psb_d_base_vect_mod
procedure, pass(x) :: amax => d_base_amax
procedure, pass(x) :: asum => d_base_asum
!
! Comparison and mask operation
!
procedure, pass(z) :: cmp_a2 => d_base_cmp_a2
procedure, pass(z) :: cmp_v2 => d_base_cmp_v2
generic, public :: cmp => cmp_a2,cmp_v2
end type psb_d_base_vect_type
public :: psb_d_base_vect
@@ -1401,8 +1408,58 @@ contains
end subroutine d_base_inv_a2_check
!
!> Function base_inv_a2_check
!! \memberof psb_d_base_vect_type
!! \brief Compare entry-by-entry the vector x with the scalar c
!! \param x The array to be compared
!! \param z The vector containing in position i 1 if |x(i)| > c, 0 otherwise
!! \param c The comparison term
!! \param info return code
!
subroutine d_base_cmp_a2(x,c,z,info)
use psi_serial_mod
implicit none
real(psb_dpk_), intent(in) :: c
real(psb_dpk_), intent(inout) :: x(:)
class(psb_d_base_vect_type), intent(inout) :: z
integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_) :: i, n
if (z%is_dev()) call z%sync()
n = size(x)
do i = 1, n, 1
if ( abs(x(i)).ge.c ) then
z%v(i) = 1_psb_dpk_
else
z%v(i) = 0_psb_dpk_
end if
end do
info = 0
end subroutine d_base_cmp_a2
!
!> Function base_cmp_v2
!! \memberof psb_d_base_vect_type
!! \brief Compare entry-by-entry the vector x with the scalar c
!! \param x The vector to be compared
!! \param z The vector containing in position i 1 if |x(i)| > c, 0 otherwise
!! \param c The comparison term
!! \param info return code
!
subroutine d_base_cmp_v2(x,c,z,info)
use psi_serial_mod
implicit none
class(psb_d_base_vect_type), intent(inout) :: x
real(psb_dpk_), intent(in) :: c
class(psb_d_base_vect_type), intent(inout) :: z
integer(psb_ipk_), intent(out) :: info
info = 0
if (x%is_dev()) call x%sync()
call z%cmp(x%v,c,info)
end subroutine d_base_cmp_v2
!
! Simple scaling
!
+36
View File
@@ -111,6 +111,9 @@ module psb_d_vect_mod
procedure, pass(x) :: nrm2 => d_vect_nrm2
procedure, pass(x) :: amax => d_vect_amax
procedure, pass(x) :: asum => d_vect_asum
procedure, pass(z) :: cmp_a2 => d_vect_cmp_a2
procedure, pass(z) :: cmp_v2 => d_vect_cmp_v2
generic, public :: cmp => cmp_a2, cmp_v2
end type psb_d_vect_type
public :: psb_d_vect
@@ -135,6 +138,11 @@ module psb_d_vect_mod
& d_vect_absval2, d_vect_nrm2, d_vect_amax, d_vect_asum
! @NOTCPLXS@
! @NOTINTS@
! private :: d_vect_cmp_a2, d_vect_cmp_v2
! @NOTINTE@
! @NOTCPLXE@
class(psb_d_base_vect_type), allocatable, target,&
& save, private :: psb_d_base_vect_default
@@ -855,6 +863,34 @@ contains
end subroutine d_vect_inv_a2_check
subroutine d_vect_cmp_a2(x,c,z,info)
use psi_serial_mod
implicit none
real(psb_dpk_), intent(in) :: c
real(psb_dpk_), intent(inout) :: x(:)
class(psb_d_vect_type), intent(inout) :: z
integer(psb_ipk_), intent(out) :: info
info = 0
if (allocated(z%v)) &
& call z%cmp(x,c,info)
end subroutine d_vect_cmp_a2
subroutine d_vect_cmp_v2(x,c,z,info)
use psi_serial_mod
implicit none
real(psb_dpk_), intent(in) :: c
class(psb_d_vect_type), intent(inout) :: x
class(psb_d_vect_type), intent(inout) :: z
integer(psb_ipk_), intent(out) :: info
info = 0
if (allocated(x%v).and.allocated(z%v)) &
& call z%v%cmp(x%v,c,info)
end subroutine d_vect_cmp_v2
subroutine d_vect_scal(alpha, x)
use psi_serial_mod
implicit none
@@ -142,6 +142,7 @@ module psb_i_base_vect_mod
end type psb_i_base_vect_type
public :: psb_i_base_vect
+5
View File
@@ -98,6 +98,11 @@ module psb_i_vect_mod
& i_vect_set_dev, i_vect_set_sync
! @NOTCPLXS@
! @NOTINTS@
! private :: i_vect_cmp_a2, i_vect_cmp_v2
! @NOTINTE@
! @NOTCPLXE@
class(psb_i_base_vect_type), allocatable, target,&
& save, private :: psb_i_base_vect_default
@@ -143,6 +143,7 @@ module psb_l_base_vect_mod
end type psb_l_base_vect_type
public :: psb_l_base_vect
+5
View File
@@ -99,6 +99,11 @@ module psb_l_vect_mod
& l_vect_set_dev, l_vect_set_sync
! @NOTCPLXS@
! @NOTINTS@
! private :: l_vect_cmp_a2, l_vect_cmp_v2
! @NOTINTE@
! @NOTCPLXE@
class(psb_l_base_vect_type), allocatable, target,&
& save, private :: psb_l_base_vect_default
@@ -187,6 +187,13 @@ module psb_s_base_vect_mod
procedure, pass(x) :: amax => s_base_amax
procedure, pass(x) :: asum => s_base_asum
!
! Comparison and mask operation
!
procedure, pass(z) :: cmp_a2 => s_base_cmp_a2
procedure, pass(z) :: cmp_v2 => s_base_cmp_v2
generic, public :: cmp => cmp_a2,cmp_v2
end type psb_s_base_vect_type
public :: psb_s_base_vect
@@ -1401,8 +1408,58 @@ contains
end subroutine s_base_inv_a2_check
!
!> Function base_inv_a2_check
!! \memberof psb_s_base_vect_type
!! \brief Compare entry-by-entry the vector x with the scalar c
!! \param x The array to be compared
!! \param z The vector containing in position i 1 if |x(i)| > c, 0 otherwise
!! \param c The comparison term
!! \param info return code
!
subroutine s_base_cmp_a2(x,c,z,info)
use psi_serial_mod
implicit none
real(psb_spk_), intent(in) :: c
real(psb_spk_), intent(inout) :: x(:)
class(psb_s_base_vect_type), intent(inout) :: z
integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_) :: i, n
if (z%is_dev()) call z%sync()
n = size(x)
do i = 1, n, 1
if ( abs(x(i)).ge.c ) then
z%v(i) = 1_psb_spk_
else
z%v(i) = 0_psb_spk_
end if
end do
info = 0
end subroutine s_base_cmp_a2
!
!> Function base_cmp_v2
!! \memberof psb_s_base_vect_type
!! \brief Compare entry-by-entry the vector x with the scalar c
!! \param x The vector to be compared
!! \param z The vector containing in position i 1 if |x(i)| > c, 0 otherwise
!! \param c The comparison term
!! \param info return code
!
subroutine s_base_cmp_v2(x,c,z,info)
use psi_serial_mod
implicit none
class(psb_s_base_vect_type), intent(inout) :: x
real(psb_spk_), intent(in) :: c
class(psb_s_base_vect_type), intent(inout) :: z
integer(psb_ipk_), intent(out) :: info
info = 0
if (x%is_dev()) call x%sync()
call z%cmp(x%v,c,info)
end subroutine s_base_cmp_v2
!
! Simple scaling
!
+36
View File
@@ -111,6 +111,9 @@ module psb_s_vect_mod
procedure, pass(x) :: nrm2 => s_vect_nrm2
procedure, pass(x) :: amax => s_vect_amax
procedure, pass(x) :: asum => s_vect_asum
procedure, pass(z) :: cmp_a2 => s_vect_cmp_a2
procedure, pass(z) :: cmp_v2 => s_vect_cmp_v2
generic, public :: cmp => cmp_a2, cmp_v2
end type psb_s_vect_type
public :: psb_s_vect
@@ -135,6 +138,11 @@ module psb_s_vect_mod
& s_vect_absval2, s_vect_nrm2, s_vect_amax, s_vect_asum
! @NOTCPLXS@
! @NOTINTS@
! private :: s_vect_cmp_a2, s_vect_cmp_v2
! @NOTINTE@
! @NOTCPLXE@
class(psb_s_base_vect_type), allocatable, target,&
& save, private :: psb_s_base_vect_default
@@ -855,6 +863,34 @@ contains
end subroutine s_vect_inv_a2_check
subroutine s_vect_cmp_a2(x,c,z,info)
use psi_serial_mod
implicit none
real(psb_spk_), intent(in) :: c
real(psb_spk_), intent(inout) :: x(:)
class(psb_s_vect_type), intent(inout) :: z
integer(psb_ipk_), intent(out) :: info
info = 0
if (allocated(z%v)) &
& call z%cmp(x,c,info)
end subroutine s_vect_cmp_a2
subroutine s_vect_cmp_v2(x,c,z,info)
use psi_serial_mod
implicit none
real(psb_spk_), intent(in) :: c
class(psb_s_vect_type), intent(inout) :: x
class(psb_s_vect_type), intent(inout) :: z
integer(psb_ipk_), intent(out) :: info
info = 0
if (allocated(x%v).and.allocated(z%v)) &
& call z%v%cmp(x%v,c,info)
end subroutine s_vect_cmp_v2
subroutine s_vect_scal(alpha, x)
use psi_serial_mod
implicit none
+1 -2
View File
@@ -187,6 +187,7 @@ module psb_z_base_vect_mod
procedure, pass(x) :: amax => z_base_amax
procedure, pass(x) :: asum => z_base_asum
end type psb_z_base_vect_type
public :: psb_z_base_vect
@@ -1401,8 +1402,6 @@ contains
end subroutine z_base_inv_a2_check
!
! Simple scaling
!
+6
View File
@@ -135,6 +135,11 @@ module psb_z_vect_mod
& z_vect_absval2, z_vect_nrm2, z_vect_amax, z_vect_asum
! @NOTCPLXS@
! @NOTINTS@
! private :: z_vect_cmp_a2, z_vect_cmp_v2
! @NOTINTE@
! @NOTCPLXE@
class(psb_z_base_vect_type), allocatable, target,&
& save, private :: psb_z_base_vect_default
@@ -855,6 +860,7 @@ contains
end subroutine z_vect_inv_a2_check
subroutine z_vect_scal(alpha, x)
use psi_serial_mod
implicit none