[petsc-users] Inquiry about the preconditioner setup of KSP.

Jed Brown jed at jedbrown.org
Tue Mar 3 22:46:48 CST 2020


Xiaodong Liu <xliu29 at ncsu.edu> writes:

> Thanks  a lot.  I am transferring  a dense matrix from Julia to Petsc.
> I will check this.
> In addition, could you please show me where is
>
>  Where is the subroutine for the GMRES solver, namely,
>   ierr=(*KSP->ops->solve)(ksp);

$ git grep KSPSolve_GMRES
src/docs/tex/manual/developers.tex:\item Names of implementations of class functions should begin with the function name, an underscore, and the name of the implementation, for example, \lstinline{KSPSolve_GMRES()}.
src/ksp/ksp/impls/gmres/gmres.c:PetscErrorCode KSPSolve_GMRES(KSP ksp)
src/ksp/ksp/impls/gmres/gmres.c:  ksp->ops->solve                        = KSPSolve_GMRES;


>
> Xiaodong Liu, PhD
> X: Computational Physics Division
> Los Alamos National Laboratory
> P.O. Box 1663,
> Los Alamos, NM 87544
> 505-709-0534
>
>
> On Tue, Mar 3, 2020 at 8:21 PM Jed Brown <jed at jedbrown.org> wrote:
>
>> Is it possible that Julia is transferring the matrix to PETSc as a dense
>> matrix (storing the nonzeros) instead of preserving sparsity?  If you
>> store the zeros, then ILU will be allowed to fill those entries, thereby
>> becoming LU.
>>
>> Xiaodong Liu <xliu29 at ncsu.edu> writes:
>>
>> > I am trying to use Julia to call Petsc.
>> > 1) First, I run the built-in example ex2.c
>> >
>> https://www.mcs.anl.gov/petsc/petsc-current/src/ksp/pc/examples/tutorials/ex2.c.html
>> >
>> > For this case,  I tried KSPGMRES , initial zero solution and different PC
>> > (LU, ILU, ICC, JACOBI). And they work as expected.
>> >
>> >  75: KSPSetType(ksp,KSPGMRES);
>> >  76: KSPSetInitialGuessNonzero(ksp,PETSC_FALSE);
>> >  87: KSPGetPC(ksp,&pc);
>> >  88: PCSetType(pc,PCICC);
>> >
>> > 2) Second, I tried to call KSP from Julia using the same matrix and right
>> > hand side as ex2.c . A wrapper has been written to call Petsc code from
>> > Julia. After I transfer matrix to from Julia to Petsc, I checked the
>> matrix
>> > and preconditioner matrix in the context of Petsc. These two matrices are
>> > right. For no preconditioner,Jacobi precontioner and LU, the residual for
>> > Julia version is same as that of original Petsc one for every iteration.
>> > However, for ILU preconditioner, the residual for Julia is alwaysthe same
>> > as the LU one. This is not expected. For both Julia and original Petsc
>> > version, I checked the PC type inside the subroutine PCSetType and the
>> > types are correct, namely ilu.I am trying to dig into the source code to
>> > check how the preconditioner is interacting with GMRES.
>> >
>> > Where is the subroutine for the GMRES solver, namely,
>> >  ierr=(*KSP->ops->solve)(ksp);
>> >
>> > Or do you have any suggestions?
>> >
>> > Thanks,
>> >
>> > Xiaodong Liu, PhD
>> > X: Computational Physics Division
>> > Los Alamos National Laboratory
>> > P.O. Box 1663,
>> > Los Alamos, NM 87544
>> > 505-709-0534
>>


More information about the petsc-users mailing list