Actual source code: ex21.c

petsc-3.14.6 2021-03-30
Report Typos and Errors

  2: static char help[] = "Tests PetscTreeProcess()";

  4: #include <petscsys.h>

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

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


 49: /*TEST

 51:    test:

 53: TEST*/