Actual source code: ex13.c
2: static char help[] = "Tests copying and ordering uniprocessor row-based sparse matrices.\n\n";
4: #include <petscmat.h>
6: int main(int argc, char **args)
7: {
8: Mat C, A;
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(MatCreateSeqAIJ(PETSC_COMM_SELF, m * n, m * n, 5, NULL, &C));
16: /* create the matrix for the five point stencil, YET AGAIN*/
17: for (i = 0; i < m; i++) {
18: for (j = 0; j < n; j++) {
19: v = -1.0;
20: Ii = j + n * i;
21: if (i > 0) {
22: J = Ii - n;
23: PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES));
24: }
25: if (i < m - 1) {
26: J = Ii + n;
27: PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES));
28: }
29: if (j > 0) {
30: J = Ii - 1;
31: PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES));
32: }
33: if (j < n - 1) {
34: J = Ii + 1;
35: PetscCall(MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES));
36: }
37: v = 4.0;
38: PetscCall(MatSetValues(C, 1, &Ii, 1, &Ii, &v, INSERT_VALUES));
39: }
40: }
41: PetscCall(MatAssemblyBegin(C, MAT_FINAL_ASSEMBLY));
42: PetscCall(MatAssemblyEnd(C, MAT_FINAL_ASSEMBLY));
44: PetscCall(MatConvert(C, MATSAME, MAT_INITIAL_MATRIX, &A));
46: PetscCall(MatGetOrdering(A, MATORDERINGND, &perm, &iperm));
47: PetscCall(ISView(perm, PETSC_VIEWER_STDOUT_SELF));
48: PetscCall(ISView(iperm, PETSC_VIEWER_STDOUT_SELF));
49: PetscCall(MatView(A, PETSC_VIEWER_STDOUT_SELF));
51: PetscCall(ISDestroy(&perm));
52: PetscCall(ISDestroy(&iperm));
53: PetscCall(MatDestroy(&C));
54: PetscCall(MatDestroy(&A));
55: PetscCall(PetscFinalize());
56: return 0;
57: }
59: /*TEST
61: test:
62: filter: grep -v " MPI process"
64: TEST*/