From 1b214f3f00640efd757f480a0eee35ae0771890a Mon Sep 17 00:00:00 2001 From: Cirdans-Home Date: Fri, 21 Feb 2020 09:56:10 +0100 Subject: [PATCH] added weighted 2-norm function --- base/modules/psblas/psb_c_psblas_mod.F90 | 12 +- base/modules/psblas/psb_d_psblas_mod.F90 | 12 +- base/modules/psblas/psb_s_psblas_mod.F90 | 12 +- base/modules/psblas/psb_z_psblas_mod.F90 | 12 +- base/modules/serial/psb_c_vect_mod.F90 | 21 ++- base/modules/serial/psb_d_vect_mod.F90 | 21 ++- base/modules/serial/psb_s_vect_mod.F90 | 21 ++- base/modules/serial/psb_z_vect_mod.F90 | 21 ++- base/psblas/psb_cnrm2.f90 | 177 ++++++++++++++++++----- base/psblas/psb_dnrm2.f90 | 177 ++++++++++++++++++----- base/psblas/psb_snrm2.f90 | 177 ++++++++++++++++++----- base/psblas/psb_znrm2.f90 | 177 ++++++++++++++++++----- test/kernel/vecoperation.f90 | 18 ++- 13 files changed, 704 insertions(+), 154 deletions(-) diff --git a/base/modules/psblas/psb_c_psblas_mod.F90 b/base/modules/psblas/psb_c_psblas_mod.F90 index 085c3011..217632fb 100644 --- a/base/modules/psblas/psb_c_psblas_mod.F90 +++ b/base/modules/psblas/psb_c_psblas_mod.F90 @@ -273,11 +273,21 @@ module psb_c_psblas_mod integer(psb_ipk_), intent(out) :: info logical, intent(in), optional :: global end function psb_cnrm2_vect + function psb_cnrm2_weight_vect(x,w, desc_a, info,global) result(res) + import :: psb_desc_type, psb_spk_, psb_ipk_, & + & psb_c_vect_type, psb_cspmat_type + real(psb_spk_) :: res + type(psb_c_vect_type), intent (inout) :: x + type(psb_c_vect_type), intent (inout) :: w + type(psb_desc_type), intent (in) :: desc_a + integer(psb_ipk_), intent(out) :: info + logical, intent(in), optional :: global + end function psb_cnrm2_weight_vect end interface #if ! defined(HAVE_BUGGY_GENERICS) interface psb_norm2 - procedure psb_cnrm2, psb_cnrm2v, psb_cnrm2_vect + procedure psb_cnrm2, psb_cnrm2v, psb_cnrm2_vect, psb_cnrm2_weight_vect end interface #endif diff --git a/base/modules/psblas/psb_d_psblas_mod.F90 b/base/modules/psblas/psb_d_psblas_mod.F90 index 2ab73364..011ce683 100644 --- a/base/modules/psblas/psb_d_psblas_mod.F90 +++ b/base/modules/psblas/psb_d_psblas_mod.F90 @@ -273,11 +273,21 @@ module psb_d_psblas_mod integer(psb_ipk_), intent(out) :: info logical, intent(in), optional :: global end function psb_dnrm2_vect + function psb_dnrm2_weight_vect(x,w, desc_a, info,global) result(res) + import :: psb_desc_type, psb_dpk_, psb_ipk_, & + & psb_d_vect_type, psb_dspmat_type + real(psb_dpk_) :: res + type(psb_d_vect_type), intent (inout) :: x + type(psb_d_vect_type), intent (inout) :: w + type(psb_desc_type), intent (in) :: desc_a + integer(psb_ipk_), intent(out) :: info + logical, intent(in), optional :: global + end function psb_dnrm2_weight_vect end interface #if ! defined(HAVE_BUGGY_GENERICS) interface psb_norm2 - procedure psb_dnrm2, psb_dnrm2v, psb_dnrm2_vect + procedure psb_dnrm2, psb_dnrm2v, psb_dnrm2_vect, psb_dnrm2_weight_vect end interface #endif diff --git a/base/modules/psblas/psb_s_psblas_mod.F90 b/base/modules/psblas/psb_s_psblas_mod.F90 index f71adc45..32296412 100644 --- a/base/modules/psblas/psb_s_psblas_mod.F90 +++ b/base/modules/psblas/psb_s_psblas_mod.F90 @@ -273,11 +273,21 @@ module psb_s_psblas_mod integer(psb_ipk_), intent(out) :: info logical, intent(in), optional :: global end function psb_snrm2_vect + function psb_snrm2_weight_vect(x,w, desc_a, info,global) result(res) + import :: psb_desc_type, psb_spk_, psb_ipk_, & + & psb_s_vect_type, psb_sspmat_type + real(psb_spk_) :: res + type(psb_s_vect_type), intent (inout) :: x + type(psb_s_vect_type), intent (inout) :: w + type(psb_desc_type), intent (in) :: desc_a + integer(psb_ipk_), intent(out) :: info + logical, intent(in), optional :: global + end function psb_snrm2_weight_vect end interface #if ! defined(HAVE_BUGGY_GENERICS) interface psb_norm2 - procedure psb_snrm2, psb_snrm2v, psb_snrm2_vect + procedure psb_snrm2, psb_snrm2v, psb_snrm2_vect, psb_snrm2_weight_vect end interface #endif diff --git a/base/modules/psblas/psb_z_psblas_mod.F90 b/base/modules/psblas/psb_z_psblas_mod.F90 index 5d7f4d15..71394e68 100644 --- a/base/modules/psblas/psb_z_psblas_mod.F90 +++ b/base/modules/psblas/psb_z_psblas_mod.F90 @@ -273,11 +273,21 @@ module psb_z_psblas_mod integer(psb_ipk_), intent(out) :: info logical, intent(in), optional :: global end function psb_znrm2_vect + function psb_znrm2_weight_vect(x,w, desc_a, info,global) result(res) + import :: psb_desc_type, psb_dpk_, psb_ipk_, & + & psb_z_vect_type, psb_zspmat_type + real(psb_dpk_) :: res + type(psb_z_vect_type), intent (inout) :: x + type(psb_z_vect_type), intent (inout) :: w + type(psb_desc_type), intent (in) :: desc_a + integer(psb_ipk_), intent(out) :: info + logical, intent(in), optional :: global + end function psb_znrm2_weight_vect end interface #if ! defined(HAVE_BUGGY_GENERICS) interface psb_norm2 - procedure psb_znrm2, psb_znrm2v, psb_znrm2_vect + procedure psb_znrm2, psb_znrm2v, psb_znrm2_vect, psb_znrm2_weight_vect end interface #endif diff --git a/base/modules/serial/psb_c_vect_mod.F90 b/base/modules/serial/psb_c_vect_mod.F90 index bc65eb96..8fc78b2c 100644 --- a/base/modules/serial/psb_c_vect_mod.F90 +++ b/base/modules/serial/psb_c_vect_mod.F90 @@ -108,7 +108,9 @@ module psb_c_vect_mod procedure, pass(x) :: absval1 => c_vect_absval1 procedure, pass(x) :: absval2 => c_vect_absval2 generic, public :: absval => absval1, absval2 - procedure, pass(x) :: nrm2 => c_vect_nrm2 + procedure, pass(x) :: nrm2std => c_vect_nrm2 + procedure, pass(x) :: nrm2weight => c_vect_nrm2_weight + generic, public :: nrm2 => nrm2std, nrm2weight procedure, pass(x) :: amax => c_vect_amax procedure, pass(x) :: asum => c_vect_asum end type psb_c_vect_type @@ -903,6 +905,23 @@ contains end function c_vect_nrm2 + function c_vect_nrm2_weight(n,x,w) result(res) + implicit none + class(psb_c_vect_type), intent(inout) :: x + class(psb_c_vect_type), intent(inout) :: w + integer(psb_ipk_), intent(in) :: n + real(psb_spk_) :: res + integer(psb_ipk_) :: info + + if (allocated(x%v).and.allocated(w%v)) then + call w%v%mlt(x%v,info) + res = w%v%nrm2(n) + else + res = szero + end if + + end function c_vect_nrm2_weight + function c_vect_amax(n,x) result(res) implicit none class(psb_c_vect_type), intent(inout) :: x diff --git a/base/modules/serial/psb_d_vect_mod.F90 b/base/modules/serial/psb_d_vect_mod.F90 index be322f9c..40c9f9a2 100644 --- a/base/modules/serial/psb_d_vect_mod.F90 +++ b/base/modules/serial/psb_d_vect_mod.F90 @@ -108,7 +108,9 @@ module psb_d_vect_mod procedure, pass(x) :: absval1 => d_vect_absval1 procedure, pass(x) :: absval2 => d_vect_absval2 generic, public :: absval => absval1, absval2 - procedure, pass(x) :: nrm2 => d_vect_nrm2 + procedure, pass(x) :: nrm2std => d_vect_nrm2 + procedure, pass(x) :: nrm2weight => d_vect_nrm2_weight + generic, public :: nrm2 => nrm2std, nrm2weight procedure, pass(x) :: amax => d_vect_amax procedure, pass(x) :: asum => d_vect_asum procedure, pass(z) :: cmp_a2 => d_vect_cmp_a2 @@ -933,6 +935,23 @@ contains end function d_vect_nrm2 + function d_vect_nrm2_weight(n,x,w) result(res) + implicit none + class(psb_d_vect_type), intent(inout) :: x + class(psb_d_vect_type), intent(inout) :: w + integer(psb_ipk_), intent(in) :: n + real(psb_dpk_) :: res + integer(psb_ipk_) :: info + + if (allocated(x%v).and.allocated(w%v)) then + call w%v%mlt(x%v,info) + res = w%v%nrm2(n) + else + res = dzero + end if + + end function d_vect_nrm2_weight + function d_vect_amax(n,x) result(res) implicit none class(psb_d_vect_type), intent(inout) :: x diff --git a/base/modules/serial/psb_s_vect_mod.F90 b/base/modules/serial/psb_s_vect_mod.F90 index c1f71208..26f8a3b1 100644 --- a/base/modules/serial/psb_s_vect_mod.F90 +++ b/base/modules/serial/psb_s_vect_mod.F90 @@ -108,7 +108,9 @@ module psb_s_vect_mod procedure, pass(x) :: absval1 => s_vect_absval1 procedure, pass(x) :: absval2 => s_vect_absval2 generic, public :: absval => absval1, absval2 - procedure, pass(x) :: nrm2 => s_vect_nrm2 + procedure, pass(x) :: nrm2std => s_vect_nrm2 + procedure, pass(x) :: nrm2weight => s_vect_nrm2_weight + generic, public :: nrm2 => nrm2std, nrm2weight procedure, pass(x) :: amax => s_vect_amax procedure, pass(x) :: asum => s_vect_asum procedure, pass(z) :: cmp_a2 => s_vect_cmp_a2 @@ -933,6 +935,23 @@ contains end function s_vect_nrm2 + function s_vect_nrm2_weight(n,x,w) result(res) + implicit none + class(psb_s_vect_type), intent(inout) :: x + class(psb_s_vect_type), intent(inout) :: w + integer(psb_ipk_), intent(in) :: n + real(psb_spk_) :: res + integer(psb_ipk_) :: info + + if (allocated(x%v).and.allocated(w%v)) then + call w%v%mlt(x%v,info) + res = w%v%nrm2(n) + else + res = szero + end if + + end function s_vect_nrm2_weight + function s_vect_amax(n,x) result(res) implicit none class(psb_s_vect_type), intent(inout) :: x diff --git a/base/modules/serial/psb_z_vect_mod.F90 b/base/modules/serial/psb_z_vect_mod.F90 index e9d5e1dd..2caf2950 100644 --- a/base/modules/serial/psb_z_vect_mod.F90 +++ b/base/modules/serial/psb_z_vect_mod.F90 @@ -108,7 +108,9 @@ module psb_z_vect_mod procedure, pass(x) :: absval1 => z_vect_absval1 procedure, pass(x) :: absval2 => z_vect_absval2 generic, public :: absval => absval1, absval2 - procedure, pass(x) :: nrm2 => z_vect_nrm2 + procedure, pass(x) :: nrm2std => z_vect_nrm2 + procedure, pass(x) :: nrm2weight => z_vect_nrm2_weight + generic, public :: nrm2 => nrm2std, nrm2weight procedure, pass(x) :: amax => z_vect_amax procedure, pass(x) :: asum => z_vect_asum end type psb_z_vect_type @@ -903,6 +905,23 @@ contains end function z_vect_nrm2 + function z_vect_nrm2_weight(n,x,w) result(res) + implicit none + class(psb_z_vect_type), intent(inout) :: x + class(psb_z_vect_type), intent(inout) :: w + integer(psb_ipk_), intent(in) :: n + real(psb_dpk_) :: res + integer(psb_ipk_) :: info + + if (allocated(x%v).and.allocated(w%v)) then + call w%v%mlt(x%v,info) + res = w%v%nrm2(n) + else + res = dzero + end if + + end function z_vect_nrm2_weight + function z_vect_amax(n,x) result(res) implicit none class(psb_z_vect_type), intent(inout) :: x diff --git a/base/psblas/psb_cnrm2.f90 b/base/psblas/psb_cnrm2.f90 index 1db5773a..c3ad75a4 100644 --- a/base/psblas/psb_cnrm2.f90 +++ b/base/psblas/psb_cnrm2.f90 @@ -1,9 +1,9 @@ -! +! ! Parallel Sparse BLAS version 3.5 ! (C) Copyright 2006-2018 -! Salvatore Filippone -! Alfredo Buttari -! +! Salvatore Filippone +! Alfredo Buttari +! ! Redistribution and use in source and binary forms, with or without ! modification, are permitted provided that the following conditions ! are met: @@ -15,7 +15,7 @@ ! 3. The name of the PSBLAS group or the names of its contributors may ! not be used to endorse or promote products derived from this ! software without specific written permission. -! +! ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -27,8 +27,8 @@ ! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ! POSSIBILITY OF SUCH DAMAGE. -! -! +! +! ! File: psb_cnrm2.f90 ! ! Function: psb_cnrm2 @@ -111,7 +111,7 @@ function psb_cnrm2(x, desc_a, info, jx,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = scnrm2( int(ndim,kind=psb_mpk_), x(iix:,jjx), int(ione,kind=psb_mpk_) ) @@ -120,16 +120,16 @@ function psb_cnrm2(x, desc_a, info, jx,global) result(res) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(sone - dd*(abs(x(idx,jjx))/res)**2) + res = res * sqrt(sone - dd*(abs(x(idx,jjx))/res)**2) end do - else + else res = szero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) @@ -138,12 +138,12 @@ end function psb_cnrm2 -!!$ +!!$ !!$ Parallel Sparse BLAS version 3.5 !!$ (C) Copyright 2006-2018 !!$ Salvatore Filippone University of Rome Tor Vergata -!!$ Alfredo Buttari -!!$ +!!$ Alfredo Buttari +!!$ !!$ Redistribution and use in source and binary forms, with or without !!$ modification, are permitted provided that the following conditions !!$ are met: @@ -155,7 +155,7 @@ end function psb_cnrm2 !!$ 3. The name of the PSBLAS group or the names of its contributors may !!$ not be used to endorse or promote products derived from this !!$ software without specific written permission. -!!$ +!!$ !!$ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS !!$ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED !!$ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -167,7 +167,7 @@ end function psb_cnrm2 !!$ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) !!$ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE !!$ POSSIBILITY OF SUCH DAMAGE. -!!$ +!!$ !!$ ! ! Function: psb_cnrm2 @@ -226,7 +226,7 @@ function psb_cnrm2v(x, desc_a, info,global) result(res) ix = 1 jx=1 m = desc_a%get_global_rows() - ldx = size(x,1) + ldx = size(x,1) call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) if(info /= psb_success_) then info=psb_err_from_subroutine_ @@ -240,7 +240,7 @@ function psb_cnrm2v(x, desc_a, info,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = scnrm2( int(ndim,kind=psb_mpk_), x, int(ione,kind=psb_mpk_) ) ! adjust because overlapped elements are computed more than once @@ -248,16 +248,16 @@ function psb_cnrm2v(x, desc_a, info,global) result(res) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(sone - dd*(abs(x(idx))/res)**2) + res = res * sqrt(sone - dd*(abs(x(idx))/res)**2) end do - else + else res = szero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) @@ -314,7 +314,7 @@ function psb_cnrm2_vect(x, desc_a, info,global) result(res) goto 9999 endif - if (.not.allocated(x%v)) then + if (.not.allocated(x%v)) then info = psb_err_invalid_vect_state_ call psb_errpush(info,name) goto 9999 @@ -343,7 +343,7 @@ function psb_cnrm2_vect(x, desc_a, info,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = x%nrm2(ndim) ! adjust because overlapped elements are computed more than once @@ -356,27 +356,134 @@ function psb_cnrm2_vect(x, desc_a, info,global) result(res) res = res - sqrt(cone - dd*(abs(x%v%v(idx))/res)**2) end do end if - else + else res = szero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) return end function psb_cnrm2_vect +! Function: psb_cnrm2_weight_vect +! Computes the weighted norm2 of a distributed vector, +! +! norm2 := sqrt ( (w.*X)**C * (w.*X)) +! +! Arguments: +! x - type(psb_c_vect_type) The input vector containing the entries of X. +! w - type(psb_c_vect_type) The input vector containing the entries of W. +! desc_a - type(psb_desc_type). The communication descriptor. +! info - integer. Return code +! global - logical(optional) Whether to perform the global reduction, default: .true. +! +function psb_cnrm2_weight_vect(x,w, desc_a, info,global) result(res) + use psb_desc_mod + use psb_check_mod + use psb_error_mod + use psb_penv_mod + use psb_c_vect_mod + implicit none + + real(psb_spk_) :: res + type(psb_c_vect_type), intent (inout) :: x + type(psb_c_vect_type), intent (inout) :: w + type(psb_desc_type), intent(in) :: desc_a + integer(psb_ipk_), intent(out) :: info + logical, intent(in), optional :: global + + ! locals + integer(psb_ipk_) :: ictxt, np, me,& + & err_act, iix, jjx, ndim, i, id, idx, ndm, ldx + integer(psb_lpk_) :: ix, jx, iy, ijy, m + logical :: global_ + real(psb_spk_) :: snrm2, dd + character(len=20) :: name, ch_err + + name='psb_cnrm2v_weight' + if (psb_errstatus_fatal()) then + info = psb_err_internal_error_ ; goto 9999 + end if + info=psb_success_ + call psb_erractionsave(err_act) + + ictxt=desc_a%get_context() -!!$ + call psb_info(ictxt, me, np) + if (np == -1) then + info=psb_err_context_error_ + call psb_errpush(info,name) + goto 9999 + endif + + if (.not.allocated(x%v)) then + info = psb_err_invalid_vect_state_ + call psb_errpush(info,name) + goto 9999 + endif + + if (present(global)) then + global_ = global + else + global_ = .true. + end if + + ix = 1 + jx = 1 + m = desc_a%get_global_rows() + ldx = x%get_nrows() + call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) + if(info /= psb_success_) then + info=psb_err_from_subroutine_ + ch_err='psb_chkvect' + call psb_errpush(info,name,a_err=ch_err) + end if + + if (iix /= 1) then + info=psb_err_ix_n1_iy_n1_unsupported_ + call psb_errpush(info,name) + goto 9999 + end if + + if (desc_a%get_local_rows() > 0) then + ndim = desc_a%get_local_rows() + res = x%nrm2(ndim,w) + ! adjust because overlapped elements are computed more than once + if (size(desc_a%ovrlap_elem,1)>0) then + if (x%is_dev()) call x%sync() + do i=1,size(desc_a%ovrlap_elem,1) + idx = desc_a%ovrlap_elem(i,1) + ndm = desc_a%ovrlap_elem(i,2) + dd = dble(ndm-1)/dble(ndm) + res = res - sqrt(cone - dd*(abs(x%v%v(idx))/res)**2) + end do + end if + else + res = szero + end if + + if (global_) call psb_nrm2(ictxt,res) + + call psb_erractionrestore(err_act) + return + +9999 call psb_error_handler(ictxt,err_act) + + return +end function psb_cnrm2_weight_vect + + +!!$ !!$ Parallel Sparse BLAS version 3.5 !!$ (C) Copyright 2006-2018 !!$ Salvatore Filippone University of Rome Tor Vergata -!!$ Alfredo Buttari -!!$ +!!$ Alfredo Buttari +!!$ !!$ Redistribution and use in source and binary forms, with or without !!$ modification, are permitted provided that the following conditions !!$ are met: @@ -388,7 +495,7 @@ end function psb_cnrm2_vect !!$ 3. The name of the PSBLAS group or the names of its contributors may !!$ not be used to endorse or promote products derived from this !!$ software without specific written permission. -!!$ +!!$ !!$ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS !!$ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED !!$ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -400,7 +507,7 @@ end function psb_cnrm2_vect !!$ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) !!$ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE !!$ POSSIBILITY OF SUCH DAMAGE. -!!$ +!!$ !!$ ! ! Subroutine: psb_cnrm2vs @@ -461,7 +568,7 @@ subroutine psb_cnrm2vs(res, x, desc_a, info,global) ix = 1 jx = 1 m = desc_a%get_global_rows() - ldx = size(x,1) + ldx = size(x,1) call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) if(info /= psb_success_) then info=psb_err_from_subroutine_ @@ -475,7 +582,7 @@ subroutine psb_cnrm2vs(res, x, desc_a, info,global) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = scnrm2( int(ndim,kind=psb_mpk_), x, int(ione,kind=psb_mpk_) ) @@ -484,9 +591,9 @@ subroutine psb_cnrm2vs(res, x, desc_a, info,global) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(sone - dd*(abs(x(idx))/res)**2) + res = res * sqrt(sone - dd*(abs(x(idx))/res)**2) end do - else + else res = szero end if @@ -494,7 +601,7 @@ subroutine psb_cnrm2vs(res, x, desc_a, info,global) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) diff --git a/base/psblas/psb_dnrm2.f90 b/base/psblas/psb_dnrm2.f90 index 0845aac4..96eded9a 100644 --- a/base/psblas/psb_dnrm2.f90 +++ b/base/psblas/psb_dnrm2.f90 @@ -1,9 +1,9 @@ -! +! ! Parallel Sparse BLAS version 3.5 ! (C) Copyright 2006-2018 -! Salvatore Filippone -! Alfredo Buttari -! +! Salvatore Filippone +! Alfredo Buttari +! ! Redistribution and use in source and binary forms, with or without ! modification, are permitted provided that the following conditions ! are met: @@ -15,7 +15,7 @@ ! 3. The name of the PSBLAS group or the names of its contributors may ! not be used to endorse or promote products derived from this ! software without specific written permission. -! +! ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -27,8 +27,8 @@ ! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ! POSSIBILITY OF SUCH DAMAGE. -! -! +! +! ! File: psb_dnrm2.f90 ! ! Function: psb_dnrm2 @@ -111,7 +111,7 @@ function psb_dnrm2(x, desc_a, info, jx,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = dnrm2( int(ndim,kind=psb_mpk_), x(iix:,jjx), int(ione,kind=psb_mpk_) ) @@ -120,16 +120,16 @@ function psb_dnrm2(x, desc_a, info, jx,global) result(res) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(done - dd*(abs(x(idx,jjx))/res)**2) + res = res * sqrt(done - dd*(abs(x(idx,jjx))/res)**2) end do - else + else res = dzero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) @@ -138,12 +138,12 @@ end function psb_dnrm2 -!!$ +!!$ !!$ Parallel Sparse BLAS version 3.5 !!$ (C) Copyright 2006-2018 !!$ Salvatore Filippone University of Rome Tor Vergata -!!$ Alfredo Buttari -!!$ +!!$ Alfredo Buttari +!!$ !!$ Redistribution and use in source and binary forms, with or without !!$ modification, are permitted provided that the following conditions !!$ are met: @@ -155,7 +155,7 @@ end function psb_dnrm2 !!$ 3. The name of the PSBLAS group or the names of its contributors may !!$ not be used to endorse or promote products derived from this !!$ software without specific written permission. -!!$ +!!$ !!$ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS !!$ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED !!$ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -167,7 +167,7 @@ end function psb_dnrm2 !!$ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) !!$ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE !!$ POSSIBILITY OF SUCH DAMAGE. -!!$ +!!$ !!$ ! ! Function: psb_dnrm2 @@ -226,7 +226,7 @@ function psb_dnrm2v(x, desc_a, info,global) result(res) ix = 1 jx=1 m = desc_a%get_global_rows() - ldx = size(x,1) + ldx = size(x,1) call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) if(info /= psb_success_) then info=psb_err_from_subroutine_ @@ -240,7 +240,7 @@ function psb_dnrm2v(x, desc_a, info,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = dnrm2( int(ndim,kind=psb_mpk_), x, int(ione,kind=psb_mpk_) ) ! adjust because overlapped elements are computed more than once @@ -248,16 +248,16 @@ function psb_dnrm2v(x, desc_a, info,global) result(res) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(done - dd*(abs(x(idx))/res)**2) + res = res * sqrt(done - dd*(abs(x(idx))/res)**2) end do - else + else res = dzero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) @@ -314,7 +314,7 @@ function psb_dnrm2_vect(x, desc_a, info,global) result(res) goto 9999 endif - if (.not.allocated(x%v)) then + if (.not.allocated(x%v)) then info = psb_err_invalid_vect_state_ call psb_errpush(info,name) goto 9999 @@ -343,7 +343,7 @@ function psb_dnrm2_vect(x, desc_a, info,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = x%nrm2(ndim) ! adjust because overlapped elements are computed more than once @@ -356,27 +356,134 @@ function psb_dnrm2_vect(x, desc_a, info,global) result(res) res = res - sqrt(done - dd*(abs(x%v%v(idx))/res)**2) end do end if - else + else res = dzero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) return end function psb_dnrm2_vect +! Function: psb_dnrm2_weight_vect +! Computes the weighted norm2 of a distributed vector, +! +! norm2 := sqrt ( (w.*X)**C * (w.*X)) +! +! Arguments: +! x - type(psb_d_vect_type) The input vector containing the entries of X. +! w - type(psb_d_vect_type) The input vector containing the entries of W. +! desc_a - type(psb_desc_type). The communication descriptor. +! info - integer. Return code +! global - logical(optional) Whether to perform the global reduction, default: .true. +! +function psb_dnrm2_weight_vect(x,w, desc_a, info,global) result(res) + use psb_desc_mod + use psb_check_mod + use psb_error_mod + use psb_penv_mod + use psb_d_vect_mod + implicit none + + real(psb_dpk_) :: res + type(psb_d_vect_type), intent (inout) :: x + type(psb_d_vect_type), intent (inout) :: w + type(psb_desc_type), intent(in) :: desc_a + integer(psb_ipk_), intent(out) :: info + logical, intent(in), optional :: global + + ! locals + integer(psb_ipk_) :: ictxt, np, me,& + & err_act, iix, jjx, ndim, i, id, idx, ndm, ldx + integer(psb_lpk_) :: ix, jx, iy, ijy, m + logical :: global_ + real(psb_dpk_) :: snrm2, dd + character(len=20) :: name, ch_err + + name='psb_dnrm2v_weight' + if (psb_errstatus_fatal()) then + info = psb_err_internal_error_ ; goto 9999 + end if + info=psb_success_ + call psb_erractionsave(err_act) + + ictxt=desc_a%get_context() -!!$ + call psb_info(ictxt, me, np) + if (np == -1) then + info=psb_err_context_error_ + call psb_errpush(info,name) + goto 9999 + endif + + if (.not.allocated(x%v)) then + info = psb_err_invalid_vect_state_ + call psb_errpush(info,name) + goto 9999 + endif + + if (present(global)) then + global_ = global + else + global_ = .true. + end if + + ix = 1 + jx = 1 + m = desc_a%get_global_rows() + ldx = x%get_nrows() + call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) + if(info /= psb_success_) then + info=psb_err_from_subroutine_ + ch_err='psb_chkvect' + call psb_errpush(info,name,a_err=ch_err) + end if + + if (iix /= 1) then + info=psb_err_ix_n1_iy_n1_unsupported_ + call psb_errpush(info,name) + goto 9999 + end if + + if (desc_a%get_local_rows() > 0) then + ndim = desc_a%get_local_rows() + res = x%nrm2(ndim,w) + ! adjust because overlapped elements are computed more than once + if (size(desc_a%ovrlap_elem,1)>0) then + if (x%is_dev()) call x%sync() + do i=1,size(desc_a%ovrlap_elem,1) + idx = desc_a%ovrlap_elem(i,1) + ndm = desc_a%ovrlap_elem(i,2) + dd = dble(ndm-1)/dble(ndm) + res = res - sqrt(done - dd*(abs(x%v%v(idx))/res)**2) + end do + end if + else + res = dzero + end if + + if (global_) call psb_nrm2(ictxt,res) + + call psb_erractionrestore(err_act) + return + +9999 call psb_error_handler(ictxt,err_act) + + return +end function psb_dnrm2_weight_vect + + +!!$ !!$ Parallel Sparse BLAS version 3.5 !!$ (C) Copyright 2006-2018 !!$ Salvatore Filippone University of Rome Tor Vergata -!!$ Alfredo Buttari -!!$ +!!$ Alfredo Buttari +!!$ !!$ Redistribution and use in source and binary forms, with or without !!$ modification, are permitted provided that the following conditions !!$ are met: @@ -388,7 +495,7 @@ end function psb_dnrm2_vect !!$ 3. The name of the PSBLAS group or the names of its contributors may !!$ not be used to endorse or promote products derived from this !!$ software without specific written permission. -!!$ +!!$ !!$ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS !!$ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED !!$ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -400,7 +507,7 @@ end function psb_dnrm2_vect !!$ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) !!$ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE !!$ POSSIBILITY OF SUCH DAMAGE. -!!$ +!!$ !!$ ! ! Subroutine: psb_dnrm2vs @@ -461,7 +568,7 @@ subroutine psb_dnrm2vs(res, x, desc_a, info,global) ix = 1 jx = 1 m = desc_a%get_global_rows() - ldx = size(x,1) + ldx = size(x,1) call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) if(info /= psb_success_) then info=psb_err_from_subroutine_ @@ -475,7 +582,7 @@ subroutine psb_dnrm2vs(res, x, desc_a, info,global) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = dnrm2( int(ndim,kind=psb_mpk_), x, int(ione,kind=psb_mpk_) ) @@ -484,9 +591,9 @@ subroutine psb_dnrm2vs(res, x, desc_a, info,global) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(done - dd*(abs(x(idx))/res)**2) + res = res * sqrt(done - dd*(abs(x(idx))/res)**2) end do - else + else res = dzero end if @@ -494,7 +601,7 @@ subroutine psb_dnrm2vs(res, x, desc_a, info,global) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) diff --git a/base/psblas/psb_snrm2.f90 b/base/psblas/psb_snrm2.f90 index 35260ef7..cb2dd507 100644 --- a/base/psblas/psb_snrm2.f90 +++ b/base/psblas/psb_snrm2.f90 @@ -1,9 +1,9 @@ -! +! ! Parallel Sparse BLAS version 3.5 ! (C) Copyright 2006-2018 -! Salvatore Filippone -! Alfredo Buttari -! +! Salvatore Filippone +! Alfredo Buttari +! ! Redistribution and use in source and binary forms, with or without ! modification, are permitted provided that the following conditions ! are met: @@ -15,7 +15,7 @@ ! 3. The name of the PSBLAS group or the names of its contributors may ! not be used to endorse or promote products derived from this ! software without specific written permission. -! +! ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -27,8 +27,8 @@ ! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ! POSSIBILITY OF SUCH DAMAGE. -! -! +! +! ! File: psb_snrm2.f90 ! ! Function: psb_snrm2 @@ -111,7 +111,7 @@ function psb_snrm2(x, desc_a, info, jx,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = snrm2( int(ndim,kind=psb_mpk_), x(iix:,jjx), int(ione,kind=psb_mpk_) ) @@ -120,16 +120,16 @@ function psb_snrm2(x, desc_a, info, jx,global) result(res) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(sone - dd*(abs(x(idx,jjx))/res)**2) + res = res * sqrt(sone - dd*(abs(x(idx,jjx))/res)**2) end do - else + else res = szero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) @@ -138,12 +138,12 @@ end function psb_snrm2 -!!$ +!!$ !!$ Parallel Sparse BLAS version 3.5 !!$ (C) Copyright 2006-2018 !!$ Salvatore Filippone University of Rome Tor Vergata -!!$ Alfredo Buttari -!!$ +!!$ Alfredo Buttari +!!$ !!$ Redistribution and use in source and binary forms, with or without !!$ modification, are permitted provided that the following conditions !!$ are met: @@ -155,7 +155,7 @@ end function psb_snrm2 !!$ 3. The name of the PSBLAS group or the names of its contributors may !!$ not be used to endorse or promote products derived from this !!$ software without specific written permission. -!!$ +!!$ !!$ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS !!$ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED !!$ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -167,7 +167,7 @@ end function psb_snrm2 !!$ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) !!$ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE !!$ POSSIBILITY OF SUCH DAMAGE. -!!$ +!!$ !!$ ! ! Function: psb_snrm2 @@ -226,7 +226,7 @@ function psb_snrm2v(x, desc_a, info,global) result(res) ix = 1 jx=1 m = desc_a%get_global_rows() - ldx = size(x,1) + ldx = size(x,1) call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) if(info /= psb_success_) then info=psb_err_from_subroutine_ @@ -240,7 +240,7 @@ function psb_snrm2v(x, desc_a, info,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = snrm2( int(ndim,kind=psb_mpk_), x, int(ione,kind=psb_mpk_) ) ! adjust because overlapped elements are computed more than once @@ -248,16 +248,16 @@ function psb_snrm2v(x, desc_a, info,global) result(res) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(sone - dd*(abs(x(idx))/res)**2) + res = res * sqrt(sone - dd*(abs(x(idx))/res)**2) end do - else + else res = szero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) @@ -314,7 +314,7 @@ function psb_snrm2_vect(x, desc_a, info,global) result(res) goto 9999 endif - if (.not.allocated(x%v)) then + if (.not.allocated(x%v)) then info = psb_err_invalid_vect_state_ call psb_errpush(info,name) goto 9999 @@ -343,7 +343,7 @@ function psb_snrm2_vect(x, desc_a, info,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = x%nrm2(ndim) ! adjust because overlapped elements are computed more than once @@ -356,27 +356,134 @@ function psb_snrm2_vect(x, desc_a, info,global) result(res) res = res - sqrt(sone - dd*(abs(x%v%v(idx))/res)**2) end do end if - else + else res = szero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) return end function psb_snrm2_vect +! Function: psb_snrm2_weight_vect +! Computes the weighted norm2 of a distributed vector, +! +! norm2 := sqrt ( (w.*X)**C * (w.*X)) +! +! Arguments: +! x - type(psb_s_vect_type) The input vector containing the entries of X. +! w - type(psb_s_vect_type) The input vector containing the entries of W. +! desc_a - type(psb_desc_type). The communication descriptor. +! info - integer. Return code +! global - logical(optional) Whether to perform the global reduction, default: .true. +! +function psb_snrm2_weight_vect(x,w, desc_a, info,global) result(res) + use psb_desc_mod + use psb_check_mod + use psb_error_mod + use psb_penv_mod + use psb_s_vect_mod + implicit none + + real(psb_spk_) :: res + type(psb_s_vect_type), intent (inout) :: x + type(psb_s_vect_type), intent (inout) :: w + type(psb_desc_type), intent(in) :: desc_a + integer(psb_ipk_), intent(out) :: info + logical, intent(in), optional :: global + + ! locals + integer(psb_ipk_) :: ictxt, np, me,& + & err_act, iix, jjx, ndim, i, id, idx, ndm, ldx + integer(psb_lpk_) :: ix, jx, iy, ijy, m + logical :: global_ + real(psb_spk_) :: snrm2, dd + character(len=20) :: name, ch_err + + name='psb_snrm2v_weight' + if (psb_errstatus_fatal()) then + info = psb_err_internal_error_ ; goto 9999 + end if + info=psb_success_ + call psb_erractionsave(err_act) + + ictxt=desc_a%get_context() -!!$ + call psb_info(ictxt, me, np) + if (np == -1) then + info=psb_err_context_error_ + call psb_errpush(info,name) + goto 9999 + endif + + if (.not.allocated(x%v)) then + info = psb_err_invalid_vect_state_ + call psb_errpush(info,name) + goto 9999 + endif + + if (present(global)) then + global_ = global + else + global_ = .true. + end if + + ix = 1 + jx = 1 + m = desc_a%get_global_rows() + ldx = x%get_nrows() + call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) + if(info /= psb_success_) then + info=psb_err_from_subroutine_ + ch_err='psb_chkvect' + call psb_errpush(info,name,a_err=ch_err) + end if + + if (iix /= 1) then + info=psb_err_ix_n1_iy_n1_unsupported_ + call psb_errpush(info,name) + goto 9999 + end if + + if (desc_a%get_local_rows() > 0) then + ndim = desc_a%get_local_rows() + res = x%nrm2(ndim,w) + ! adjust because overlapped elements are computed more than once + if (size(desc_a%ovrlap_elem,1)>0) then + if (x%is_dev()) call x%sync() + do i=1,size(desc_a%ovrlap_elem,1) + idx = desc_a%ovrlap_elem(i,1) + ndm = desc_a%ovrlap_elem(i,2) + dd = dble(ndm-1)/dble(ndm) + res = res - sqrt(sone - dd*(abs(x%v%v(idx))/res)**2) + end do + end if + else + res = szero + end if + + if (global_) call psb_nrm2(ictxt,res) + + call psb_erractionrestore(err_act) + return + +9999 call psb_error_handler(ictxt,err_act) + + return +end function psb_snrm2_weight_vect + + +!!$ !!$ Parallel Sparse BLAS version 3.5 !!$ (C) Copyright 2006-2018 !!$ Salvatore Filippone University of Rome Tor Vergata -!!$ Alfredo Buttari -!!$ +!!$ Alfredo Buttari +!!$ !!$ Redistribution and use in source and binary forms, with or without !!$ modification, are permitted provided that the following conditions !!$ are met: @@ -388,7 +495,7 @@ end function psb_snrm2_vect !!$ 3. The name of the PSBLAS group or the names of its contributors may !!$ not be used to endorse or promote products derived from this !!$ software without specific written permission. -!!$ +!!$ !!$ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS !!$ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED !!$ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -400,7 +507,7 @@ end function psb_snrm2_vect !!$ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) !!$ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE !!$ POSSIBILITY OF SUCH DAMAGE. -!!$ +!!$ !!$ ! ! Subroutine: psb_snrm2vs @@ -461,7 +568,7 @@ subroutine psb_snrm2vs(res, x, desc_a, info,global) ix = 1 jx = 1 m = desc_a%get_global_rows() - ldx = size(x,1) + ldx = size(x,1) call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) if(info /= psb_success_) then info=psb_err_from_subroutine_ @@ -475,7 +582,7 @@ subroutine psb_snrm2vs(res, x, desc_a, info,global) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = snrm2( int(ndim,kind=psb_mpk_), x, int(ione,kind=psb_mpk_) ) @@ -484,9 +591,9 @@ subroutine psb_snrm2vs(res, x, desc_a, info,global) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(sone - dd*(abs(x(idx))/res)**2) + res = res * sqrt(sone - dd*(abs(x(idx))/res)**2) end do - else + else res = szero end if @@ -494,7 +601,7 @@ subroutine psb_snrm2vs(res, x, desc_a, info,global) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) diff --git a/base/psblas/psb_znrm2.f90 b/base/psblas/psb_znrm2.f90 index 9f327773..0cde7e21 100644 --- a/base/psblas/psb_znrm2.f90 +++ b/base/psblas/psb_znrm2.f90 @@ -1,9 +1,9 @@ -! +! ! Parallel Sparse BLAS version 3.5 ! (C) Copyright 2006-2018 -! Salvatore Filippone -! Alfredo Buttari -! +! Salvatore Filippone +! Alfredo Buttari +! ! Redistribution and use in source and binary forms, with or without ! modification, are permitted provided that the following conditions ! are met: @@ -15,7 +15,7 @@ ! 3. The name of the PSBLAS group or the names of its contributors may ! not be used to endorse or promote products derived from this ! software without specific written permission. -! +! ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ! ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ! TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -27,8 +27,8 @@ ! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ! POSSIBILITY OF SUCH DAMAGE. -! -! +! +! ! File: psb_znrm2.f90 ! ! Function: psb_znrm2 @@ -111,7 +111,7 @@ function psb_znrm2(x, desc_a, info, jx,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = dznrm2( int(ndim,kind=psb_mpk_), x(iix:,jjx), int(ione,kind=psb_mpk_) ) @@ -120,16 +120,16 @@ function psb_znrm2(x, desc_a, info, jx,global) result(res) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(done - dd*(abs(x(idx,jjx))/res)**2) + res = res * sqrt(done - dd*(abs(x(idx,jjx))/res)**2) end do - else + else res = dzero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) @@ -138,12 +138,12 @@ end function psb_znrm2 -!!$ +!!$ !!$ Parallel Sparse BLAS version 3.5 !!$ (C) Copyright 2006-2018 !!$ Salvatore Filippone University of Rome Tor Vergata -!!$ Alfredo Buttari -!!$ +!!$ Alfredo Buttari +!!$ !!$ Redistribution and use in source and binary forms, with or without !!$ modification, are permitted provided that the following conditions !!$ are met: @@ -155,7 +155,7 @@ end function psb_znrm2 !!$ 3. The name of the PSBLAS group or the names of its contributors may !!$ not be used to endorse or promote products derived from this !!$ software without specific written permission. -!!$ +!!$ !!$ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS !!$ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED !!$ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -167,7 +167,7 @@ end function psb_znrm2 !!$ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) !!$ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE !!$ POSSIBILITY OF SUCH DAMAGE. -!!$ +!!$ !!$ ! ! Function: psb_znrm2 @@ -226,7 +226,7 @@ function psb_znrm2v(x, desc_a, info,global) result(res) ix = 1 jx=1 m = desc_a%get_global_rows() - ldx = size(x,1) + ldx = size(x,1) call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) if(info /= psb_success_) then info=psb_err_from_subroutine_ @@ -240,7 +240,7 @@ function psb_znrm2v(x, desc_a, info,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = dznrm2( int(ndim,kind=psb_mpk_), x, int(ione,kind=psb_mpk_) ) ! adjust because overlapped elements are computed more than once @@ -248,16 +248,16 @@ function psb_znrm2v(x, desc_a, info,global) result(res) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(done - dd*(abs(x(idx))/res)**2) + res = res * sqrt(done - dd*(abs(x(idx))/res)**2) end do - else + else res = dzero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) @@ -314,7 +314,7 @@ function psb_znrm2_vect(x, desc_a, info,global) result(res) goto 9999 endif - if (.not.allocated(x%v)) then + if (.not.allocated(x%v)) then info = psb_err_invalid_vect_state_ call psb_errpush(info,name) goto 9999 @@ -343,7 +343,7 @@ function psb_znrm2_vect(x, desc_a, info,global) result(res) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = x%nrm2(ndim) ! adjust because overlapped elements are computed more than once @@ -356,27 +356,134 @@ function psb_znrm2_vect(x, desc_a, info,global) result(res) res = res - sqrt(zone - dd*(abs(x%v%v(idx))/res)**2) end do end if - else + else res = dzero end if if (global_) call psb_nrm2(ictxt,res) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) return end function psb_znrm2_vect +! Function: psb_znrm2_weight_vect +! Computes the weighted norm2 of a distributed vector, +! +! norm2 := sqrt ( (w.*X)**C * (w.*X)) +! +! Arguments: +! x - type(psb_z_vect_type) The input vector containing the entries of X. +! w - type(psb_z_vect_type) The input vector containing the entries of W. +! desc_a - type(psb_desc_type). The communication descriptor. +! info - integer. Return code +! global - logical(optional) Whether to perform the global reduction, default: .true. +! +function psb_znrm2_weight_vect(x,w, desc_a, info,global) result(res) + use psb_desc_mod + use psb_check_mod + use psb_error_mod + use psb_penv_mod + use psb_z_vect_mod + implicit none + + real(psb_dpk_) :: res + type(psb_z_vect_type), intent (inout) :: x + type(psb_z_vect_type), intent (inout) :: w + type(psb_desc_type), intent(in) :: desc_a + integer(psb_ipk_), intent(out) :: info + logical, intent(in), optional :: global + + ! locals + integer(psb_ipk_) :: ictxt, np, me,& + & err_act, iix, jjx, ndim, i, id, idx, ndm, ldx + integer(psb_lpk_) :: ix, jx, iy, ijy, m + logical :: global_ + real(psb_dpk_) :: snrm2, dd + character(len=20) :: name, ch_err + + name='psb_znrm2v_weight' + if (psb_errstatus_fatal()) then + info = psb_err_internal_error_ ; goto 9999 + end if + info=psb_success_ + call psb_erractionsave(err_act) + + ictxt=desc_a%get_context() -!!$ + call psb_info(ictxt, me, np) + if (np == -1) then + info=psb_err_context_error_ + call psb_errpush(info,name) + goto 9999 + endif + + if (.not.allocated(x%v)) then + info = psb_err_invalid_vect_state_ + call psb_errpush(info,name) + goto 9999 + endif + + if (present(global)) then + global_ = global + else + global_ = .true. + end if + + ix = 1 + jx = 1 + m = desc_a%get_global_rows() + ldx = x%get_nrows() + call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) + if(info /= psb_success_) then + info=psb_err_from_subroutine_ + ch_err='psb_chkvect' + call psb_errpush(info,name,a_err=ch_err) + end if + + if (iix /= 1) then + info=psb_err_ix_n1_iy_n1_unsupported_ + call psb_errpush(info,name) + goto 9999 + end if + + if (desc_a%get_local_rows() > 0) then + ndim = desc_a%get_local_rows() + res = x%nrm2(ndim,w) + ! adjust because overlapped elements are computed more than once + if (size(desc_a%ovrlap_elem,1)>0) then + if (x%is_dev()) call x%sync() + do i=1,size(desc_a%ovrlap_elem,1) + idx = desc_a%ovrlap_elem(i,1) + ndm = desc_a%ovrlap_elem(i,2) + dd = dble(ndm-1)/dble(ndm) + res = res - sqrt(zone - dd*(abs(x%v%v(idx))/res)**2) + end do + end if + else + res = dzero + end if + + if (global_) call psb_nrm2(ictxt,res) + + call psb_erractionrestore(err_act) + return + +9999 call psb_error_handler(ictxt,err_act) + + return +end function psb_znrm2_weight_vect + + +!!$ !!$ Parallel Sparse BLAS version 3.5 !!$ (C) Copyright 2006-2018 !!$ Salvatore Filippone University of Rome Tor Vergata -!!$ Alfredo Buttari -!!$ +!!$ Alfredo Buttari +!!$ !!$ Redistribution and use in source and binary forms, with or without !!$ modification, are permitted provided that the following conditions !!$ are met: @@ -388,7 +495,7 @@ end function psb_znrm2_vect !!$ 3. The name of the PSBLAS group or the names of its contributors may !!$ not be used to endorse or promote products derived from this !!$ software without specific written permission. -!!$ +!!$ !!$ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS !!$ ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED !!$ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR @@ -400,7 +507,7 @@ end function psb_znrm2_vect !!$ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) !!$ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE !!$ POSSIBILITY OF SUCH DAMAGE. -!!$ +!!$ !!$ ! ! Subroutine: psb_znrm2vs @@ -461,7 +568,7 @@ subroutine psb_znrm2vs(res, x, desc_a, info,global) ix = 1 jx = 1 m = desc_a%get_global_rows() - ldx = size(x,1) + ldx = size(x,1) call psb_chkvect(m,lone,ldx,ix,jx,desc_a,info,iix,jjx) if(info /= psb_success_) then info=psb_err_from_subroutine_ @@ -475,7 +582,7 @@ subroutine psb_znrm2vs(res, x, desc_a, info,global) goto 9999 end if - if (desc_a%get_local_rows() > 0) then + if (desc_a%get_local_rows() > 0) then ndim = desc_a%get_local_rows() res = dznrm2( int(ndim,kind=psb_mpk_), x, int(ione,kind=psb_mpk_) ) @@ -484,9 +591,9 @@ subroutine psb_znrm2vs(res, x, desc_a, info,global) idx = desc_a%ovrlap_elem(i,1) ndm = desc_a%ovrlap_elem(i,2) dd = real(ndm-1)/real(ndm) - res = res * sqrt(done - dd*(abs(x(idx))/res)**2) + res = res * sqrt(done - dd*(abs(x(idx))/res)**2) end do - else + else res = dzero end if @@ -494,7 +601,7 @@ subroutine psb_znrm2vs(res, x, desc_a, info,global) call psb_erractionrestore(err_act) - return + return 9999 call psb_error_handler(ictxt,err_act) diff --git a/test/kernel/vecoperation.f90 b/test/kernel/vecoperation.f90 index d8fb234a..506a185c 100644 --- a/test/kernel/vecoperation.f90 +++ b/test/kernel/vecoperation.f90 @@ -53,7 +53,7 @@ program vecoperation integer(psb_ipk_) :: nr, nlr, info, i, ii, ib=1 integer(psb_lpk_) :: nt integer(psb_lpk_), allocatable :: myidx(:) - real(psb_dpk_) :: zt(1), dotresult, norm2, norm1, norminf + real(psb_dpk_) :: zt(1), dotresult, norm2, norm1, norminf, norm2w character(len=20) :: name,ch_err,readinput real(psb_dpk_), allocatable :: vx(:), vy(:), vz(:) real(psb_dpk_) :: c @@ -160,10 +160,6 @@ program vecoperation ! dotresult = psb_gedot(x,y,desc_a,info) ! Dot-product if (iam == psb_root_) write(psb_out_unit,'("Dot product result : ",es12.5)')dotresult - norm1 = psb_norm1(x,desc_a,info) - norm2 = psb_norm2(x,desc_a,info) - norminf = psb_normi(x,desc_a,info) - if (iam == psb_root_) write(psb_out_unit,'("\|x\|_inf : ",es12.5," \|x\|_1 :",es12.5," \|x\|_2",es12.5)')norminf,norm1,norm2 call psb_geaxpby(1.0_psb_dpk_, x, 1.0_psb_dpk_, y, desc_a, info) ! \alpha x + \beta y if (iam == psb_root_) then @@ -218,7 +214,7 @@ program vecoperation write(psb_out_unit,'("|x| = ",es12.1)')vz(:) end if - c = 1.0/2.0; + c = 1.0/5.0; call psb_gecmp(x,c,z,desc_a,info); if (iam == psb_root_) then @@ -229,6 +225,16 @@ program vecoperation write(psb_out_unit,'("z = ",es12.1)')vz(:) end if + write(psb_out_unit,'("Computation of vector norms:")') + norm1 = psb_norm1(x,desc_a,info) + norm2 = psb_norm2(x,desc_a,info) + norm2w = psb_norm2(x,absz,desc_a,info) + norminf = psb_normi(x,desc_a,info) + write(psb_out_unit,'("\|x\|_inf : ",es12.5," \|x\|_1 :",es12.5)')norminf,norm1 + write(psb_out_unit,'(" \|x\|_2 : ",es12.5," \|x\|_2,w : ",es12.5)')norm2,norm2w + + + ! ! cleanup storage and exit !