Actual source code: ex6.c
2: static char help[] = "Tests reordering a matrix.\n\n";
4: #include <petscmat.h>
6: int main(int argc, char **args)
7: {
8: Mat C;
9: PetscInt i, j, m = 5, n = 5, Ii, J;
10: PetscScalar v;
11: IS perm, iperm;
13: PetscFunctionBeginUser;
14: PetscCall(PetscInitialize(&argc, &args, (char *)0, help));
15: PetscCall(MatCreate(PETSC_COMM_SELF, &C));
16: PetscCall(MatSetSizes(C, PETSC_DECIDE, PETSC_DECIDE, m * n, m * n));
17: PetscCall(MatSetFromOptions(C));
18: PetscCall(MatSetUp(C));
20: /* create the matrix for the five point stencil, YET AGAIN*/
21: for (i = 0; i < m; i++) {
22: for (j = 0; j < n; j++) {
23: v = -1.0;
24: Ii = j + n * i;
25: if (i > 0) {
26: J = Ii - n;
27: PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES));
28: }
29: if (i < m - 1) {
30: J = Ii + n;
31: PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES));
32: }
33: if (j > 0) {
34: J = Ii - 1;
35: PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES));
36: }
37: if (j < n - 1) {
38: J = Ii + 1;
39: PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES));
40: }
41: v = 4.0;
42: PetscCall(MatSetValues(C, 1, &Ii, 1, &Ii, &v, INSERT_VALUES));
43: }
44: }
45: PetscCall(MatAssemblyBegin(C, MAT_FINAL_ASSEMBLY));
46: PetscCall(MatAssemblyEnd(C, MAT_FINAL_ASSEMBLY));
48: PetscCall(MatGetOrdering(C, MATORDERINGND, &perm, &iperm));
49: PetscCall(ISView(perm, PETSC_VIEWER_STDOUT_SELF));
50: PetscCall(ISView(iperm, PETSC_VIEWER_STDOUT_SELF));
51: PetscCall(MatView(C, PETSC_VIEWER_STDOUT_SELF));
53: PetscCall(ISDestroy(&perm));
54: PetscCall(ISDestroy(&iperm));
55: PetscCall(MatDestroy(&C));
56: PetscCall(PetscFinalize());
57: return 0;
58: }
60: /*TEST
62: test:
64: TEST*/