Actual source code: ex3.c
petsc-3.8.3 2017-12-09
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: {
13: PetscInt i,n,*indices;
14: PetscInt rank,size;
15: IS is,newis;
17: PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
18: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
19: MPI_Comm_size(PETSC_COMM_WORLD,&size);
21: /*
22: Create IS
23: */
24: n = 4 + rank;
25: PetscMalloc1(n,&indices);
26: for (i=0; i<n; i++) indices[i] = rank + i;
27: ISCreateGeneral(PETSC_COMM_WORLD,n,indices,PETSC_COPY_VALUES,&is);
28: PetscFree(indices);
30: /*
31: Stick them together from all processors
32: */
33: ISAllGather(is,&newis);
35: if (!rank) {
36: ISView(newis,PETSC_VIEWER_STDOUT_SELF);
37: }
39: ISDestroy(&newis);
40: ISDestroy(&is);
41: PetscFinalize();
42: return ierr;
43: }