Actual source code: ex6.c
1: /*$Id: ex6.c,v 1.20 2001/08/10 03:34:29 bsmith Exp $*/
3: static char help[] = "Tests removing entries from an AOData. nn";
5: #include petscao.h
7: int main(int argc,char **argv)
8: {
9: int n,nglobal,bs = 2,*keys,*data,ierr,rank,size,i,start;
10: PetscReal *gd;
11: AOData aodata;
13: PetscInitialize(&argc,&argv,(char*)0,help);
14: PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
16: MPI_Comm_rank(PETSC_COMM_WORLD,&rank); n = rank + 2;
17: MPI_Allreduce(&n,&nglobal,1,MPI_INT,MPI_SUM,PETSC_COMM_WORLD);
18: MPI_Comm_size(PETSC_COMM_WORLD,&size);
20: /*
21: Create a database with two sets of keys
22: */
23: AODataCreateBasic(PETSC_COMM_WORLD,&aodata);
25: /*
26: Put two segments in the first key and one in the second
27: */
28: AODataKeyAdd(aodata,"key1",PETSC_DECIDE,nglobal);
29: AODataKeyAdd(aodata,"key2",PETSC_DECIDE,nglobal);
31: /* allocate space for the keys each processor will provide */
32: PetscMalloc(n*sizeof(int),&keys);
34: /*
35: We assign the first set of keys (0 to 2) to processor 0, etc.
36: This computes the first local key on each processor
37: */
38: MPI_Scan(&n,&start,1,MPI_INT,MPI_SUM,PETSC_COMM_WORLD);
39: start -= n;
41: for (i=0; i<n; i++) {
42: keys[i] = start + i;
43: }
45: /*
46: Allocate data for the first key and first segment
47: */
48: PetscMalloc(bs*n*sizeof(int),&data);
49: for (i=0; i<n; i++) {
50: data[2*i] = -(start + i);
51: data[2*i+1] = -(start + i) - 10000;
52: }
53: AODataSegmentAdd(aodata,"key1","seg1",bs,n,keys,data,PETSC_INT);
54: PetscFree(data);
56: /*
57: Allocate data for first key and second segment
58: */
59: bs = 3;
60: PetscMalloc(bs*n*sizeof(PetscReal),&gd);
61: for (i=0; i<n; i++) {
62: gd[3*i] = -(start + i);
63: gd[3*i+1] = -(start + i) - 10000;
64: gd[3*i+2] = -(start + i) - 100000;
65: }
66: AODataSegmentAdd(aodata,"key1","seg2",bs,n,keys,gd,PETSC_REAL);
68: /*
69: Use same data for second key and first segment
70: */
71: AODataSegmentAdd(aodata,"key2","seg1",bs,n,keys,gd,PETSC_REAL);
72: PetscFree(gd);
73: PetscFree(keys);
75: /*
76: View the database
77: */
78: AODataView(aodata,PETSC_VIEWER_STDOUT_WORLD);
80: /*
81: Remove a key and a single segment from the database
82: */
83: AODataKeyRemove(aodata,"key2");
84: AODataSegmentRemove(aodata,"key1","seg1");
86: AODataView(aodata,PETSC_VIEWER_STDOUT_WORLD);
88: AODataDestroy(aodata);
90: PetscFinalize();
91: return 0;
92: }
93: