[ADD] Nested (MATNEST-style) block matrix support and tests

Add a block-structured distributed operator that presents itself to Krylov
solvers and preconditioners as a single ordinary distributed matrix (the
PSBLAS analogue of PETSc MATNEST), targeting saddle-point systems
M = [[A, B^T], [B, 0]] with possibly rectangular sub-blocks.

Library (base/modules):
- psb_desc_nest_mod, psb_d_nest_mat_mod: grid of per-field descriptors and
  per-block sparse storage.
- psb_d_nest_base_mat_mod: psb_d_nest_base_mat, the operator extending
  psb_d_base_sparse_mat (local csmv, free, field-split hooks for a future
  block preconditioner).
- psb_cd_nest_tools_mod / psb_d_nest_tools_mod: composed global descriptor
  with union halo (psb_cd_nest_compose) and rectangular local block builder
  (psb_d_nest_rect_block), plus the per-block assembly wrappers.
- psb_d_nest_builder_mod: psb_d_nest_matrix, the user frontend with the
  init/ins/asb/free pattern hiding all descriptor/halo/compose/setup
  boilerplate.
- psb_d_nest_mod: umbrella module (use psb_d_nest_mod).

Remove the earlier bespoke per-block prototype (comm/psblas/vect modules and
the pde_nest_psblas test) superseded by the single MATNEST design.

Tests (test/nested): glob (square operator vs monolithic CSR oracle), rect
(genuinely rectangular blocks), cg (low-level path, ill-conditioned SPD
red-black Laplacian solved with standard CG), builder (same solve via the
utility), plus a README describing the design and usage. All pass serially
and in parallel, with results invariant to the process count.

Build hooks updated (autotools Makefiles + CMakeLists); the nested tests are
relocated out of test/pdegen into test/nested.

