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

 11: int main(int argc,char **argv)
 12: {
 13:   PetscMPIInt    rank,size;
 14:   PetscInt       i,n,*indices,*ii;
 15:   IS             is,newis;
 16:   PetscTruth     flg;

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

 23:   /*
 24:      Test IS of size 0 
 25:   */
 26:   ISCreateGeneral(PETSC_COMM_SELF,0,&n,&is);
 27:   ISGetSize(is,&n);
 28:   if (n != 0) SETERRQ(1,"ISGetSize");
 29:   ISDestroy(is);

 31:   /*
 32:      Create large IS and test ISGetIndices()
 33:   */
 34:   n = 10000 + rank;
 35:   PetscMalloc(n*sizeof(PetscInt),&indices);
 36:   for (i=0; i<n; i++) {
 37:     indices[i] = rank + i;
 38:   }
 39:   ISCreateGeneral(PETSC_COMM_SELF,n,indices,&is);
 40:   ISGetIndices(is,&ii);
 41:   for (i=0; i<n; i++) {
 42:     if (ii[i] != indices[i]) SETERRQ(1,"ISGetIndices");
 43:   }
 44:   ISRestoreIndices(is,&ii);

 46:   /* 
 47:      Check identity and permutation 
 48:   */
 49:   ISPermutation(is,&flg);
 50:   if (flg) SETERRQ(1,"ISPermutation");
 51:   ISIdentity(is,&flg);
 52:   if (flg != PETSC_TRUE) SETERRQ(1,"ISIdentity");
 53:   ISSetPermutation(is);
 54:   ISSetIdentity(is);
 55:   ISPermutation(is,&flg);
 56:   if (flg != PETSC_TRUE) SETERRQ(1,"ISPermutation");
 57:   ISIdentity(is,&flg);
 58:   if (flg != PETSC_TRUE) SETERRQ(1,"ISIdentity");

 60:   /*
 61:      Check equality of index sets 
 62:   */
 63:   ISEqual(is,is,&flg);
 64:   if (flg != PETSC_TRUE) SETERRQ(1,"ISEqual");

 66:   /*
 67:      Sorting 
 68:   */
 69:   ISSort(is);
 70:   ISSorted(is,&flg);
 71:   if (flg != PETSC_TRUE) SETERRQ(1,"ISSort");

 73:   /*
 74:      Thinks it is a different type?
 75:   */
 76:   ISStride(is,&flg);
 77:   if (flg) SETERRQ(1,"ISStride");
 78:   ISBlock(is,&flg);
 79:   if (flg) SETERRQ(1,"ISBlock");

 81:   ISDestroy(is);

 83:   /*
 84:      Inverting permutation
 85:   */
 86:   for (i=0; i<n; i++) {
 87:     indices[i] = n - i - 1;
 88:   }
 89:   ISCreateGeneral(PETSC_COMM_SELF,n,indices,&is);
 90:   PetscFree(indices);
 91:   ISSetPermutation(is);
 92:   ISInvertPermutation(is,PETSC_DECIDE,&newis);
 93:   ISGetIndices(newis,&ii);
 94:   for (i=0; i<n; i++) {
 95:     if (ii[i] != n - i - 1) SETERRQ(1,"ISInvertPermutation");
 96:   }
 97:   ISRestoreIndices(newis,&ii);
 98:   ISDestroy(newis);
 99:   ISDestroy(is);
100:   PetscFinalize();
101:   return 0;
102: }
103: