Actual source code: ex29.c
petsc-3.7.3 2016-08-01
1: static char help[] = "Tests PetscHeapCreate)_\n\n";
3: #include <../src/mat/utils/petscheap.h>
4: #include <petscviewer.h>
8: int main(int argc,char **args)
9: {
11: PetscHeap h;
12: PetscInt id,val,cnt,*values;
14: PetscInitialize(&argc,&args,(char*)0,help);
15: PetscHeapCreate(9,&h);
16: PetscHeapAdd(h,0,100);
17: PetscHeapAdd(h,1,19);
18: PetscHeapAdd(h,2,36);
19: PetscHeapAdd(h,3,17);
20: PetscHeapAdd(h,4,3);
21: PetscHeapAdd(h,5,25);
22: PetscHeapAdd(h,6,1);
23: PetscHeapAdd(h,8,2);
24: PetscHeapAdd(h,9,7);
25: PetscPrintf(PETSC_COMM_SELF,"Initial heap:\n");
26: PetscHeapView(h,NULL);
28: PetscHeapPop(h,&id,&val);
29: PetscHeapStash(h,id,val+10);
30: PetscHeapPop(h,&id,&val);
31: PetscHeapStash(h,id,val+10);
32: PetscPrintf(PETSC_COMM_SELF,"Pop two items, increment, and place in stash:\n");
33: PetscHeapView(h,NULL);
35: PetscHeapUnstash(h);
36: PetscPrintf(PETSC_COMM_SELF,"After unpacking the stash:\n");
37: PetscHeapView(h,NULL);
39: PetscMalloc1(9,&values);
40: PetscHeapPop(h,&id,&val);
41: cnt = 0;
42: while (id >= 0) {
43: values[cnt++] = val;
44: PetscHeapPop(h,&id,&val);
45: }
46: PetscPrintf(PETSC_COMM_SELF,"Sorted values:\n");
47: PetscIntView(cnt,values,PETSC_VIEWER_STDOUT_SELF);
48: PetscFree(values);
49: PetscHeapDestroy(&h);
50: PetscFinalize();
51: return 0;
52: }