Actual source code: ex42.c
1: static char help[] = "Test scalability of PetscHSetI hash set.\n\n";
3: #include <petscsys.h>
4: #include <petsctime.h>
5: #include <petsc/private/hashseti.h>
7: int main(int argc, char **argv)
8: {
9: PetscHSetI table;
10: PetscInt N = 0, i, j, n;
11: PetscBool flag;
12: PetscLogDouble t_add = 0;
13: PetscLogDouble t_has = 0;
14: PetscLogDouble t_del = 0;
16: PetscFunctionBeginUser;
17: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
18: PetscCall(PetscOptionsGetInt(NULL, NULL, "-N", &N, NULL));
19: PetscCall(PetscHSetICreate(&table));
21: /* The following line silences warnings from Clang Static Analyzer */
22: PetscCall(PetscHSetIResize(table, 0));
24: PetscCall(PetscTimeSubtract(&t_add));
25: for (i = 0; i < N; ++i) {
26: for (j = 0; j < N; ++j) {
27: PetscInt key = i + j * N;
28: PetscCall(PetscHSetIQueryAdd(table, key, &flag));
29: }
30: }
31: PetscCall(PetscTimeAdd(&t_add));
33: PetscCall(PetscHSetIGetSize(table, &n));
35: PetscCall(PetscTimeSubtract(&t_has));
36: for (i = 0; i < N; ++i) {
37: for (j = 0; j < N; ++j) {
38: PetscInt key = i + j * N;
39: PetscCall(PetscHSetIHas(table, key, &flag));
40: }
41: }
42: PetscCall(PetscTimeAdd(&t_has));
44: PetscCall(PetscTimeSubtract(&t_del));
45: for (i = 0; i < N; ++i) {
46: for (j = 0; j < N; ++j) {
47: PetscInt key = i + j * N;
48: PetscCall(PetscHSetIQueryDel(table, key, &flag));
49: }
50: }
51: PetscCall(PetscTimeAdd(&t_del));
53: PetscCall(PetscPrintf(PETSC_COMM_WORLD, "N = %" PetscInt_FMT " - table size: %" PetscInt_FMT ", add: %g, has: %g, del: %g\n", N, n, t_add, t_has, t_del));
55: PetscCall(PetscHSetIDestroy(&table));
56: PetscCall(PetscFinalize());
57: return 0;
58: }
60: /*TEST
62: test:
63: args: -N 32
65: TEST*/