Actual source code: ex3.c


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

  4: /*T
  5:     Concepts: index sets^creating a block index set;
  6:     Concepts: IS^creating a block index set;

  8:     Description:  Creates an index set based on blocks of integers. Views that index set
  9:     and then destroys it.
 10: T*/

 12: #include <petscis.h>
 13: #include <petscviewer.h>

 15: int main(int argc,char **argv)
 16: {
 17:   PetscInt       i,n = 4, inputindices[] = {0,1,3,4},bs = 3,issize;
 18:   const PetscInt *indices;
 19:   IS             set;
 20:   PetscBool      isblock;

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

 24:   /*
 25:     Create a block index set. The index set has 4 blocks each of size 3.
 26:     The indices are {0,1,2,3,4,5,9,10,11,12,13,14}
 27:     Note each processor is generating its own index set
 28:     (in this case they are all identical)
 29:   */
 30:   ISCreateBlock(PETSC_COMM_SELF,bs,n,inputindices,PETSC_COPY_VALUES,&set);
 31:   ISView(set,PETSC_VIEWER_STDOUT_SELF);

 33:   /*
 34:     Extract indices from set.
 35:   */
 36:   ISGetLocalSize(set,&issize);
 37:   ISGetIndices(set,&indices);
 38:   PetscPrintf(PETSC_COMM_SELF,"Printing indices directly\n");
 39:   for (i=0; i<issize; i++) {
 40:     PetscPrintf(PETSC_COMM_SELF,"%" PetscInt_FMT "\n",indices[i]);
 41:   }
 42:   ISRestoreIndices(set,&indices);

 44:   /*
 45:     Extract the block indices. This returns one index per block.
 46:   */
 47:   ISBlockGetIndices(set,&indices);
 48:   PetscPrintf(PETSC_COMM_SELF,"Printing block indices directly\n");
 49:   for (i=0; i<n; i++) {
 50:     PetscPrintf(PETSC_COMM_SELF,"%" PetscInt_FMT "\n",indices[i]);
 51:   }
 52:   ISBlockRestoreIndices(set,&indices);

 54:   /*
 55:     Check if this is really a block index set
 56:   */
 57:   PetscObjectTypeCompare((PetscObject)set,ISBLOCK,&isblock);

 60:   /*
 61:     Determine the block size of the index set
 62:   */
 63:   ISGetBlockSize(set,&bs);

 66:   /*
 67:     Get the number of blocks
 68:   */
 69:   ISBlockGetLocalSize(set,&n);

 72:   ISDestroy(&set);
 73:   PetscFinalize();
 74:   return 0;
 75: }

 77: /*TEST

 79:    test:

 81: TEST*/