Actual source code: ex3.c
1: static char help[] = "Demonstrates creating a blocked index set.\n\n";
3: #include <petscis.h>
5: int main(int argc, char **argv)
6: {
7: PetscInt i, n = 4, inputindices[] = {0, 1, 3, 4}, bs = 3, issize;
8: const PetscInt *indices;
9: IS set;
10: PetscBool isblock;
12: PetscFunctionBeginUser;
13: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
15: /*
16: Create a block index set. The index set has 4 blocks each of size 3.
17: The indices are {0,1,2,3,4,5,9,10,11,12,13,14}
18: Note each processor is generating its own index set
19: (in this case they are all identical)
20: */
21: PetscCall(ISCreateBlock(PETSC_COMM_SELF, bs, n, inputindices, PETSC_COPY_VALUES, &set));
22: PetscCall(ISView(set, PETSC_VIEWER_STDOUT_SELF));
24: /*
25: Extract indices from set.
26: */
27: PetscCall(ISGetLocalSize(set, &issize));
28: PetscCall(ISGetIndices(set, &indices));
29: PetscCall(PetscPrintf(PETSC_COMM_SELF, "Printing indices directly\n"));
30: for (i = 0; i < issize; i++) PetscCall(PetscPrintf(PETSC_COMM_SELF, "%" PetscInt_FMT "\n", indices[i]));
31: PetscCall(ISRestoreIndices(set, &indices));
33: /*
34: Extract the block indices. This returns one index per block.
35: */
36: PetscCall(ISBlockGetIndices(set, &indices));
37: PetscCall(PetscPrintf(PETSC_COMM_SELF, "Printing block indices directly\n"));
38: for (i = 0; i < n; i++) PetscCall(PetscPrintf(PETSC_COMM_SELF, "%" PetscInt_FMT "\n", indices[i]));
39: PetscCall(ISBlockRestoreIndices(set, &indices));
41: /*
42: Check if this is really a block index set
43: */
44: PetscCall(PetscObjectTypeCompare((PetscObject)set, ISBLOCK, &isblock));
45: PetscCheck(isblock, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Index set is not blocked!");
47: /*
48: Determine the block size of the index set
49: */
50: PetscCall(ISGetBlockSize(set, &bs));
51: PetscCheck(bs == 3, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Block size is not 3!");
53: /*
54: Get the number of blocks
55: */
56: PetscCall(ISBlockGetLocalSize(set, &n));
57: PetscCheck(n == 4, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Number of blocks not 4!");
59: PetscCall(ISDestroy(&set));
60: PetscCall(PetscFinalize());
61: return 0;
62: }
64: /*TEST
66: test:
68: TEST*/