Actual source code: power.c

      1: #include <petsc/private/matimpl.h>

      3: static PetscErrorCode MatColoringApply_Power(MatColoring mc,ISColoring *iscoloring)
      4: {
      5:   PetscErrorCode  ierr;
      6:   Mat             m = mc->mat,mp,ms;
      7:   MatColoring     imc;
      8:   PetscInt        i;
      9:   const char      *optionsprefix;

     12:   /* square the matrix repeatedly if necessary */
     13:   if (mc->dist == 1) {
     14:     mp = m;
     15:   } else {
     16:     MatMatMult(m,m,MAT_INITIAL_MATRIX,2.0,&mp);
     17:     for (i=2;i<mc->dist;i++) {
     18:       ms = mp;
     19:       MatMatMult(m,ms,MAT_INITIAL_MATRIX,2.0,&mp);
     20:       MatDestroy(&ms);
     21:     }
     22:   }
     23:   MatColoringCreate(mp,&imc);
     24:   PetscObjectGetOptionsPrefix((PetscObject)mc,&optionsprefix);
     25:   PetscObjectSetOptionsPrefix((PetscObject)imc,optionsprefix);
     26:   PetscObjectAppendOptionsPrefix((PetscObject)imc,"power_");
     27:   MatColoringSetType(imc,MATCOLORINGGREEDY);
     28:   MatColoringSetDistance(imc,1);
     29:   MatColoringSetWeightType(imc,mc->weight_type);
     30:   MatColoringSetFromOptions(imc);
     31:   MatColoringApply(imc,iscoloring);
     32:   MatColoringDestroy(&imc);
     33:   if (mp != m) {MatDestroy(&mp);}
     34:   return(0);
     35: }

     37: /*MC
     38:   MATCOLORINGPOWER - Take the matrix's nth power, then do one-coloring on it.

     40:    Level: beginner

     42:    Notes:
     43:    This is merely a trivial test algorithm.

     45:    Supports any distance coloring.

     47: .seealso: MatColoringCreate(), MatColoring, MatColoringSetType()
     48: M*/
     49: PETSC_EXTERN PetscErrorCode MatColoringCreate_Power(MatColoring mc)
     50: {
     52:   mc->ops->apply          = MatColoringApply_Power;
     53:   mc->ops->view           = NULL;
     54:   mc->ops->destroy        = NULL;
     55:   mc->ops->setfromoptions = NULL;
     56:   return(0);
     57: }