[petsc-users] KSP and matrix-free matrix (shell)

Matthew Knepley knepley at gmail.com
Thu Oct 18 17:22:42 CDT 2018


On Thu, Oct 18, 2018 at 12:07 PM Zhang, Hong <hzhang at mcs.anl.gov> wrote:

> When you use shell matrix, i.e., matrix-free, you cannot it as a
> preconditioner. Add option '-pc_type none'.
>

There are some you can use, like -pc_type cheby

   MAtt


> Hong
>
> On Thu, Oct 18, 2018 at 10:57 AM Florian Lindner <mailinglists at xgm.de>
> wrote:
>
>> Hello,
>>
>> I try to use the KSP solver package together with a shell matrix:
>>
>>
>>   MyContext mycontext; // an empty struct, not sure it it's needed?
>>   Mat s;
>>   ierr = MatCreateShell(PETSC_COMM_WORLD, size, size, PETSC_DECIDE,
>> PETSC_DECIDE, &mycontext, &s);
>>   ierr = MatShellSetOperation(s, MATOP_MULT, (void(*)(void))usermult);
>> CHKERRQ(ierr);
>>
>> To simulate a meaningfull usermult, I use MatMult on an actual existing
>> matrix of same dimensions:
>>
>> extern PetscErrorCode usermult(Mat m ,Vec x, Vec y)
>> {
>>   PetscErrorCode ierr = 0;
>>   ierr = MatMult(matrix, x, y);
>>   printf("Call\n");
>>   return ierr;
>> }
>>
>> Btw, what is the significance of the Mat m argument here?
>>
>> matrix is created like:
>>
>>   ierr = MatCreate(PETSC_COMM_WORLD, &matrix); CHKERRQ(ierr);
>>   ierr = MatSetSizes(matrix, size, size, PETSC_DECIDE, PETSC_DECIDE);
>> CHKERRQ(ierr);
>>   ierr = MatSetFromOptions(matrix); CHKERRQ(ierr);
>>   ierr = MatSetUp(matrix); CHKERRQ(ierr);
>>
>>
>>   MatMult(s, b, x);
>>
>> works. The usermult function is called.
>>
>> But trying to use a KSP gives an error:
>>
>>   KSP solver;
>>   KSPCreate(PETSC_COMM_WORLD, &solver);
>>   KSPSetFromOptions(solver);
>>   KSPSetOperators(solver, s, s);
>>
>>
>> error:
>>
>> [0]PETSC ERROR: --------------------- Error Message
>> --------------------------------------------------------------
>> [0]PETSC ERROR: See
>> http://www.mcs.anl.gov/petsc/documentation/linearsolvertable.html for
>> possible LU and Cholesky solvers
>> [0]PETSC ERROR: Could not locate a solver package. Perhaps you must
>> ./configure with --download-<package>
>> [0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html
>> for trouble shooting.
>> [0]PETSC ERROR: Petsc Release Version 3.9.3, unknown
>> [0]PETSC ERROR: ./a.out on a arch-linux2-c-opt named asaru by lindnefn
>> Thu Oct 18 17:39:52 2018
>> [0]PETSC ERROR: Configure options --with-debugging=0 COPTFLAGS="-O3
>> -march=native -mtune=native" CXXOPTFLAGS="-O3 -march=native -mtune=native"
>> FOPTFLAGS="-O3 -march=native -mtune=native" --download-petsc4py
>> --download-mpi4py --with-mpi-dir=/opt/mpich
>> [0]PETSC ERROR: #1 MatGetFactor() line 4328 in
>> /home/lindnefn/software/petsc/src/mat/interface/matrix.c
>> [0]PETSC ERROR: #2 PCSetUp_ILU() line 142 in
>> /home/lindnefn/software/petsc/src/ksp/pc/impls/factor/ilu/ilu.c
>> [0]PETSC ERROR: #3 PCSetUp() line 923 in
>> /home/lindnefn/software/petsc/src/ksp/pc/interface/precon.c
>> [0]PETSC ERROR: #4 KSPSetUp() line 381 in
>> /home/lindnefn/software/petsc/src/ksp/ksp/interface/itfunc.c
>> [0]PETSC ERROR: #5 KSPSolve() line 612 in
>> /home/lindnefn/software/petsc/src/ksp/ksp/interface/itfunc.c
>>
>> Do I need to MatShellSetOperations additional operations? Like
>> MATOP_ILUFACTOR? How can I know what operations to implement?
>>
>> Best Thanks,
>> Florian
>>
>>
>>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20181018/7d6cc19f/attachment.html>


More information about the petsc-users mailing list