Actual source code: ex2.c


  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;

 18:   PetscFunctionBeginUser;
 19:   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));

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

 36:   /*
 37:      Test ISGetIndices()
 38:   */
 39:   PetscCall(ISCreateStride(PETSC_COMM_SELF, 10000, -8, 3, &is));
 40:   PetscCall(ISGetLocalSize(is, &n));
 41:   PetscCall(ISGetIndices(is, &ii));
 42:   for (i = 0; i < 10000; i++) PetscCheck(ii[i] == -8 + 3 * i, PETSC_COMM_SELF, PETSC_ERR_PLIB, "ISGetIndices");
 43:   PetscCall(ISRestoreIndices(is, &ii));
 44:   PetscCall(ISDestroy(&is));

 46:   PetscCall(PetscFinalize());
 47:   return 0;
 48: }

 50: /*TEST

 52:    test:
 53:      output_file: output/ex1_1.out

 55: TEST*/