[petsc-users] reuse of KSP is sometimes harmful

Cristian Tibirna ctibirna at giref.ulaval.ca
Fri Jan 28 14:28:05 CST 2011


Hello

We use PETSc-2.3.3-p15 (long story...) embedded inside a large FE code from 
which it would be difficult for me to extract exact PETSc code. Sorry for 
this. But we have a rather ugly problem and I would like to know just if it is 
our use or there might be some intrinsic problem.

What we do, in principle, is 
1) create a KSP, a Mat and some Vec
2) start a loop (e.g. a home-made nonlinear solver)
	inside the loop:
	2.1)  reassemble Mat either through one of two variants:
		a) sometimes the nonzero structure is constant
			only the assembled values are changing
		b) sometimes the nonzero structure changes too,
			which brings us to create and use a new Mat
	2.2) reassemble the rhs Vec
	2.3) on fait un KSPSetOperators avec
	2.4) solve the system and get the solution (or correction)

NOTE: As you see, the KSP is created only once then reused.
NOTE: the point b) -- the main issue of this email -- consists most usually of 
a MatPtAP operation, which naturally gives us a new Mat with new non-zero 
structure.

If we do the above with the variant a), all works perfectly.
if we do the variant b), the solution is completely aberant.

The only workaround we found was to recreate the KSP at each iteration in the 
loop. Then the solution vector is correctly computed.

What gives?

-- 
Cristian Tibirna				(1-418-) 656-2131 / 4340
  Laval University - Quebec, CAN ... http://www.giref.ulaval.ca/~ctibirna
  Research professional at GIREF ... ctibirna at giref.ulaval.ca


More information about the petsc-users mailing list