[petsc-users] matrix free and preconditioner

Barry Smith bsmith at mcs.anl.gov
Tue Mar 22 22:29:50 CDT 2011


  Call MatMFFDSetFromOptions(sys.J); after the MatCreateSNESMF().
  
  Your jacobian_matrix() HAS to call MatAssemblyBegin/End() on the first matrix passed into it (this one passed in will be sys.J) as well as whatever it does for the sys.P matrix.

   If this does not resolve the problem please let us know.

   Barry


On Mar 22, 2011, at 9:46 PM, Kontsantinos Kontzialis wrote:

> Dear all,
> 
> I'm using a matrix free formulation of the Newton-Krylov method.
>     My code is running when I use a constant matrix as a preconditioner.
>     However, when I want to use another matrix (problem specific) I read to the
>     manual that I have to use the -snes_mf_operator option, with 
>     appropriately setting
>     snessetjacobian function. I do that in my code as follows:
>     ierr = MatCreateSNESMF(sys.snes, &sys.J);
>          CHKERRQ(ierr);
>     ierr = SNESSetJacobian(sys.snes, sys.J, sys.P, jacobian_matrix, &sys);
>           CHKERRQ(ierr);
>     I have preallocated space for matrix sys.P, but when I start running I 
>     get the following error:
>     [1]PETSC ERROR: --------------------- Error Message 
>     ------------------------------------
>     [1]PETSC ERROR: Null argument, when expecting valid pointer!
>     [1]PETSC ERROR: Null Object: Parameter # 1!
>     [1]PETSC ERROR: 
>     ------------------------------------------------------------------------
>     [1]PETSC ERROR: Petsc Release Version 3.1.0, Patch 7, Mon Dec 20 
> 
> - Ignored:
>     14:26:37 CST 2010
>     [1]PETSC ERROR: See docs/changes/index.html for recent updates.
>     [1]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
>     [1]PETSC ERROR: See docs/index.html for manual pages.
>     [1]PETSC ERROR: 
>     ------------------------------------------------------------------------
>     [1]PETSC ERROR: ./hoac_forth on a linux-gnu named localhost by 
>     kontzialis Wed Mar 23 04:42:52 2011
>     [1]PETSC ERROR: Libraries linked from 
>     /home/kontzialis/PETSC/petsc-3.1-p7/linux-gnu-c-debug/lib
>     [1]PETSC ERROR: Configure run at Mon Feb 21 14:55:24 2011
>     [1]PETSC ERROR: Configure options --with-debugging=1 --with-cc=mpicc 
>     --with-fc=mpif90 --with-shared=1 --with-shared-libraries --wi[0]PETSC 
>     ERROR: --------------------- Error Message 
>     ------------------------------------
>     [0]PETSC ERROR: Null argument, when expecting valid pointer!
>     [0]PETSC ERROR: Null Object: Parameter # 1!
>     [0]PETSC ERROR: 
>     ------------------------------------------------------------------------
>     [0]PETSC ERROR: Petsc Release Version 3.1.0, Patch 7, Mon Dec 20 
>     14:26:37 CST 2010
>     [0]PETSC ERROR: See docs/changes/index.html for recent updates.
>     [0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
>     [0]PETSC ERROR: See docs/index.html for manual pages.
>     [0]PETSC ERROR: 
>     ------------------------------------------------------------------------
>     [0]PETSC ERROR: ./hoac_forth on a linux-gnu named localhost by 
>     kontzialis Wed Mar 23 04:42:52 2011
>     [0]PETSC ERROR: Libraries linked from 
>     /home/kontzialis/PETSC/petsc-3.1-p7/linux-gnu-c-debug/lib
>     [0]PETSC ERROR: Configure run at Mon Feb 21 14:55:24 2011
>     [0]PETSC ERROR: Configure options --with-debugging=1 --with-cc=mpicc 
>     --with-fc=mpif90 --with-shared=1 --with-shared-libraries 
>     --with-large-file-io=1 --with-precision=double --with-blacs=1 
>     --download-blacs=yes --download-f-blas-lapack=yes --with-plapack=1 
>     --download-plapack=yes --with-scalapack=1 --download-scalapack=yes 
>     --with-superlu=1 --download-superlu=yes --with-superlu_dist=1 
>     --download-superlu_dist=yes --with-ml=1 --download-ml=yes 
>     --with-umfpack=1 --download-umfpack=yes --with-mpi=1 --download-mpich=1 
>     --with-sundials=1 --download-sundials=1 --with-parmetis=1 
>     --download-parmetis=1 --with-hypre=1 --download-hypre=1
>     [1]PETSC ERROR: 
>     ------------------------------------------------------------------------
>     [1]PETSC ERROR: PetscObjectGetComm() line 34 in src/sys/objects/gcomm.c
>     [1]PETSC ERROR: VecNormBegin() line 495 in src/vec/vec/utils/comb.c
>     [1]PETSC ERROR: MatMFFDCompute_WP() line 73 in src/mat/impls/mffd/wp.c
>     [1]PETSC ERROR: MatMult_MFFD() line 315 in src/mat/impls/mffd/mffd.c
>     [1]PETSC ERROR: MatMult() line 1899 in src/mat/interface/matrix.c
>     [1]PETSC ERROR: PCApplyBAorAB() line 585 in src/ksp/pc/interface/precon.c
>     [1]PETSC ERROR: Gth-large-file-io=1 --with-precision=double 
>     --with-blacs=1 --download-blacs=yes --download-f-blas-lapack=yes 
>     --with-plapack=1 --download-plapack=yes --with-scalapack=1 
>     --download-scalapack=yes --with-superlu=1 --download-superlu=yes 
>     --with-superlu_dist=1 --download-superlu_dist=yes --with-ml=1 
>     --download-ml=yes --with-umfpack=1 --download-umfpack=yes --with-mpi=1 
>     --download-mpich=1 --with-sundials=1 --download-sundials=1 
>     --with-parmetis=1 --download-parmetis=1 --with-hypre=1 --download-hypre=1
>     [0]PETSC ERROR: 
>     ------------------------------------------------------------------------
>     [0]PETSC ERROR: PetscObjectGetComm() line 34 in src/sys/objects/gcomm.c
>     [0]PETSC ERROR: VecNormBegin() line 495 in src/vec/vec/utils/comb.c
>     [0]PETSC ERROR: MatMFFDCompute_WP() line 73 in src/mat/impls/mffd/wp.c
>     [0]PETSC ERROR: MatMult_MFFD() line 315 in src/mat/impls/mffd/mffd.c
>     [0]PETSC ERROR: MatMult() line 1899 in src/mat/interface/matrix.c
>     [0]PETSC ERROR: PCApplyBAorAB() line 585 in src/ksp/pc/interface/precon.c
>     [0]PETSC ERROR: GMREScycle() line 161 in src/ksp/ksp/impls/gmres/gmres.c
>     [1]PETSC ERROR: KSPSolve_GMRES() line 241 in src/ksp/ksp/impls/gmres/gmres.c
>     [1]PETSC ERROR: KSPSolve() line 396 in src/ksp/ksp/interface/itfunc.c
>     [1]PETSC ERROR: SNES_KSPSolve() line 2944 in src/snes/interface/snes.c
>     [1]PETSC ERROR: SNESSolve_LS() line 191 in src/snes/impls/ls/ls.c
>     [1]PETSC ERROR: SNESSolve() line 2255 in src/snes/interface/snes.c
>     [1]PETSC ERROR: User provided function() line 33 in 
>     "unknowndirectory/"../crank_nickolson.c
>     [1]PETSC ERROR: User provided function() line 84 in 
>     "unknowndirectory/"../implicit_time.c
>     [1]PETSC ERROR: User provided function() line 1158 in 
>     "unknowndirectory/"../hoac.c
>     MREScycle() line 161 in src/ksp/ksp/impls/gmres/gmres.c
>     [0]PETSC ERROR: KSPSolve_GMRES() line 241 in src/ksp/ksp/impls/gmres/gmres.c
>     [0]PETSC ERROR: KSPSolve() line 396 in src/ksp/ksp/interface/itfunc.c
>     [0]PETSC ERROR: SNES_KSPSolve() line 2944 in src/snes/interface/snes.c
>     [0]PETSC ERROR: SNESSolve_LS() line 191 in src/snes/impls/ls/ls.c
>     [0]PETSC ERROR: SNESSolve() line 2255 in src/snes/interface/snes.c
>     [0]PETSC ERROR: User provided function() line 33 in 
>     "unknowndirectory/"../crank_nickolson.c
>     [0]PETSC ERROR: User provided function() line 84 in 
>     "unknowndirectory/"../implicit_time.c
>     [0]PETSC ERROR: User provided function() line 1158 in 
>     "unknowndirectory/"../hoac.c
>     
>     Please help.
>     
>     Costas
>     
> 
> - Done.
> 
> 
> 
> matrix free and preconditioner.eml
> Subject: matrix free and preconditioner
> From: Kontsantinos Kontzialis <ckontzialis at lycos.com>
> Date: Wed, 23 Mar 2011 04:43:43 +0200
> To: petsc-users-request at mcs.anl.gov
> Dear Petsc team, 
> 
>  I'm using a matrix free formulation of the Newton-Krylov method. 
> My code is running when I use a constant matrix as a preconditioner. 
> However, when I want to use another matrix (problem specific) I read to the 
> manual that I have to use the -snes_mf_operator option, with appropriately setting 
> snessetjacobian function. I do that in my code as follows: 
> 
> ierr = MatCreateSNESMF(sys.snes, &sys.J); 
>     CHKERRQ(ierr); 
> 
> ierr = SNESSetJacobian(sys.snes, sys.J, sys.P, jacobian_matrix, &sys); 
>      CHKERRQ(ierr); 
> 
> I have preallocated space for matrix sys.P, but when I start running I get the following error: 
> 
> [1]PETSC ERROR: --------------------- Error Message ------------------------------------ 
> [1]PETSC ERROR: Null argument, when expecting valid pointer! 
> [1]PETSC ERROR: Null Object: Parameter # 1! 
> [1]PETSC ERROR: ------------------------------------------------------------------------ 
> [1]PETSC ERROR: Petsc Release Version 3.1.0, Patch 7, Mon Dec 20 14:26:37 CST 2010 
> [1]PETSC ERROR: See docs/changes/index.html for recent updates. 
> [1]PETSC ERROR: See docs/faq.html for hints about trouble shooting. 
> [1]PETSC ERROR: See docs/index.html for manual pages. 
> [1]PETSC ERROR: ------------------------------------------------------------------------ 
> [1]PETSC ERROR: ./hoac_forth on a linux-gnu named localhost by kontzialis Wed Mar 23 04:42:52 2011 
> [1]PETSC ERROR: Libraries linked from /home/kontzialis/PETSC/petsc-3.1-p7/linux-gnu-c-debug/lib 
> [1]PETSC ERROR: Configure run at Mon Feb 21 14:55:24 2011 
> [1]PETSC ERROR: Configure options --with-debugging=1 --with-cc=mpicc --with-fc=mpif90 --with-shared=1 --with-shared-libraries --wi[0]PETSC ERROR: --------------------- Error Message ------------------------------------ 
> [0]PETSC ERROR: Null argument, when expecting valid pointer! 
> [0]PETSC ERROR: Null Object: Parameter # 1! 
> [0]PETSC ERROR: ------------------------------------------------------------------------ 
> [0]PETSC ERROR: Petsc Release Version 3.1.0, Patch 7, Mon Dec 20 14:26:37 CST 2010 
> [0]PETSC ERROR: See docs/changes/index.html for recent updates. 
> [0]PETSC ERROR: See docs/faq.html for hints about trouble shooting. 
> [0]PETSC ERROR: See docs/index.html for manual pages. 
> [0]PETSC ERROR: ------------------------------------------------------------------------ 
> [0]PETSC ERROR: ./hoac_forth on a linux-gnu named localhost by kontzialis Wed Mar 23 04:42:52 2011 
> [0]PETSC ERROR: Libraries linked from /home/kontzialis/PETSC/petsc-3.1-p7/linux-gnu-c-debug/lib 
> [0]PETSC ERROR: Configure run at Mon Feb 21 14:55:24 2011 
> [0]PETSC ERROR: Configure options --with-debugging=1 --with-cc=mpicc --with-fc=mpif90 --with-shared=1 --with-shared-libraries --with-large-file-io=1 --with-precision=double --with-blacs=1 --download-blacs=yes --download-f-blas-lapack=yes --with-plapack=1 --download-plapack=yes --with-scalapack=1 --download-scalapack=yes --with-superlu=1 --download-superlu=yes --with-superlu_dist=1 --download-superlu_dist=yes --with-ml=1 --download-ml=yes --with-umfpack=1 --download-umfpack=yes --with-mpi=1 --download-mpich=1 --with-sundials=1 --download-sundials=1 --with-parmetis=1 --download-parmetis=1 --with-hypre=1 --download-hypre=1 
> [1]PETSC ERROR: ------------------------------------------------------------------------ 
> [1]PETSC ERROR: PetscObjectGetComm() line 34 in src/sys/objects/gcomm.c 
> [1]PETSC ERROR: VecNormBegin() line 495 in src/vec/vec/utils/comb.c 
> [1]PETSC ERROR: MatMFFDCompute_WP() line 73 in src/mat/impls/mffd/wp.c 
> [1]PETSC ERROR: MatMult_MFFD() line 315 in src/mat/impls/mffd/mffd.c 
> [1]PETSC ERROR: MatMult() line 1899 in src/mat/interface/matrix.c 
> [1]PETSC ERROR: PCApplyBAorAB() line 585 in src/ksp/pc/interface/precon.c 
> [1]PETSC ERROR: Gth-large-file-io=1 --with-precision=double --with-blacs=1 --download-blacs=yes --download-f-blas-lapack=yes --with-plapack=1 --download-plapack=yes --with-scalapack=1 --download-scalapack=yes --with-superlu=1 --download-superlu=yes --with-superlu_dist=1 --download-superlu_dist=yes --with-ml=1 --download-ml=yes --with-umfpack=1 --download-umfpack=yes --with-mpi=1 --download-mpich=1 --with-sundials=1 --download-sundials=1 --with-parmetis=1 --download-parmetis=1 --with-hypre=1 --download-hypre=1 
> [0]PETSC ERROR: ------------------------------------------------------------------------ 
> [0]PETSC ERROR: PetscObjectGetComm() line 34 in src/sys/objects/gcomm.c 
> [0]PETSC ERROR: VecNormBegin() line 495 in src/vec/vec/utils/comb.c 
> [0]PETSC ERROR: MatMFFDCompute_WP() line 73 in src/mat/impls/mffd/wp.c 
> [0]PETSC ERROR: MatMult_MFFD() line 315 in src/mat/impls/mffd/mffd.c 
> [0]PETSC ERROR: MatMult() line 1899 in src/mat/interface/matrix.c 
> [0]PETSC ERROR: PCApplyBAorAB() line 585 in src/ksp/pc/interface/precon.c 
> [0]PETSC ERROR: GMREScycle() line 161 in src/ksp/ksp/impls/gmres/gmres.c 
> [1]PETSC ERROR: KSPSolve_GMRES() line 241 in src/ksp/ksp/impls/gmres/gmres.c 
> [1]PETSC ERROR: KSPSolve() line 396 in src/ksp/ksp/interface/itfunc.c 
> [1]PETSC ERROR: SNES_KSPSolve() line 2944 in src/snes/interface/snes.c 
> [1]PETSC ERROR: SNESSolve_LS() line 191 in src/snes/impls/ls/ls.c 
> [1]PETSC ERROR: SNESSolve() line 2255 in src/snes/interface/snes.c 
> [1]PETSC ERROR: User provided function() line 33 in "unknowndirectory/"../crank_nickolson.c 
> [1]PETSC ERROR: User provided function() line 84 in "unknowndirectory/"../implicit_time.c 
> [1]PETSC ERROR: User provided function() line 1158 in "unknowndirectory/"../hoac.c 
> MREScycle() line 161 in src/ksp/ksp/impls/gmres/gmres.c 
> [0]PETSC ERROR: KSPSolve_GMRES() line 241 in src/ksp/ksp/impls/gmres/gmres.c 
> [0]PETSC ERROR: KSPSolve() line 396 in src/ksp/ksp/interface/itfunc.c 
> [0]PETSC ERROR: SNES_KSPSolve() line 2944 in src/snes/interface/snes.c 
> [0]PETSC ERROR: SNESSolve_LS() line 191 in src/snes/impls/ls/ls.c 
> [0]PETSC ERROR: SNESSolve() line 2255 in src/snes/interface/snes.c 
> [0]PETSC ERROR: User provided function() line 33 in "unknowndirectory/"../crank_nickolson.c 
> [0]PETSC ERROR: User provided function() line 84 in "unknowndirectory/"../implicit_time.c 
> [0]PETSC ERROR: User provided function() line 1158 in "unknowndirectory/"../hoac.c 
> 
> Please help. 
> 
> Costas 



More information about the petsc-users mailing list