Actual source code: ex21.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  2: static char help[] = "Tests PetscTreeProcess()";

  4: #include <petscsys.h>

  6: /*
  7:                           2              6
  8:                     1         4
  9:                     5
 10: */
 13: int main(int argc,char **argv)
 14: {
 16:   PetscInt       n          = 7,cnt = 0,i,j;
 17:   PetscBool      mask[]     = {PETSC_TRUE,PETSC_FALSE,PETSC_FALSE,PETSC_TRUE,PETSC_FALSE,PETSC_FALSE,PETSC_FALSE};
 18:   PetscInt       parentId[] = {-1,         2,         0,         -1,         2,         1,         0};
 19:   PetscInt       Nlevels,*Level,*Levelcnt,*Idbylevel,*Column;

 21:   PetscInitialize(&argc,&argv,NULL,help);
 22:   PetscProcessTree(n,mask,parentId,&Nlevels,&Level,&Levelcnt,&Idbylevel,&Column);
 23:   for (i=0; i<n; i++) {
 24:     if (!mask[i]) {
 25:       PetscPrintf(PETSC_COMM_WORLD," %D ",Level[i]);
 26:     }
 27:   }
 28:   PetscPrintf(PETSC_COMM_WORLD,"\nNumber of levels %D\n",Nlevels);
 29:   for (i=0; i<Nlevels; i++) {
 30:     PetscPrintf(PETSC_COMM_WORLD,"\nLevel %D ",i);
 31:     for (j=0; j<Levelcnt[i]; j++) {
 32:       PetscPrintf(PETSC_COMM_WORLD,"%D ",Idbylevel[cnt++]);
 33:     }
 34:   }
 35:   PetscPrintf(PETSC_COMM_WORLD,"\nColumn of each node");
 36:   for (i=0; i<n; i++) {
 37:     if (!mask[i]) {
 38:       PetscPrintf(PETSC_COMM_WORLD," %D ",Column[i]);
 39:     }
 40:   }
 41:   PetscFree(Level);
 42:   PetscFree(Levelcnt);
 43:   PetscFree(Idbylevel);
 44:   PetscFree(Column);
 45:   PetscFinalize();
 46:   return 0;
 47: }