You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
266 lines
7.6 KiB
Fortran
266 lines
7.6 KiB
Fortran
8 years ago
|
!
|
||
8 years ago
|
! Parallel Sparse BLAS version 3.5
|
||
7 years ago
|
! (C) Copyright 2006-2018
|
||
|
! Salvatore Filippone
|
||
|
! Alfredo Buttari
|
||
8 years ago
|
!
|
||
|
! 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.
|
||
|
!
|
||
|
!
|
||
14 years ago
|
!
|
||
|
!
|
||
|
! package: psb_glist_map_mod
|
||
|
! Defines the GLIST_MAP type.
|
||
|
!
|
||
|
! This is almost identical to the LIST_MAP type, but it has an additional
|
||
|
! vector of size GLOB_ROWS giving, for each index, the owning process.
|
||
|
! This implies that:
|
||
|
! 1. We have room for such an additional vector;
|
||
|
! 2. There are no overlap (only one process owns a given index).
|
||
|
!
|
||
|
!
|
||
14 years ago
|
module psb_glist_map_mod
|
||
|
use psb_const_mod
|
||
|
use psb_desc_const_mod
|
||
|
use psb_list_map_mod
|
||
|
|
||
|
type, extends(psb_list_map) :: psb_glist_map
|
||
13 years ago
|
integer(psb_ipk_), allocatable :: vgp(:)
|
||
14 years ago
|
contains
|
||
|
procedure, pass(idxmap) :: glist_map_init => glist_initvg
|
||
|
procedure, pass(idxmap) :: sizeof => glist_sizeof
|
||
|
procedure, pass(idxmap) :: free => glist_free
|
||
14 years ago
|
procedure, pass(idxmap) :: clone => glist_clone
|
||
14 years ago
|
procedure, nopass :: get_fmt => glist_get_fmt
|
||
14 years ago
|
procedure, pass(idxmap) :: fnd_owner => glist_fnd_owner
|
||
|
|
||
|
end type psb_glist_map
|
||
|
|
||
|
private :: glist_initvg, glist_sizeof, glist_free, glist_get_fmt
|
||
|
|
||
|
|
||
|
contains
|
||
|
|
||
|
|
||
|
function glist_sizeof(idxmap) result(val)
|
||
|
implicit none
|
||
|
class(psb_glist_map), intent(in) :: idxmap
|
||
6 years ago
|
integer(psb_epk_) :: val
|
||
14 years ago
|
|
||
|
val = idxmap%psb_list_map%sizeof()
|
||
|
|
||
|
if (allocated(idxmap%vgp)) &
|
||
6 years ago
|
& val = val + size(idxmap%vgp)*psb_sizeof_ip
|
||
14 years ago
|
|
||
|
end function glist_sizeof
|
||
|
|
||
|
|
||
|
subroutine glist_free(idxmap)
|
||
|
implicit none
|
||
|
class(psb_glist_map), intent(inout) :: idxmap
|
||
|
|
||
|
if (allocated(idxmap%vgp)) &
|
||
|
& deallocate(idxmap%vgp)
|
||
|
|
||
|
call idxmap%psb_list_map%free()
|
||
|
|
||
|
end subroutine glist_free
|
||
|
|
||
|
|
||
|
|
||
|
|
||
4 years ago
|
subroutine glist_initvg(idxmap,ctxt,vg,info)
|
||
14 years ago
|
use psb_penv_mod
|
||
|
use psb_error_mod
|
||
|
implicit none
|
||
|
class(psb_glist_map), intent(inout) :: idxmap
|
||
4 years ago
|
type(psb_ctxt_type), intent(in) :: ctxt
|
||
13 years ago
|
integer(psb_ipk_), intent(in) :: vg(:)
|
||
13 years ago
|
integer(psb_ipk_), intent(out) :: info
|
||
14 years ago
|
! To be implemented
|
||
5 years ago
|
integer(psb_ipk_) :: iam, np
|
||
6 years ago
|
integer(psb_ipk_) :: nl
|
||
|
integer(psb_lpk_) :: i, n
|
||
14 years ago
|
|
||
|
|
||
|
info = 0
|
||
4 years ago
|
call psb_info(ctxt,iam,np)
|
||
14 years ago
|
if (np < 0) then
|
||
4 years ago
|
write(psb_err_unit,*) 'Invalid ctxt'
|
||
14 years ago
|
info = -1
|
||
|
return
|
||
|
end if
|
||
|
n = size(vg)
|
||
|
|
||
|
idxmap%global_rows = n
|
||
|
idxmap%global_cols = n
|
||
|
|
||
|
allocate(idxmap%loc_to_glob(n),idxmap%glob_to_loc(n),&
|
||
|
& idxmap%vgp(n),stat=info)
|
||
|
if (info /= 0) then
|
||
|
info = -2
|
||
|
return
|
||
|
end if
|
||
|
|
||
4 years ago
|
idxmap%ctxt = ctxt
|
||
5 years ago
|
idxmap%state = psb_desc_bld_
|
||
4 years ago
|
idxmap%mpic = psb_get_mpi_comm(ctxt)
|
||
14 years ago
|
|
||
|
nl = 0
|
||
|
do i=1, n
|
||
|
if ((vg(i) > np-1).or.(vg(i) < 0)) then
|
||
|
info=psb_err_partfunc_wrong_pid_
|
||
|
exit
|
||
|
end if
|
||
|
idxmap%vgp(i) = vg(i)
|
||
|
if (vg(i) == iam) then
|
||
|
! this point belongs to me
|
||
|
nl = nl + 1
|
||
|
idxmap%glob_to_loc(i) = nl
|
||
|
idxmap%loc_to_glob(nl) = i
|
||
|
else
|
||
|
idxmap%glob_to_loc(i) = -(np+vg(i)+1)
|
||
|
end if
|
||
|
end do
|
||
|
|
||
|
call idxmap%set_lr(nl)
|
||
|
call idxmap%set_lc(nl)
|
||
|
|
||
|
end subroutine glist_initvg
|
||
|
|
||
3 years ago
|
subroutine glist_fnd_owner(idx,iprc,idxmap,info,adj)
|
||
14 years ago
|
use psb_penv_mod
|
||
|
use psb_sort_mod
|
||
3 years ago
|
use psb_realloc_mod
|
||
14 years ago
|
implicit none
|
||
5 years ago
|
integer(psb_lpk_), intent(in) :: idx(:)
|
||
13 years ago
|
integer(psb_ipk_), allocatable, intent(out) :: iprc(:)
|
||
3 years ago
|
class(psb_glist_map), intent(in) :: idxmap
|
||
5 years ago
|
integer(psb_ipk_), intent(out) :: info
|
||
3 years ago
|
integer(psb_ipk_), optional, allocatable, intent(out) :: adj(:)
|
||
|
|
||
4 years ago
|
type(psb_ctxt_type) :: ctxt
|
||
4 years ago
|
integer(psb_mpk_) :: iam, np
|
||
3 years ago
|
integer(psb_ipk_) :: nadj
|
||
4 years ago
|
integer(psb_lpk_) :: nv, i, ngp
|
||
14 years ago
|
|
||
4 years ago
|
ctxt = idxmap%get_ctxt()
|
||
|
call psb_info(ctxt,iam,np)
|
||
14 years ago
|
nv = size(idx)
|
||
|
allocate(iprc(nv),stat=info)
|
||
|
if (info /= 0) then
|
||
|
write(0,*) 'Memory allocation failure in repl_map_fnd-owner'
|
||
|
return
|
||
|
end if
|
||
|
|
||
|
ngp = size(idxmap%vgp)
|
||
|
do i=1, nv
|
||
13 years ago
|
if ((1<=idx(i)).and.(idx(i)<=ngp)) then
|
||
14 years ago
|
iprc(i) = idxmap%vgp(idx(i))
|
||
|
else
|
||
|
iprc(i) = -1
|
||
|
end if
|
||
|
end do
|
||
|
|
||
3 years ago
|
if (present(adj)) then
|
||
|
adj = iprc
|
||
|
call psb_msort_unique(adj,nadj)
|
||
|
call psb_realloc(nadj,adj,info)
|
||
|
end if
|
||
|
|
||
14 years ago
|
end subroutine glist_fnd_owner
|
||
|
|
||
14 years ago
|
function glist_get_fmt() result(res)
|
||
14 years ago
|
implicit none
|
||
|
character(len=5) :: res
|
||
|
res = 'GLIST'
|
||
|
end function glist_get_fmt
|
||
|
|
||
|
|
||
14 years ago
|
|
||
|
subroutine glist_clone(idxmap,outmap,info)
|
||
|
use psb_penv_mod
|
||
|
use psb_error_mod
|
||
|
use psb_realloc_mod
|
||
|
implicit none
|
||
12 years ago
|
class(psb_glist_map), intent(inout) :: idxmap
|
||
14 years ago
|
class(psb_indx_map), allocatable, intent(out) :: outmap
|
||
13 years ago
|
integer(psb_ipk_), intent(out) :: info
|
||
|
integer(psb_ipk_) :: err_act
|
||
14 years ago
|
character(len=20) :: name='glist_clone'
|
||
|
logical, parameter :: debug=.false.
|
||
|
|
||
|
info = psb_success_
|
||
|
call psb_get_erraction(err_act)
|
||
6 years ago
|
if (allocated(outmap)) then
|
||
|
call outmap%free()
|
||
|
deallocate(outmap,stat=info)
|
||
|
end if
|
||
|
if (info /= 0) then
|
||
|
write(0,*) 'Error: could not cleanup output'
|
||
14 years ago
|
info = -87
|
||
|
goto 9999
|
||
|
end if
|
||
|
|
||
6 years ago
|
|
||
14 years ago
|
allocate(psb_glist_map :: outmap, stat=info)
|
||
|
if (info /= psb_success_) then
|
||
|
info = psb_err_alloc_dealloc_
|
||
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
|
end if
|
||
|
|
||
|
select type (outmap)
|
||
|
type is (psb_glist_map)
|
||
|
|
||
5 years ago
|
call idxmap%psb_indx_map%cpy(outmap%psb_indx_map,info)
|
||
|
if (info == psb_success_) outmap%pnt_h = idxmap%pnt_h
|
||
14 years ago
|
if (info == psb_success_)&
|
||
|
& call psb_safe_ab_cpy(idxmap%loc_to_glob,outmap%loc_to_glob,info)
|
||
|
if (info == psb_success_)&
|
||
|
& call psb_safe_ab_cpy(idxmap%glob_to_loc,outmap%glob_to_loc,info)
|
||
|
if (info == psb_success_)&
|
||
|
& call psb_safe_ab_cpy(idxmap%vgp,outmap%vgp,info)
|
||
|
class default
|
||
|
! This should be impossible
|
||
|
info = -1
|
||
|
end select
|
||
|
|
||
|
if (info /= psb_success_) then
|
||
|
info = psb_err_from_subroutine_
|
||
|
call psb_errpush(info,name)
|
||
|
goto 9999
|
||
|
end if
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
|
||
|
9999 call psb_error_handler(err_act)
|
||
|
|
||
14 years ago
|
return
|
||
|
end subroutine glist_clone
|
||
|
|
||
14 years ago
|
end module psb_glist_map_mod
|