@@ -137,8 +137,8 @@ contains
137
137
module subroutine factorize_ssor_dense_${s}$(A, w, L, D)
138
138
${t}$, intent(in) :: A(:,:)
139
139
${t}$, intent(in) :: w
140
- ${t}$, intent(out ) :: L(:,:)
141
- ${t}$, intent(out ) :: D(:)
140
+ ${t}$, intent(inout ) :: L(:,:)
141
+ ${t}$, intent(inout ) :: D(:)
142
142
143
143
integer(ilp) :: i, j, n
144
144
${t}$ :: inv_w
@@ -164,8 +164,8 @@ contains
164
164
module subroutine factorize_ssor_csr_${s}$(A, w, L, D)
165
165
type(CSR_${s}$_type), intent(in) :: A
166
166
${t}$, intent(in) :: w
167
- type(CSR_${s}$_type), intent(out ) :: L
168
- ${t}$, intent(out ) :: D(:)
167
+ type(CSR_${s}$_type), intent(inout ) :: L
168
+ ${t}$, intent(inout ) :: D(:)
169
169
170
170
integer(ilp) :: i, j, n
171
171
${t}$ :: inv_w
@@ -204,8 +204,8 @@ contains
204
204
#:for k, t, s in R_KINDS_TYPES
205
205
module subroutine factorize_ldlt_dense_${s}$(A, L, D)
206
206
${t}$, intent(in) :: A(:,:)
207
- ${t}$, intent(out ) :: L(:,:)
208
- ${t}$, intent(out ) :: D(:)
207
+ ${t}$, intent(inout ) :: L(:,:)
208
+ ${t}$, intent(inout ) :: D(:)
209
209
210
210
${t}$:: auxsum
211
211
integer(ilp) :: i, j, k, n
@@ -244,67 +244,43 @@ contains
244
244
#:for k, t, s in R_KINDS_TYPES
245
245
module subroutine factorize_ldlt_csr_${s}$(A, L, D)
246
246
type(CSR_${s}$_type), intent(in) :: A
247
- type(CSR_${s}$_type), intent(out ) :: L
248
- ${t}$, intent(out ) :: D(:)
247
+ type(CSR_${s}$_type), intent(inout ) :: L
248
+ ${t}$, intent(inout ) :: D(:)
249
249
250
- ${t}$:: auxsum
251
- integer(ilp) :: i, j, k, n, p, q
252
-
253
- integer, allocatable :: col_to_pos(:)
254
- ${t}$, allocatable :: temp(:)
255
-
256
- allocate(col_to_pos(n), source=-1)
257
- allocate(temp(n),source=zero_${s}$)
250
+ ${t}$:: aux_diag, nondiag
251
+ integer(ilp) :: i, j, k, m, n, p, q, r, ad1, ad2
258
252
259
- n = A%nrows
260
- do i = 1, n
261
- ! Zero the temp workspace
262
- temp = zero_${s}$
263
-
264
- ! Load row i into temp (lower triangle only)
265
- do p = A%rowptr(i), A%rowptr(i+1) - 1
266
- j = A%col(p)
267
- if (j > i) cycle
268
- temp(j) = A%data(p)
269
- col_to_pos(j) = p ! map column to position in L%data
270
- end do
253
+ D = zero_${s}$
254
+ L%data = zero_${s}$
271
255
272
- ! Compute L(i, k) * D(k) * L(i, k) contributions
273
- do p = A%rowptr(i), A%rowptr(i+1) - 1
274
- k = A%col(p)
275
- if (k >= i) exit
276
-
277
- auxsum = temp(k)
278
-
279
- ! Compute L(i, 1:k-1) ⋅ D(1:k-1) ⋅ L(k, 1:k-1)
280
- do q = A%rowptr(k), A%rowptr(k+1) - 1
281
- j = A%col(q)
282
- if (j >= k) exit
283
- auxsum = auxsum - L%data(col_to_pos(j)) * D(j) * L%data(q)
284
- end do
285
-
286
- L%data(p) = auxsum / D(k)
287
- temp(k) = zero_${s}$ ! Clear temp slot
288
- end do
289
-
290
- ! Compute D(i)
291
- auxsum = temp(i)
292
- do p = A%rowptr(i), A%rowptr(i+1) - 1
293
- k = A%col(p)
294
- if (k >= i) exit
295
- auxsum = auxsum - L%data(p)**2 * D(k)
296
- end do
297
-
298
- D(i) = merge( auxsum, one_${s}$ , auxsum > zero_${s}$)
299
-
300
- ! Set L(i, i) = 1.0
301
- L%data(col_to_pos(i)) = one_${s}$
302
-
303
- ! Reset col_to_pos map
304
- do p = A%rowptr(i), A%rowptr(i+1) - 1
305
- col_to_pos(A%col(p)) = -1
256
+ select case(A%storage)
257
+ case(sparse_lower)
258
+ do i = 1, A%nrows
259
+ ad1 = A%rowptr(i)
260
+ ad2 = A%rowptr(i+1)-1
261
+ L%data(ad2) = one_${s}$
262
+ aux_diag = zero_${s}$
263
+ do m = ad1, ad2-1
264
+ j = A%col(m)
265
+ nondiag = A%data(m)
266
+ q = ad1
267
+ do p = A%rowptr(j), A%rowptr(j+1)-2
268
+ k = A%col(p)
269
+ do r = q, m-1
270
+ n = A%col(r)
271
+ if( k == n ) then
272
+ nondiag = nondiag - L%data(r)*L%data(p)*D(k) ! Aij - Lik Ljk Dk
273
+ q = r + 1
274
+ end if
275
+ end do
276
+ end do
277
+ L%data(m) = nondiag / D(j) ! Lij = (Aij - Lik Ljk Dk)/Dj
278
+ aux_diag = aux_diag + (L%data(m) * nondiag)
279
+ end do
280
+ D(i) = A%data(ad2) - aux_diag ! Dj = Ajj - Ljk^2 Dk
281
+ if (D(i) <= zero_${s}$) D(i)= one_${s}$
306
282
end do
307
- end do
283
+ end select
308
284
end subroutine
309
285
310
286
#:endfor
0 commit comments