[petsc-users] KSP solver increases the solution time
Jose E. Roman
jroman at dsic.upv.es
Wed Apr 27 04:32:27 CDT 2011
El 27/04/2011, a las 09:17, Alejandro Marcos Aragón escribió:
> I understand that, but I'm trying to provide default behavior for the solver because the default one (no parameters) works very bad in my case.
> However, I'm stuck because I can't set the same parameters that I obtain with command line arguments "-pc_type asm -sub_pc_type lu".
>
> Can someone point me where is the error with the following code?
You should call KSPSetOperators before doing all the setup.
Jose
>
> ...
> ...
> PetscInitialize(&argc, &argv,NULL,NULL);
> PetscErrorCode ierr = MatCreate(PETSC_COMM_WORLD,&A_);CHKERR(ierr);
>
> // create linear solver context
> ierr = KSPCreate(PETSC_COMM_WORLD,&ksp_);CHKERR(ierr);
>
> // initial nonzero guess
> ierr = KSPSetInitialGuessNonzero(ksp_,PETSC_TRUE); CHKERR(ierr);
>
> // set runtime options
> ierr = KSPSetFromOptions(ksp_);CHKERR(ierr);
>
> // set the default preconditioner for this program to be ASM
> PC pc;
> ierr = KSPGetPC(ksp_,&pc); CHKERR(ierr);
> ierr = PCSetType(pc, PCASM); CHKERR(ierr);
>
> KSP *subksp; /* array of KSP contexts for local subblocks */
> PetscInt nlocal,first; /* number of local subblocks, first local subblock */
> PC subpc; /* PC context for subblock */
>
> /*
> Call KSPSetUp() to set the block Jacobi data structures (including
> creation of an internal KSP context for each block).
>
> Note: KSPSetUp() MUST be called before PCASMGetSubKSP().
> */
> ierr = KSPSetUp(ksp_);CHKERR(ierr);
>
> /*
> Extract the array of KSP contexts for the local blocks
> */
> ierr = PCASMGetSubKSP(pc,&nlocal,&first,&subksp);CHKERR(ierr);
>
> /*
> Loop over the local blocks, setting various KSP options
> for each block.
> */
> for (int i=0; i<nlocal; i++) {
> ierr = KSPGetPC(subksp[i],&subpc);CHKERR(ierr);
> ierr = PCSetType(subpc,PCLU);CHKERR(ierr);
> }
>
> This is the error I get:
>
> User explicitly sets subdomain solvers.
> [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: yafeq/a.out on a darwin10. named lsmspc26.epfl.ch by aaragon Wed Apr 27 09:14:25 2011
> [0]PETSC ERROR: Libraries linked from /Users/aaragon/Local/lib
> [0]PETSC ERROR: Configure run at Thu Apr 7 17:01:26 2011
> [0]PETSC ERROR: Configure options --prefix=/Users/aaragon/Local --with-mpi-include=/Users/aaragon/Local/include --with-mpi-lib=/Users/aaragon/Local/lib/libmpich.a --with-superlu=1 --with-superlu-include=/Users/aaragon/Local/include/superlu --with-superlu-lib=/Users/aaragon/Local/lib/libsuperlu.a --with-superlu_dist=1 --with-superlu_dist-include=/Users/aaragon/Local/include/superlu_dist --with-superlu_dist-lib=/Users/aaragon/Local/lib/libsuperlu_dist.a --with-parmetis=1 --download-parmetis=ifneeded
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: MatGetVecs() line 7265 in src/mat/interface/matrix.c
> [0]PETSC ERROR: KSPGetVecs() line 806 in src/ksp/ksp/interface/iterativ.c
> [0]PETSC ERROR: KSPSetUp_GMRES() line 94 in src/ksp/ksp/impls/gmres/gmres.c
> [0]PETSC ERROR: KSPSetUp() line 199 in src/ksp/ksp/interface/itfunc.c
> [0]PETSC ERROR: User provided function() line 397 in "unknowndirectory/"/Users/aaragon/Local/include/cpputils/solver.hpp
> [0]PETSC ERROR: --------------------- Error Message ------------------------------------
> [0]PETSC ERROR: Operation done in wrong order!
> [0]PETSC ERROR: Need to call PCSetUP() on PC (or KSPSetUp() on the outer KSP object) before calling here!
> [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: yafeq/a.out on a darwin10. named lsmspc26.epfl.ch by aaragon Wed Apr 27 09:14:25 2011
> [0]PETSC ERROR: Libraries linked from /Users/aaragon/Local/lib
> [0]PETSC ERROR: Configure run at Thu Apr 7 17:01:26 2011
> [0]PETSC ERROR: Configure options --prefix=/Users/aaragon/Local --with-mpi-include=/Users/aaragon/Local/include --with-mpi-lib=/Users/aaragon/Local/lib/libmpich.a --with-superlu=1 --with-superlu-include=/Users/aaragon/Local/include/superlu --with-superlu-lib=/Users/aaragon/Local/lib/libsuperlu.a --with-superlu_dist=1 --with-superlu_dist-include=/Users/aaragon/Local/include/superlu_dist --with-superlu_dist-lib=/Users/aaragon/Local/lib/libsuperlu_dist.a --with-parmetis=1 --download-parmetis=ifneeded
> [0]PETSC ERROR: ------------------------------------------------------------------------
> [0]PETSC ERROR: PCASMGetSubKSP_ASM() line 644 in src/ksp/pc/impls/asm/asm.c
> [0]PETSC ERROR: PCASMGetSubKSP() line 926 in src/ksp/pc/impls/asm/asm.c
> [0]PETSC ERROR: User provided function() line 402 in "unknowndirectory/"/Users/aaragon/Local/include/cpputils/solver.hpp
> [0]PETSC ERROR: --------------------- Error Message ------------------------------------
> [0]PETSC ERROR: Invalid argument!
> [0]PETSC ERROR: Wrong type of 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
>
> and the error continues...
>
More information about the petsc-users
mailing list