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: {
     18:   PetscInt       i,n = 4, inputindices[] = {0,1,3,4},bs = 3,issize;
     19:   const PetscInt *indices;
     20:   IS             set;
     21:   PetscBool      isblock;

     23:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;

     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,PETSC_COPY_VALUES,&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:   PetscObjectTypeCompare((PetscObject)set,ISBLOCK,&isblock);
     59:   if (!isblock) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Index set is not blocked!");

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

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

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

     78: /*TEST

     80:    test:

     82: TEST*/