Actual source code: ex45.c

  1: /*
  2:    Creates a DMShell and uses it with a KSP
  3:    This tests that the KSP object can still create vectors using the Mat object

  5:    Contributed by Lawrence Mitchell as part of pull request 221

  7: */
  8: #include <petscdm.h>
  9: #include <petscdmshell.h>
 10: #include <petscksp.h>
 11: int main(int argc, char **argv)
 12: {
 13:     Mat            A;
 14:     KSP            ksp;
 15:     DM             shell;
 16:     Vec            *left, *right;
 17:     MPI_Comm       c;

 19:     PetscInitialize(&argc, &argv, NULL, NULL);
 20:     c = PETSC_COMM_WORLD;

 22:     MatCreate(c, &A);
 23:     MatSetSizes(A, 1, 1, PETSC_DECIDE, PETSC_DECIDE);
 24:     MatSetFromOptions(A);
 25:     MatSetUp(A);
 26:     KSPCreate(c, &ksp);
 27:     KSPSetOperators(ksp, A, A);
 28:     KSPSetFromOptions(ksp);
 29:     DMShellCreate(c, &shell);
 30:     DMSetFromOptions(shell);
 31:     DMSetUp(shell);
 32:     KSPSetDM(ksp, shell);

 34:     KSPCreateVecs(ksp, 1, &right, 1, &left);
 35:     VecView(right[0], PETSC_VIEWER_STDOUT_(c));
 36:     VecDestroyVecs(1,&right);
 37:     VecDestroyVecs(1,&left);

 39:     DMDestroy(&shell);
 40:     KSPDestroy(&ksp);
 41:     MatDestroy(&A);
 42:     PetscFinalize();
 43:     return 0;
 44: }

 46: /*TEST

 48:    test:

 50: TEST*/