FrontISTR  5.7.0
Large-scale structural analysis program with finit element method
hecmw_solver_GMRESR.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 !-------------------------------------------------------------------------------
5 
6 !C***
7 !C*** module hecmw_solver_GMRESR
8 !C***
9 !
11 
12  public :: hecmw_solve_gmresr
13 
14 contains
15  !C
16  !C*** hecmw_solve_GMRESR
17  !C
18  subroutine hecmw_solve_gmresr( hecMESH, hecMAT, ITER, RESID, error, &
19  & Tset, Tsol, Tcomm )
22  use m_hecmw_comm_f
27  use hecmw_precond
29 
30  implicit none
31 
32  type(hecmwst_local_mesh) :: hecmesh
33  type(hecmwst_matrix) :: hecmat
34  integer(kind=kint ), intent(inout):: iter, error
35  real (kind=kreal), intent(inout):: resid, tset, tsol, tcomm
36 
37  integer(kind=kint ) :: n, np, ndof, nndof
38  integer(kind=kint ) :: my_rank
39  integer(kind=kint ) :: iterlog, timelog
40  real(kind=kreal), pointer :: b(:), x(:)
41 
42  integer(kind=kint),dimension(:), allocatable :: idxbfgs
43  real(kind=kreal), dimension(:) , allocatable :: vecr,workpc,tmpvecbfgs,rho,alpha
44  real(kind=kreal), dimension(:,:), allocatable :: u,c,uin,cin,sbfgs,ybfgs
45 
46  integer(kind=kint ) :: maxit, nrest,nbfgs
47 
48  real (kind=kreal) :: tol
49 
50  real (kind=kreal) zero, one
51  parameter( zero = 0.0d+0, one = 1.0d+0 )
52 
53  integer(kind=kint ) :: nrk,i,k,kk,jj,info,ik,iorth,idx,tmpidx,ibfgs
54  integer(kind=kint ) :: irow
55  real (kind=kreal) :: s_time,e_time,s1_time,e1_time
56  real (kind=kreal) :: ldh,ldw,bnrm2,dnrm2,rnorm
57  real (kind=kreal) :: commtime,comptime, coef,coef2,val,vcs,vsn,dtemp,aa,bb,r0,scale,rr
58  integer(kind=kint ) :: estcond
59  real (kind=kreal) :: t_max,t_min,t_avg,t_sd
60 
61 
62  call hecmw_barrier(hecmesh)
63  s_time= hecmw_wtime()
64  !C
65  !C-- INIT.
66  n = hecmat%N
67  np = hecmat%NP
68  ndof = hecmat%NDOF
69  nndof = n * ndof
70  my_rank = hecmesh%my_rank
71  x => hecmat%X
72  b => hecmat%B
73 
74  iterlog = hecmw_mat_get_iterlog( hecmat )
75  timelog = hecmw_mat_get_timelog( hecmat )
76  maxit = hecmw_mat_get_iter( hecmat )
77  tol = hecmw_mat_get_resid( hecmat )
78  nrest = hecmw_mat_get_nrest( hecmat )
79  nbfgs = hecmw_mat_get_nbfgs( hecmat )
80  estcond = hecmw_mat_get_estcond( hecmat )
81 
82  error= 0
83 
84  allocate (vecr(ndof*np))
85  allocate (workpc(ndof*np))
86  allocate (u(ndof*np,nrest))
87  allocate (c(ndof*np,nrest))
88  allocate (uin(ndof*np,nrest))
89  allocate (cin(ndof*np,nrest))
90 
91  if(nbfgs>0)then
92  allocate (tmpvecbfgs(ndof*np))
93  allocate (sbfgs(ndof*np,nbfgs))
94  allocate (ybfgs(ndof*np,nbfgs))
95  allocate (idxbfgs(nbfgs))
96  allocate (rho(nbfgs))
97  allocate (alpha(nbfgs))
98  endif
99 
100  do idx = 1, nbfgs
101  idxbfgs(idx) = idx
102  enddo
103 
104  commtime= 0.d0
105  comptime= 0.d0
106 
107  !C
108  !C-- SCALING
109  call hecmw_solver_scaling_fw(hecmesh, hecmat, tcomm)
110 
111  !C===
112  !C +----------------------+
113  !C | SETUP PRECONDITIONER |
114  !C +----------------------+
115  !C===
116  call hecmw_precond_setup(hecmat, hecmesh, 0)
117 
118 
119  call hecmw_innerproduct_r(hecmesh, ndof, b, b, bnrm2, tcomm)
120  if (bnrm2.eq.0.d0) then
121  iter = 0
122  maxit = 0
123  resid = 0.d0
124  x = 0.d0
125  endif
126 
127  e_time= hecmw_wtime()
128  if (timelog.eq.2) then
129  call hecmw_time_statistics(hecmesh, e_time - s_time, &
130  t_max, t_min, t_avg, t_sd)
131  if (hecmesh%my_rank.eq.0) then
132  write(*,*) 'Time solver setup'
133  write(*,*) ' Max :',t_max
134  write(*,*) ' Min :',t_min
135  write(*,*) ' Avg :',t_avg
136  write(*,*) ' Std Dev :',t_sd
137  endif
138  tset = t_max
139  else
140  tset = e_time - s_time
141  endif
142  !C===
143 
144 
145  call hecmw_barrier(hecmesh)
146  s1_time= hecmw_wtime()
147  iter= 0
148  ibfgs=0
149  outer: do
150 
151  call hecmw_matresid(hecmesh, hecmat, x, b, vecr, tcomm)
152  do i = 1, nrest
153  iter= iter + 1
154 
155  !C Solve M*r = uin(:,1)
156  if (ibfgs == 0)then
157  call hecmw_precond_apply(hecmesh, hecmat, vecr, uin(:,1), workpc, tcomm)
158  else
159  do kk= 1, nndof
160  tmpvecbfgs(kk)= vecr(kk)
161  enddo
162  do k = 1,ibfgs
163  idx = idxbfgs(k)
164  call hecmw_innerproduct_r(hecmesh, ndof, sbfgs(:,idx), ybfgs(:,idx), coef, tcomm)
165  rho(k) = 1.0d0 / coef
166  call hecmw_innerproduct_r(hecmesh, ndof, sbfgs(:,idx), tmpvecbfgs, coef2, tcomm)
167  alpha(k) = rho(k)*coef2
168  do kk= 1, nndof
169  tmpvecbfgs(kk)= tmpvecbfgs(kk) - alpha(k)*ybfgs(kk,idx)
170  enddo
171  enddo
172  call hecmw_precond_apply(hecmesh, hecmat, tmpvecbfgs, uin(:,1), workpc, tcomm)
173  do k = ibfgs,1,-1
174  idx = idxbfgs(k)
175  call hecmw_innerproduct_r(hecmesh, ndof, ybfgs(:,idx), uin(:,1), coef, tcomm)
176  coef2 = rho(k) * coef
177  do kk= 1, nndof
178  uin(kk,1)= uin(kk,1) + (alpha(k)-coef2)*sbfgs(kk,idx)
179  enddo
180  enddo
181  endif
182  !C cin(:,1) = A*uin(:,1)
183  call hecmw_matvec(hecmesh, hecmat, uin(:,1), cin(:,1), tcomm)
184 
185  do iorth = 1, i-1
186  !C c_{i}^T cin_{i}
187  call hecmw_innerproduct_r(hecmesh, ndof, c(:,iorth), cin(:,iorth), coef, tcomm)
188 
189  do kk= 1, nndof
190  cin(kk,iorth+1)= cin(kk,iorth) - coef * c(kk,iorth)
191  uin(kk,iorth+1)= uin(kk,iorth) - coef * u(kk,iorth)
192  enddo
193  enddo
194  call hecmw_innerproduct_r(hecmesh, ndof, cin(:,i), cin(:,i), coef, tcomm)
195  coef = 1.0d0 / dsqrt(coef)
196  do kk= 1, nndof
197  c(kk,i)= coef * cin(kk,i)
198  u(kk,i)= coef * uin(kk,i)
199  enddo
200 
201  call hecmw_innerproduct_r(hecmesh, ndof, c(:,i), vecr, coef, tcomm)
202  do kk= 1, nndof
203  x(kk)= x(kk) + coef*u(kk,i)
204  vecr(kk)= vecr(kk) - coef*c(kk,i)
205  enddo
206 
207  if (nbfgs > 0)then
208  ibfgs = ibfgs + 1
209  if (ibfgs == nbfgs+1)then
210  tmpidx = idxbfgs(1)
211  do kk = 1, nbfgs-1
212  idxbfgs(kk) = idxbfgs(kk+1)
213  enddo
214  idxbfgs(nbfgs) = tmpidx
215  ibfgs = ibfgs - 1
216  endif
217  do kk= 1, nndof
218  ybfgs(kk,idxbfgs(ibfgs))= coef*c(kk,i)
219  sbfgs(kk,idxbfgs(ibfgs))= coef*u(kk,i)
220  enddo
221  endif
222 
223 
224  call hecmw_innerproduct_r(hecmesh, ndof, vecr, vecr, dnrm2, tcomm)
225  resid= dsqrt(dnrm2/bnrm2)
226 
227  !C##### ITERATION HISTORY
228  if (my_rank.eq.0.and.iterlog.eq.1) write (*,'(i7, 1pe16.6)') iter, resid
229  !C#####
230 
231  if ( resid.le.tol ) exit outer
232  if ( iter.gt.maxit ) then
234  exit outer
235  end if
236  end do
237 
238  end do outer
239 
240  call hecmw_solver_scaling_bk(hecmat)
241 
242  !C
243  !C-- INTERFACE data EXCHANGE
244  s_time = hecmw_wtime()
245  !call hecmw_update_m_R (hecMESH, X, hecMAT%NP, hecMAT%NDOF)
246  call hecmw_update_r (hecmesh, x, hecmat%NP, hecmat%NDOF)
247 
248  e_time = hecmw_wtime()
249  tcomm = tcomm + e_time - s_time
250 
251  !deallocate (H, WW, SS)
252  deallocate (vecr)
253  deallocate (workpc)
254  deallocate (u )
255  deallocate (c )
256  deallocate (uin)
257  deallocate (cin)
258  call hecmw_precond_clear(hecmat)
259 
260  e1_time= hecmw_wtime()
261  if (timelog.eq.2) then
262  call hecmw_time_statistics(hecmesh, e1_time - s1_time, &
263  t_max, t_min, t_avg, t_sd)
264  if (hecmesh%my_rank.eq.0) then
265  write(*,*) 'Time solver iterations'
266  write(*,*) ' Max :',t_max
267  write(*,*) ' Min :',t_min
268  write(*,*) ' Avg :',t_avg
269  write(*,*) ' Std Dev :',t_sd
270  endif
271  tsol = t_max
272  else
273  tsol = e1_time - s1_time
274  endif
275 
276  end subroutine hecmw_solve_gmresr
277 
278 end module hecmw_solver_gmresr
hecmw_precond::hecmw_precond_setup
subroutine, public hecmw_precond_setup(hecMAT, hecMESH, sym)
Definition: hecmw_precond.f90:30
hecmw_solver_las::hecmw_matvec
subroutine, public hecmw_matvec(hecMESH, hecMAT, X, Y, COMMtime)
Definition: hecmw_solver_las.f90:43
hecmw_util::hecmw_wtime
real(kind=kreal) function hecmw_wtime()
Definition: hecmw_util_f.F90:549
hecmw_solver_scaling::hecmw_solver_scaling_bk
subroutine, public hecmw_solver_scaling_bk(hecMAT)
Definition: hecmw_solver_scaling.f90:39
hecmw_precond::hecmw_precond_clear
subroutine, public hecmw_precond_clear(hecMAT)
Definition: hecmw_precond.f90:58
hecmw_matrix_misc::hecmw_mat_get_iter
integer(kind=kint) function, public hecmw_mat_get_iter(hecMAT)
Definition: hecmw_matrix_misc.f90:279
hecmw_solver_las
Definition: hecmw_solver_las.f90:6
hecmw_matrix_misc::hecmw_mat_get_timelog
integer(kind=kint) function, public hecmw_mat_get_timelog(hecMAT)
Definition: hecmw_matrix_misc.f90:488
hecmw_solver_gmresr::hecmw_solve_gmresr
subroutine, public hecmw_solve_gmresr(hecMESH, hecMAT, ITER, RESID, error, Tset, Tsol, Tcomm)
Definition: hecmw_solver_GMRESR.f90:20
m_hecmw_comm_f::hecmw_barrier
subroutine hecmw_barrier(hecMESH)
Definition: hecmw_comm_f.F90:15
hecmw_solver_las::hecmw_matresid
subroutine, public hecmw_matresid(hecMESH, hecMAT, X, B, R, COMMtime)
Definition: hecmw_solver_las.f90:95
hecmw_matrix_misc::hecmw_mat_get_nrest
integer(kind=kint) function, public hecmw_mat_get_nrest(hecMAT)
Definition: hecmw_matrix_misc.f90:366
hecmw_matrix_misc::hecmw_mat_get_resid
real(kind=kreal) function, public hecmw_mat_get_resid(hecMAT)
Definition: hecmw_matrix_misc.f90:672
hecmw_solver_misc::hecmw_innerproduct_r
subroutine hecmw_innerproduct_r(hecMESH, ndof, X, Y, sum, COMMtime)
Definition: hecmw_solver_misc.f90:47
hecmw_matrix_misc::hecmw_mat_get_estcond
integer(kind=kint) function, public hecmw_mat_get_estcond(hecMAT)
Definition: hecmw_matrix_misc.f90:443
hecmw_util
I/O and Utility.
Definition: hecmw_util_f.F90:7
hecmw_util::hecmwst_local_mesh
Definition: hecmw_util_f.F90:234
hecmw_solver_scaling
Definition: hecmw_solver_scaling.f90:6
m_hecmw_comm_f
Definition: hecmw_comm_f.F90:6
hecmw_matrix_misc::hecmw_mat_get_iterlog
integer(kind=kint) function, public hecmw_mat_get_iterlog(hecMAT)
Definition: hecmw_matrix_misc.f90:474
hecmw_solver_gmresr
Definition: hecmw_solver_GMRESR.f90:10
hecmw_estimate_condition
Definition: hecmw_estimate_condition.F90:6
hecmw_util::kreal
integer(kind=4), parameter kreal
Definition: hecmw_util_f.F90:16
hecmw_solver_misc::hecmw_time_statistics
subroutine hecmw_time_statistics(hecMESH, time, t_max, t_min, t_avg, t_sd)
Definition: hecmw_solver_misc.f90:269
hecmw_matrix_misc::hecmw_mat_get_nbfgs
integer(kind=kint) function, public hecmw_mat_get_nbfgs(hecMAT)
Definition: hecmw_matrix_misc.f90:380
hecmw_matrix_misc
Definition: hecmw_matrix_misc.f90:6
m_hecmw_solve_error
Definition: hecmw_solve_error.f90:6
hecmw_precond::hecmw_precond_apply
subroutine, public hecmw_precond_apply(hecMESH, hecMAT, R, Z, ZP, COMMtime)
Definition: hecmw_precond.f90:82
hecmw_solver_scaling::hecmw_solver_scaling_fw
subroutine, public hecmw_solver_scaling_fw(hecMESH, hecMAT, COMMtime)
Definition: hecmw_solver_scaling.f90:22
hecmw_solver_misc
Definition: hecmw_solver_misc.f90:6
m_hecmw_solve_error::hecmw_solver_error_noconv_maxit
integer(kind=kint), parameter hecmw_solver_error_noconv_maxit
Definition: hecmw_solve_error.f90:9
hecmw_precond
Definition: hecmw_precond.f90:6
m_hecmw_comm_f::hecmw_update_r
subroutine hecmw_update_r(hecMESH, val, n, m)
Definition: hecmw_comm_f.F90:683
hecmw_util::hecmwst_matrix
Definition: hecmw_util_f.F90:444