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[] = { 8, 6, 7, -5, 3, 0, 9, };
 30:   PetscInt       bs = 5, n = 7, key = 16, nonkey = 7, keylocation = 21, sortedlocation = 11, location;
 31:   IS             is;

 33:   ISCreateBlock(comm,bs,n,idx,PETSC_COPY_VALUES,&is);
 34:   ISLocate(is,key,&location);
 36:   ISLocate(is,nonkey,&location);
 38:   ISSort(is);
 39:   ISLocate(is,key,&location);
 41:   ISLocate(is,nonkey,&location);
 43:   ISDestroy(&is);
 44:   return 0;
 45: }

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

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

 65: int main(int argc,char **argv)
 66: {

 68:   PetscInitialize(&argc,&argv,NULL,help);
 69:   TestGeneral();
 70:   TestBlock();
 71:   TestStride();
 72:   PetscFinalize();
 73:   return 0;
 74: }

 76: /*TEST

 78:    test:
 79:       output_file: output/ex1_1.out

 81: TEST*/