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.
454 lines
14 KiB
Fortran
454 lines
14 KiB
Fortran
8 years ago
|
!
|
||
|
!
|
||
7 years ago
|
! MLD2P4 version 2.2
|
||
8 years ago
|
! MultiLevel Domain Decomposition Parallel Preconditioners Package
|
||
8 years ago
|
! based on PSBLAS (Parallel Sparse BLAS version 3.5)
|
||
8 years ago
|
!
|
||
7 years ago
|
! (C) Copyright 2008-2018
|
||
8 years ago
|
!
|
||
7 years ago
|
! Salvatore Filippone
|
||
|
! Pasqua D'Ambra
|
||
|
! Daniela di Serafino
|
||
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 MLD2P4 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 MLD2P4 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
|
!
|
||
4 years ago
|
! File: amg_d_umf_solver_mod.f90
|
||
14 years ago
|
!
|
||
4 years ago
|
! Module: amg_d_umf_solver_mod
|
||
14 years ago
|
!
|
||
8 years ago
|
! This module defines:
|
||
4 years ago
|
! - the amg_d_umf_solver_type data structure containing the ingredients
|
||
8 years ago
|
! to interface with the UMFPACK package.
|
||
|
! 1. The factorization is restricted to the diagonal block of the
|
||
|
! current image.
|
||
14 years ago
|
!
|
||
4 years ago
|
module amg_d_umf_solver
|
||
14 years ago
|
|
||
|
use iso_c_binding
|
||
4 years ago
|
use amg_d_base_solver_mod
|
||
14 years ago
|
|
||
7 years ago
|
#if defined(IPK8)
|
||
4 years ago
|
type, extends(amg_d_base_solver_type) :: amg_d_umf_solver_type
|
||
12 years ago
|
|
||
4 years ago
|
end type amg_d_umf_solver_type
|
||
12 years ago
|
|
||
12 years ago
|
#else
|
||
12 years ago
|
|
||
4 years ago
|
type, extends(amg_d_base_solver_type) :: amg_d_umf_solver_type
|
||
14 years ago
|
type(c_ptr) :: symbolic=c_null_ptr, numeric=c_null_ptr
|
||
|
integer(c_long_long) :: symbsize=0, numsize=0
|
||
|
contains
|
||
13 years ago
|
procedure, pass(sv) :: build => d_umf_solver_bld
|
||
|
procedure, pass(sv) :: apply_a => d_umf_solver_apply
|
||
12 years ago
|
procedure, pass(sv) :: apply_v => d_umf_solver_apply_vect
|
||
13 years ago
|
procedure, pass(sv) :: free => d_umf_solver_free
|
||
5 years ago
|
procedure, pass(sv) :: clear_data => d_umf_solver_clear_data
|
||
13 years ago
|
procedure, pass(sv) :: descr => d_umf_solver_descr
|
||
|
procedure, pass(sv) :: sizeof => d_umf_solver_sizeof
|
||
6 years ago
|
procedure, nopass :: get_fmt => d_umf_solver_get_fmt
|
||
|
procedure, nopass :: get_id => d_umf_solver_get_id
|
||
12 years ago
|
final :: d_umf_solver_finalize
|
||
4 years ago
|
end type amg_d_umf_solver_type
|
||
14 years ago
|
|
||
|
|
||
|
private :: d_umf_solver_bld, d_umf_solver_apply, &
|
||
12 years ago
|
& d_umf_solver_free, d_umf_solver_descr, &
|
||
8 years ago
|
& d_umf_solver_sizeof, d_umf_solver_apply_vect, &
|
||
5 years ago
|
& d_umf_solver_get_fmt, d_umf_solver_get_id, &
|
||
|
& d_umf_solver_clear_data
|
||
12 years ago
|
private :: d_umf_solver_finalize
|
||
|
|
||
14 years ago
|
|
||
|
|
||
|
interface
|
||
4 years ago
|
function amg_dumf_fact(n,nnz,values,rowind,colptr,&
|
||
14 years ago
|
& symptr,numptr,ssize,nsize)&
|
||
4 years ago
|
& bind(c,name='amg_dumf_fact') result(info)
|
||
14 years ago
|
use iso_c_binding
|
||
|
integer(c_int), value :: n,nnz
|
||
|
integer(c_int) :: info
|
||
|
integer(c_long_long) :: ssize, nsize
|
||
|
integer(c_int) :: rowind(*),colptr(*)
|
||
12 years ago
|
real(c_double) :: values(*)
|
||
14 years ago
|
type(c_ptr) :: symptr, numptr
|
||
4 years ago
|
end function amg_dumf_fact
|
||
14 years ago
|
end interface
|
||
|
|
||
|
interface
|
||
4 years ago
|
function amg_dumf_solve(itrans,n,x, b, ldb, numptr)&
|
||
|
& bind(c,name='amg_dumf_solve') result(info)
|
||
14 years ago
|
use iso_c_binding
|
||
|
integer(c_int) :: info
|
||
|
integer(c_int), value :: itrans,n,ldb
|
||
12 years ago
|
real(c_double) :: x(*), b(ldb,*)
|
||
14 years ago
|
type(c_ptr), value :: numptr
|
||
4 years ago
|
end function amg_dumf_solve
|
||
14 years ago
|
end interface
|
||
|
|
||
|
interface
|
||
4 years ago
|
function amg_dumf_free(symptr, numptr)&
|
||
|
& bind(c,name='amg_dumf_free') result(info)
|
||
14 years ago
|
use iso_c_binding
|
||
|
integer(c_int) :: info
|
||
|
type(c_ptr), value :: symptr, numptr
|
||
4 years ago
|
end function amg_dumf_free
|
||
14 years ago
|
end interface
|
||
|
|
||
|
contains
|
||
|
|
||
9 years ago
|
subroutine d_umf_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_d_umf_solver_type), intent(inout) :: sv
|
||
14 years ago
|
real(psb_dpk_),intent(inout) :: x(:)
|
||
14 years ago
|
real(psb_dpk_),intent(inout) :: y(:)
|
||
|
real(psb_dpk_),intent(in) :: alpha,beta
|
||
|
character(len=1),intent(in) :: trans
|
||
|
real(psb_dpk_),target, intent(inout) :: work(:)
|
||
|
integer, intent(out) :: info
|
||
9 years ago
|
character, intent(in), optional :: init
|
||
|
real(psb_dpk_),intent(inout), optional :: initu(:)
|
||
14 years ago
|
|
||
|
integer :: n_row,n_col
|
||
|
real(psb_dpk_), pointer :: ww(:)
|
||
|
integer :: ictxt,np,me,i, err_act
|
||
|
character :: trans_
|
||
|
character(len=20) :: name='d_umf_solver_apply'
|
||
9 years ago
|
|
||
14 years ago
|
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_dpk_)')
|
||
|
goto 9999
|
||
|
end if
|
||
|
endif
|
||
|
|
||
|
select case(trans_)
|
||
|
case('N')
|
||
4 years ago
|
info = amg_dumf_solve(0,n_row,ww,x,n_row,sv%numeric)
|
||
12 years ago
|
case('T')
|
||
|
!
|
||
|
! Note: with UMF, 1 meand Ctranspose, 2 means transpose
|
||
|
! even for complex data.
|
||
|
!
|
||
|
if (psb_d_is_complex_) then
|
||
4 years ago
|
info = amg_dumf_solve(2,n_row,ww,x,n_row,sv%numeric)
|
||
12 years ago
|
else
|
||
4 years ago
|
info = amg_dumf_solve(1,n_row,ww,x,n_row,sv%numeric)
|
||
12 years ago
|
end if
|
||
|
case('C')
|
||
4 years ago
|
info = amg_dumf_solve(1,n_row,ww,x,n_row,sv%numeric)
|
||
14 years ago
|
case default
|
||
|
call psb_errpush(psb_err_internal_error_,name,a_err='Invalid TRANS in ILU subsolve')
|
||
|
goto 9999
|
||
|
end select
|
||
|
|
||
|
if (info == psb_success_) call psb_geaxpby(alpha,ww,beta,y,desc_data,info)
|
||
|
|
||
|
|
||
|
if (info /= psb_success_) then
|
||
|
call psb_errpush(psb_err_internal_error_,name,a_err='Error in subsolve')
|
||
|
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 d_umf_solver_apply
|
||
|
|
||
9 years ago
|
subroutine d_umf_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_d_umf_solver_type), intent(inout) :: sv
|
||
12 years ago
|
type(psb_d_vect_type),intent(inout) :: x
|
||
|
type(psb_d_vect_type),intent(inout) :: y
|
||
|
real(psb_dpk_),intent(in) :: alpha,beta
|
||
7 years ago
|
character(len=1),intent(in) :: trans
|
||
12 years ago
|
real(psb_dpk_),target, intent(inout) :: work(:)
|
||
7 years ago
|
type(psb_d_vect_type),intent(inout) :: wv(:)
|
||
12 years ago
|
integer, intent(out) :: info
|
||
9 years ago
|
character, intent(in), optional :: init
|
||
|
type(psb_d_vect_type),intent(inout), optional :: initu
|
||
12 years ago
|
|
||
|
integer :: err_act
|
||
|
character(len=20) :: name='d_umf_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
|
||
|
|
||
|
end subroutine d_umf_solver_apply_vect
|
||
|
|
||
8 years ago
|
subroutine d_umf_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_dspmat_type), intent(in), target :: a
|
||
6 years ago
|
Type(psb_desc_type), Intent(inout) :: desc_a
|
||
4 years ago
|
class(amg_d_umf_solver_type), intent(inout) :: sv
|
||
13 years ago
|
integer, intent(out) :: info
|
||
|
type(psb_dspmat_type), intent(in), target, optional :: b
|
||
|
class(psb_d_base_sparse_mat), intent(in), optional :: amold
|
||
|
class(psb_d_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_dspmat_type) :: atmp
|
||
|
type(psb_d_csc_sparse_mat) :: acsc
|
||
|
integer :: n_row,n_col, nrow_a, nztota
|
||
|
integer :: ictxt,np,me,i, err_act, debug_unit, debug_level
|
||
|
character(len=20) :: name='d_umf_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'
|
||
|
|
||
|
|
||
14 years ago
|
n_row = desc_a%get_local_rows()
|
||
|
n_col = desc_a%get_local_cols()
|
||
14 years ago
|
|
||
8 years ago
|
call a%cscnv(atmp,info,type='coo')
|
||
|
call psb_rwextd(n_row,atmp,info,b=b)
|
||
|
call atmp%cscnv(info,type='csc',dupl=psb_dupl_add_)
|
||
|
call atmp%mv_to(acsc)
|
||
|
nrow_a = acsc%get_nrows()
|
||
|
nztota = acsc%get_nzeros()
|
||
|
! Fix the entres to call C-base UMFPACK.
|
||
|
acsc%ia(:) = acsc%ia(:) - 1
|
||
|
acsc%icp(:) = acsc%icp(:) - 1
|
||
4 years ago
|
info = amg_dumf_fact(nrow_a,nztota,acsc%val,&
|
||
8 years ago
|
& acsc%ia,acsc%icp,sv%symbolic,sv%numeric,&
|
||
|
& sv%symbsize,sv%numsize)
|
||
|
|
||
|
if (info /= psb_success_) then
|
||
|
info=psb_err_from_subroutine_
|
||
4 years ago
|
ch_err='amg_dumf_fact'
|
||
8 years ago
|
call psb_errpush(info,name,a_err=ch_err)
|
||
12 years ago
|
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 d_umf_solver_bld
|
||
|
|
||
|
subroutine d_umf_solver_free(sv,info)
|
||
|
|
||
|
Implicit None
|
||
|
|
||
|
! Arguments
|
||
4 years ago
|
class(amg_d_umf_solver_type), intent(inout) :: sv
|
||
14 years ago
|
integer, intent(out) :: info
|
||
|
Integer :: err_act
|
||
|
character(len=20) :: name='d_umf_solver_free'
|
||
|
|
||
|
call psb_erractionsave(err_act)
|
||
|
|
||
5 years ago
|
call sv%clear_data(info)
|
||
14 years ago
|
|
||
|
if (info /= psb_success_) goto 9999
|
||
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
10 years ago
|
9999 call psb_error_handler(err_act)
|
||
14 years ago
|
return
|
||
|
end subroutine d_umf_solver_free
|
||
|
|
||
5 years ago
|
|
||
|
subroutine d_umf_solver_clear_data(sv,info)
|
||
|
|
||
|
Implicit None
|
||
|
|
||
|
! Arguments
|
||
4 years ago
|
class(amg_d_umf_solver_type), intent(inout) :: sv
|
||
5 years ago
|
integer, intent(out) :: info
|
||
|
Integer :: err_act
|
||
|
character(len=20) :: name='d_umf_solver_clear_data'
|
||
|
|
||
|
call psb_erractionsave(err_act)
|
||
|
info = 0
|
||
|
if (c_associated(sv%symbolic).and.c_associated(sv%numeric)) then
|
||
4 years ago
|
info = amg_dumf_free(sv%symbolic,sv%numeric)
|
||
5 years ago
|
|
||
|
if (info /= psb_success_) goto 9999
|
||
|
sv%symbolic = c_null_ptr
|
||
|
sv%numeric = c_null_ptr
|
||
|
sv%symbsize = 0
|
||
|
sv%numsize = 0
|
||
|
end if
|
||
|
|
||
|
call psb_erractionrestore(err_act)
|
||
|
return
|
||
|
|
||
|
9999 call psb_error_handler(err_act)
|
||
|
return
|
||
|
end subroutine d_umf_solver_clear_data
|
||
|
|
||
12 years ago
|
subroutine d_umf_solver_finalize(sv)
|
||
|
|
||
|
Implicit None
|
||
|
|
||
|
! Arguments
|
||
4 years ago
|
type(amg_d_umf_solver_type), intent(inout) :: sv
|
||
12 years ago
|
integer :: info
|
||
|
Integer :: err_act
|
||
|
character(len=20) :: name='d_umf_solver_finalize'
|
||
|
|
||
|
call sv%free(info)
|
||
|
|
||
|
return
|
||
|
|
||
|
end subroutine d_umf_solver_finalize
|
||
|
|
||
14 years ago
|
subroutine d_umf_solver_descr(sv,info,iout,coarse)
|
||
14 years ago
|
|
||
|
Implicit None
|
||
|
|
||
|
! Arguments
|
||
4 years ago
|
class(amg_d_umf_solver_type), intent(in) :: sv
|
||
14 years ago
|
integer, intent(out) :: info
|
||
|
integer, intent(in), optional :: iout
|
||
14 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_d_umf_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_,*) ' UMFPACK 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 d_umf_solver_descr
|
||
|
|
||
|
function d_umf_solver_sizeof(sv) result(val)
|
||
13 years ago
|
|
||
14 years ago
|
implicit none
|
||
|
! Arguments
|
||
4 years ago
|
class(amg_d_umf_solver_type), intent(in) :: sv
|
||
7 years ago
|
integer(psb_epk_) :: val
|
||
14 years ago
|
integer :: i
|
||
|
|
||
7 years ago
|
val = 2*psb_sizeof_lp
|
||
14 years ago
|
val = val + sv%symbsize
|
||
|
val = val + sv%numsize
|
||
|
return
|
||
|
end function d_umf_solver_sizeof
|
||
8 years ago
|
|
||
6 years ago
|
function d_umf_solver_get_fmt() result(val)
|
||
8 years ago
|
implicit none
|
||
|
character(len=32) :: val
|
||
|
|
||
|
val = "UMFPACK solver"
|
||
6 years ago
|
end function d_umf_solver_get_fmt
|
||
8 years ago
|
|
||
6 years ago
|
function d_umf_solver_get_id() result(val)
|
||
8 years ago
|
implicit none
|
||
|
integer(psb_ipk_) :: val
|
||
|
|
||
4 years ago
|
val = amg_umf_
|
||
6 years ago
|
end function d_umf_solver_get_id
|
||
12 years ago
|
#endif
|
||
4 years ago
|
end module amg_d_umf_solver
|