Actual source code: power.c

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

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

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

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

 38:    Level: beginner

 40:    Notes:
 41:    This is merely a trivial test algorithm.

 43:    Supports any distance coloring.

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