27 integer(kind=kint) :: N
28 real(kind=
kreal),
pointer :: d(:) => null()
29 real(kind=
kreal),
pointer :: al(:) => null()
30 real(kind=
kreal),
pointer :: au(:) => null()
31 integer(kind=kint),
pointer :: indexL(:) => null()
32 integer(kind=kint),
pointer :: indexU(:) => null()
33 integer(kind=kint),
pointer :: itemL(:) => null()
34 integer(kind=kint),
pointer :: itemU(:) => null()
35 real(kind=
kreal),
pointer :: alu(:) => null()
37 integer(kind=kint) :: NColor
38 integer(kind=kint),
pointer :: COLORindex(:) => null()
39 integer(kind=kint),
pointer :: perm(:) => null()
40 integer(kind=kint),
pointer :: iperm(:) => null()
42 logical,
save :: isFirst = .true.
44 logical,
save :: INITIALIZED = .false.
50 real(kind=
kreal),
save :: omega = 1.d0
53 integer(kind=kint),
parameter :: numOfBlockPerThread = 100
54 integer(kind=kint),
save :: numOfThread = 1, numofblock
55 integer(kind=kint),
save,
allocatable :: icToBlockIndex(:)
56 integer(kind=kint),
save,
allocatable :: blockIndexToColorIndex(:)
57 integer(kind=kint),
save :: sectorCacheSize0, sectorCacheSize1
59 integer(kind=kint),
parameter :: SSOR_DEBUG = 0
66 integer(kind=kint ) :: npl, npu
67 integer(kind=kint ) :: ncolor_in
68 real (kind=
kreal) :: omega_inv
69 real (kind=
kreal) :: alutmp(hecmat%NDOF,hecmat%NDOF), pw(hecmat%NDOF)
70 integer(kind=kint ) :: ii, i, j, k, ndof, ndof2
71 integer(kind=kint ) :: nthreads = 1
72 integer(kind=kint ),
allocatable :: perm_tmp(:)
73 real (kind=
kreal) :: t0
75 if (ssor_debug >= 1)
then
77 write(*,*)
'DEBUG: SSOR setup start',
hecmw_wtime()-t0
81 if (hecmat%Iarray(98) == 1)
then
83 else if (hecmat%Iarray(97) == 1)
then
100 omega_inv = 1.d0 / omega
103 allocate(colorindex(0:n), perm_tmp(n), perm(n), iperm(n))
105 hecmat%indexU, hecmat%itemU, perm_tmp, iperm)
106 if (ssor_debug >= 1)
write(*,*)
'DEBUG: RCM ordering done',
hecmw_wtime()-t0
108 hecmat%indexU, hecmat%itemU, perm_tmp, &
109 ncolor_in, ncolor, colorindex, perm, iperm)
110 if (ssor_debug >= 1)
write(*,*)
'DEBUG: MC ordering done',
hecmw_wtime()-t0
114 if (nthreads == 1)
then
116 allocate(colorindex(0:1), perm(n), iperm(n))
124 allocate(colorindex(0:n), perm_tmp(n), perm(n), iperm(n))
126 hecmat%indexU, hecmat%itemU, perm_tmp, iperm)
127 if (ssor_debug >= 1)
write(*,*)
'DEBUG: RCM ordering done',
hecmw_wtime()-t0
129 hecmat%indexU, hecmat%itemU, perm_tmp, &
130 ncolor_in, ncolor, colorindex, perm, iperm)
131 if (ssor_debug >= 1)
write(*,*)
'DEBUG: MC ordering done',
hecmw_wtime()-t0
139 do j=hecmat%indexU(i-1)+1,hecmat%indexU(i)
140 if( hecmat%itemU(j) > n )
exit
144 npl = max(hecmat%indexL(n),npl)
145 npu = hecmat%indexU(n)
146 allocate(indexl(0:n), indexu(0:n), iteml(npl), itemu(npu))
148 hecmat%indexL, hecmat%indexU, hecmat%itemL, hecmat%itemU, &
149 indexl, indexu, iteml, itemu)
150 if (ssor_debug >= 1)
write(*,*)
'DEBUG: reordering profile done',
hecmw_wtime()-t0
153 allocate(d(ndof2*n), al(ndof2*npl), au(ndof2*npu))
155 hecmat%indexL, hecmat%indexU, hecmat%itemL, hecmat%itemU, &
156 hecmat%AL, hecmat%AU, hecmat%D, &
157 indexl, indexu, iteml, itemu, al, au, d)
158 if (ssor_debug >= 1)
write(*,*)
'DEBUG: reordering values done',
hecmw_wtime()-t0
163 allocate(alu(ndof2*n))
180 alutmp(i,j) = alu(ndof2*(ii-1)+(i-1)*ndof+j) * omega_inv
184 alutmp(k,k)= 1.d0/alutmp(k,k)
186 alutmp(i,k)= alutmp(i,k) * alutmp(k,k)
188 pw(j)= alutmp(i,j) - alutmp(i,k)*alutmp(k,j)
197 alu(ndof2*(ii-1)+(i-1)*ndof+j)= alutmp(i,j)
211 hecmat%Iarray(98) = 0
212 hecmat%Iarray(97) = 0
214 if (ssor_debug >= 1)
write(*,*)
'DEBUG: SSOR setup done',
hecmw_wtime()-t0
218 subroutine setup_tuning_parameters(NDOF)
221 integer(kind=kint),
intent(in) :: ndof
222 integer(kind=kint) :: blockindex, elementcount, numofelement, ii
223 real(kind=
kreal) :: numofelementperblock
224 integer(kind=kint) :: ic, i
225 if (ssor_debug >= 1)
write(*,*)
'DEBUG: setting up tuning parameters for SSOR'
230 numofblock = numofthread * numofblockperthread
231 if (
allocated(ictoblockindex))
deallocate(ictoblockindex)
232 if (
allocated(blockindextocolorindex))
deallocate(blockindextocolorindex)
233 allocate (ictoblockindex(0:ncolor), &
234 blockindextocolorindex(0:numofblock + ncolor))
235 numofelement = n + indexl(n) + indexu(n)
236 numofelementperblock = dble(numofelement) / numofblock
239 ictoblockindex(0) = 0
240 blockindextocolorindex = -1
241 blockindextocolorindex(0) = 0
245 do i = colorindex(ic-1)+1, colorindex(ic)
246 elementcount = elementcount + 1
247 elementcount = elementcount + (indexl(i) - indexl(i-1))
248 elementcount = elementcount + (indexu(i) - indexu(i-1))
249 if (elementcount > ii * numofelementperblock &
250 .or. i == colorindex(ic))
then
252 blockindex = blockindex + 1
253 blockindextocolorindex(blockindex) = i
256 ictoblockindex(ic) = blockindex
258 numofblock = blockindex
261 sectorcachesize0, sectorcachesize1 )
262 end subroutine setup_tuning_parameters
266 real(kind=
kreal),
intent(inout) :: zp(:)
267 integer(kind=kint) :: ic, i, iold, j, isl, iel, isu, ieu, k, ndof, ndof2, idof,jdof
268 real(kind=
kreal) :: sw(ndof), x(ndof)
270 real(kind=
kreal) :: omega_fac
273 integer(kind=kint) :: blockindex
278 call setup_tuning_parameters(ndof)
284 omega_fac = 2.d0 - omega
303 do i = colorindex(ic-1)+1, colorindex(ic)
306 do blockindex = ictoblockindex(ic-1)+1, ictoblockindex(ic)
307 do i = blockindextocolorindex(blockindex-1)+1, &
308 blockindextocolorindex(blockindex)
312 sw(idof) = omega_fac * zp(ndof*(iold-1)+idof)
319 x(idof) = zp(ndof*(k-1)+idof)
323 sw(idof) = sw(idof) - al(ndof2*(j-1)+ndof*(idof-1)+jdof)*x(jdof)
331 x(idof) = x(idof) - alu(ndof2*(i-1)+ndof*(idof-1)+jdof )*x(jdof)
334 do idof = ndof, 1, -1
335 do jdof = ndof, idof+1, -1
336 x(idof) = x(idof) - alu(ndof2*(i-1)+ndof*(idof-1)+jdof)*x(jdof)
338 x(idof) = alu(ndof2*(i-1)+(ndof+1)*(idof-1)+1)*x(idof)
340 zp(ndof*(iold-1)+1:ndof*(iold-1)+ndof) = x(1:ndof)
357 do i = colorindex(ic-1)+1, colorindex(ic)
360 do blockindex = ictoblockindex(ic), ictoblockindex(ic-1)+1, -1
361 do i = blockindextocolorindex(blockindex), &
362 blockindextocolorindex(blockindex-1)+1, -1
374 x(idof) = zp(ndof*(k-1)+idof)
378 sw(idof) = sw(idof) + au(ndof2*(j-1)+ndof*(idof-1)+jdof)*x(jdof)
386 x(idof) = x(idof) - alu(ndof2*(i-1)+ndof*(idof-1)+k)*x(k)
389 do idof = ndof, 1, -1
390 do k = ndof, idof+1, -1
391 x(idof) = x(idof) - alu(ndof2*(i-1)+ndof*(idof-1)+k)*x(k)
393 x(idof) = alu(ndof2*(i-1)+(ndof+1)*(idof-1)+1)*x(idof)
397 zp(ndof*(iold-1)+idof) = zp(ndof*(iold-1)+idof) - x(idof)
422 if (
associated(colorindex))
deallocate(colorindex)
423 if (
associated(perm))
deallocate(perm)
424 if (
associated(iperm))
deallocate(iperm)
425 if (
associated(alu))
deallocate(alu)
426 if (
associated(d))
deallocate(d)
427 if (
associated(al))
deallocate(al)
428 if (
associated(au))
deallocate(au)
429 if (
associated(indexl))
deallocate(indexl)
430 if (
associated(indexu))
deallocate(indexu)
431 if (
associated(iteml))
deallocate(iteml)
432 if (
associated(itemu))
deallocate(itemu)
444 initialized = .false.
real(kind=kreal) function, public hecmw_mat_get_omega(hecMAT)
integer(kind=kint) function, public hecmw_mat_get_ncolor_in(hecMAT)
subroutine, public hecmw_matrix_reorder_values(N, NDOF, perm, iperm, indexL, indexU, itemL, itemU, AL, AU, D, indexLp, indexUp, itemLp, itemUp, ALp, AUp, Dp)
subroutine, public hecmw_matrix_reorder_renum_item(N, perm, indexXp, itemXp)
subroutine, public hecmw_matrix_reorder_profile(N, perm, iperm, indexL, indexU, itemL, itemU, indexLp, indexUp, itemLp, itemUp)
subroutine, public hecmw_precond_ssor_nn_setup(hecMAT)
subroutine, public hecmw_precond_ssor_nn_clear(hecMAT)
subroutine, public hecmw_precond_ssor_nn_apply(ZP, NDOF)
subroutine, public hecmw_tuning_fx_calc_sector_cache(N, NDOF, sectorCacheSize0, sectorCacheSize1)
integer(kind=4), parameter kreal
real(kind=kreal) function hecmw_wtime()
subroutine, public hecmw_matrix_ordering_rcm(N, indexL, itemL, indexU, itemU, perm, iperm)
subroutine, public hecmw_matrix_ordering_mc(N, indexL, itemL, indexU, itemU, perm_cur, ncolor_in, ncolor_out, COLORindex, perm, iperm)