Actual source code: ex6.c

  2: static char help[] = "Tests removing entries from an AOData. \n\n";

 4:  #include petscao.h

  8: int main(int argc,char **argv)
  9: {
 10:   int         n,nglobal,bs = 2,*keys,*data,ierr,rank,size,i,start;
 11:   PetscReal   *gd;
 12:   AOData      aodata;

 14:   PetscInitialize(&argc,&argv,(char*)0,help);
 15:   PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);

 17:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank); n = rank + 2;
 18:   MPI_Allreduce(&n,&nglobal,1,MPI_INT,MPI_SUM,PETSC_COMM_WORLD);
 19:   MPI_Comm_size(PETSC_COMM_WORLD,&size);

 21:   /*
 22:        Create a database with two sets of keys 
 23:   */
 24:   AODataCreateBasic(PETSC_COMM_WORLD,&aodata);

 26:   /*
 27:        Put two segments in the first key and one in the second
 28:   */
 29:   AODataKeyAdd(aodata,"key1",PETSC_DECIDE,nglobal);
 30:   AODataKeyAdd(aodata,"key2",PETSC_DECIDE,nglobal);

 32:   /* allocate space for the keys each processor will provide */
 33:   PetscMalloc(n*sizeof(PetscInt),&keys);

 35:   /*
 36:      We assign the first set of keys (0 to 2) to processor 0, etc.
 37:      This computes the first local key on each processor
 38:   */
 39:   MPI_Scan(&n,&start,1,MPI_INT,MPI_SUM,PETSC_COMM_WORLD);
 40:   start -= n;

 42:   for (i=0; i<n; i++) {
 43:     keys[i]     = start + i;
 44:   }

 46:   /* 
 47:       Allocate data for the first key and first segment 
 48:   */
 49:   PetscMalloc(bs*n*sizeof(PetscInt),&data);
 50:   for (i=0; i<n; i++) {
 51:     data[2*i]   = -(start + i);
 52:     data[2*i+1] = -(start + i) - 10000;
 53:   }
 54:   AODataSegmentAdd(aodata,"key1","seg1",bs,n,keys,data,PETSC_INT);
 55:   PetscFree(data);

 57:   /*
 58:       Allocate data for first key and second segment 
 59:   */
 60:   bs   = 3;
 61:   PetscMalloc(bs*n*sizeof(PetscReal),&gd);
 62:   for (i=0; i<n; i++) {
 63:     gd[3*i]   = -(start + i);
 64:     gd[3*i+1] = -(start + i) - 10000;
 65:     gd[3*i+2] = -(start + i) - 100000;
 66:   }
 67:   AODataSegmentAdd(aodata,"key1","seg2",bs,n,keys,gd,PETSC_REAL);

 69:   /*
 70:        Use same data for second key and first segment 
 71:   */
 72:   AODataSegmentAdd(aodata,"key2","seg1",bs,n,keys,gd,PETSC_REAL);
 73:   PetscFree(gd);
 74:   PetscFree(keys);

 76:   /*
 77:      View the database
 78:   */
 79:   AODataView(aodata,PETSC_VIEWER_STDOUT_WORLD);

 81:   /*
 82:        Remove a key and a single segment from the database
 83:   */
 84:   AODataKeyRemove(aodata,"key2");
 85:   AODataSegmentRemove(aodata,"key1","seg1");

 87:   AODataView(aodata,PETSC_VIEWER_STDOUT_WORLD);

 89:   AODataDestroy(aodata);

 91:   PetscFinalize();
 92:   return 0;
 93: }
 94: