Actual source code: ex34.c


  2: static char help[] = "Tests solving linear system with KSPFGMRES + PCSOR (omega != 1) on a matrix obtained from MatTransposeMatMult.\n\n";

  4: #include <petscksp.h>

  6: int main(int argc, char **args)
  7: {
  8:   Mat       A, Ad, B;
  9:   PetscInt  N = 10, M = 3;
 10:   PetscBool no_inodes = PETSC_TRUE, flg;
 11:   KSP       ksp;
 12:   PC        pc;
 13:   Vec       x, y;
 14:   char      mtype[256];

 17:   PetscInitialize(&argc, &args, (char *)0, help);
 18:   PetscOptionsGetInt(NULL, NULL, "-N", &N, NULL);
 19:   PetscOptionsGetInt(NULL, NULL, "-M", &M, NULL);
 20:   PetscOptionsGetString(NULL, NULL, "-mtype", mtype, sizeof(mtype), &flg);
 21:   PetscOptionsGetBool(NULL, NULL, "-no_inodes", &no_inodes, NULL);
 22:   MatCreateDense(PETSC_COMM_WORLD, PETSC_DECIDE, PETSC_DECIDE, M, N, NULL, &Ad);
 23:   MatSetRandom(Ad, NULL);
 24:   MatConvert(Ad, flg ? mtype : MATAIJ, MAT_INITIAL_MATRIX, &A);
 25:   MatProductCreate(A, A, NULL, &B);
 26:   MatProductSetType(B, MATPRODUCT_AtB);
 27:   MatProductSetAlgorithm(B, "default");
 28:   MatProductSetFill(B, PETSC_DEFAULT);
 29:   MatProductSetFromOptions(B);
 30:   MatProductSymbolic(B);
 31:   if (no_inodes) MatSetOption(B, MAT_USE_INODES, PETSC_FALSE);
 32:   MatProductNumeric(B);
 33:   MatTransposeMatMultEqual(A, A, B, 10, &flg);
 34:   if (!flg) PetscPrintf(PETSC_COMM_WORLD, "Wrong MatTransposeMat");
 35:   KSPCreate(PETSC_COMM_WORLD, &ksp);
 36:   KSPSetOperators(ksp, B, B);
 37:   KSPGetPC(ksp, &pc);
 38:   PCSetType(pc, PCSOR);
 39:   PCSORSetOmega(pc, 1.1);
 40:   KSPSetUp(ksp);
 41:   KSPView(ksp, NULL);
 42:   KSPGetPC(ksp, &pc);
 43:   MatCreateVecs(B, &y, &x);
 44:   VecSetRandom(x, NULL);
 45:   PCApply(pc, x, y);
 46:   KSPDestroy(&ksp);
 47:   VecDestroy(&x);
 48:   VecDestroy(&y);
 49:   MatDestroy(&B);
 50:   MatDestroy(&Ad);
 51:   MatDestroy(&A);
 52:   PetscFinalize();
 53:   return 0;
 54: }

 56: /*TEST

 58:     test:
 59:       nsize: 1
 60:       suffix: 1

 62:     test:
 63:       nsize: 1
 64:       suffix: 1_mpiaij
 65:       args: -mtype mpiaij

 67:     test:
 68:       nsize: 3
 69:       suffix: 2

 71: TEST*/