Actual source code: ex78.c

  1: #include <petsc.h>

  3: static char help[] = "Exercises switching back and forth between different KSP and KSPHPDDM types.\n\n";

  5: int main(int argc, char **args)
  6: {
  7:   KSP ksp;
  8: #if PetscDefined(HAVE_HPDDM)
  9:   KSPHPDDMType type;
 10:   PetscBool    flg;
 11: #endif
 12:   const char *common[] = {KSPGMRES, KSPCG, KSPPREONLY};

 14:   PetscFunctionBeginUser;
 15:   PetscCall(PetscInitialize(&argc, &args, NULL, help));
 16:   PetscCall(KSPCreate(PETSC_COMM_WORLD, &ksp));
 17:   for (PetscInt i = 0; i < 3; i++) {
 18:     PetscCall(KSPSetType(ksp, common[i]));
 19:     PetscCall(KSPSetType(ksp, KSPHPDDM));
 20: #if PetscDefined(HAVE_HPDDM)
 21:     PetscCall(KSPHPDDMGetType(ksp, &type));
 22:     PetscCall(PetscStrcmp(KSPHPDDMTypes[type], common[i], &flg));
 23:     PetscCheck(flg, PetscObjectComm((PetscObject)ksp), PETSC_ERR_PLIB, "KSPType and KSPHPDDMType do not match: %s != %s", common[i], KSPHPDDMTypes[type]);
 24:     PetscCall(KSPSetFromOptions(ksp));
 25:     PetscCall(KSPHPDDMGetType(ksp, &type));
 26:     PetscCheck(type == KSP_HPDDM_TYPE_GCRODR, PetscObjectComm((PetscObject)ksp), PETSC_ERR_PLIB, "-ksp_hpddm_type gcrodr and KSPHPDDMType do not match: gcrodr != %s", KSPHPDDMTypes[type]);
 27:     PetscCall(KSPHPDDMSetType(ksp, KSP_HPDDM_TYPE_BGMRES));
 28: #endif
 29:   }
 30:   PetscCall(KSPDestroy(&ksp));
 31:   PetscCall(PetscFinalize());
 32:   return 0;
 33: }

 35: /*TEST

 37:    test:
 38:       requires: hpddm
 39:       nsize: 1
 40:       suffix: 1
 41:       output_file: output/empty.out
 42:       args: -ksp_type hpddm -ksp_hpddm_type gcrodr

 44: TEST*/