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;
14: PetscInitialize(&argc, &args, (char *)0, help);
15: 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: MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES);
24: }
25: if (i < m - 1) {
26: J = Ii + n;
27: MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES);
28: }
29: if (j > 0) {
30: J = Ii - 1;
31: MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES);
32: }
33: if (j < n - 1) {
34: J = Ii + 1;
35: MatSetValues(C, 1, &Ii, 1, &J, &v, INSERT_VALUES);
36: }
37: v = 4.0;
38: MatSetValues(C, 1, &Ii, 1, &Ii, &v, INSERT_VALUES);
39: }
40: }
41: MatAssemblyBegin(C, MAT_FINAL_ASSEMBLY);
42: MatAssemblyEnd(C, MAT_FINAL_ASSEMBLY);
44: MatConvert(C, MATSAME, MAT_INITIAL_MATRIX, &A);
46: MatGetOrdering(A, MATORDERINGND, &perm, &iperm);
47: ISView(perm, PETSC_VIEWER_STDOUT_SELF);
48: ISView(iperm, PETSC_VIEWER_STDOUT_SELF);
49: MatView(A, PETSC_VIEWER_STDOUT_SELF);
51: ISDestroy(&perm);
52: ISDestroy(&iperm);
53: MatDestroy(&C);
54: MatDestroy(&A);
55: PetscFinalize();
56: return 0;
57: }
59: /*TEST
61: test:
62: filter: grep -v " MPI process"
64: TEST*/