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;

 15:   PetscInitialize(&argc, &argv, (char *)0, help);
 16:   MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
 17:   MPI_Comm_size(PETSC_COMM_WORLD, &size);

 19:   n      = 3 * size;                    /* Number of local indices, same on each process. */
 20:   rstart = 3 * (size + 2) * rank;       /* start of local range */
 21:   rend   = 3 * (size + 2) * (rank + 1); /* end of local range */
 22:   for (i = 0; i < 2; i++) {
 23:     ISCreate(PETSC_COMM_WORLD, &is[i]);
 24:     ISSetType(is[i], ISGENERAL);
 25:   }
 26:   {
 27:     PetscBool *mask;

 29:     PetscCalloc1(rend - rstart, &mask);
 30:     for (i = 0; i < 3; i++) {
 31:       for (j = 0; j < size; j++) mask[i * (size + 2) + j] = PETSC_TRUE;
 32:     }
 33:     ISGeneralSetIndicesFromMask(is[0], rstart, rend, mask);
 34:     PetscFree(mask);
 35:   }
 36:   {
 37:     PetscInt *indices;

 39:     PetscMalloc1(n, &indices);
 40:     for (i = 0; i < 3; i++) {
 41:       for (j = 0; j < size; j++) indices[cnt++] = rstart + i * (size + 2) + j;
 42:     }
 44:     ISGeneralSetIndices(is[1], n, indices, PETSC_COPY_VALUES);
 45:     PetscFree(indices);
 46:   }

 48:   ISEqual(is[0], is[1], &flg);

 51:   ISComplement(is[0], rstart, rend, &isc);
 52:   ISView(is[0], PETSC_VIEWER_STDOUT_WORLD);
 53:   ISView(isc, PETSC_VIEWER_STDOUT_WORLD);

 55:   for (i = 0; i < 2; i++) ISDestroy(&is[i]);
 56:   ISDestroy(&isc);
 57:   PetscFinalize();
 58:   return 0;
 59: }

 61: /*TEST

 63:    test:
 64:       suffix: 3
 65:       nsize: 3

 67: TEST*/