Actual source code: ex24.c
2: static char help[] = "Tests the different MatColoring implementations and ISColoringTestValid() \n\
3: Modified from the code contributed by Ali Berk Kahraman. \n\n";
4: #include <petscmat.h>
6: PetscErrorCode FormJacobian(Mat A)
7: {
8: PetscInt M, ownbegin, ownend, i, j;
9: PetscScalar dummy = 0.0;
12: MatGetSize(A, &M, NULL);
13: MatGetOwnershipRange(A, &ownbegin, &ownend);
15: for (i = ownbegin; i < ownend; i++) {
16: for (j = i - 3; j < i + 3; j++) {
17: if (j >= 0 && j < M) MatSetValues(A, 1, &i, 1, &j, &dummy, INSERT_VALUES);
18: }
19: }
20: MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
21: MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
22: return 0;
23: }
25: int main(int argc, char *argv[])
26: {
27: Mat J;
28: PetscMPIInt size;
29: PetscInt M = 8;
30: ISColoring iscoloring;
31: MatColoring coloring;
34: PetscInitialize(&argc, &argv, (char *)0, help);
35: MPI_Comm_size(PETSC_COMM_WORLD, &size);
37: MatCreate(PETSC_COMM_WORLD, &J);
38: MatSetSizes(J, PETSC_DECIDE, PETSC_DECIDE, M, M);
39: MatSetFromOptions(J);
40: MatSetUp(J);
42: FormJacobian(J);
43: MatView(J, PETSC_VIEWER_STDOUT_WORLD);
45: /*
46: Color the matrix, i.e. determine groups of columns that share no common
47: rows. These columns in the Jacobian can all be computed simultaneously.
48: */
49: MatColoringCreate(J, &coloring);
50: MatColoringSetType(coloring, MATCOLORINGGREEDY);
51: MatColoringSetFromOptions(coloring);
52: MatColoringApply(coloring, &iscoloring);
54: if (size == 1) MatISColoringTest(J, iscoloring);
56: ISColoringDestroy(&iscoloring);
57: MatColoringDestroy(&coloring);
58: MatDestroy(&J);
59: PetscFinalize();
60: return 0;
61: }
63: /*TEST
65: test:
66: suffix: sl
67: requires: !complex double !defined(PETSC_USE_64BIT_INDICES)
68: args: -mat_coloring_type sl
69: output_file: output/ex24_1.out
71: test:
72: suffix: lf
73: requires: !complex double !defined(PETSC_USE_64BIT_INDICES)
74: args: -mat_coloring_type lf
75: output_file: output/ex24_1.out
77: test:
78: suffix: id
79: requires: !complex double !defined(PETSC_USE_64BIT_INDICES)
80: args: -mat_coloring_type id
81: output_file: output/ex24_1.out
83: TEST*/