Skip to content

Commit af81bf2

Browse files
committed
Documentation
1 parent 29341cb commit af81bf2

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

docs/examples.jl

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ IV = map(row_partition) do row_indices
144144
end
145145
I,V
146146
end
147-
I,V = tuple_of_arrays(IV)
148-
b = pvector(I,V,row_partition) |> fetch
147+
II,VV = tuple_of_arrays(IV)
148+
b = pvector(II,VV,row_partition) |> fetch
149149

150150

151151
# Compute the system matrix
@@ -183,6 +183,31 @@ IterativeSolvers.cg!(x,A,b)
183183
r = A*x - b
184184
norm(r)
185185

186+
# Imagine, that we want to create the system several times
187+
# (e.g., in a nonlinear solver). We can use the key-word argument `reuse`
188+
# to enable efficient re-construction of the matrix/vector.
189+
190+
b,cacheb = pvector(II,VV,row_partition,reuse=true) |> fetch
191+
A,cacheA= psparse(I,J,V,row_partition,col_partition,reuse=true) |> fetch;
192+
193+
# Now modify the values. For example:
194+
195+
V = map(i->2*i,V)
196+
197+
#
198+
199+
VV = map(i->2*i,VV)
200+
201+
# Update the matrix and the vector accordingly:
202+
203+
pvector!(b,VV,cacheb) |> wait
204+
psparse!(A,V,cacheA) |> wait
205+
206+
# The solution should be the same as before in this case.
207+
208+
r = A*x - b
209+
norm(r)
210+
186211

187212

188213

0 commit comments

Comments
 (0)