Actual source code: ex7.c
petsc-3.13.4 2020-08-01
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;
14: ISCreateGeneral(comm,n,idx,PETSC_COPY_VALUES,&is);
15: ISLocate(is,key,&location);
16: if (location != keylocation) SETERRQ3(comm,PETSC_ERR_PLIB,"Key %D not at %D: %D",key,keylocation,location);
17: ISLocate(is,nonkey,&location);
18: if (location >= 0) SETERRQ2(comm,PETSC_ERR_PLIB,"Nonkey %D found at %D",nonkey,location);
19: ISSort(is);
20: ISLocate(is,key,&location);
21: if (location != sortedlocation) SETERRQ3(comm,PETSC_ERR_PLIB,"Key %D not at %D: %D",key,sortedlocation,location);
22: ISLocate(is,nonkey,&location);
23: if (location >= 0) SETERRQ2(comm,PETSC_ERR_PLIB,"Nonkey %D found at %D",nonkey,location);
24: ISDestroy(&is);
25: return(0);
26: }
28: static PetscErrorCode TestBlock(void)
29: {
30: MPI_Comm comm = PETSC_COMM_SELF;
31: const PetscInt idx[] = { 8, 6, 7, -5, 3, 0, 9, };
32: PetscInt bs = 5, n = 7, key = 16, nonkey = 7, keylocation = 21, sortedlocation = 11, location;
33: IS is;
37: ISCreateBlock(comm,bs,n,idx,PETSC_COPY_VALUES,&is);
38: ISLocate(is,key,&location);
39: if (location != keylocation) SETERRQ3(comm,PETSC_ERR_PLIB,"Key %D not at %D: %D",key,keylocation,location);
40: ISLocate(is,nonkey,&location);
41: if (location >= 0) SETERRQ2(comm,PETSC_ERR_PLIB,"Nonkey %D found at %D",nonkey,location);
42: ISSort(is);
43: ISLocate(is,key,&location);
44: if (location != sortedlocation) SETERRQ3(comm,PETSC_ERR_PLIB,"Key %D not at %D: %D",key,sortedlocation,location);
45: ISLocate(is,nonkey,&location);
46: if (location >= 0) SETERRQ2(comm,PETSC_ERR_PLIB,"Nonkey %D found at %D",nonkey,location);
47: ISDestroy(&is);
48: return(0);
49: }
51: static PetscErrorCode TestStride(void)
52: {
53: MPI_Comm comm = PETSC_COMM_SELF;
54: PetscInt stride = 7, first = -3, n = 18, key = 39, keylocation = 6;
55: PetscInt nonkey[] = {-2,123}, i, location;
56: IS is;
60: ISCreateStride(comm,n,first,stride,&is);
61: ISLocate(is,key,&location);
62: if (location != keylocation) SETERRQ3(comm,PETSC_ERR_PLIB,"Key %D not at %D: %D",key,keylocation,location);
63: for (i = 0; i < 2; i++) {
64: ISLocate(is,nonkey[i],&location);
65: if (location >= 0) SETERRQ2(comm,PETSC_ERR_PLIB,"Nonkey %D found at %D",nonkey[i],location);
66: }
67: ISDestroy(&is);
68: return(0);
69: }
71: int main(int argc,char **argv)
72: {
75: PetscInitialize(&argc,&argv,NULL,help);if (ierr) return ierr;
76: TestGeneral();
77: TestBlock();
78: TestStride();
79: PetscFinalize();
80: return ierr;
81: }
84: /*TEST
86: test:
87: output_file: output/ex1_1.out
89: TEST*/