Actual source code: ex3.c

  2: /*      "$Id: ex3.c,v 1.21 2001/03/23 23:21:14 balay Exp $"; */

  4: static char help[] = "Demonstrates creating a blocked index set.nn";

  6: /*T
  7:     Concepts: index sets^creating a block index set;
  8:     Concepts: IS^creating a block index set;

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

 14:  #include petscis.h

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

 22:   PetscInitialize(&argc,&argv,(char*)0,help);
 23: 
 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,&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 directlyn");
 39:   for (i=0; i<issize; i++) {
 40:     PetscPrintf(PETSC_COMM_SELF,"%dn",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 directlyn");
 49:   for (i=0; i<n; i++) {
 50:     PetscPrintf(PETSC_COMM_SELF,"%dn",indices[i]);
 51:   }
 52:   ISBlockRestoreIndices(set,&indices);

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

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

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

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