mirror of
https://github.com/sfilippone/psblas3.git
synced 2026-10-20 04:42:08 +00:00
[ADD] Generate the nested matrix support for s/c/z from the templates
Extend the nested (MATNEST) matrix support to all the arithmetics: the
psb_{s,c,z}_nest_{mat,base_mat,tools,builder}_mod modules and the
psb_{s,c,z}_nest_mod umbrellas are generated from the template-psblas
X_nest_* templates; the d sources are regenerated byte-identical.
Preparatory changes to the d sources for clean templating: rowsum/arwsum and
colsum/aclsum no longer share a helper (for the complex arithmetics the
absolute sums are real-valued while the plain sums are complex-valued), the
transposed kernel forwards the actual 'T'/'C' character to the blocks
(conjugate transpose for the complex types), and the capacity helper takes a
type-neutral name.
Build hooks (autotools Makefile and CMakeLists) updated with the per-arith
objects, compile rules and dependencies. All four d tests keep passing.
Author: Simone Staccone (Stack-1)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,149 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! 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:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 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 without 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
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! 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.
|
||||
!
|
||||
!
|
||||
! module: psb_c_nest_mat_mod
|
||||
! Author: Simone Staccone (Stack-1)
|
||||
!
|
||||
! Defines psb_c_nest_sparse_mat: a block-structured distributed sparse
|
||||
! matrix for double precision real arithmetic.
|
||||
!
|
||||
! The matrix is stored as a 2-D array of psb_cspmat_type sub-matrices.
|
||||
! Block presence is determined directly from the sub-matrix storage: a block
|
||||
! (i,j) is present iff mats(i,j)%a is allocated (absent blocks contribute zero
|
||||
! to any product). There is no separate presence flag array.
|
||||
!
|
||||
! Descriptor convention (current nested design)
|
||||
! ---------------------------------------------
|
||||
! Each matrix block (i,j) is associated with descs(i,j) from the
|
||||
! corresponding psb_desc_nest_type. Nested tools (psb_spall_nest,
|
||||
! psb_spins_nest, psb_spasb_nest, psb_spmm) consistently pass
|
||||
! descs(i,j) together with mats(i,j).
|
||||
!
|
||||
! A block may be structurally absent (NULL/zero): this is represented by
|
||||
! mats(i,j) left unbuilt (mats(i,j)%a not allocated). In that case the
|
||||
! block contributes zero and is skipped by nested kernels.
|
||||
!
|
||||
! Descriptor storage is distinct from matrix presence: descriptors are
|
||||
! typically defined for all block positions in descs(:,:), while actual
|
||||
! matrix blocks may be present only on a subset.
|
||||
!
|
||||
! Reference examples in test/pdegen:
|
||||
! * psb_c_pde_nest.full.F90 (A(2,2) left NULL, mats(2,2)%a not allocated)
|
||||
! * psb_c_nest_tools.F90 and psb_c_pde_nest_full_tools.F90
|
||||
! (2-D desc_nest%descs(i,j) used in nested allocation/assembly).
|
||||
!
|
||||
module psb_c_nest_mat_mod
|
||||
use psb_c_mat_mod
|
||||
implicit none
|
||||
|
||||
type :: psb_c_nest_sparse_mat
|
||||
integer(psb_ipk_) :: nrblocks = 0
|
||||
integer(psb_ipk_) :: ncblocks = 0
|
||||
type(psb_cspmat_type), allocatable :: mats(:,:)
|
||||
contains
|
||||
procedure :: get_nrblocks => psb_c_nest_mat_get_nrb
|
||||
procedure :: get_ncblocks => psb_c_nest_mat_get_ncb
|
||||
procedure :: has_block => psb_c_nest_mat_has_block
|
||||
procedure :: sizeof => psb_c_nest_mat_sizeof
|
||||
procedure :: free => psb_c_nest_mat_free
|
||||
end type psb_c_nest_sparse_mat
|
||||
|
||||
contains
|
||||
|
||||
! get_nrblocks / get_ncblocks
|
||||
function psb_c_nest_mat_get_nrb(a) result(n)
|
||||
class(psb_c_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_ipk_) :: n
|
||||
n = a%nrblocks
|
||||
end function psb_c_nest_mat_get_nrb
|
||||
|
||||
function psb_c_nest_mat_get_ncb(a) result(n)
|
||||
class(psb_c_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_ipk_) :: n
|
||||
n = a%ncblocks
|
||||
end function psb_c_nest_mat_get_ncb
|
||||
|
||||
! has_block: return .true. if block (i,j) is non-null
|
||||
function psb_c_nest_mat_has_block(a, i_block_row, j_block_col) result(has)
|
||||
class(psb_c_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_ipk_), intent(in) :: i_block_row, j_block_col
|
||||
logical :: has
|
||||
|
||||
has = .false.
|
||||
if (i_block_row < 1 .or. i_block_row > a%nrblocks) return
|
||||
if (j_block_col < 1 .or. j_block_col > a%ncblocks) return
|
||||
if (.not. allocated(a%mats)) return
|
||||
! P3: presence is determined solely by whether the sub-matrix has been
|
||||
! built (its polymorphic storage %a is allocated). No parallel flag array.
|
||||
has = allocated(a%mats(i_block_row, j_block_col)%a)
|
||||
end function psb_c_nest_mat_has_block
|
||||
|
||||
! sizeof: total storage across all allocated sub-matrices
|
||||
function psb_c_nest_mat_sizeof(a) result(total_bytes)
|
||||
class(psb_c_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_epk_) :: total_bytes
|
||||
integer(psb_ipk_) :: i_block_row, j_block_col
|
||||
|
||||
total_bytes = 0_psb_epk_
|
||||
if (allocated(a%mats)) then
|
||||
do j_block_col = 1, a%ncblocks
|
||||
do i_block_row = 1, a%nrblocks
|
||||
if (allocated(a%mats(i_block_row, j_block_col)%a)) &
|
||||
& total_bytes = total_bytes + a%mats(i_block_row, j_block_col)%sizeof()
|
||||
end do
|
||||
end do
|
||||
end if
|
||||
end function psb_c_nest_mat_sizeof
|
||||
|
||||
! free: release all sub-matrices
|
||||
subroutine psb_c_nest_mat_free(a, info)
|
||||
class(psb_c_nest_sparse_mat), intent(inout) :: a
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
|
||||
integer(psb_ipk_) :: i_block_row, j_block_col, local_info
|
||||
|
||||
info = 0
|
||||
if (allocated(a%mats)) then
|
||||
do j_block_col = 1, a%ncblocks
|
||||
do i_block_row = 1, a%nrblocks
|
||||
if (allocated(a%mats(i_block_row, j_block_col)%a)) then
|
||||
call a%mats(i_block_row, j_block_col)%free()
|
||||
end if
|
||||
end do
|
||||
end do
|
||||
deallocate(a%mats, stat=local_info)
|
||||
if (local_info /= 0 .and. info == 0) info = local_info
|
||||
end if
|
||||
a%nrblocks = 0
|
||||
a%ncblocks = 0
|
||||
end subroutine psb_c_nest_mat_free
|
||||
|
||||
end module psb_c_nest_mat_mod
|
||||
@@ -362,7 +362,7 @@ contains
|
||||
real(psb_dpk_), allocatable :: x_host(:), y_host(:)
|
||||
x_host = x%get_vect()
|
||||
y_host = y%get_vect()
|
||||
call psb_d_nest_base_csmv_t(alpha, a, x_host, beta, y_host, info)
|
||||
call psb_d_nest_base_csmv_t(alpha, a, x_host, beta, y_host, info, trans_)
|
||||
call y%bld(y_host)
|
||||
end block
|
||||
return
|
||||
@@ -536,8 +536,8 @@ contains
|
||||
if (present(trans)) trans_op = trans
|
||||
if (trans_op /= 'N' .and. trans_op /= 'n') then
|
||||
! transposed product: the block structure of A^T is the transpose of the
|
||||
! block grid, handled by the dedicated kernel below
|
||||
call psb_d_nest_base_csmv_t(alpha, a, x, beta, y, info)
|
||||
! block grid, handled by the dedicated kernel below ('T' or 'C')
|
||||
call psb_d_nest_base_csmv_t(alpha, a, x, beta, y, info, trans_op)
|
||||
return
|
||||
end if
|
||||
if (.not. associated(a%block_storage)) then
|
||||
@@ -601,11 +601,12 @@ contains
|
||||
! local columns of each column field (owned + ghosts); the distributed caller
|
||||
! (psb_spmm with trans='T') then accumulates the ghost contributions to their
|
||||
! owners through the transposed halo exchange.
|
||||
subroutine psb_d_nest_base_csmv_t(alpha, a, x, beta, y, info)
|
||||
subroutine psb_d_nest_base_csmv_t(alpha, a, x, beta, y, info, trans)
|
||||
real(psb_dpk_), intent(in) :: alpha, beta, x(:)
|
||||
class(psb_d_nest_base_mat), intent(in) :: a
|
||||
real(psb_dpk_), intent(inout) :: y(:)
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
character, intent(in) :: trans
|
||||
|
||||
real(psb_dpk_), allocatable :: x_field(:), y_field(:)
|
||||
integer(psb_ipk_) :: i_block_row, j_block_col, i_entry
|
||||
@@ -650,9 +651,9 @@ contains
|
||||
do i_entry = 1, n_owned_row_field
|
||||
x_field(i_entry) = x(a%field_map(i_block_row)%global_local_pos(i_entry))
|
||||
end do
|
||||
! y_field <- alpha * A(i,j)^T * x_field + y_field
|
||||
! y_field <- alpha * A(i,j)^T (or ^H) * x_field + y_field
|
||||
call a%block_storage%mats(i_block_row, j_block_col)%a%csmv( &
|
||||
& alpha, x_field, done, y_field, info, 'T')
|
||||
& alpha, x_field, done, y_field, info, trans)
|
||||
if (info /= psb_success_) then
|
||||
call psb_errpush(psb_err_from_subroutine_, name, a_err='block csmv T')
|
||||
return
|
||||
@@ -805,24 +806,11 @@ contains
|
||||
if (info == psb_success_) call a%free()
|
||||
end subroutine psb_d_nest_base_mv_to_coo
|
||||
|
||||
! rowsum/arwsum: (absolute) row sums, accumulated across the blocks of each
|
||||
! row field; d is in the global-local row layout
|
||||
! rowsum: row sums (matrix-valued type), accumulated across the blocks of
|
||||
! each row field; d is in the global-local row layout
|
||||
subroutine psb_d_nest_base_rowsum(d, a)
|
||||
class(psb_d_nest_base_mat), intent(in) :: a
|
||||
real(psb_dpk_), intent(out) :: d(:)
|
||||
call psb_d_nest_base_sum_rows(d, a, absolute=.false.)
|
||||
end subroutine psb_d_nest_base_rowsum
|
||||
|
||||
subroutine psb_d_nest_base_arwsum(d, a)
|
||||
class(psb_d_nest_base_mat), intent(in) :: a
|
||||
real(psb_dpk_), intent(out) :: d(:)
|
||||
call psb_d_nest_base_sum_rows(d, a, absolute=.true.)
|
||||
end subroutine psb_d_nest_base_arwsum
|
||||
|
||||
subroutine psb_d_nest_base_sum_rows(d, a, absolute)
|
||||
real(psb_dpk_), intent(out) :: d(:)
|
||||
class(psb_d_nest_base_mat), intent(in) :: a
|
||||
logical, intent(in) :: absolute
|
||||
|
||||
real(psb_dpk_), allocatable :: block_sums(:)
|
||||
integer(psb_ipk_) :: i_field, j_field, k_entry, n_owned, owned_offset
|
||||
@@ -835,11 +823,7 @@ contains
|
||||
allocate(block_sums(n_owned))
|
||||
do j_field = 1, a%n_fields
|
||||
if (.not. a%block_storage%has_block(i_field, j_field)) cycle
|
||||
if (absolute) then
|
||||
call a%block_storage%mats(i_field,j_field)%a%arwsum(block_sums)
|
||||
else
|
||||
call a%block_storage%mats(i_field,j_field)%a%rowsum(block_sums)
|
||||
end if
|
||||
call a%block_storage%mats(i_field,j_field)%a%rowsum(block_sums)
|
||||
do k_entry = 1, n_owned
|
||||
d(owned_offset+k_entry) = d(owned_offset+k_entry) + block_sums(k_entry)
|
||||
end do
|
||||
@@ -847,26 +831,39 @@ contains
|
||||
deallocate(block_sums)
|
||||
owned_offset = owned_offset + n_owned
|
||||
end do
|
||||
end subroutine psb_d_nest_base_sum_rows
|
||||
end subroutine psb_d_nest_base_rowsum
|
||||
|
||||
! colsum/aclsum: (absolute) column sums in the operator's column space,
|
||||
! arwsum: absolute row sums (always real-valued)
|
||||
subroutine psb_d_nest_base_arwsum(d, a)
|
||||
class(psb_d_nest_base_mat), intent(in) :: a
|
||||
real(psb_dpk_), intent(out) :: d(:)
|
||||
|
||||
real(psb_dpk_), allocatable :: block_sums(:)
|
||||
integer(psb_ipk_) :: i_field, j_field, k_entry, n_owned, owned_offset
|
||||
|
||||
d(:) = dzero
|
||||
if (.not. associated(a%block_storage)) return
|
||||
owned_offset = 0
|
||||
do i_field = 1, a%n_fields
|
||||
n_owned = a%field_map(i_field)%n_owned
|
||||
allocate(block_sums(n_owned))
|
||||
do j_field = 1, a%n_fields
|
||||
if (.not. a%block_storage%has_block(i_field, j_field)) cycle
|
||||
call a%block_storage%mats(i_field,j_field)%a%arwsum(block_sums)
|
||||
do k_entry = 1, n_owned
|
||||
d(owned_offset+k_entry) = d(owned_offset+k_entry) + block_sums(k_entry)
|
||||
end do
|
||||
end do
|
||||
deallocate(block_sums)
|
||||
owned_offset = owned_offset + n_owned
|
||||
end do
|
||||
end subroutine psb_d_nest_base_arwsum
|
||||
|
||||
! colsum: column sums (matrix-valued type) in the operator's column space,
|
||||
! accumulated across the blocks of each column field
|
||||
subroutine psb_d_nest_base_colsum(d, a)
|
||||
class(psb_d_nest_base_mat), intent(in) :: a
|
||||
real(psb_dpk_), intent(out) :: d(:)
|
||||
call psb_d_nest_base_sum_cols(d, a, absolute=.false.)
|
||||
end subroutine psb_d_nest_base_colsum
|
||||
|
||||
subroutine psb_d_nest_base_aclsum(d, a)
|
||||
class(psb_d_nest_base_mat), intent(in) :: a
|
||||
real(psb_dpk_), intent(out) :: d(:)
|
||||
call psb_d_nest_base_sum_cols(d, a, absolute=.true.)
|
||||
end subroutine psb_d_nest_base_aclsum
|
||||
|
||||
subroutine psb_d_nest_base_sum_cols(d, a, absolute)
|
||||
real(psb_dpk_), intent(out) :: d(:)
|
||||
class(psb_d_nest_base_mat), intent(in) :: a
|
||||
logical, intent(in) :: absolute
|
||||
|
||||
real(psb_dpk_), allocatable :: field_sums(:), block_sums(:)
|
||||
integer(psb_ipk_) :: i_field, j_field, k_entry, n_local
|
||||
@@ -879,11 +876,7 @@ contains
|
||||
field_sums(:) = dzero
|
||||
do i_field = 1, a%n_fields
|
||||
if (.not. a%block_storage%has_block(i_field, j_field)) cycle
|
||||
if (absolute) then
|
||||
call a%block_storage%mats(i_field,j_field)%a%aclsum(block_sums)
|
||||
else
|
||||
call a%block_storage%mats(i_field,j_field)%a%colsum(block_sums)
|
||||
end if
|
||||
call a%block_storage%mats(i_field,j_field)%a%colsum(block_sums)
|
||||
field_sums(1:n_local) = field_sums(1:n_local) + block_sums(1:n_local)
|
||||
end do
|
||||
do k_entry = 1, n_local
|
||||
@@ -891,7 +884,33 @@ contains
|
||||
end do
|
||||
deallocate(field_sums, block_sums)
|
||||
end do
|
||||
end subroutine psb_d_nest_base_sum_cols
|
||||
end subroutine psb_d_nest_base_colsum
|
||||
|
||||
! aclsum: absolute column sums (always real-valued)
|
||||
subroutine psb_d_nest_base_aclsum(d, a)
|
||||
class(psb_d_nest_base_mat), intent(in) :: a
|
||||
real(psb_dpk_), intent(out) :: d(:)
|
||||
|
||||
real(psb_dpk_), allocatable :: field_sums(:), block_sums(:)
|
||||
integer(psb_ipk_) :: i_field, j_field, k_entry, n_local
|
||||
|
||||
d(:) = dzero
|
||||
if (.not. associated(a%block_storage)) return
|
||||
do j_field = 1, a%n_fields
|
||||
n_local = size(a%field_map(j_field)%global_local_pos)
|
||||
allocate(field_sums(n_local), block_sums(n_local))
|
||||
field_sums(:) = dzero
|
||||
do i_field = 1, a%n_fields
|
||||
if (.not. a%block_storage%has_block(i_field, j_field)) cycle
|
||||
call a%block_storage%mats(i_field,j_field)%a%aclsum(block_sums)
|
||||
field_sums(1:n_local) = field_sums(1:n_local) + block_sums(1:n_local)
|
||||
end do
|
||||
do k_entry = 1, n_local
|
||||
d(a%field_map(j_field)%global_local_pos(k_entry)) = field_sums(k_entry)
|
||||
end do
|
||||
deallocate(field_sums, block_sums)
|
||||
end do
|
||||
end subroutine psb_d_nest_base_aclsum
|
||||
|
||||
! maxval / infinity norm / 1-norm, by delegation/accumulation over blocks
|
||||
function psb_d_nest_base_maxval(a) result(res)
|
||||
@@ -915,7 +934,7 @@ contains
|
||||
res = dzero
|
||||
if (a%get_nrows() <= 0) return
|
||||
allocate(row_sums(a%get_nrows()))
|
||||
call psb_d_nest_base_sum_rows(row_sums, a, absolute=.true.)
|
||||
call psb_d_nest_base_arwsum(row_sums, a)
|
||||
res = maxval(row_sums)
|
||||
end function psb_d_nest_base_csnmi
|
||||
|
||||
@@ -926,7 +945,7 @@ contains
|
||||
res = dzero
|
||||
if (a%get_ncols() <= 0) return
|
||||
allocate(col_sums(a%get_ncols()))
|
||||
call psb_d_nest_base_sum_cols(col_sums, a, absolute=.true.)
|
||||
call psb_d_nest_base_aclsum(col_sums, a)
|
||||
res = maxval(col_sums)
|
||||
end function psb_d_nest_base_csnm1
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,149 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! 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:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 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 without 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
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! 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.
|
||||
!
|
||||
!
|
||||
! module: psb_s_nest_mat_mod
|
||||
! Author: Simone Staccone (Stack-1)
|
||||
!
|
||||
! Defines psb_s_nest_sparse_mat: a block-structured distributed sparse
|
||||
! matrix for double precision real arithmetic.
|
||||
!
|
||||
! The matrix is stored as a 2-D array of psb_sspmat_type sub-matrices.
|
||||
! Block presence is determined directly from the sub-matrix storage: a block
|
||||
! (i,j) is present iff mats(i,j)%a is allocated (absent blocks contribute zero
|
||||
! to any product). There is no separate presence flag array.
|
||||
!
|
||||
! Descriptor convention (current nested design)
|
||||
! ---------------------------------------------
|
||||
! Each matrix block (i,j) is associated with descs(i,j) from the
|
||||
! corresponding psb_desc_nest_type. Nested tools (psb_spall_nest,
|
||||
! psb_spins_nest, psb_spasb_nest, psb_spmm) consistently pass
|
||||
! descs(i,j) together with mats(i,j).
|
||||
!
|
||||
! A block may be structurally absent (NULL/zero): this is represented by
|
||||
! mats(i,j) left unbuilt (mats(i,j)%a not allocated). In that case the
|
||||
! block contributes zero and is skipped by nested kernels.
|
||||
!
|
||||
! Descriptor storage is distinct from matrix presence: descriptors are
|
||||
! typically defined for all block positions in descs(:,:), while actual
|
||||
! matrix blocks may be present only on a subset.
|
||||
!
|
||||
! Reference examples in test/pdegen:
|
||||
! * psb_s_pde_nest.full.F90 (A(2,2) left NULL, mats(2,2)%a not allocated)
|
||||
! * psb_s_nest_tools.F90 and psb_s_pde_nest_full_tools.F90
|
||||
! (2-D desc_nest%descs(i,j) used in nested allocation/assembly).
|
||||
!
|
||||
module psb_s_nest_mat_mod
|
||||
use psb_s_mat_mod
|
||||
implicit none
|
||||
|
||||
type :: psb_s_nest_sparse_mat
|
||||
integer(psb_ipk_) :: nrblocks = 0
|
||||
integer(psb_ipk_) :: ncblocks = 0
|
||||
type(psb_sspmat_type), allocatable :: mats(:,:)
|
||||
contains
|
||||
procedure :: get_nrblocks => psb_s_nest_mat_get_nrb
|
||||
procedure :: get_ncblocks => psb_s_nest_mat_get_ncb
|
||||
procedure :: has_block => psb_s_nest_mat_has_block
|
||||
procedure :: sizeof => psb_s_nest_mat_sizeof
|
||||
procedure :: free => psb_s_nest_mat_free
|
||||
end type psb_s_nest_sparse_mat
|
||||
|
||||
contains
|
||||
|
||||
! get_nrblocks / get_ncblocks
|
||||
function psb_s_nest_mat_get_nrb(a) result(n)
|
||||
class(psb_s_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_ipk_) :: n
|
||||
n = a%nrblocks
|
||||
end function psb_s_nest_mat_get_nrb
|
||||
|
||||
function psb_s_nest_mat_get_ncb(a) result(n)
|
||||
class(psb_s_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_ipk_) :: n
|
||||
n = a%ncblocks
|
||||
end function psb_s_nest_mat_get_ncb
|
||||
|
||||
! has_block: return .true. if block (i,j) is non-null
|
||||
function psb_s_nest_mat_has_block(a, i_block_row, j_block_col) result(has)
|
||||
class(psb_s_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_ipk_), intent(in) :: i_block_row, j_block_col
|
||||
logical :: has
|
||||
|
||||
has = .false.
|
||||
if (i_block_row < 1 .or. i_block_row > a%nrblocks) return
|
||||
if (j_block_col < 1 .or. j_block_col > a%ncblocks) return
|
||||
if (.not. allocated(a%mats)) return
|
||||
! P3: presence is determined solely by whether the sub-matrix has been
|
||||
! built (its polymorphic storage %a is allocated). No parallel flag array.
|
||||
has = allocated(a%mats(i_block_row, j_block_col)%a)
|
||||
end function psb_s_nest_mat_has_block
|
||||
|
||||
! sizeof: total storage across all allocated sub-matrices
|
||||
function psb_s_nest_mat_sizeof(a) result(total_bytes)
|
||||
class(psb_s_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_epk_) :: total_bytes
|
||||
integer(psb_ipk_) :: i_block_row, j_block_col
|
||||
|
||||
total_bytes = 0_psb_epk_
|
||||
if (allocated(a%mats)) then
|
||||
do j_block_col = 1, a%ncblocks
|
||||
do i_block_row = 1, a%nrblocks
|
||||
if (allocated(a%mats(i_block_row, j_block_col)%a)) &
|
||||
& total_bytes = total_bytes + a%mats(i_block_row, j_block_col)%sizeof()
|
||||
end do
|
||||
end do
|
||||
end if
|
||||
end function psb_s_nest_mat_sizeof
|
||||
|
||||
! free: release all sub-matrices
|
||||
subroutine psb_s_nest_mat_free(a, info)
|
||||
class(psb_s_nest_sparse_mat), intent(inout) :: a
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
|
||||
integer(psb_ipk_) :: i_block_row, j_block_col, local_info
|
||||
|
||||
info = 0
|
||||
if (allocated(a%mats)) then
|
||||
do j_block_col = 1, a%ncblocks
|
||||
do i_block_row = 1, a%nrblocks
|
||||
if (allocated(a%mats(i_block_row, j_block_col)%a)) then
|
||||
call a%mats(i_block_row, j_block_col)%free()
|
||||
end if
|
||||
end do
|
||||
end do
|
||||
deallocate(a%mats, stat=local_info)
|
||||
if (local_info /= 0 .and. info == 0) info = local_info
|
||||
end if
|
||||
a%nrblocks = 0
|
||||
a%ncblocks = 0
|
||||
end subroutine psb_s_nest_mat_free
|
||||
|
||||
end module psb_s_nest_mat_mod
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,149 @@
|
||||
!
|
||||
! Parallel Sparse BLAS version 3.5
|
||||
! (C) Copyright 2006-2018
|
||||
! 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:
|
||||
! 1. Redistributions of source code must retain the above copyright
|
||||
! notice, this list of conditions and the following disclaimer.
|
||||
! 2. Redistributions in binary form must reproduce the above copyright
|
||||
! notice, this list of conditions, and the following disclaimer in the
|
||||
! documentation and/or other materials provided with the distribution.
|
||||
! 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 without 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
|
||||
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PSBLAS GROUP OR ITS CONTRIBUTORS
|
||||
! BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
! 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.
|
||||
!
|
||||
!
|
||||
! module: psb_z_nest_mat_mod
|
||||
! Author: Simone Staccone (Stack-1)
|
||||
!
|
||||
! Defines psb_z_nest_sparse_mat: a block-structured distributed sparse
|
||||
! matrix for double precision real arithmetic.
|
||||
!
|
||||
! The matrix is stored as a 2-D array of psb_zspmat_type sub-matrices.
|
||||
! Block presence is determined directly from the sub-matrix storage: a block
|
||||
! (i,j) is present iff mats(i,j)%a is allocated (absent blocks contribute zero
|
||||
! to any product). There is no separate presence flag array.
|
||||
!
|
||||
! Descriptor convention (current nested design)
|
||||
! ---------------------------------------------
|
||||
! Each matrix block (i,j) is associated with descs(i,j) from the
|
||||
! corresponding psb_desc_nest_type. Nested tools (psb_spall_nest,
|
||||
! psb_spins_nest, psb_spasb_nest, psb_spmm) consistently pass
|
||||
! descs(i,j) together with mats(i,j).
|
||||
!
|
||||
! A block may be structurally absent (NULL/zero): this is represented by
|
||||
! mats(i,j) left unbuilt (mats(i,j)%a not allocated). In that case the
|
||||
! block contributes zero and is skipped by nested kernels.
|
||||
!
|
||||
! Descriptor storage is distinct from matrix presence: descriptors are
|
||||
! typically defined for all block positions in descs(:,:), while actual
|
||||
! matrix blocks may be present only on a subset.
|
||||
!
|
||||
! Reference examples in test/pdegen:
|
||||
! * psb_z_pde_nest.full.F90 (A(2,2) left NULL, mats(2,2)%a not allocated)
|
||||
! * psb_z_nest_tools.F90 and psb_z_pde_nest_full_tools.F90
|
||||
! (2-D desc_nest%descs(i,j) used in nested allocation/assembly).
|
||||
!
|
||||
module psb_z_nest_mat_mod
|
||||
use psb_z_mat_mod
|
||||
implicit none
|
||||
|
||||
type :: psb_z_nest_sparse_mat
|
||||
integer(psb_ipk_) :: nrblocks = 0
|
||||
integer(psb_ipk_) :: ncblocks = 0
|
||||
type(psb_zspmat_type), allocatable :: mats(:,:)
|
||||
contains
|
||||
procedure :: get_nrblocks => psb_z_nest_mat_get_nrb
|
||||
procedure :: get_ncblocks => psb_z_nest_mat_get_ncb
|
||||
procedure :: has_block => psb_z_nest_mat_has_block
|
||||
procedure :: sizeof => psb_z_nest_mat_sizeof
|
||||
procedure :: free => psb_z_nest_mat_free
|
||||
end type psb_z_nest_sparse_mat
|
||||
|
||||
contains
|
||||
|
||||
! get_nrblocks / get_ncblocks
|
||||
function psb_z_nest_mat_get_nrb(a) result(n)
|
||||
class(psb_z_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_ipk_) :: n
|
||||
n = a%nrblocks
|
||||
end function psb_z_nest_mat_get_nrb
|
||||
|
||||
function psb_z_nest_mat_get_ncb(a) result(n)
|
||||
class(psb_z_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_ipk_) :: n
|
||||
n = a%ncblocks
|
||||
end function psb_z_nest_mat_get_ncb
|
||||
|
||||
! has_block: return .true. if block (i,j) is non-null
|
||||
function psb_z_nest_mat_has_block(a, i_block_row, j_block_col) result(has)
|
||||
class(psb_z_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_ipk_), intent(in) :: i_block_row, j_block_col
|
||||
logical :: has
|
||||
|
||||
has = .false.
|
||||
if (i_block_row < 1 .or. i_block_row > a%nrblocks) return
|
||||
if (j_block_col < 1 .or. j_block_col > a%ncblocks) return
|
||||
if (.not. allocated(a%mats)) return
|
||||
! P3: presence is determined solely by whether the sub-matrix has been
|
||||
! built (its polymorphic storage %a is allocated). No parallel flag array.
|
||||
has = allocated(a%mats(i_block_row, j_block_col)%a)
|
||||
end function psb_z_nest_mat_has_block
|
||||
|
||||
! sizeof: total storage across all allocated sub-matrices
|
||||
function psb_z_nest_mat_sizeof(a) result(total_bytes)
|
||||
class(psb_z_nest_sparse_mat), intent(in) :: a
|
||||
integer(psb_epk_) :: total_bytes
|
||||
integer(psb_ipk_) :: i_block_row, j_block_col
|
||||
|
||||
total_bytes = 0_psb_epk_
|
||||
if (allocated(a%mats)) then
|
||||
do j_block_col = 1, a%ncblocks
|
||||
do i_block_row = 1, a%nrblocks
|
||||
if (allocated(a%mats(i_block_row, j_block_col)%a)) &
|
||||
& total_bytes = total_bytes + a%mats(i_block_row, j_block_col)%sizeof()
|
||||
end do
|
||||
end do
|
||||
end if
|
||||
end function psb_z_nest_mat_sizeof
|
||||
|
||||
! free: release all sub-matrices
|
||||
subroutine psb_z_nest_mat_free(a, info)
|
||||
class(psb_z_nest_sparse_mat), intent(inout) :: a
|
||||
integer(psb_ipk_), intent(out) :: info
|
||||
|
||||
integer(psb_ipk_) :: i_block_row, j_block_col, local_info
|
||||
|
||||
info = 0
|
||||
if (allocated(a%mats)) then
|
||||
do j_block_col = 1, a%ncblocks
|
||||
do i_block_row = 1, a%nrblocks
|
||||
if (allocated(a%mats(i_block_row, j_block_col)%a)) then
|
||||
call a%mats(i_block_row, j_block_col)%free()
|
||||
end if
|
||||
end do
|
||||
end do
|
||||
deallocate(a%mats, stat=local_info)
|
||||
if (local_info /= 0 .and. info == 0) info = local_info
|
||||
end if
|
||||
a%nrblocks = 0
|
||||
a%ncblocks = 0
|
||||
end subroutine psb_z_nest_mat_free
|
||||
|
||||
end module psb_z_nest_mat_mod
|
||||
Reference in New Issue
Block a user