I'm a bit confused. Since the C KSPSolve() always resets the counter to zero I don't understand why the Python call (which presumably calls the C version doesn't get it reset). Or does the python version not call the C version.
I'm fine with either solution I guess but I'd like to understand why the C behavior doesn't just automatically happen with the Python. Barry > On Mar 4, 2019, at 12:07 AM, Lisandro Dalcin <dalc...@gmail.com> wrote: > > I pushed the fix to branch dalcinl/fix-ksp-ex100 > > On Mon, 4 Mar 2019 at 09:01, Lisandro Dalcin <dalc...@gmail.com> wrote: > 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. <bsm...@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@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 > > > -- > 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