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;

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

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

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

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

 43:   /*
 44:     Check if this is really a block index set
 45:   */
 46:   PetscObjectTypeCompare((PetscObject)set, ISBLOCK, &isblock);

 49:   /*
 50:     Determine the block size of the index set
 51:   */
 52:   ISGetBlockSize(set, &bs);

 55:   /*
 56:     Get the number of blocks
 57:   */
 58:   ISBlockGetLocalSize(set, &n);

 61:   ISDestroy(&set);
 62:   PetscFinalize();
 63:   return 0;
 64: }

 66: /*TEST

 68:    test:

 70: TEST*/