Actual source code: ex2.c

petsc-3.12.2 2019-11-22
Report Typos and Errors

  2: /*
  3:        Formatted test for ISStride routines.
  4: */

  6: static char help[] = "Tests IS stride routines.\n\n";

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

 11: int main(int argc,char **argv)
 12: {
 13:   PetscInt       i,n,start,stride;
 14:   const PetscInt *ii;
 15:   IS             is;
 16:   PetscBool      flg;

 19:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;

 21:   /*
 22:      Test IS of size 0
 23:   */
 24:   ISCreateStride(PETSC_COMM_SELF,0,0,2,&is);
 25:   ISGetSize(is,&n);
 26:   if (n != 0) SETERRQ(PETSC_COMM_SELF,1,"ISCreateStride");
 27:   ISStrideGetInfo(is,&start,&stride);
 28:   if (start != 0) SETERRQ(PETSC_COMM_SELF,1,"ISStrideGetInfo");
 29:   if (stride != 2) SETERRQ(PETSC_COMM_SELF,1,"ISStrideGetInfo");
 30:   PetscObjectTypeCompare((PetscObject)is,ISSTRIDE,&flg);
 31:   if (!flg) SETERRQ(PETSC_COMM_SELF,1,"ISStride");
 32:   ISGetIndices(is,&ii);
 33:   ISRestoreIndices(is,&ii);
 34:   ISDestroy(&is);

 36:   /*
 37:      Test ISGetIndices()
 38:   */
 39:   ISCreateStride(PETSC_COMM_SELF,10000,-8,3,&is);
 40:   ISGetLocalSize(is,&n);
 41:   ISGetIndices(is,&ii);
 42:   for (i=0; i<10000; i++) {
 43:     if (ii[i] != -8 + 3*i) SETERRQ(PETSC_COMM_SELF,1,"ISGetIndices");
 44:   }
 45:   ISRestoreIndices(is,&ii);
 46:   ISDestroy(&is);

 48:   PetscFinalize();
 49:   return ierr;
 50: }

 52: /*TEST

 54:    test:
 55:      output_file: output/ex1_1.out

 57: TEST*/