Date: 2013-07-02T14:40:29+00:00

Actual source code: ex6.c
petsc-3.4.2 2013-07-02

      2: static char help[] = "Tests ISComplement().\n\n";

      4: #include <petscis.h>
      5: #include <petscviewer.h>

      9: int main(int argc,char **argv)
     10: {
     11:   PetscMPIInt    rank,size;
     12:   PetscInt       i,j,n,cnt=0,rstart,rend,*indices;
     13:   IS             is,isc;

     16:   PetscInitialize(&argc,&argv,(char*)0,help);
     17:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
     18:   MPI_Comm_size(PETSC_COMM_WORLD,&size);

     20:   n      = 3*size;              /* Number of local indices, same on each process. */
     21:   rstart = 3*(size+2)*rank;     /* start of local range */
     22:   rend   = 3*(size+2)*(rank+1); /* end of local range */
     23:   PetscMalloc(n*sizeof(PetscInt),&indices);
     24:   for (i=0; i<3; i++) {
     25:     for (j=0; j<size; j++) indices[cnt++] = rstart+i*(size+2)+j;
     26:   }
     27:   if (cnt != n) SETERRQ(PETSC_COMM_SELF,1,"inconsistent count");
     28:   ISCreateGeneral(PETSC_COMM_WORLD,n,indices,PETSC_COPY_VALUES,&is);
     29:   PetscFree(indices);
     30:   ISComplement(is,rstart,rend,&isc);
     31:   ISView(is,PETSC_VIEWER_STDOUT_WORLD);
     32:   ISView(isc,PETSC_VIEWER_STDOUT_WORLD);

     34:   ISDestroy(&is);
     35:   ISDestroy(&isc);
     36:   PetscFinalize();
     37:   return 0;
     38: }