Actual source code: power.c

petsc-3.10.5 2019-03-28
Report Typos and Errors
  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: .seealso: MatColoringCreate(), MatColoring, MatColoringSetType()
 46: M*/
 47: PETSC_EXTERN PetscErrorCode MatColoringCreate_Power(MatColoring mc)
 48: {
 50:   mc->ops->apply          = MatColoringApply_Power;
 51:   mc->ops->view           = NULL;
 52:   mc->ops->destroy        = NULL;
 53:   mc->ops->setfromoptions = NULL;
 54:   return(0);
 55: }