Actual source code: ex151.c
1: static char help[] = "Tests MatPermute() in parallel.\n\n";
2: /* Results:
3: Sequential:
4: - seqaij: correct permutation
5: - seqbaij: permutation not supported for this MATTYPE
6: - seqsbaij: permutation not supported for this MATTYPE
7: Parallel:
8: - mpiaij: correct permutation
9: - mpibaij: correct permutation
10: - mpisbaij: permutation not supported for this MATTYPE
11: */
13: #include <petscmat.h>
15: int main(int argc, char **argv)
16: {
17: const struct {
18: PetscInt i, j;
19: PetscScalar v;
20: } entries[] = {
21: {0, 3, 1.},
22: {1, 2, 2.},
23: {2, 1, 3.},
24: {2, 5, 4.},
25: {3, 0, 5.},
26: {3, 6, 6.},
27: {4, 1, 7.},
28: {4, 4, 8.}
29: };
30: const PetscInt ixrow[5] = {4, 2, 1, 0, 3}, ixcol[7] = {5, 3, 6, 1, 2, 0, 4};
31: Mat A, B;
32: PetscInt i, rstart, rend, cstart, cend;
33: IS isrow, iscol;
34: PetscViewer viewer;
35: PetscBool view_sparse;
38: PetscInitialize(&argc, &argv, (char *)0, help);
39: /* ------- Assemble matrix, --------- */
40: MatCreate(PETSC_COMM_WORLD, &A);
41: MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, 5, 7);
42: MatSetFromOptions(A);
43: MatSetUp(A);
44: MatGetOwnershipRange(A, &rstart, &rend);
45: MatGetOwnershipRangeColumn(A, &cstart, &cend);
47: for (i = 0; i < (PetscInt)PETSC_STATIC_ARRAY_LENGTH(entries); i++) MatSetValue(A, entries[i].i, entries[i].j, entries[i].v, INSERT_VALUES);
48: MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
49: MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
51: /* ------ Prepare index sets ------ */
52: ISCreateGeneral(PETSC_COMM_WORLD, rend - rstart, ixrow + rstart, PETSC_USE_POINTER, &isrow);
53: ISCreateGeneral(PETSC_COMM_WORLD, cend - cstart, ixcol + cstart, PETSC_USE_POINTER, &iscol);
54: ISSetPermutation(isrow);
55: ISSetPermutation(iscol);
57: PetscViewerASCIIGetStdout(PETSC_COMM_WORLD, &viewer);
58: view_sparse = PETSC_FALSE;
59: PetscOptionsGetBool(NULL, NULL, "-view_sparse", &view_sparse, NULL);
60: if (!view_sparse) PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_DENSE);
61: PetscViewerASCIIPrintf(viewer, "Original matrix\n");
62: MatView(A, viewer);
64: MatPermute(A, isrow, iscol, &B);
65: PetscViewerASCIIPrintf(viewer, "Permuted matrix\n");
66: MatView(B, viewer);
68: if (!view_sparse) PetscViewerPopFormat(viewer);
69: PetscViewerASCIIPrintf(viewer, "Row permutation\n");
70: ISView(isrow, viewer);
71: PetscViewerASCIIPrintf(viewer, "Column permutation\n");
72: ISView(iscol, viewer);
74: /* Free data structures */
75: ISDestroy(&isrow);
76: ISDestroy(&iscol);
77: MatDestroy(&A);
78: MatDestroy(&B);
80: PetscFinalize();
81: return 0;
82: }
84: /*TEST
86: build:
87: requires: !complex
89: test:
90: args: -view_sparse
92: test:
93: suffix: 2
94: nsize: 2
95: args: -view_sparse
97: test:
98: suffix: 2b
99: nsize: 2
100: args: -mat_type baij -view_sparse
102: test:
103: suffix: 3
104: nsize: 3
105: args: -view_sparse
107: test:
108: suffix: 3b
109: nsize: 3
110: args: -mat_type baij -view_sparse
112: test:
113: suffix: dense
114: args: -mat_type dense
116: TEST*/