Actual source code: ex43.c
1: static char help[] = "Test scalability of PetscHSetIJ hash set.\n\n";
3: #include <petscsys.h>
4: #include <petsctime.h>
5: #include <petsc/private/hashsetij.h>
7: int main(int argc, char **argv)
8: {
9: PetscHSetIJ table;
10: PetscInt N = 0, i, j, n;
11: PetscHashIJKey key;
12: PetscBool flag;
13: PetscLogDouble t_add = 0;
14: PetscLogDouble t_has = 0;
15: PetscLogDouble t_del = 0;
18: PetscInitialize(&argc, &argv, NULL, help);
19: PetscOptionsGetInt(NULL, NULL, "-N", &N, NULL);
20: PetscHSetIJCreate(&table);
22: /* The following line silences warnings from Clang Static Analyzer */
23: PetscHSetIJResize(table, 0);
25: PetscTimeSubtract(&t_add);
26: for (i = 0; i < N; ++i) {
27: for (j = 0; j < N; ++j) {
28: key.i = PetscMin(i, j);
29: key.j = PetscMax(i, j);
30: PetscHSetIJQueryAdd(table, key, &flag);
31: }
32: }
33: PetscTimeAdd(&t_add);
35: PetscHSetIJGetSize(table, &n);
37: PetscTimeSubtract(&t_has);
38: for (i = 0; i < N; ++i) {
39: for (j = 0; j < N; ++j) {
40: key.i = i;
41: key.j = j;
42: PetscHSetIJHas(table, key, &flag);
43: }
44: }
45: PetscTimeAdd(&t_has);
47: PetscTimeSubtract(&t_del);
48: for (i = 0; i < N; ++i) {
49: for (j = 0; j < N; ++j) {
50: key.i = i;
51: key.j = j;
52: PetscHSetIJQueryDel(table, key, &flag);
53: }
54: }
55: PetscTimeAdd(&t_del);
57: 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);
59: PetscHSetIJDestroy(&table);
60: PetscFinalize();
61: return 0;
62: }
64: /*TEST
66: test:
67: args: -N 32
69: TEST*/