Actual source code: ex7.c

  1: static char help[] = "Tests ISLocate().\n\n";

  3: #include <petscis.h>

  5: static PetscErrorCode TestGeneral(void)
  6: {
  7:   MPI_Comm       comm  = PETSC_COMM_SELF;
  8:   const PetscInt idx[] = {8, 6, 7, -5, 3, 0, 9};
  9:   PetscInt       n = 7, key = 3, nonkey = 1, keylocation = 4, sortedlocation = 2, location;
 10:   IS             is;

 12:   ISCreateGeneral(comm, n, idx, PETSC_COPY_VALUES, &is);
 13:   ISLocate(is, key, &location);
 15:   ISLocate(is, nonkey, &location);
 17:   ISSort(is);
 18:   ISLocate(is, key, &location);
 20:   ISLocate(is, nonkey, &location);
 22:   ISDestroy(&is);
 23:   return 0;
 24: }

 26: static PetscErrorCode TestBlock(void)
 27: {
 28:   MPI_Comm       comm  = PETSC_COMM_SELF;
 29:   const PetscInt idx[] = {
 30:     8, 6, 7, -5, 3, 0, 9,
 31:   };
 32:   PetscInt bs = 5, n = 7, key = 16, nonkey = 7, keylocation = 21, sortedlocation = 11, location;
 33:   IS       is;

 35:   ISCreateBlock(comm, bs, n, idx, PETSC_COPY_VALUES, &is);
 36:   ISLocate(is, key, &location);
 38:   ISLocate(is, nonkey, &location);
 40:   ISSort(is);
 41:   ISLocate(is, key, &location);
 43:   ISLocate(is, nonkey, &location);
 45:   ISDestroy(&is);
 46:   return 0;
 47: }

 49: static PetscErrorCode TestStride(void)
 50: {
 51:   MPI_Comm comm   = PETSC_COMM_SELF;
 52:   PetscInt stride = 7, first = -3, n = 18, key = 39, keylocation = 6;
 53:   PetscInt nonkey[] = {-2, 123}, i, location;
 54:   IS       is;

 56:   ISCreateStride(comm, n, first, stride, &is);
 57:   ISLocate(is, key, &location);
 59:   for (i = 0; i < 2; i++) {
 60:     ISLocate(is, nonkey[i], &location);
 62:   }
 63:   ISDestroy(&is);
 64:   return 0;
 65: }

 67: int main(int argc, char **argv)
 68: {
 70:   PetscInitialize(&argc, &argv, NULL, help);
 71:   TestGeneral();
 72:   TestBlock();
 73:   TestStride();
 74:   PetscFinalize();
 75:   return 0;
 76: }

 78: /*TEST

 80:    test:
 81:       output_file: output/ex1_1.out

 83: TEST*/