Actual source code: ex1.c

  1: /*
  2:        Formatted test for ISGeneral routines.
  3: */

  5: static char help[] = "Tests IS general routines.\n\n";

  7: #include <petscis.h>
  8: #include <petscviewer.h>

 10: int main(int argc,char **argv)
 11: {
 12:   PetscMPIInt    rank,size;
 13:   PetscInt       i,n,*indices;
 14:   const PetscInt *ii;
 15:   IS             is,newis;
 16:   PetscBool      flg;
 17:   PetscBool      permanent = PETSC_FALSE;
 18:   PetscBool      compute = PETSC_TRUE;

 20:   PetscInitialize(&argc,&argv,(char*)0,help);
 21:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
 22:   MPI_Comm_size(PETSC_COMM_WORLD,&size);

 24:   /*
 25:      Test IS of size 0
 26:   */
 27:   ISCreateGeneral(PETSC_COMM_SELF,0,&n,PETSC_COPY_VALUES,&is);
 28:   ISGetSize(is,&n);
 30:   ISDestroy(&is);

 32:   /*
 33:      Create large IS and test ISGetIndices()
 34:   */
 35:   n    = 10000 + rank;
 36:   PetscMalloc1(n,&indices);
 37:   for (i=0; i<n; i++) indices[i] = rank + i;
 38:   ISCreateGeneral(PETSC_COMM_SELF,n,indices,PETSC_COPY_VALUES,&is);
 39:   ISGetIndices(is,&ii);
 40:   for (i=0; i<n; i++) {
 42:   }
 43:   ISRestoreIndices(is,&ii);

 45:   /*
 46:      Check identity and permutation
 47:   */
 48:   /* ISPermutation doesn't check if not set */
 49:   ISPermutation(is,&flg);
 51:   ISGetInfo(is,IS_PERMUTATION,IS_LOCAL,compute,&flg);
 54:   ISIdentity(is,&flg);
 57:   ISGetInfo(is,IS_IDENTITY,IS_LOCAL,compute,&flg);
 60:   /* we can override the computed values with ISSetInfo() */
 61:   ISSetInfo(is,IS_PERMUTATION,IS_LOCAL,permanent,PETSC_TRUE);
 62:   ISSetInfo(is,IS_IDENTITY,IS_LOCAL,permanent,PETSC_TRUE);
 63:   ISGetInfo(is,IS_PERMUTATION,IS_LOCAL,compute,&flg);
 65:   ISGetInfo(is,IS_IDENTITY,IS_LOCAL,compute,&flg);

 68:   ISClearInfoCache(is,PETSC_TRUE);

 70:   /*
 71:      Check equality of index sets
 72:   */
 73:   ISEqual(is,is,&flg);

 76:   /*
 77:      Sorting
 78:   */
 79:   ISSort(is);
 80:   ISSorted(is,&flg);
 82:   ISGetInfo(is,IS_SORTED,IS_LOCAL,compute,&flg);
 84:   ISSorted(is,&flg);
 86:   ISGetInfo(is,IS_SORTED,IS_LOCAL,compute,&flg);

 89:   /*
 90:      Thinks it is a different type?
 91:   */
 92:   PetscObjectTypeCompare((PetscObject)is,ISSTRIDE,&flg);
 94:   PetscObjectTypeCompare((PetscObject)is,ISBLOCK,&flg);

 97:   ISDestroy(&is);

 99:   /*
100:      Inverting permutation
101:   */
102:   for (i=0; i<n; i++) indices[i] = n - i - 1;
103:   ISCreateGeneral(PETSC_COMM_SELF,n,indices,PETSC_COPY_VALUES,&is);
104:   PetscFree(indices);
105:   ISSetPermutation(is);
106:   ISInvertPermutation(is,PETSC_DECIDE,&newis);
107:   ISGetIndices(newis,&ii);
108:   for (i=0; i<n; i++) {
110:   }
111:   ISRestoreIndices(newis,&ii);
112:   ISDestroy(&newis);
113:   ISDestroy(&is);
114:   PetscFinalize();
115:   return 0;
116: }

118: /*TEST

120:    test:
121:       nsize: {{1 2 3 4 5}}

123: TEST*/