Actual source code: ex6.c
2: static char help[] = "Tests ISComplement().\n\n";
4: #include <petscis.h>
5: #include <petscviewer.h>
7: int main(int argc,char **argv)
8: {
9: PetscMPIInt rank,size;
10: PetscInt i,j,n,cnt=0,rstart,rend;
11: PetscBool flg;
12: IS is[2],isc;
14: PetscInitialize(&argc,&argv,(char*)0,help);
15: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
16: MPI_Comm_size(PETSC_COMM_WORLD,&size);
18: n = 3*size; /* Number of local indices, same on each process. */
19: rstart = 3*(size+2)*rank; /* start of local range */
20: rend = 3*(size+2)*(rank+1); /* end of local range */
21: for (i=0; i<2; i++) {
22: ISCreate(PETSC_COMM_WORLD,&is[i]);
23: ISSetType(is[i],ISGENERAL);
24: }
25: {
26: PetscBool *mask;
28: PetscCalloc1(rend-rstart,&mask);
29: for (i=0; i<3; i++) {
30: for (j=0; j<size; j++) {
31: mask[i*(size+2)+j] = PETSC_TRUE;
32: }
33: }
34: ISGeneralSetIndicesFromMask(is[0],rstart,rend,mask);
35: PetscFree(mask);
36: }
37: {
38: PetscInt *indices;
40: PetscMalloc1(n,&indices);
41: for (i=0; i<3; i++) {
42: for (j=0; j<size; j++) indices[cnt++] = rstart+i*(size+2)+j;
43: }
45: ISGeneralSetIndices(is[1],n,indices,PETSC_COPY_VALUES);
46: PetscFree(indices);
47: }
49: ISEqual(is[0],is[1],&flg);
52: ISComplement(is[0],rstart,rend,&isc);
53: ISView(is[0],PETSC_VIEWER_STDOUT_WORLD);
54: ISView(isc,PETSC_VIEWER_STDOUT_WORLD);
56: for (i=0; i<2; i++) ISDestroy(&is[i]);
57: ISDestroy(&isc);
58: PetscFinalize();
59: return 0;
60: }
62: /*TEST
64: test:
65: suffix: 3
66: nsize: 3
68: TEST*/