Actual source code: ex35.c
2: static char help[] = "MatLoad test for loading matrices that are created by DMCreateMatrix() and\n\
3: stored in binary via MatView_MPI_DA.MatView_MPI_DA stores the matrix\n\
4: in natural ordering. Hence MatLoad() has to read the matrix first in\n\
5: natural ordering and then permute it back to the application ordering.This\n\
6: example is used for testing the subroutine MatLoad_MPI_DA\n\n";
8: #include <petscdm.h>
9: #include <petscdmda.h>
11: int main(int argc, char **argv)
12: {
13: PetscInt X = 10, Y = 8, Z = 8;
14: DM da;
15: PetscViewer viewer;
16: Mat A;
19: PetscInitialize(&argc, &argv, (char *)0, help);
20: PetscViewerBinaryOpen(PETSC_COMM_WORLD, "temp.dat", FILE_MODE_WRITE, &viewer);
22: /* Read options */
23: PetscOptionsGetInt(NULL, NULL, "-X", &X, NULL);
24: PetscOptionsGetInt(NULL, NULL, "-Y", &Y, NULL);
25: PetscOptionsGetInt(NULL, NULL, "-Z", &Z, NULL);
27: /* Create distributed array and get vectors */
28: DMDACreate3d(PETSC_COMM_WORLD, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DMDA_STENCIL_STAR, X, Y, Z, PETSC_DECIDE, PETSC_DECIDE, PETSC_DECIDE, 1, 1, NULL, NULL, NULL, &da);
29: DMSetFromOptions(da);
30: DMSetUp(da);
31: DMSetMatType(da, MATMPIAIJ);
32: DMCreateMatrix(da, &A);
33: MatShift(A, X);
34: MatView(A, viewer);
35: MatDestroy(&A);
36: PetscViewerDestroy(&viewer);
38: PetscViewerBinaryOpen(PETSC_COMM_WORLD, "temp.dat", FILE_MODE_READ, &viewer);
39: DMCreateMatrix(da, &A);
40: MatLoad(A, viewer);
42: /* Free memory */
43: MatDestroy(&A);
44: PetscViewerDestroy(&viewer);
45: DMDestroy(&da);
46: PetscFinalize();
47: return 0;
48: }