Actual source code: ex24.c
2: static char help[] = "Tests the different MatColoring implementatons and ISColoringTestValid() \n\
3: Modifed 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) {
18: MatSetValues(A,1,&i,1,&j,&dummy,INSERT_VALUES);
19: }
20: }
21: }
22: MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
23: MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
24: return 0;
25: }
27: int main(int argc, char *argv[])
28: {
29: Mat J;
30: PetscMPIInt size;
31: PetscInt M=8;
32: ISColoring iscoloring;
33: MatColoring coloring;
35: PetscInitialize(&argc,&argv,(char*)0,help);
36: MPI_Comm_size(PETSC_COMM_WORLD,&size);
38: MatCreate(PETSC_COMM_WORLD,&J);
39: MatSetSizes(J, PETSC_DECIDE, PETSC_DECIDE, M, M);
40: MatSetFromOptions(J);
41: MatSetUp(J);
43: FormJacobian(J);
44: MatView(J,PETSC_VIEWER_STDOUT_WORLD);
46: /*
47: Color the matrix, i.e. determine groups of columns that share no common
48: rows. These columns in the Jacobian can all be computed simultaneously.
49: */
50: MatColoringCreate(J, &coloring);
51: MatColoringSetType(coloring,MATCOLORINGGREEDY);
52: MatColoringSetFromOptions(coloring);
53: MatColoringApply(coloring, &iscoloring);
55: if (size == 1) {
56: MatISColoringTest(J,iscoloring);
57: }
59: ISColoringDestroy(&iscoloring);
60: MatColoringDestroy(&coloring);
61: MatDestroy(&J);
62: PetscFinalize();
63: return 0;
64: }
66: /*TEST
68: test:
69: suffix: sl
70: requires: !complex double !defined(PETSC_USE_64BIT_INDICES)
71: args: -mat_coloring_type sl
72: output_file: output/ex24_1.out
74: test:
75: suffix: lf
76: requires: !complex double !defined(PETSC_USE_64BIT_INDICES)
77: args: -mat_coloring_type lf
78: output_file: output/ex24_1.out
80: test:
81: suffix: id
82: requires: !complex double !defined(PETSC_USE_64BIT_INDICES)
83: args: -mat_coloring_type id
84: output_file: output/ex24_1.out
86: TEST*/