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.
448 lines
13 KiB
Fortran
448 lines
13 KiB
Fortran
8 years ago
|
!
|
||
|
!
|
||
4 years ago
|
! AMG4PSBLAS version 1.0
|
||
|
! Algebraic Multigrid Package
|
||
8 years ago
|
! based on PSBLAS (Parallel Sparse BLAS version 3.5)
|
||
8 years ago
|
!
|
||
4 years ago
|
! (C) Copyright 2020
|
||
8 years ago
|
!
|
||
7 years ago
|
! Salvatore Filippone
|
||
|
! Pasqua D'Ambra
|
||
4 years ago
|
! Fabio Durastante
|
||
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.
|
||
4 years ago
|
! 3. The name of the AMG4PSBLAS group or the names of its contributors may
|
||
8 years ago
|
! 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
|
||
4 years ago
|
! PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AMG4PSBLAS GROUP OR ITS CONTRIBUTORS
|
||
8 years ago
|
! 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
|
!
|
||
4 years ago
|
! File: amg_s_slu_solver_mod.f90
|
||
14 years ago
|
!
|
||
4 years ago
|
! Module: amg_s_slu_solver_mod
|
||
14 years ago
|
!
|
||
8 years ago
|
! This module defines:
|
||
4 years ago
|
! - the amg_s_slu_solver_type data structure containing the ingredients
|
||
8 years ago
|
! to interface with the SuperLU package.
|
||
|
! 1. The factorization is restricted to the diagonal block of the
|
||
|
! current image.
|
||
14 years ago
|
!
|
||
4 years ago
|
module amg_s_slu_solver
|
||
14 years ago
|
|
||
|
use iso_c_binding
|
||
4 years ago
|
use amg_s_base_solver_mod
|
||
14 years ago
|
|
||
7 years ago
|
#if defined(IPK8)
|
||
12 years ago
|
|
||
4 years ago
|
type, extends(amg_s_base_solver_type) :: amg_s_slu_solver_type
|
||
12 years ago
|
|
||
4 years ago
|
end type amg_s_slu_solver_type
|
||
12 years ago
|
|
||
12 years ago
|
#else
|
||
|
|
||
4 years ago
|
type, extends(amg_s_base_solver_type) :: amg_s_slu_solver_type
|
||
14 years ago
|
type(c_ptr) :: lufactors=c_null_ptr
|
||
|
integer(c_long_long) :: symbsize=0, numsize=0
|
||
|
contains
|
||
13 years ago
|
procedure, pass(sv) :: build => s_slu_solver_bld
|
||
|
procedure, pass(sv) :: apply_a => s_slu_solver_apply
|
||
12 years ago
|
procedure, pass(sv) :: apply_v => s_slu_solver_apply_vect
|
||
13 years ago
|
procedure, pass(sv) :: free => s_slu_solver_free
|
||
5 years ago
|
procedure, pass(sv) :: clear_data => s_slu_solver_clear_data
|
||
13 years ago
|
procedure, pass(sv) :: descr => s_slu_solver_descr
|
||
|
procedure, pass(sv) :: sizeof => s_slu_solver_sizeof
|
||
6 years ago
|
procedure, nopass :: get_fmt => s_slu_solver_get_fmt
|
||
|
procedure, nopass :: get_id => s_slu_solver_get_id
|
||
12 years ago
|
final :: s_slu_solver_finalize
|
||
4 years ago
|
end type amg_s_slu_solver_type
|
||
14 years ago
|
|
||
|
|
||
|
private :: s_slu_solver_bld, s_slu_solver_apply, &
|
||
12 years ago
|
& s_slu_solver_free, s_slu_solver_descr, &
|
||
8 years ago
|
& s_slu_solver_sizeof, s_slu_solver_apply_vect, &
|
||
5 years ago
|
& s_slu_solver_get_fmt, s_slu_solver_get_id, &
|
||
|
& s_slu_solver_clear_data
|
||
12 years ago
|
private :: s_slu_solver_finalize
|
||
|
|
||
14 years ago
|
|
||
|
|
||
|
interface
|
||
4 years ago
|
function amg_sslu_fact(n,nnz,values,rowptr,colind,&
|
||
14 years ago
|
& lufactors)&
|
||
4 years ago
|
& bind(c,name='amg_sslu_fact') result(info)
|
||
14 years ago
|
use iso_c_binding
|
||
|
integer(c_int), value :: n,nnz
|
||
|
integer(c_int) :: info
|
||
|
integer(c_int) :: rowptr(*),colind(*)
|
||
13 years ago
|
real(c_float) :: values(*)
|
||
14 years ago
|
type(c_ptr) :: lufactors
|
||
4 years ago
|
end function amg_sslu_fact
|
||
14 years ago
|
end interface
|
||
|
|
||
|
interface
|
||
4 years ago
|
function amg_sslu_solve(itrans,n,nrhs,b,ldb,lufactors)&
|
||
|
& bind(c,name='amg_sslu_solve') result(info)
|
||
14 years ago
|
use iso_c_binding
|
||
|
integer(c_int) :: info
|
||
12 years ago
|
integer(c_int), value :: itrans,n,nrhs,ldb
|
||
|
real(c_float) :: b(ldb,*)
|
||
14 years ago
|
type(c_ptr), value :: lufactors
|
||
4 years ago
|
end function amg_sslu_solve
|
||
14 years ago
|
end interface
|
||
|
|
||
|
interface
|
||
4 years ago
|
function amg_sslu_free(lufactors)&
|
||
|
& bind(c,name='amg_sslu_free') result(info)
|
||
14 years ago
|
use iso_c_binding
|
||
|
integer(c_int) :: info
|
||
|
type(c_ptr), value :: lufactors
|
||
4 years ago
|
end function amg_sslu_free
|
||
14 years ago
|
end interface
|
||
|
|
||
|
contains
|
||
|
|
||
9 years ago
|
subroutine s_slu_solver_apply(alpha,sv,x,beta,y,desc_data,&
|
||
|
& trans,work,info,init,initu)
|
||
14 years ago
|
use psb_base_mod
|
||
13 years ago
|
implicit none
|
||
14 years ago
|
type(psb_desc_type), intent(in) :: desc_data
|
||
4 years ago
|
class(amg_s_slu_solver_type), intent(inout) :: sv
|
||
14 years ago
|
real(psb_spk_),intent(inout) :: x(:)
|
||
14 years ago
|
real(psb_spk_),intent(inout) :: y(:)
|
||
|
real(psb_spk_),intent(in) :: alpha,beta
|
||
|
character(len=1),intent(in) :: trans
|
||
|
real(psb_spk_),target, intent(inout) :: work(:)
|
||
|
integer, intent(out) :: info
|
||
9 years ago
|
character, intent(in), optional :: init
|
||
|
real(psb_spk_),intent(inout), optional :: initu(:)
|
||
14 years ago
|
|
||
|
integer :: n_row,n_col
|
||
|
real(psb_spk_), pointer :: ww(:)
|
||
|
integer :: ictxt,np,me,i, err_act
|
||
|
character :: trans_
|
||
|
character(len=20) :: name='s_slu_solver_apply'
|
||
|
|
||
|
call psb_erractionsave(err_act)
|
||
|
|
||
|
info = psb_success_
|
||
|
|
||
|
trans_ = psb_toupper(trans)
|
||
|
select case(trans_)
|
||
|
case('N')
|
||
|
case('T','C')
|
||
|
case default
|
||
|
call psb_errpush(psb_err_iarg_invalid_i_,name)
|
||
|
goto 9999
|
||
|
end select
|
||
9 years ago
|
!
|
||
|
! For non-iterative solvers, init and initu are ignored.
|
||
|
!
|
||
14 years ago
|
|
||
14 years ago
|
n_row = desc_data%get_local_rows()
|
||
|
n_col = desc_data%get_local_cols()
|
||
14 years ago
|
|
||
|
if (n_col <= size(work)) then
|
||
|
ww => work(1:n_col)
|
||
|
else
|
||
|
allocate(ww(n_col),stat=info)
|
||
|
if (info /= psb_success_) then
|
||
|
info=psb_err_alloc_request_
|
||
|
call psb_errpush(info,name,i_err=(/n_col,0,0,0,0/),&
|
||
|
& a_err='real(psb_spk_)')
|
||
|
goto 9999
|
||
|
end if
|
||
|
endif
|
||
|
|
||
12 years ago
|
ww(1:n_row) = x(1:n_row)
|
||
14 years ago
|
select case(trans_)
|
||
|
case('N')
|
||
4 years ago
|
info = amg_sslu_solve(0,n_row,1,ww,n_row,sv%lufactors)
|
||
12 years ago
|
case('T')
|
||
4 years ago
|
info = amg_sslu_solve(1,n_row,1,ww,n_row,sv%lufactors)
|
||
12 years ago
|
case('C')
|
||
4 years ago
|
info = amg_sslu_solve(2,n_row,1,ww,n_row,sv%lufactors)
|
||
14 years ago
|
case default
|
||
12 years ago
|
call psb_errpush(psb_err_internal_error_, &
|
||
|
& name,a_err='Invalid TRANS in ILU subsolve')
|
||
14 years ago
|
goto 9999
|
||
|
end select
|
||
|
|
||
12 years ago
|
if (info == psb_success_) &
|
||
|
& call psb_geaxpby(alpha,ww,beta,y,desc_data,info)
|
||
14 years ago
|
|
||
|
|
||
|
if (info /= psb_success_) then
|
||
12 years ago
|
call psb_errpush(psb_err_internal_error_,&
|
||
|
& name,a_err='Error in subsolve')
|
||
14 years ago
|
goto 9999
|
||
|
endif
|
||
|
|
||
|
if (n_col > size(work)) then
|
||
|
deallocate(ww)
|
||
|
endif
|
||
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(err_act)
|
||
14 years ago
|
return
|
||
|
|
||
|
end subroutine s_slu_solver_apply
|
||
12 years ago
|
|
||
9 years ago
|
subroutine s_slu_solver_apply_vect(alpha,sv,x,beta,y,desc_data,&
|
||
7 years ago
|
& trans,work,wv,info,init,initu)
|
||
12 years ago
|
use psb_base_mod
|
||
|
implicit none
|
||
|
type(psb_desc_type), intent(in) :: desc_data
|
||
4 years ago
|
class(amg_s_slu_solver_type), intent(inout) :: sv
|
||
12 years ago
|
type(psb_s_vect_type),intent(inout) :: x
|
||
|
type(psb_s_vect_type),intent(inout) :: y
|
||
|
real(psb_spk_),intent(in) :: alpha,beta
|
||
7 years ago
|
character(len=1),intent(in) :: trans
|
||
12 years ago
|
real(psb_spk_),target, intent(inout) :: work(:)
|
||
7 years ago
|
type(psb_s_vect_type),intent(inout) :: wv(:)
|
||
|
integer, intent(out) :: info
|
||
9 years ago
|
character, intent(in), optional :: init
|
||
|
type(psb_s_vect_type),intent(inout), optional :: initu
|
||
12 years ago
|
|
||
|
integer :: err_act
|
||
|
character(len=20) :: name='s_slu_solver_apply_vect'
|
||
|
|
||
|
call psb_erractionsave(err_act)
|
||
|
|
||
|
info = psb_success_
|
||
9 years ago
|
!
|
||
|
! For non-iterative solvers, init and initu are ignored.
|
||
|
!
|
||
12 years ago
|
|
||
|
call x%v%sync()
|
||
|
call y%v%sync()
|
||
|
call sv%apply(alpha,x%v%v,beta,y%v%v,desc_data,trans,work,info)
|
||
|
call y%v%set_host()
|
||
|
if (info /= 0) goto 9999
|
||
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(err_act)
|
||
12 years ago
|
return
|
||
10 years ago
|
|
||
12 years ago
|
end subroutine s_slu_solver_apply_vect
|
||
14 years ago
|
|
||
8 years ago
|
subroutine s_slu_solver_bld(a,desc_a,sv,info,b,amold,vmold,imold)
|
||
14 years ago
|
|
||
14 years ago
|
use psb_base_mod
|
||
14 years ago
|
|
||
|
Implicit None
|
||
|
|
||
|
! Arguments
|
||
13 years ago
|
type(psb_sspmat_type), intent(in), target :: a
|
||
6 years ago
|
Type(psb_desc_type), Intent(inout) :: desc_a
|
||
4 years ago
|
class(amg_s_slu_solver_type), intent(inout) :: sv
|
||
13 years ago
|
integer, intent(out) :: info
|
||
|
type(psb_sspmat_type), intent(in), target, optional :: b
|
||
|
class(psb_s_base_sparse_mat), intent(in), optional :: amold
|
||
|
class(psb_s_base_vect_type), intent(in), optional :: vmold
|
||
11 years ago
|
class(psb_i_base_vect_type), intent(in), optional :: imold
|
||
14 years ago
|
! Local variables
|
||
|
type(psb_sspmat_type) :: atmp
|
||
9 years ago
|
type(psb_s_csc_sparse_mat) :: acsc
|
||
12 years ago
|
type(psb_s_coo_sparse_mat) :: acoo
|
||
14 years ago
|
integer :: n_row,n_col, nrow_a, nztota
|
||
|
integer :: ictxt,np,me,i, err_act, debug_unit, debug_level
|
||
|
character(len=20) :: name='s_slu_solver_bld', ch_err
|
||
|
|
||
|
info=psb_success_
|
||
|
call psb_erractionsave(err_act)
|
||
|
debug_unit = psb_get_debug_unit()
|
||
|
debug_level = psb_get_debug_level()
|
||
14 years ago
|
ictxt = desc_a%get_context()
|
||
14 years ago
|
call psb_info(ictxt, me, np)
|
||
|
if (debug_level >= psb_debug_outer_) &
|
||
|
& write(debug_unit,*) me,' ',trim(name),' start'
|
||
8 years ago
|
|
||
|
|
||
14 years ago
|
n_row = desc_a%get_local_rows()
|
||
|
n_col = desc_a%get_local_cols()
|
||
8 years ago
|
|
||
|
|
||
|
call a%cscnv(atmp,info,type='coo')
|
||
|
call psb_rwextd(n_row,atmp,info,b=b)
|
||
|
call atmp%cscnv(info,type='coo',dupl=psb_dupl_add_)
|
||
|
nrow_a = atmp%get_nrows()
|
||
|
call atmp%a%csclip(acoo,info,jmax=nrow_a)
|
||
|
call acsc%mv_from_coo(acoo,info)
|
||
|
nztota = acsc%get_nzeros()
|
||
|
! Fix the entries to call C-base SuperLU
|
||
|
acsc%ia(:) = acsc%ia(:) - 1
|
||
|
acsc%icp(:) = acsc%icp(:) - 1
|
||
4 years ago
|
info = amg_sslu_fact(nrow_a,nztota,acsc%val,&
|
||
8 years ago
|
& acsc%icp,acsc%ia,sv%lufactors)
|
||
|
|
||
|
if (info /= psb_success_) then
|
||
|
info=psb_err_from_subroutine_
|
||
4 years ago
|
ch_err='amg_sslu_fact'
|
||
8 years ago
|
call psb_errpush(info,name,a_err=ch_err)
|
||
|
goto 9999
|
||
14 years ago
|
end if
|
||
8 years ago
|
|
||
|
call acsc%free()
|
||
|
call atmp%free()
|
||
14 years ago
|
|
||
|
if (debug_level >= psb_debug_outer_) &
|
||
|
& write(debug_unit,*) me,' ',trim(name),' end'
|
||
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(err_act)
|
||
14 years ago
|
return
|
||
|
end subroutine s_slu_solver_bld
|
||
|
|
||
|
subroutine s_slu_solver_free(sv,info)
|
||
|
|
||
|
Implicit None
|
||
|
|
||
|
! Arguments
|
||
4 years ago
|
class(amg_s_slu_solver_type), intent(inout) :: sv
|
||
14 years ago
|
integer, intent(out) :: info
|
||
|
Integer :: err_act
|
||
|
character(len=20) :: name='s_slu_solver_free'
|
||
|
|
||
|
call psb_erractionsave(err_act)
|
||
|
|
||
5 years ago
|
info = psb_success_
|
||
5 years ago
|
|
||
|
call sv%clear_data(info)
|
||
|
|
||
5 years ago
|
if (info /= psb_success_) goto 9999
|
||
14 years ago
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(err_act)
|
||
|
return
|
||
14 years ago
|
end subroutine s_slu_solver_free
|
||
|
|
||
5 years ago
|
subroutine s_slu_solver_clear_data(sv,info)
|
||
|
|
||
|
Implicit None
|
||
|
|
||
|
! Arguments
|
||
4 years ago
|
class(amg_s_slu_solver_type), intent(inout) :: sv
|
||
5 years ago
|
integer, intent(out) :: info
|
||
|
Integer :: err_act
|
||
|
character(len=20) :: name='s_slu_solver_clear_data'
|
||
|
|
||
|
call psb_erractionsave(err_act)
|
||
|
|
||
|
info = psb_success_
|
||
4 years ago
|
if (c_associated(sv%lufactors)) info = amg_sslu_free(sv%lufactors)
|
||
5 years ago
|
sv%lufactors = c_null_ptr
|
||
|
if (info /= psb_success_) goto 9999
|
||
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
|
9999 call psb_error_handler(err_act)
|
||
|
return
|
||
|
end subroutine s_slu_solver_clear_data
|
||
|
|
||
12 years ago
|
subroutine s_slu_solver_finalize(sv)
|
||
|
|
||
|
Implicit None
|
||
|
|
||
|
! Arguments
|
||
4 years ago
|
type(amg_s_slu_solver_type), intent(inout) :: sv
|
||
12 years ago
|
integer :: info
|
||
|
Integer :: err_act
|
||
|
character(len=20) :: name='s_slu_solver_finalize'
|
||
|
|
||
|
call sv%free(info)
|
||
|
|
||
|
return
|
||
|
|
||
|
end subroutine s_slu_solver_finalize
|
||
|
|
||
14 years ago
|
subroutine s_slu_solver_descr(sv,info,iout,coarse)
|
||
14 years ago
|
|
||
|
Implicit None
|
||
|
|
||
|
! Arguments
|
||
4 years ago
|
class(amg_s_slu_solver_type), intent(in) :: sv
|
||
14 years ago
|
integer, intent(out) :: info
|
||
|
integer, intent(in), optional :: iout
|
||
13 years ago
|
logical, intent(in), optional :: coarse
|
||
14 years ago
|
|
||
|
! Local variables
|
||
|
integer :: err_act
|
||
|
integer :: ictxt, me, np
|
||
4 years ago
|
character(len=20), parameter :: name='amg_s_slu_solver_descr'
|
||
14 years ago
|
integer :: iout_
|
||
|
|
||
|
call psb_erractionsave(err_act)
|
||
|
info = psb_success_
|
||
|
if (present(iout)) then
|
||
|
iout_ = iout
|
||
|
else
|
||
8 years ago
|
iout_ = psb_out_unit
|
||
14 years ago
|
endif
|
||
|
|
||
|
write(iout_,*) ' SuperLU Sparse Factorization Solver. '
|
||
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(err_act)
|
||
14 years ago
|
return
|
||
|
end subroutine s_slu_solver_descr
|
||
|
|
||
|
function s_slu_solver_sizeof(sv) result(val)
|
||
13 years ago
|
|
||
14 years ago
|
implicit none
|
||
|
! Arguments
|
||
4 years ago
|
class(amg_s_slu_solver_type), intent(in) :: sv
|
||
7 years ago
|
integer(psb_epk_) :: val
|
||
14 years ago
|
integer :: i
|
||
|
|
||
7 years ago
|
val = 2*psb_sizeof_ip + psb_sizeof_dp
|
||
14 years ago
|
val = val + sv%symbsize
|
||
|
val = val + sv%numsize
|
||
|
return
|
||
|
end function s_slu_solver_sizeof
|
||
8 years ago
|
|
||
6 years ago
|
function s_slu_solver_get_fmt() result(val)
|
||
8 years ago
|
implicit none
|
||
|
character(len=32) :: val
|
||
|
|
||
|
val = "SuperLU solver"
|
||
6 years ago
|
end function s_slu_solver_get_fmt
|
||
8 years ago
|
|
||
6 years ago
|
function s_slu_solver_get_id() result(val)
|
||
8 years ago
|
implicit none
|
||
|
integer(psb_ipk_) :: val
|
||
|
|
||
4 years ago
|
val = amg_slu_
|
||
6 years ago
|
end function s_slu_solver_get_id
|
||
12 years ago
|
#endif
|
||
4 years ago
|
end module amg_s_slu_solver
|