Actual source code: ex2.c
petsc-3.7.5 2017-01-01
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>
13: int main(int argc,char **argv)
14: {
15: PetscInt i,n,start,stride;
16: const PetscInt *ii;
17: IS is;
18: PetscBool flg;
21: PetscInitialize(&argc,&argv,(char*)0,help);
23: /*
24: Test IS of size 0
25: */
26: ISCreateStride(PETSC_COMM_SELF,0,0,2,&is);
27: ISGetSize(is,&n);
28: if (n != 0) SETERRQ(PETSC_COMM_SELF,1,"ISCreateStride");
29: ISStrideGetInfo(is,&start,&stride);
30: if (start != 0) SETERRQ(PETSC_COMM_SELF,1,"ISStrideGetInfo");
31: if (stride != 2) SETERRQ(PETSC_COMM_SELF,1,"ISStrideGetInfo");
32: PetscObjectTypeCompare((PetscObject)is,ISSTRIDE,&flg);
33: if (!flg) SETERRQ(PETSC_COMM_SELF,1,"ISStride");
34: ISGetIndices(is,&ii);
35: ISRestoreIndices(is,&ii);
36: ISDestroy(&is);
38: /*
39: Test ISGetIndices()
40: */
41: ISCreateStride(PETSC_COMM_SELF,10000,-8,3,&is);
42: ISGetLocalSize(is,&n);
43: ISGetIndices(is,&ii);
44: for (i=0; i<10000; i++) {
45: if (ii[i] != -8 + 3*i) SETERRQ(PETSC_COMM_SELF,1,"ISGetIndices");
46: }
47: ISRestoreIndices(is,&ii);
48: ISDestroy(&is);
50: PetscFinalize();
51: return 0;
52: }