Actual source code: ex3.c

  1: /*
  2:        Tests ISAllGather()
  3: */

  5: static char help[] = "Tests ISAllGather().\n\n";

  7: #include <petscis.h>
  8: #include <petscviewer.h>

 10: int main(int argc, char **argv)
 11: {
 12:   PetscInt    i, n, *indices;
 13:   PetscMPIInt rank;
 14:   IS          is, newis;

 16:   PetscFunctionBeginUser;
 17:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
 18:   PetscCallMPI(MPI_Comm_rank(PETSC_COMM_WORLD, &rank));

 20:   /*
 21:      Create IS
 22:   */
 23:   n = 4 + rank;
 24:   PetscCall(PetscMalloc1(n, &indices));
 25:   for (i = 0; i < n; i++) indices[i] = rank + i;
 26:   PetscCall(ISCreateGeneral(PETSC_COMM_WORLD, n, indices, PETSC_COPY_VALUES, &is));
 27:   PetscCall(PetscFree(indices));

 29:   /*
 30:       Stick them together from all processors
 31:   */
 32:   PetscCall(ISAllGather(is, &newis));

 34:   if (rank == 0) PetscCall(ISView(newis, PETSC_VIEWER_STDOUT_SELF));

 36:   PetscCall(ISDestroy(&newis));
 37:   PetscCall(ISDestroy(&is));
 38:   PetscCall(PetscFinalize());
 39:   return 0;
 40: }

 42: /*TEST

 44:    test:

 46: TEST*/