This source file includes following definitions.
- oshmem_group_cache_init
- oshmem_group_cache_destroy
- oshmem_group_cache_find
- oshmem_group_cache_insert
1
2
3
4
5
6
7
8
9
10
11
12 #include "oshmem/proc/proc_group_cache.h"
13 #include "oshmem/constants.h"
14 #include "oshmem/runtime/runtime.h"
15
16 #define OSHMEM_GROUP_CACHE_SIZE 1024
17
18 static opal_hash_table_t group_cache;
19
20 typedef struct {
21 int pe_start;
22 int pe_size;
23 int pe_stride;
24 } oshmem_group_key_t;
25
26 static int group_cache_n_hits;
27 static int group_cache_n_lookups;
28
29 int oshmem_group_cache_init(void)
30 {
31 OBJ_CONSTRUCT(&group_cache, opal_hash_table_t);
32 if (OPAL_SUCCESS != opal_hash_table_init(&group_cache, OSHMEM_GROUP_CACHE_SIZE)) {
33 return OSHMEM_ERROR;
34 }
35 return OSHMEM_SUCCESS;
36 }
37
38 void oshmem_group_cache_destroy(void)
39 {
40 OBJ_DESTRUCT(&group_cache);
41 }
42
43 oshmem_group_t *oshmem_group_cache_find(int pe_start, int pe_stride, int pe_size)
44 {
45 oshmem_group_key_t key;
46 oshmem_group_t *group;
47
48 if (!oshmem_group_cache_enabled()) {
49 return NULL;
50 }
51
52 key.pe_start = pe_start;
53 key.pe_size = pe_size;
54 key.pe_stride = pe_stride;
55
56 group_cache_n_lookups++;
57
58 if (OPAL_SUCCESS != opal_hash_table_get_value_ptr(&group_cache, &key,
59 sizeof(key), (void **)&group)) {
60 return NULL;
61 }
62
63 group_cache_n_hits++;
64 return group;
65 }
66
67 int oshmem_group_cache_insert(oshmem_group_t *group, int pe_start,
68 int pe_stride, int pe_size)
69 {
70 oshmem_group_key_t key;
71
72 if (!oshmem_group_cache_enabled()) {
73 return OSHMEM_SUCCESS;
74 }
75
76 key.pe_start = pe_start;
77 key.pe_size = pe_size;
78 key.pe_stride = pe_stride;
79
80 if (OPAL_SUCCESS != opal_hash_table_set_value_ptr(&group_cache, &key,
81 sizeof(key), group)) {
82 return OSHMEM_ERROR;
83 }
84 return OSHMEM_SUCCESS;
85 }
86