@@ -13,41 +13,38 @@ struct MultiLevel{S, Pre, Post, TA, TP, TR, TW}
13
13
workspace:: TW
14
14
end
15
15
16
- struct MultiLevelWorkspace{TX , bs}
17
- coarse_xs:: Vector{TX }
18
- coarse_bs:: Vector{TX }
19
- res_vecs:: Vector{TX }
16
+ struct MultiLevelWorkspace{T , bs}
17
+ coarse_xs:: Vector{Vector{Vector{T}} }
18
+ coarse_bs:: Vector{Vector{Vector{T}} }
19
+ res_vecs:: Vector{Vector{Vector{T}} }
20
20
end
21
21
function MultiLevelWorkspace (:: Type{Val{bs}} , :: Type{T} ) where {bs, T<: Number }
22
- if bs === 1
23
- TX = Vector{T}
24
- else
25
- TX = Matrix{T}
26
- end
27
- MultiLevelWorkspace {TX, bs} (TX[], TX[], TX[])
22
+ MultiLevelWorkspace {T, bs} ( Vector{Vector{Vector{T}}}[],
23
+ Vector{Vector{Vector{T}}}[],
24
+ Vector{Vector{Vector{T}}}[])
28
25
end
29
- Base. eltype (w:: MultiLevelWorkspace{TX } ) where TX = eltype (TX)
30
- blocksize (w:: MultiLevelWorkspace{TX , bs} ) where {TX , bs} = bs
26
+ Base. eltype (w:: MultiLevelWorkspace{T } ) where T = T
27
+ blocksize (w:: MultiLevelWorkspace{T , bs} ) where {T , bs} = bs
31
28
32
- function residual! (m:: MultiLevelWorkspace{TX , bs} , n) where {TX , bs}
29
+ function residual! (m:: MultiLevelWorkspace{T , bs} , n) where {T , bs}
33
30
if bs === 1
34
- push! (m. res_vecs, TX (undef, n))
31
+ push! (m. res_vecs, [ Vector {T} (undef, n) for _ in 1 : nthreads ()] )
35
32
else
36
- push! (m. res_vecs, TX (undef, n, bs))
33
+ push! (m. res_vecs, [ Vector {T} (undef, n, bs) for _ in 1 : nthreads ()] )
37
34
end
38
35
end
39
- function coarse_x! (m:: MultiLevelWorkspace{TX , bs} , n) where {TX , bs}
36
+ function coarse_x! (m:: MultiLevelWorkspace{T , bs} , n) where {T , bs}
40
37
if bs === 1
41
- push! (m. coarse_xs, TX (undef, n))
38
+ push! (m. coarse_xs, [ Vector {T} (undef, n) for _ in 1 : nthreads ()] )
42
39
else
43
- push! (m. coarse_xs, TX (undef, n, bs))
40
+ push! (m. coarse_xs, [ Vector {T} (undef, n, bs) for _ in 1 : nthreads ()] )
44
41
end
45
42
end
46
- function coarse_b! (m:: MultiLevelWorkspace{TX , bs} , n) where {TX , bs}
43
+ function coarse_b! (m:: MultiLevelWorkspace{T , bs} , n) where {T , bs}
47
44
if bs === 1
48
- push! (m. coarse_bs, TX (undef, n))
45
+ push! (m. coarse_bs, [ Vector {T} (undef, n) for _ in 1 : nthreads ()] )
49
46
else
50
- push! (m. coarse_bs, TX (undef, n, bs))
47
+ push! (m. coarse_bs, [ Vector {T} (undef, n, bs) for _ in 1 : nthreads ()] )
51
48
end
52
49
end
53
50
@@ -150,7 +147,7 @@ function solve!(x, ml::MultiLevel, b::AbstractArray{T},
150
147
tol:: Float64 = 1e-5 ,
151
148
verbose:: Bool = false ,
152
149
log:: Bool = false ,
153
- calculate_residual = true ) where {T}
150
+ calculate_residual = false ) where {T}
154
151
155
152
A = length (ml) == 1 ? ml. final_A : ml. levels[1 ]. A
156
153
V = promote_type (eltype (A), eltype (b))
@@ -187,14 +184,14 @@ function __solve!(x, ml, v::V, b, lvl)
187
184
A = ml. levels[lvl]. A
188
185
ml. presmoother (A, x, b)
189
186
190
- res = ml. workspace. res_vecs[lvl]
187
+ res = ml. workspace. res_vecs[lvl][ threadid ()]
191
188
mul! (res, A, x)
192
189
reshape (res, size (b)) .= b .- reshape (res, size (b))
193
190
194
- coarse_b = ml. workspace. coarse_bs[lvl]
191
+ coarse_b = ml. workspace. coarse_bs[lvl][ threadid ()]
195
192
mul! (coarse_b, ml. levels[lvl]. R, res)
196
193
197
- coarse_x = ml. workspace. coarse_xs[lvl]
194
+ coarse_x = ml. workspace. coarse_xs[lvl][ threadid ()]
198
195
coarse_x .= 0
199
196
if lvl == length (ml. levels)
200
197
ml. coarse_solver (coarse_x, coarse_b)
0 commit comments