Actual source code: ex24.c

petsc-3.10.5 2019-03-28
Report Typos and Errors

  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: {
  9:   PetscInt       M,ownbegin,ownend,i,j;
 10:   PetscScalar    dummy=0.0;

 13:   MatGetSize(A,&M,NULL);
 14:   MatGetOwnershipRange(A,&ownbegin,&ownend);

 16:   for (i=ownbegin; i<ownend; i++) {
 17:     for(j=i-3; j<i+3; j++) {
 18:       if (j >= 0 && j < M) {
 19:         MatSetValues(A,1,&i,1,&j,&dummy,INSERT_VALUES);
 20:       }
 21:     }
 22:   }
 23:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 24:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
 25:   return(0);
 26: }

 28: int main(int argc, char *argv[])
 29: {
 31:   Mat            J;
 32:   PetscMPIInt    size;
 33:   PetscInt       M=8;
 34:   ISColoring     iscoloring;
 35:   MatColoring    coloring;

 37:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 38:   MPI_Comm_size(PETSC_COMM_WORLD,&size);

 40:   ierr= MatCreate(PETSC_COMM_WORLD,&J);
 41:   ierr= MatSetSizes(J, PETSC_DECIDE, PETSC_DECIDE, M, M);
 42:   ierr= MatSetFromOptions(J);
 43:   ierr= MatSetUp(J);

 45:   FormJacobian(J);
 46:   MatView(J,PETSC_VIEWER_STDOUT_WORLD);

 48:   /*
 49:     Color the matrix, i.e. determine groups of columns that share no common
 50:     rows. These columns in the Jacobian can all be computed simultaneously.
 51:    */
 52:   MatColoringCreate(J, &coloring);
 53:   MatColoringSetType(coloring,MATCOLORINGGREEDY);
 54:   MatColoringSetFromOptions(coloring);
 55:   MatColoringApply(coloring, &iscoloring);

 57:   if (size == 1) {
 58:     MatISColoringTest(J,iscoloring);
 59:   }

 61:   ISColoringDestroy(&iscoloring);
 62:   MatColoringDestroy(&coloring);
 63:   MatDestroy(&J);
 64:   PetscFinalize();
 65:   return ierr;
 66: }

 68: /*TEST

 70:    test:
 71:       suffix: sl
 72:       requires: !complex double !define(PETSC_USE_64BIT_INDICES)
 73:       args: -mat_coloring_type sl
 74:       output_file: output/ex24_1.out

 76:    test:
 77:       suffix: lf
 78:       requires: !complex double !define(PETSC_USE_64BIT_INDICES)
 79:       args: -mat_coloring_type lf
 80:       output_file: output/ex24_1.out

 82:    test:
 83:       suffix: id
 84:       requires: !complex double !define(PETSC_USE_64BIT_INDICES)
 85:       args: -mat_coloring_type id
 86:       output_file: output/ex24_1.out

 88: TEST*/