Actual source code: ex6.c
1: static char help[] = "Tests ISComplement().\n\n";
3: #include <petscis.h>
5: int main(int argc, char **argv)
6: {
7: PetscMPIInt rank, size;
8: PetscInt i, j, n, cnt = 0, rstart, rend;
9: PetscBool flg;
10: IS is[2], isc;
12: PetscFunctionBeginUser;
13: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
14: PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));
15: PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
17: n = 3 * size; /* Number of local indices, same on each process. */
18: rstart = 3 * (size + 2) * rank; /* start of local range */
19: rend = 3 * (size + 2) * (rank + 1); /* end of local range */
20: for (i = 0; i < 2; i++) {
21: PetscCall(ISCreate(PETSC_COMM_WORLD, &is[i]));
22: PetscCall(ISSetType(is[i], ISGENERAL));
23: }
24: {
25: PetscBool *mask;
27: PetscCall(PetscCalloc1(rend - rstart, &mask));
28: for (i = 0; i < 3; i++) {
29: for (j = 0; j < size; j++) mask[i * (size + 2) + j] = PETSC_TRUE;
30: }
31: PetscCall(ISGeneralSetIndicesFromMask(is[0], rstart, rend, mask));
32: PetscCall(PetscFree(mask));
33: }
34: {
35: PetscInt *indices;
37: PetscCall(PetscMalloc1(n, &indices));
38: for (i = 0; i < 3; i++) {
39: for (j = 0; j < size; j++) indices[cnt++] = rstart + i * (size + 2) + j;
40: }
41: PetscCheck(cnt == n, PETSC_COMM_SELF, PETSC_ERR_PLIB, "inconsistent count");
42: PetscCall(ISGeneralSetIndices(is[1], n, indices, PETSC_COPY_VALUES));
43: PetscCall(PetscFree(indices));
44: }
46: PetscCall(ISEqual(is[0], is[1], &flg));
47: PetscCheck(flg, PETSC_COMM_SELF, PETSC_ERR_PLIB, "is[0] should be equal to is[1]");
49: PetscCall(ISComplement(is[0], rstart, rend, &isc));
50: PetscCall(ISView(is[0], PETSC_VIEWER_STDOUT_WORLD));
51: PetscCall(ISView(isc, PETSC_VIEWER_STDOUT_WORLD));
53: for (i = 0; i < 2; i++) PetscCall(ISDestroy(&is[i]));
54: PetscCall(ISDestroy(&isc));
55: PetscCall(PetscFinalize());
56: return 0;
57: }
59: /*TEST
61: test:
62: suffix: 3
63: nsize: 3
65: TEST*/