Thanks for your help! Using -pc_type none makes it working so far. > Where the hell is the variable "matrix"? Is it a global variable?? If yes - > don't do that.
Yes, it's a global matrix and as I said, I just use it simulate a meaningful matrix-vector product in my 30 lines test program. Best Thanks, Florian Am 18.10.18 um 17:56 schrieb Florian Lindner: > 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 > >