@@ -54,12 +54,64 @@ static inline kmp_depnode_t *__kmp_node_ref(kmp_depnode_t *node) {
54
54
55
55
enum { KMP_DEPHASH_OTHER_SIZE = 97 , KMP_DEPHASH_MASTER_SIZE = 997 };
56
56
57
+ size_t sizes[] = { 997 , 2003 , 4001 , 8191 , 16001 , 32003 , 64007 , 131071 , 270029 };
58
+ const size_t MAX_GEN = 8 ;
59
+
57
60
static inline kmp_int32 __kmp_dephash_hash (kmp_intptr_t addr, size_t hsize) {
58
61
// TODO alternate to try: set = (((Addr64)(addrUsefulBits * 9.618)) %
59
62
// m_num_sets );
60
63
return ((addr >> 6 ) ^ (addr >> 2 )) % hsize;
61
64
}
62
65
66
+ static kmp_dephash_t *__kmp_dephash_extend (kmp_info_t *thread,
67
+ kmp_dephash_t *current_dephash) {
68
+ kmp_dephash_t *h;
69
+
70
+ size_t gen = current_dephash->generation + 1 ;
71
+ if (gen >= MAX_GEN)
72
+ return current_dephash;
73
+ size_t new_size = sizes[gen];
74
+
75
+ kmp_int32 size_to_allocate =
76
+ new_size * sizeof (kmp_dephash_entry_t *) + sizeof (kmp_dephash_t );
77
+
78
+ #if USE_FAST_MEMORY
79
+ h = (kmp_dephash_t *)__kmp_fast_allocate (thread, size_to_allocate);
80
+ #else
81
+ h = (kmp_dephash_t *)__kmp_thread_malloc (thread, size_to_allocate);
82
+ #endif
83
+
84
+ h->size = new_size;
85
+ h->nelements = current_dephash->nelements ;
86
+ h->buckets = (kmp_dephash_entry **)(h + 1 );
87
+ h->generation = gen;
88
+
89
+ // insert existing elements in the new table
90
+ for (size_t i = 0 ; i < current_dephash->size ; i++) {
91
+ kmp_dephash_entry_t *next;
92
+ for (kmp_dephash_entry_t *entry = current_dephash->buckets [i]; entry; entry = next) {
93
+ next = entry->next_in_bucket ;
94
+ // Compute the new hash using the new size, and insert the entry in
95
+ // the new bucket.
96
+ kmp_int32 new_bucket = __kmp_dephash_hash (entry->addr , h->size );
97
+ if (entry->next_in_bucket ) {
98
+ h->nconflicts ++;
99
+ }
100
+ entry->next_in_bucket = h->buckets [new_bucket];
101
+ h->buckets [new_bucket] = entry;
102
+ }
103
+ }
104
+
105
+ // Free old hash table
106
+ #if USE_FAST_MEMORY
107
+ __kmp_fast_free (thread, current_dephash);
108
+ #else
109
+ __kmp_thread_free (thread, current_dephash);
110
+ #endif
111
+
112
+ return h;
113
+ }
114
+
63
115
static kmp_dephash_t *__kmp_dephash_create (kmp_info_t *thread,
64
116
kmp_taskdata_t *current_task) {
65
117
kmp_dephash_t *h;
@@ -81,10 +133,9 @@ static kmp_dephash_t *__kmp_dephash_create(kmp_info_t *thread,
81
133
#endif
82
134
h->size = h_size;
83
135
84
- # ifdef KMP_DEBUG
136
+ h-> generation = 0 ;
85
137
h->nelements = 0 ;
86
138
h->nconflicts = 0 ;
87
- #endif
88
139
h->buckets = (kmp_dephash_entry **)(h + 1 );
89
140
90
141
for (size_t i = 0 ; i < h_size; i++)
@@ -97,7 +148,13 @@ static kmp_dephash_t *__kmp_dephash_create(kmp_info_t *thread,
97
148
#define ENTRY_LAST_MTXS 1
98
149
99
150
static kmp_dephash_entry *
100
- __kmp_dephash_find (kmp_info_t *thread, kmp_dephash_t *h, kmp_intptr_t addr) {
151
+ __kmp_dephash_find (kmp_info_t *thread, kmp_dephash_t **hash, kmp_intptr_t addr) {
152
+ kmp_dephash_t *h = *hash;
153
+ if (h->nelements != 0
154
+ && h->nconflicts /h->size >= 1 ) {
155
+ *hash = __kmp_dephash_extend (thread, h);
156
+ h = *hash;
157
+ }
101
158
kmp_int32 bucket = __kmp_dephash_hash (addr, h->size );
102
159
103
160
kmp_dephash_entry_t *entry;
@@ -122,11 +179,9 @@ __kmp_dephash_find(kmp_info_t *thread, kmp_dephash_t *h, kmp_intptr_t addr) {
122
179
entry->mtx_lock = NULL ;
123
180
entry->next_in_bucket = h->buckets [bucket];
124
181
h->buckets [bucket] = entry;
125
- #ifdef KMP_DEBUG
126
182
h->nelements ++;
127
183
if (entry->next_in_bucket )
128
184
h->nconflicts ++;
129
- #endif
130
185
}
131
186
return entry;
132
187
}
@@ -232,7 +287,7 @@ static inline kmp_int32 __kmp_depnode_link_successor(kmp_int32 gtid,
232
287
233
288
template <bool filter>
234
289
static inline kmp_int32
235
- __kmp_process_deps (kmp_int32 gtid, kmp_depnode_t *node, kmp_dephash_t *hash,
290
+ __kmp_process_deps (kmp_int32 gtid, kmp_depnode_t *node, kmp_dephash_t ** hash,
236
291
bool dep_barrier, kmp_int32 ndeps,
237
292
kmp_depend_info_t *dep_list, kmp_task_t *task) {
238
293
KA_TRACE (30 , (" __kmp_process_deps<%d>: T#%d processing %d dependencies : "
@@ -352,7 +407,7 @@ __kmp_process_deps(kmp_int32 gtid, kmp_depnode_t *node, kmp_dephash_t *hash,
352
407
353
408
// returns true if the task has any outstanding dependence
354
409
static bool __kmp_check_deps (kmp_int32 gtid, kmp_depnode_t *node,
355
- kmp_task_t *task, kmp_dephash_t *hash,
410
+ kmp_task_t *task, kmp_dephash_t ** hash,
356
411
bool dep_barrier, kmp_int32 ndeps,
357
412
kmp_depend_info_t *dep_list,
358
413
kmp_int32 ndeps_noalias,
@@ -552,7 +607,7 @@ kmp_int32 __kmpc_omp_task_with_deps(ident_t *loc_ref, kmp_int32 gtid,
552
607
__kmp_init_node (node);
553
608
new_taskdata->td_depnode = node;
554
609
555
- if (__kmp_check_deps (gtid, node, new_task, current_task->td_dephash ,
610
+ if (__kmp_check_deps (gtid, node, new_task, & current_task->td_dephash ,
556
611
NO_DEP_BARRIER, ndeps, dep_list, ndeps_noalias,
557
612
noalias_dep_list)) {
558
613
KA_TRACE (10 , (" __kmpc_omp_task_with_deps(exit): T#%d task had blocking "
@@ -633,7 +688,7 @@ void __kmpc_omp_wait_deps(ident_t *loc_ref, kmp_int32 gtid, kmp_int32 ndeps,
633
688
kmp_depnode_t node = {0 };
634
689
__kmp_init_node (&node);
635
690
636
- if (!__kmp_check_deps (gtid, &node, NULL , current_task->td_dephash ,
691
+ if (!__kmp_check_deps (gtid, &node, NULL , & current_task->td_dephash ,
637
692
DEP_BARRIER, ndeps, dep_list, ndeps_noalias,
638
693
noalias_dep_list)) {
639
694
KA_TRACE (10 , (" __kmpc_omp_wait_deps(exit): T#%d has no blocking "
0 commit comments