Actual source code: ex10.c

  1: static char help[] = "Tests ISFilter().\n\n";

  3: #include <petscis.h>
  4: #include <petscviewer.h>

  6: static PetscErrorCode CreateIS(MPI_Comm comm, PetscInt n, PetscInt first, PetscInt step, IS *is)
  7: {
  8:   PetscInt   *idx, i, j;
  9:   PetscMPIInt rank;

 11:   PetscFunctionBegin;
 12:   PetscCallMPI(MPI_Comm_rank(comm, &rank));
 13:   *is = NULL;
 14:   first += rank;
 15:   PetscCall(PetscMalloc1(n, &idx));
 16:   for (i = 0, j = first; i < n; i++, j += step) idx[i] = j;
 17:   PetscCall(ISCreateGeneral(comm, n, idx, PETSC_OWN_POINTER, is));
 18:   PetscFunctionReturn(PETSC_SUCCESS);
 19: }

 21: int main(int argc, char **argv)
 22: {
 23:   IS          is;
 24:   PetscInt    n = 10, N, first = 0, step = 0, start, end;
 25:   PetscMPIInt rank;
 26:   MPI_Comm    comm;

 28:   PetscFunctionBeginUser;
 29:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
 30:   comm = PETSC_COMM_WORLD;
 31:   PetscCallMPI(MPI_Comm_rank(comm, &rank));
 32:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL));
 33:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-first", &first, NULL));
 34:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-step", &step, NULL));
 35:   start = 0;
 36:   end   = n;
 37:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-start", &start, NULL));
 38:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-end", &end, NULL));

 40:   PetscCall(CreateIS(comm, n, first, step, &is));
 41:   PetscCall(ISGeneralFilter(is, start, end));
 42:   PetscCall(ISView(is, PETSC_VIEWER_STDOUT_(comm)));
 43:   PetscCall(ISGetSize(is, &N));
 44:   PetscCall(PetscViewerASCIIPrintf(PETSC_VIEWER_STDOUT_(comm), "global size: %" PetscInt_FMT "\n", N));

 46:   PetscCall(ISDestroy(&is));
 47:   PetscCall(PetscFinalize());
 48:   return 0;
 49: }

 51: /*TEST

 53:     test:
 54:       suffix: 1
 55:       nsize: 4
 56:       args: -n 6
 57:       args: -first -2
 58:       args: -step 1
 59:       args: -start -2 -end 2

 61:     test:
 62:       suffix: 2
 63:       nsize: 4
 64:       args: -n 6
 65:       args: -first -2
 66:       args: -step 1
 67:       args: -start 4 -end 6

 69:  TEST*/