Actual source code: ex2.c

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

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

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

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

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

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

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

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

 49: /*TEST

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

 54: TEST*/