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: #undef __FUNCT__
 18: int main(int argc,char **argv)
 19: {
 20:   int        i,n = 4,ierr, inputindices[] = {0,3,9,12},bs = 3,issize,*indices;
 21:   IS         set;
 22:   PetscTruth isblock;

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

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

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

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

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

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

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