Date: 2026-06-01T23:13:27+00:00

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 defined(PETSC_HAVE_HPDDM)
      9:   KSPHPDDMType type;
     10:   PetscBool    flg;
     11: #endif
     12:   PetscInt    i;
     13:   const char *common[] = {KSPGMRES, KSPCG, KSPPREONLY};

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

     36: /*TEST

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

     45: TEST*/