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

 16: int main(int argc,char **argv)
 17: {
 19:   PetscInt       i,n = 4, inputindices[] = {0,3,9,12},bs = 3,issize,*indices;
 20:   IS             set;
 21:   PetscTruth     isblock;

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

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

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

 55:   /*
 56:     Check if this is really a block index set
 57:   */
 58:   ISBlock(set,&isblock);
 59:   if (isblock != PETSC_TRUE) SETERRQ(1,"Index set is not blocked!");

 61:   /*
 62:     Determine the block size of the index set
 63:   */
 64:   ISBlockGetBlockSize(set,&bs);
 65:   if (bs != 3) SETERRQ(1,"Block size is not 3!");

 67:   /*
 68:     Get the number of blocks
 69:   */
 70:   ISBlockGetSize(set,&n);
 71:   if (n != 4) SETERRQ(1,"Number of blocks not 4!");

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