Actual source code: ex10.c
2: static char help[] = "Tests ISFilter().\n\n";
4: #include <petscis.h>
5: #include <petscviewer.h>
7: static PetscErrorCode CreateIS(MPI_Comm comm, PetscInt n, PetscInt first, PetscInt step, IS *is)
8: {
9: PetscInt *idx, i, j;
10: PetscMPIInt rank;
12: PetscFunctionBegin;
13: PetscCallMPI(MPI_Comm_rank(comm, &rank));
14: *is = NULL;
15: first += rank;
16: PetscCall(PetscMalloc1(n, &idx));
17: for (i = 0, j = first; i < n; i++, j += step) idx[i] = j;
18: PetscCall(ISCreateGeneral(comm, n, idx, PETSC_OWN_POINTER, is));
19: PetscFunctionReturn(PETSC_SUCCESS);
20: }
22: int main(int argc, char **argv)
23: {
24: IS is;
25: PetscInt n = 10, N, first = 0, step = 0, start, end;
26: PetscMPIInt rank;
27: MPI_Comm comm;
29: PetscFunctionBeginUser;
30: PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));
31: comm = PETSC_COMM_WORLD;
32: PetscCallMPI(MPI_Comm_rank(comm, &rank));
33: PetscCall(PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL));
34: PetscCall(PetscOptionsGetInt(NULL, NULL, "-first", &first, NULL));
35: PetscCall(PetscOptionsGetInt(NULL, NULL, "-step", &step, NULL));
36: start = 0;
37: end = n;
38: PetscCall(PetscOptionsGetInt(NULL, NULL, "-start", &start, NULL));
39: PetscCall(PetscOptionsGetInt(NULL, NULL, "-end", &end, NULL));
41: PetscCall(CreateIS(comm, n, first, step, &is));
42: PetscCall(ISGeneralFilter(is, start, end));
43: PetscCall(ISView(is, PETSC_VIEWER_STDOUT_(comm)));
44: PetscCall(ISGetSize(is, &N));
45: PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_(comm), "global size: %" PetscInt_FMT "\n", N));
47: PetscCall(ISDestroy(&is));
48: PetscCall(PetscFinalize());
49: return 0;
50: }
52: /*TEST
54: test:
55: suffix: 1
56: nsize: 4
57: args: -n 6
58: args: -first -2
59: args: -step 1
60: args: -start {{-2 4}separate output} -end {{2 6}separate output}
62: TEST*/