xref: /petsc/src/sys/tests/ex21.c (revision c4762a1b19cd2af06abeed90e8f9d34fb975dd94)
1 
2 static char help[] = "Tests PetscTreeProcess()";
3 
4 #include <petscsys.h>
5 
6 /*
7                           2              6
8                     1         4
9                     5
10 */
11 int main(int argc,char **argv)
12 {
13   PetscErrorCode ierr;
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;
18 
19   ierr = PetscInitialize(&argc,&argv,NULL,help);if (ierr) return ierr;
20   ierr = PetscProcessTree(n,mask,parentId,&Nlevels,&Level,&Levelcnt,&Idbylevel,&Column);CHKERRQ(ierr);
21   for (i=0; i<n; i++) {
22     if (!mask[i]) {
23       ierr = PetscPrintf(PETSC_COMM_WORLD," %D ",Level[i]);CHKERRQ(ierr);
24     }
25   }
26   ierr = PetscPrintf(PETSC_COMM_WORLD,"\nNumber of levels %D\n",Nlevels);CHKERRQ(ierr);
27   for (i=0; i<Nlevels; i++) {
28     ierr = PetscPrintf(PETSC_COMM_WORLD,"\nLevel %D ",i);CHKERRQ(ierr);
29     for (j=0; j<Levelcnt[i]; j++) {
30       ierr = PetscPrintf(PETSC_COMM_WORLD,"%D ",Idbylevel[cnt++]);CHKERRQ(ierr);
31     }
32   }
33   ierr = PetscPrintf(PETSC_COMM_WORLD,"\nColumn of each node");CHKERRQ(ierr);
34   for (i=0; i<n; i++) {
35     if (!mask[i]) {
36       ierr = PetscPrintf(PETSC_COMM_WORLD," %D ",Column[i]);CHKERRQ(ierr);
37     }
38   }
39   ierr = PetscPrintf(PETSC_COMM_WORLD,"\n");CHKERRQ(ierr);
40   ierr = PetscFree(Level);CHKERRQ(ierr);
41   ierr = PetscFree(Levelcnt);CHKERRQ(ierr);
42   ierr = PetscFree(Idbylevel);CHKERRQ(ierr);
43   ierr = PetscFree(Column);CHKERRQ(ierr);
44   ierr = PetscFinalize();
45   return ierr;
46 }
47 
48 
49 /*TEST
50 
51    test:
52 
53 TEST*/
54