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>
12: int main(int argc, char **argv)
13: {
14: Mat A;
15: KSP ksp;
16: DM shell;
17: Vec *left, *right;
18: MPI_Comm c;
20: PetscFunctionBeginUser;
21: PetscCall(PetscInitialize(&argc, &argv, NULL, NULL));
22: c = PETSC_COMM_WORLD;
24: PetscCall(MatCreate(c, &A));
25: PetscCall(MatSetSizes(A, 1, 1, PETSC_DECIDE, PETSC_DECIDE));
26: PetscCall(MatSetFromOptions(A));
27: PetscCall(MatSetUp(A));
28: PetscCall(KSPCreate(c, &ksp));
29: PetscCall(KSPSetOperators(ksp, A, A));
30: PetscCall(KSPSetFromOptions(ksp));
31: PetscCall(DMShellCreate(c, &shell));
32: PetscCall(DMSetFromOptions(shell));
33: PetscCall(DMSetUp(shell));
34: PetscCall(KSPSetDM(ksp, shell));
36: PetscCall(KSPCreateVecs(ksp, 1, &right, 1, &left));
37: PetscCall(VecView(right[0], PETSC_VIEWER_STDOUT_(c)));
38: PetscCall(VecDestroyVecs(1, &right));
39: PetscCall(VecDestroyVecs(1, &left));
41: PetscCall(DMDestroy(&shell));
42: PetscCall(KSPDestroy(&ksp));
43: PetscCall(MatDestroy(&A));
44: PetscCall(PetscFinalize());
45: return 0;
46: }
48: /*TEST
50: test:
52: TEST*/