Actual source code: ex3.c


  2: static char help[] = "Demonstrates creating a blocked index set.\n\n";

  4: #include <petscis.h>
  5: #include <petscviewer.h>

  7: int main(int argc,char **argv)
  8: {
  9:   PetscInt       i,n = 4, inputindices[] = {0,1,3,4},bs = 3,issize;
 10:   const PetscInt *indices;
 11:   IS             set;
 12:   PetscBool      isblock;

 14:   PetscInitialize(&argc,&argv,(char*)0,help);

 16:   /*
 17:     Create a block index set. The index set has 4 blocks each of size 3.
 18:     The indices are {0,1,2,3,4,5,9,10,11,12,13,14}
 19:     Note each processor is generating its own index set
 20:     (in this case they are all identical)
 21:   */
 22:   ISCreateBlock(PETSC_COMM_SELF,bs,n,inputindices,PETSC_COPY_VALUES,&set);
 23:   ISView(set,PETSC_VIEWER_STDOUT_SELF);

 25:   /*
 26:     Extract indices from set.
 27:   */
 28:   ISGetLocalSize(set,&issize);
 29:   ISGetIndices(set,&indices);
 30:   PetscPrintf(PETSC_COMM_SELF,"Printing indices directly\n");
 31:   for (i=0; i<issize; i++) {
 32:     PetscPrintf(PETSC_COMM_SELF,"%" PetscInt_FMT "\n",indices[i]);
 33:   }
 34:   ISRestoreIndices(set,&indices);

 36:   /*
 37:     Extract the block indices. This returns one index per block.
 38:   */
 39:   ISBlockGetIndices(set,&indices);
 40:   PetscPrintf(PETSC_COMM_SELF,"Printing block indices directly\n");
 41:   for (i=0; i<n; i++) {
 42:     PetscPrintf(PETSC_COMM_SELF,"%" PetscInt_FMT "\n",indices[i]);
 43:   }
 44:   ISBlockRestoreIndices(set,&indices);

 46:   /*
 47:     Check if this is really a block index set
 48:   */
 49:   PetscObjectTypeCompare((PetscObject)set,ISBLOCK,&isblock);

 52:   /*
 53:     Determine the block size of the index set
 54:   */
 55:   ISGetBlockSize(set,&bs);

 58:   /*
 59:     Get the number of blocks
 60:   */
 61:   ISBlockGetLocalSize(set,&n);

 64:   ISDestroy(&set);
 65:   PetscFinalize();
 66:   return 0;
 67: }

 69: /*TEST

 71:    test:

 73: TEST*/