Author: Simone Staccone (Stack-1)
This commit is contained in:
Stack-1
2026-06-11 16:53:46 +02:00
parent 784c3cc0b4
commit acdd2e9eb5
23 changed files with 2384 additions and 1889 deletions
@@ -0,0 +1,405 @@
!
! 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 prior 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
! 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.
!
!
! File: psb_d_nest_base_mat_mod.F90
!
! Module: psb_d_nest_base_mat_mod
! Author: Simone Staccone (Stack-1)
!
! Adapter that makes a block-structured (nested) operator look like a standard
! local sparse matrix to PSBLAS: psb_d_nest_base_mat EXTENDS
! psb_d_base_sparse_mat and implements csmv (the local matrix-vector product).
! Wrapped in a psb_dspmat_type and paired with the composed global descriptor
! (see psb_cd_nest_compose), the nested operator can then be fed to psb_spmm,
! psb_krylov and the AMG4PSBLAS preconditioners unchanged (MATNEST-style).
!
! The local vector handed to csmv lives in the GLOBAL local layout produced by
! psb_cd_nest_compose: the owned entries of all fields are concatenated, followed
! by the global halo. For each field we precompute field_map(field)%global_local_pos,
! the positions in that global local vector of the field's own local vector
! (owned entries first, then the field's ghosts), so we can gather the field
! input sub-vector and scatter the field output sub-vector without further
! communication (the halo exchange is done once by psb_spmm on the global desc).
!
module psb_d_nest_base_mat_mod
use psb_const_mod
use psb_error_mod
use psb_d_base_mat_mod, only : psb_d_base_sparse_mat
use psb_desc_mod, only : psb_desc_type
use psb_desc_nest_mod, only : psb_desc_nest_type
use psb_d_nest_mat_mod, only : psb_d_nest_sparse_mat
use psb_d_mat_mod, only : psb_dspmat_type
implicit none
! Per-field gather/scatter map into the global local vector.
! global_local_pos(1 : n_owned) -> the field's owned entries
! global_local_pos(n_owned+1 : size) -> the field's ghost (halo) entries
type :: psb_d_nest_field_map
integer(psb_ipk_) :: n_owned = 0
integer(psb_ipk_), allocatable :: global_local_pos(:)
end type psb_d_nest_field_map
type, extends(psb_d_base_sparse_mat) :: psb_d_nest_base_mat
integer(psb_ipk_) :: n_fields = 0
type(psb_d_nest_sparse_mat), pointer :: block_storage => null() ! blocks (not owned)
type(psb_desc_nest_type), pointer :: grid_desc => null() ! per-field descriptors (not owned)
type(psb_d_nest_field_map), allocatable :: field_map(:)
contains
procedure, pass(a) :: csmv => psb_d_nest_base_csmv
procedure, pass(a) :: get_nzeros => psb_d_nest_base_get_nzeros
procedure, nopass :: get_fmt => psb_d_nest_base_get_fmt
procedure, pass(a) :: free => psb_d_nest_base_free
end type psb_d_nest_base_mat
private
public :: psb_d_nest_base_mat, psb_d_nest_base_setup, psb_d_nest_apply_block
! field-split interface (for the block preconditioner)
public :: psb_d_nest_get_n_fields, psb_d_nest_get_field_owned, &
& psb_d_nest_get_block, psb_d_nest_get_field_desc, &
& psb_d_nest_restrict_field, psb_d_nest_prolong_field
contains
function psb_d_nest_base_get_fmt() result(format_name)
character(len=5) :: format_name
format_name = 'NEST'
end function psb_d_nest_base_get_fmt
! free: the nested operator does NOT own block_storage / grid_desc (they are
! pointers into the caller), so we only detach them and release the field maps.
subroutine psb_d_nest_base_free(a)
class(psb_d_nest_base_mat), intent(inout) :: a
a%block_storage => null()
a%grid_desc => null()
if (allocated(a%field_map)) deallocate(a%field_map)
a%n_fields = 0
call a%set_null()
end subroutine psb_d_nest_base_free
function psb_d_nest_base_get_nzeros(a) result(total_nzeros)
class(psb_d_nest_base_mat), intent(in) :: a
integer(psb_ipk_) :: total_nzeros
integer(psb_ipk_) :: i_block_row, j_block_col
total_nzeros = 0
if (associated(a%block_storage)) then
do j_block_col = 1, a%block_storage%ncblocks
do i_block_row = 1, a%block_storage%nrblocks
if (a%block_storage%has_block(i_block_row, j_block_col)) &
& total_nzeros = total_nzeros + &
& a%block_storage%mats(i_block_row, j_block_col)%get_nzeros()
end do
end do
end if
end function psb_d_nest_base_get_nzeros
! Build the per-field gather maps and set the local dimensions, from the nested
! grid descriptor (per-field distribution desc_grid%descs(1,field)) and the
! composed global descriptor desc_global (produced by psb_cd_nest_compose).
subroutine psb_d_nest_base_setup(nest_op, block_storage, desc_grid, desc_global, info)
type(psb_d_nest_base_mat), intent(inout) :: nest_op
type(psb_d_nest_sparse_mat), target, intent(in) :: block_storage
type(psb_desc_nest_type), target, intent(in) :: desc_grid
type(psb_desc_type), intent(in) :: desc_global
integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_) :: n_fields, i_field, i_entry
integer(psb_ipk_) :: n_owned, n_local, n_ghost, owned_offset, local_pos
integer(psb_lpk_) :: global_idx
integer(psb_lpk_), allocatable :: field_global_offset(:)
character(len=24) :: name
info = psb_success_
name = 'psb_d_nest_base_setup'
if (desc_grid%nrblocks /= desc_grid%ncblocks) then
info = psb_err_invalid_input_
call psb_errpush(info, name, a_err='nested block structure must be square')
return
end if
n_fields = desc_grid%ncblocks
nest_op%n_fields = n_fields
nest_op%grid_desc => desc_grid
nest_op%block_storage => block_storage
! global field offsets (used to form ghost global indices)
allocate(field_global_offset(n_fields+1), nest_op%field_map(n_fields), stat=info)
if (info /= 0) then
info = psb_err_alloc_dealloc_; call psb_errpush(info, name); return
end if
field_global_offset(1) = 0
do i_field = 1, n_fields
field_global_offset(i_field+1) = field_global_offset(i_field) &
& + desc_grid%descs(1,i_field)%get_global_rows()
end do
owned_offset = 0 ! running owned-local offset in the global local vector
do i_field = 1, n_fields
n_owned = desc_grid%descs(1,i_field)%get_local_rows()
n_local = desc_grid%descs(1,i_field)%get_local_cols()
n_ghost = n_local - n_owned
nest_op%field_map(i_field)%n_owned = n_owned
allocate(nest_op%field_map(i_field)%global_local_pos(n_local), stat=info)
if (info /= 0) then
info = psb_err_alloc_dealloc_; call psb_errpush(info, name); return
end if
! owned entries: contiguous in the global local vector
do i_entry = 1, n_owned
nest_op%field_map(i_field)%global_local_pos(i_entry) = owned_offset + i_entry
end do
! ghost entries: locate the field's ghost global index in the global descriptor
do i_entry = 1, n_ghost
call desc_grid%descs(1,i_field)%l2g(n_owned + i_entry, global_idx, info)
if (info /= 0) then
call psb_errpush(psb_err_from_subroutine_, name, a_err='l2g'); return
end if
call desc_global%g2l(field_global_offset(i_field) + global_idx, local_pos, info)
if (info /= 0) then
call psb_errpush(psb_err_from_subroutine_, name, a_err='g2l'); return
end if
nest_op%field_map(i_field)%global_local_pos(n_owned + i_entry) = local_pos
end do
owned_offset = owned_offset + n_owned
end do
call nest_op%set_nrows(desc_global%get_local_rows())
call nest_op%set_ncols(desc_global%get_local_cols())
call nest_op%set_asb()
end subroutine psb_d_nest_base_setup
! Local block matrix-vector product: y = alpha * A_nest * x + beta * y.
! x is in the global local layout (owned fields concatenated + global halo);
! y holds the owned entries (global local rows).
subroutine psb_d_nest_base_csmv(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, optional, intent(in) :: trans
real(psb_dpk_), allocatable :: x_field(:), y_field(:)
integer(psb_ipk_) :: i_block_row, j_block_col, i_entry
integer(psb_ipk_) :: n_local_col_field, n_owned_row_field
character :: trans_op
character(len=24) :: name
info = psb_success_
name = 'psb_d_nest_base_csmv'
trans_op = 'N'
if (present(trans)) trans_op = trans
if (trans_op /= 'N' .and. trans_op /= 'n') then
! Transposed nested product is not implemented (would swap block indices
! and need the transposed halo); reject explicitly. See P5.
info = psb_err_transpose_not_n_unsupported_
call psb_errpush(info, name)
return
end if
if (.not. associated(a%block_storage)) then
info = psb_err_invalid_input_
call psb_errpush(info, name, a_err='nested operator not set up')
return
end if
! y <- beta * y
if (beta == dzero) then
y(:) = dzero
else if (beta /= done) then
y(:) = beta * y(:)
end if
do j_block_col = 1, a%n_fields
n_local_col_field = size(a%field_map(j_block_col)%global_local_pos)
allocate(x_field(n_local_col_field), stat=info)
if (info /= 0) then
info = psb_err_alloc_dealloc_; call psb_errpush(info, name); return
end if
! gather the column-field input sub-vector (owned + that field's ghosts)
do i_entry = 1, n_local_col_field
x_field(i_entry) = x(a%field_map(j_block_col)%global_local_pos(i_entry))
end do
do i_block_row = 1, a%n_fields
if (a%block_storage%has_block(i_block_row, j_block_col)) then
n_owned_row_field = a%field_map(i_block_row)%n_owned
allocate(y_field(n_owned_row_field), stat=info)
if (info /= 0) then
info = psb_err_alloc_dealloc_; call psb_errpush(info, name); return
end if
! current row-field output sub-vector (owned)
do i_entry = 1, n_owned_row_field
y_field(i_entry) = y(a%field_map(i_block_row)%global_local_pos(i_entry))
end do
! y_field <- alpha * A(i_block_row, j_block_col) * x_field + y_field
call a%block_storage%mats(i_block_row, j_block_col)%a%csmv( &
& alpha, x_field, done, y_field, info, trans_op)
if (info /= psb_success_) then
call psb_errpush(psb_err_from_subroutine_, name, a_err='block csmv')
return
end if
! scatter the row-field output sub-vector back into y
do i_entry = 1, n_owned_row_field
y(a%field_map(i_block_row)%global_local_pos(i_entry)) = y_field(i_entry)
end do
deallocate(y_field)
end if
end do
deallocate(x_field)
end do
end subroutine psb_d_nest_base_csmv
! Selective (regime 2) application of a SINGLE block:
! y_field = alpha * A(i_block_row, j_block_col) * x_field + beta * y_field
! x_field is the column-field local vector (owned + ghosts) ALREADY halo-exchanged
! by the caller; y_field is the row-field owned local vector. The caller chooses
! the exchange regime (the union halo, or just this block's halo), so this
! routine is purely local. It is FORMAT-AGNOSTIC: it dispatches to the block's
! own polymorphic csmv, so the block may be CSR, COO, ... independently of the
! other blocks. (The full-operator matvec, regime 1, is psb_d_nest_base_csmv.)
subroutine psb_d_nest_apply_block(nest_op, i_block_row, j_block_col, alpha, x_field, beta, y_field, info)
type(psb_d_nest_base_mat), intent(in) :: nest_op
integer(psb_ipk_), intent(in) :: i_block_row, j_block_col
real(psb_dpk_), intent(in) :: alpha, beta, x_field(:)
real(psb_dpk_), intent(inout) :: y_field(:)
integer(psb_ipk_), intent(out) :: info
character(len=24) :: name
info = psb_success_
name = 'psb_d_nest_apply_block'
if (.not. associated(nest_op%block_storage)) then
info = psb_err_invalid_input_
call psb_errpush(info, name, a_err='nested operator not set up')
return
end if
if (.not. nest_op%block_storage%has_block(i_block_row, j_block_col)) then
! absent block contributes zero: y_field <- beta * y_field
if (beta == dzero) then
y_field(:) = dzero
else if (beta /= done) then
y_field(:) = beta * y_field(:)
end if
return
end if
! polymorphic dispatch: the block applies its own format (CSR/COO/...)
call nest_op%block_storage%mats(i_block_row, j_block_col)%a%csmv( &
& alpha, x_field, beta, y_field, info)
if (info /= psb_success_) &
& call psb_errpush(psb_err_from_subroutine_, name, a_err='block csmv')
end subroutine psb_d_nest_apply_block
! ====================================================================
! Field-split interface (for the block preconditioner).
! Exposes the field structure so a fieldsplit/Schur preconditioner can:
! - know how many fields there are and their owned sizes;
! - get a block as a standard psb_dspmat_type (sub-preconditioner on A,
! Schur-complement matvecs with B / B^T);
! - get a field descriptor (run a field-level Krylov / halo exchange);
! - restrict the global vector to a field sub-vector and prolong it back.
! ====================================================================
function psb_d_nest_get_n_fields(nest_op) result(n_fields)
type(psb_d_nest_base_mat), intent(in) :: nest_op
integer(psb_ipk_) :: n_fields
n_fields = nest_op%n_fields
end function psb_d_nest_get_n_fields
function psb_d_nest_get_field_owned(nest_op, field) result(n_owned)
type(psb_d_nest_base_mat), intent(in) :: nest_op
integer(psb_ipk_), intent(in) :: field
integer(psb_ipk_) :: n_owned
n_owned = 0
if (allocated(nest_op%field_map) .and. field >= 1 .and. field <= nest_op%n_fields) &
& n_owned = nest_op%field_map(field)%n_owned
end function psb_d_nest_get_field_owned
! Pointer to block (i,j) as a standard psb_dspmat_type (null if absent).
function psb_d_nest_get_block(nest_op, i_block_row, j_block_col) result(block_ptr)
type(psb_d_nest_base_mat), target, intent(in) :: nest_op
integer(psb_ipk_), intent(in) :: i_block_row, j_block_col
type(psb_dspmat_type), pointer :: block_ptr
block_ptr => null()
if (associated(nest_op%block_storage)) then
if (nest_op%block_storage%has_block(i_block_row, j_block_col)) &
& block_ptr => nest_op%block_storage%mats(i_block_row, j_block_col)
end if
end function psb_d_nest_get_block
! Pointer to field k's descriptor (null if not set up).
function psb_d_nest_get_field_desc(nest_op, field) result(desc_ptr)
type(psb_d_nest_base_mat), target, intent(in) :: nest_op
integer(psb_ipk_), intent(in) :: field
type(psb_desc_type), pointer :: desc_ptr
desc_ptr => null()
if (associated(nest_op%grid_desc) .and. field >= 1 .and. field <= nest_op%n_fields) &
& desc_ptr => nest_op%grid_desc%descs(1, field)
end function psb_d_nest_get_field_desc
! Restrict: extract field k's OWNED sub-vector from the global local vector.
subroutine psb_d_nest_restrict_field(nest_op, field, x_global, x_field, info)
type(psb_d_nest_base_mat), intent(in) :: nest_op
integer(psb_ipk_), intent(in) :: field
real(psb_dpk_), intent(in) :: x_global(:)
real(psb_dpk_), intent(out) :: x_field(:)
integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_) :: i_entry, n_owned
info = psb_success_
if (field < 1 .or. field > nest_op%n_fields) then
info = psb_err_invalid_input_; return
end if
n_owned = nest_op%field_map(field)%n_owned
do i_entry = 1, n_owned
x_field(i_entry) = x_global(nest_op%field_map(field)%global_local_pos(i_entry))
end do
end subroutine psb_d_nest_restrict_field
! Prolong: insert field k's OWNED sub-vector into the global local vector.
subroutine psb_d_nest_prolong_field(nest_op, field, x_field, x_global, info)
type(psb_d_nest_base_mat), intent(in) :: nest_op
integer(psb_ipk_), intent(in) :: field
real(psb_dpk_), intent(in) :: x_field(:)
real(psb_dpk_), intent(inout) :: x_global(:)
integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_) :: i_entry, n_owned
info = psb_success_
if (field < 1 .or. field > nest_op%n_fields) then
info = psb_err_invalid_input_; return
end if
n_owned = nest_op%field_map(field)%n_owned
do i_entry = 1, n_owned
x_global(nest_op%field_map(field)%global_local_pos(i_entry)) = x_field(i_entry)
end do
end subroutine psb_d_nest_prolong_field
end module psb_d_nest_base_mat_mod
+31 -31
View File
@@ -30,13 +30,15 @@
!
!
! module: psb_d_nest_mat_mod
! Author: Simone Staccone (Stack-1)
!
! Defines psb_d_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_dspmat_type sub-matrices.
! A companion logical array blk_present(i,j) flags which blocks are
! non-null (absent blocks contribute zero to any product).
! 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)
! ---------------------------------------------
@@ -46,7 +48,7 @@
! descs(i,j) together with mats(i,j).
!
! A block may be structurally absent (NULL/zero): this is represented by
! blk_present(i,j)=.false. and mats(i,j) left unbuilt. In that case the
! 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
@@ -54,7 +56,7 @@
! matrix blocks may be present only on a subset.
!
! Reference examples in test/pdegen:
! * psb_d_pde_nest.full.F90 (A(2,2) left NULL, blk_present(2,2)=.false.)
! * psb_d_pde_nest.full.F90 (A(2,2) left NULL, mats(2,2)%a not allocated)
! * psb_d_nest_tools.F90 and psb_d_pde_nest_full_tools.F90
! (2-D desc_nest%descs(i,j) used in nested allocation/assembly).
!
@@ -66,7 +68,6 @@ module psb_d_nest_mat_mod
integer(psb_ipk_) :: nrblocks = 0
integer(psb_ipk_) :: ncblocks = 0
type(psb_dspmat_type), allocatable :: mats(:,:)
logical, allocatable :: blk_present(:,:)
contains
procedure :: get_nrblocks => psb_d_nest_mat_get_nrb
procedure :: get_ncblocks => psb_d_nest_mat_get_ncb
@@ -91,29 +92,32 @@ contains
end function psb_d_nest_mat_get_ncb
! has_block: return .true. if block (i,j) is non-null
function psb_d_nest_mat_has_block(a, i, j) result(hp)
function psb_d_nest_mat_has_block(a, i_block_row, j_block_col) result(has)
class(psb_d_nest_sparse_mat), intent(in) :: a
integer(psb_ipk_), intent(in) :: i, j
logical :: hp
integer(psb_ipk_), intent(in) :: i_block_row, j_block_col
logical :: has
hp = .false.
if (i < 1 .or. i > a%nrblocks) return
if (j < 1 .or. j > a%ncblocks) return
if (.not. allocated(a%blk_present)) return
hp = a%blk_present(i, j)
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_d_nest_mat_has_block
! sizeof: total storage across all allocated sub-matrices
function psb_d_nest_mat_sizeof(a) result(s)
function psb_d_nest_mat_sizeof(a) result(total_bytes)
class(psb_d_nest_sparse_mat), intent(in) :: a
integer(psb_epk_) :: s
integer(psb_ipk_) :: i, j
integer(psb_epk_) :: total_bytes
integer(psb_ipk_) :: i_block_row, j_block_col
s = 0_psb_epk_
total_bytes = 0_psb_epk_
if (allocated(a%mats)) then
do j = 1, a%ncblocks
do i = 1, a%nrblocks
if (a%blk_present(i, j)) s = s + a%mats(i, j)%sizeof()
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
@@ -124,23 +128,19 @@ contains
class(psb_d_nest_sparse_mat), intent(inout) :: a
integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_) :: i, j, linfo
integer(psb_ipk_) :: i_block_row, j_block_col, local_info
info = 0
if (allocated(a%mats)) then
do j = 1, a%ncblocks
do i = 1, a%nrblocks
if (a%blk_present(i, j)) then
call a%mats(i, j)%free()
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=linfo)
if (linfo /= 0 .and. info == 0) info = linfo
end if
if (allocated(a%blk_present)) then
deallocate(a%blk_present, stat=linfo)
if (linfo /= 0 .and. info == 0) info = linfo
deallocate(a%mats, stat=local_info)
if (local_info /= 0 .and. info == 0) info = local_info
end if
a%nrblocks = 0
a%ncblocks = 0
-109
View File
@@ -1,109 +0,0 @@
!
! 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 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
! 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_d_nest_vect_mod
!
! Defines psb_d_nest_vect_type: a block-structured distributed dense
! vector for double precision real arithmetic. Each sub-vector is a
! standard psb_d_vect_type assembled under its own descriptor.
!
! Parallel BLAS operations (nrm2, dot, axpby) are exposed as module
! subroutines/functions in psb_d_nest_psblas_mod so that they can
! exploit a single global reduction per call.
!
module psb_d_nest_vect_mod
use psb_d_vect_mod
use psb_desc_mod
implicit none
type :: psb_d_nest_vect_type
integer(psb_ipk_) :: nblocks = 0
type(psb_d_vect_type), allocatable :: vects(:)
contains
procedure :: get_nblocks => psb_d_nest_vect_get_nblocks
procedure :: zero => psb_d_nest_vect_zero
procedure :: sizeof => psb_d_nest_vect_sizeof
procedure :: free => psb_d_nest_vect_free
end type psb_d_nest_vect_type
contains
! get_nblocks
function psb_d_nest_vect_get_nblocks(x) result(nb)
class(psb_d_nest_vect_type), intent(in) :: x
integer(psb_ipk_) :: nb
nb = x%nblocks
end function psb_d_nest_vect_get_nblocks
! zero: set all sub-vectors to zero (local, no halo zeroing needed)
subroutine psb_d_nest_vect_zero(x)
class(psb_d_nest_vect_type), intent(inout) :: x
integer(psb_ipk_) :: i
if (allocated(x%vects)) then
do i = 1, x%nblocks
call x%vects(i)%zero()
end do
end if
end subroutine psb_d_nest_vect_zero
! sizeof: total bytes across all sub-vectors
function psb_d_nest_vect_sizeof(x) result(s)
class(psb_d_nest_vect_type), intent(in) :: x
integer(psb_epk_) :: s
integer(psb_ipk_) :: i
s = 0_psb_epk_
if (allocated(x%vects)) then
do i = 1, x%nblocks
s = s + x%vects(i)%sizeof()
end do
end if
end function psb_d_nest_vect_sizeof
! free: release all sub-vectors
subroutine psb_d_nest_vect_free(x, info)
class(psb_d_nest_vect_type), intent(inout) :: x
integer(psb_ipk_), intent(out) :: info
integer(psb_ipk_) :: i, linfo
info = 0
if (allocated(x%vects)) then
do i = 1, x%nblocks
call x%vects(i)%free(linfo)
if (linfo /= 0 .and. info == 0) info = linfo
end do
deallocate(x%vects, stat=linfo)
if (linfo /= 0 .and. info == 0) info = linfo
end if
x%nblocks = 0
end subroutine psb_d_nest_vect_free
end module psb_d_nest_vect_mod