"Mark F. Adams" <[email protected]> writes:
> I pushed a pull request to fix this.  You should not fail here but you
> should always use KSPSetFromOptions anyway.

Amended PR and merged to 'next'.

Mark, relative to your patch, I simplified setting and took out the
now-unnecessary logic in PCSetFromOptions_GAMG.

commit bd94a7aa4cff05a8b49c3b8be9fd5e557f431631
Author: Jed Brown <[email protected]>
Date:   Wed Oct 16 18:45:43 2013 -0400

    PCGAMG: set default type (AGG); PCSetUp_GAMG crashes if not set
    
    If PCSetFromOptions had not been called, PCSetUp_GAMG would crash due to
    missing subtype.  It is more conventional with top-level objects to use
    a lazy choice of type, but there is no great setup involved, and no
    known order-dependence, so it looks safe to simply set the type to the
    default value (AGG) up-front.
    
    Reported-by: Einar Sørheim <[email protected]>
    Based-on-patch-by: Mark Adams <[email protected]>

diff --git a/src/ksp/pc/impls/gamg/gamg.c b/src/ksp/pc/impls/gamg/gamg.c
index 39b3ac4..dadb0e2 100644
--- a/src/ksp/pc/impls/gamg/gamg.c
+++ b/src/ksp/pc/impls/gamg/gamg.c
@@ -1275,12 +1275,11 @@ PetscErrorCode PCSetFromOptions_GAMG(PC pc)
   {
     /* -pc_gamg_type */
     {
-      char tname[256] = PCGAMGAGG;
-      const char *deftype = pc_gamg->gamg_type_name ? pc_gamg->gamg_type_name 
: tname;
-      ierr = PetscOptionsList("-pc_gamg_type","Type of AMG 
method","PCGAMGSetType",GAMGList, tname, tname, sizeof(tname), 
&flag);CHKERRQ(ierr);
+      char tname[256];
+      ierr = PetscOptionsList("-pc_gamg_type","Type of AMG 
method","PCGAMGSetType",GAMGList, pc_gamg->gamg_type_name, tname, 
sizeof(tname), &flag);CHKERRQ(ierr);
       /* call PCCreateGAMG_XYZ */
-      if (flag || !pc_gamg->gamg_type_name) {
-        ierr = PCGAMGSetType(pc, flag ? tname : deftype);CHKERRQ(ierr);
+      if (flag) {
+        ierr = PCGAMGSetType(pc,tname);CHKERRQ(ierr);
       }
     }
     /* -pc_gamg_verbose */
@@ -1468,7 +1467,8 @@ PETSC_EXTERN PetscErrorCode PCCreate_GAMG(PC pc)
 #endif
   }
 #endif
-
+  /* PCSetUp_GAMG assumes that the type has been set, so set it to the default 
now */
+  ierr = PCGAMGSetType(pc,PCGAMGAGG);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 

Attachment: pgpsMkROYIAXE.pgp
Description: PGP signature

Reply via email to