[petsc-dev] KSPMonitor and petsc4py
Lisandro Dalcin
dalcinl at gmail.com
Mon Mar 4 00:01:13 CST 2019
Well, this is just because the Python code implementing KSPSolve does not
reset the iteration counter to zero. This was an oversight on my part when
I wrote that code ages ago.
Barry, I'm wondering whether this should be done at the interface rather
than implementation level? If you do not want to change things in core KSP
(and then maybe SNES, etc), the the following patch should fix things.
diff --git a/src/ksp/ksp/examples/tutorials/example100.py
b/src/ksp/ksp/examples/tutorials/example100.py
index ef085522bf..7ad03ec194 100644
--- a/src/ksp/ksp/examples/tutorials/example100.py
+++ b/src/ksp/ksp/examples/tutorials/example100.py
@@ -119,11 +119,13 @@ class ConjGrad(object):
def solve(self, ksp, b, x):
LOG('ConjGrad.solve()')
+ ksp.setIterationNumber(0)
A, P = get_op_pc(ksp, transpose=False)
pcg(ksp, A, P, b, x, *self.work)
def solveTranspose(self, ksp, b, x):
LOG('ConjGrad.solveTranspose()')
+ ksp.setIterationNumber(0)
A, P = get_op_pc(ksp, transpose=True)
pcg(ksp, A, P, b, x, *self.work)
On Mon, 4 Mar 2019 at 06:15, Smith, Barry F. <bsmith at mcs.anl.gov> wrote:
>
> Pierre,
>
> I can confirm the problem.
>
> Lisandro,
>
> Could you please take a look at this? I have no explanation for why
> this would happen.
>
> Barry
>
>
>
> > On Feb 25, 2019, at 1:21 PM, Pierre Jolivet via petsc-dev <
> petsc-dev at mcs.anl.gov> wrote:
> >
> > I’m not sure this is the expected behavior. Is it?
> > $ git diff ex100.py
> > diff --git a/src/ksp/ksp/examples/tutorials/ex100.py
> b/src/ksp/ksp/examples/tutorials/ex100.py
> > index dbb3f8e012..051637ce1d 100644
> > --- a/src/ksp/ksp/examples/tutorials/ex100.py
> > +++ b/src/ksp/ksp/examples/tutorials/ex100.py
> > @@ -29,6 +29,7 @@ def RunTest():
> > ksp.setOperators(A, A)
> > ksp.setFromOptions()
> > ksp.solve(b, x)
> > + ksp.solve(b, x)
> >
> > r = b.duplicate()
> > A.mult(x, r)
> >
> > $ mpirun -np 8 python ./ex100.py -ksp_converged_reason -ksp_monitor
> > 0 KSP Residual norm 5.101520253035e-04
> > 1 KSP Residual norm 1.168905135944e-03
> > [..]
> > 12 KSP Residual norm 5.101520253035e-05
> > 13 KSP Residual norm 7.504522604366e-20
> > Linear solve converged due to CONVERGED_RTOL iterations 13
> > 13 KSP Residual norm 5.101520253035e-04
> > 14 KSP Residual norm 1.168905135944e-03
> > [..]
> > 25 KSP Residual norm 5.101520253035e-05
> > 26 KSP Residual norm 7.504522604366e-20
> > Linear solve converged due to CONVERGED_RTOL iterations 26
> >
> > Shouldn’t the iterate number be reset to 0 for the 2nd KSPSolve?
> >
> > Thanks,
> > Pierre
>
>
--
Lisandro Dalcin
============
Research Scientist
Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
Extreme Computing Research Center (ECRC)
King Abdullah University of Science and Technology (KAUST)
http://ecrc.kaust.edu.sa/
4700 King Abdullah University of Science and Technology
al-Khawarizmi Bldg (Bldg 1), Office # 0109
Thuwal 23955-6900, Kingdom of Saudi Arabia
http://www.kaust.edu.sa
Office Phone: +966 12 808-0459
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20190304/24a225a3/attachment.html>
More information about the petsc-dev
mailing list