FrontISTR  6.0.0
Large-scale structural analysis program with finit element method
hecmw_MKL_wrapper.F90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
2 ! Copyright (c) 2019 FrontISTR Commons
3 ! This software is released under the MIT License, see LICENSE.txt
4 !-------------------------------------------------------------------------------
6 #ifdef HECMW_WITH_MKL
7 include 'mkl_pardiso.f90'
8 #endif
9 
11  use hecmw_util
12  use m_sparse_matrix
13 
14 #ifdef HECMW_WITH_MKL
15  use mkl_pardiso
16 #endif
17 
18  implicit none
19 
20  private ! default
21  public :: hecmw_mkl_wrapper ! only entry point of Parallel Direct Solver is public
22 
23  logical, save :: INITIALIZED = .false.
24 #ifdef HECMW_WITH_MKL
25  type(MKL_PARDISO_HANDLE) :: pt(64)
26 #endif
27  integer maxfct, mnum, mtype, nrhs, msglvl
28  integer idum(1), i
29  data nrhs /1/, maxfct /1/, mnum /1/
30 
31  integer, save :: iparm(64)
32 
33 contains
34 
35  subroutine hecmw_mkl_wrapper(spMAT, phase_start, solx, istat)
36  implicit none
37  type (sparse_matrix), intent(inout) :: spmat
38  integer(kind=kint), intent(in) :: phase_start
39  integer(kind=kint), intent(out) :: istat
40  real(kind=kreal), pointer, intent(inout) :: solx(:)
41 
42 #ifdef HECMW_WITH_MKL
43 
44  integer(kind=kint) :: myrank, phase
45  real(kind=kreal) :: t2,t3,t4,t5
46 
47  myrank=hecmw_comm_get_rank()
48 
49  if (.not. initialized) then
50  do i=1,64
51  pt(i)%dummy = 0
52  enddo
53  iparm(:) = 0
54  iparm(1) = 1 ! no solver default
55  iparm(2) = 3 ! fill-in reordering from METIS
56  iparm(3) = 1
57  iparm(10) = 13 ! perturb the pivot elements with 1E-13
58  iparm(11) = 1 ! use nonsymmetric permutation and scaling MPS
59  iparm(13) = 1 ! maximum weighted matching algorithm is switched-off
60  iparm(18) = -1
61  iparm(19) = -1
62  msglvl = 0 ! print statistical information
63  if (spmat%loglevel > 1) msglvl = 1
64  initialized = .true.
65  endif
66 
67  if ( phase_start == 1 ) then
68  phase = -1
69  call pardiso(pt, maxfct, mnum, mtype, phase, spmat%N, spmat%A, spmat%IRN, spmat%JCN, idum, &
70  nrhs, iparm, msglvl, spmat%RHS, solx, istat)
71  if (istat < 0) then
72  write(*,*) 'ERROR: MKL returned with error', istat
73  return
74  endif
75 
76  if (spmat%symtype == sparse_matrix_symtype_spd) then
77  mtype = 2
78  else if (spmat%symtype == sparse_matrix_symtype_sym) then
79  mtype = -2
80  else
81  mtype = 11
82  endif
83 
84  ! ANALYSIS
85  t2=hecmw_wtime()
86 
87  phase = 11
88  call pardiso(pt, maxfct, mnum, mtype, phase, spmat%N, spmat%A, spmat%IRN, spmat%JCN, idum, &
89  nrhs, iparm, msglvl, spmat%RHS, solx, istat)
90  if (istat < 0) then
91  write(*,*) 'ERROR: MKL returned with error', istat
92  return
93  endif
94 
95  t3=hecmw_wtime()
96  if (myrank==0 .and. spmat%loglevel > 0) &
97  write(*,'(A)') ' [Pardiso]: Analysis completed.'
98  if (myrank==0 .and. spmat%timelog > 0) &
99  write(*,'(A,f10.3)') ' [Pardiso]: Analysis time(sec)=',t3-t2
100  endif
101 
102  ! FACTORIZATION
103  if ( phase_start .le. 2 ) then
104  t3=hecmw_wtime()
105 
106  phase = 22
107  call pardiso(pt, maxfct, mnum, mtype, phase, spmat%N, spmat%A, spmat%IRN, spmat%JCN, idum, &
108  nrhs, iparm, msglvl, spmat%RHS, solx, istat)
109  if (istat < 0) then
110  write(*,*) 'ERROR: MKL returned with error', istat
111  return
112  endif
113 
114  t4=hecmw_wtime()
115  if (myrank==0 .and. spmat%loglevel > 0) &
116  write(*,'(A)') ' [Pardiso]: Factorization completed.'
117  if (myrank==0 .and. spmat%timelog > 0) &
118  write(*,'(A,f10.3)') ' [Pardiso]: Factorization time(sec)=',t4-t3
119  endif
120 
121  ! SOLUTION
122  t4=hecmw_wtime()
123  phase = 33
124  call pardiso(pt, maxfct, mnum, mtype, phase, spmat%N, spmat%A, spmat%IRN, spmat%JCN, idum, &
125  nrhs, iparm, msglvl, spmat%RHS, solx, istat)
126  if (istat < 0) then
127  write(*,*) 'ERROR: MKL returned with error', istat
128  return
129  endif
130 
131  t5=hecmw_wtime()
132  if (myrank==0 .and. spmat%loglevel > 0) &
133  write(*,'(A)') ' [Pardiso]: Solution completed.'
134  if (myrank==0 .and. spmat%timelog > 0) &
135  write(*,'(A,f10.3)') ' [Pardiso]: Solution time(sec)=',t5-t4
136 
137 #else
138  stop "MKL Pardiso not available"
139 #endif
140  end subroutine hecmw_mkl_wrapper
141 
142 end module m_hecmw_mkl_wrapper
I/O and Utility.
Definition: hecmw_util_f.F90:7
integer(kind=4), parameter kreal
integer(kind=kint) function hecmw_comm_get_rank()
real(kind=kreal) function hecmw_wtime()
This module provides linear equation solver interface for Pardiso.
subroutine, public hecmw_mkl_wrapper(spMAT, phase_start, solx, istat)
This module provides DOF based sparse matrix data structure (CSR and COO)
integer(kind=kint), parameter, public sparse_matrix_symtype_sym
integer(kind=kint), parameter, public sparse_matrix_symtype_spd