Index: runtime/src/kmp_runtime.cpp =================================================================== --- runtime/src/kmp_runtime.cpp +++ runtime/src/kmp_runtime.cpp @@ -88,7 +88,7 @@ static int __kmp_load_balance_nproc(kmp_root_t *root, int set_nproc); #endif -static int __kmp_expand_threads(int nWish, int nNeed); +static int __kmp_expand_threads(int nNeed); #if KMP_OS_WINDOWS static int __kmp_unregister_root_other_thread(int gtid); #endif @@ -941,7 +941,7 @@ int slotsRequired = __kmp_nth + new_nthreads - (root->r.r_active ? 1 : root->r.r_hot_team->t.t_nproc) - capacity; - int slotsAdded = __kmp_expand_threads(slotsRequired, slotsRequired); + int slotsAdded = __kmp_expand_threads(slotsRequired); if (slotsAdded < slotsRequired) { // The threads array was not expanded enough. new_nthreads -= (slotsRequired - slotsAdded); @@ -3501,22 +3501,16 @@ __kmpc_threadprivate_cached is done using __kmp_tp_cached_lock. After any dead root reclamation, if the clipping value allows array expansion - to result in the generation of a total of nWish free slots, the function does - that expansion. If not, but the clipping value allows array expansion to - result in the generation of a total of nNeed free slots, the function does - that expansion. Otherwise, nothing is done beyond the possible initial root - thread reclamation. However, if nNeed is zero, a best-effort attempt is made - to fulfil nWish as far as possible, i.e. the function will attempt to create - as many free slots as possible up to nWish. + to result in the generation of a total of nNeed free slots, the function does + that expansion. If not, nothing is done beyond the possible initial root + thread reclamation. If any argument is negative, the behavior is undefined. */ -static int __kmp_expand_threads(int nWish, int nNeed) { +static int __kmp_expand_threads(int nNeed) { int added = 0; int old_tp_cached; int __kmp_actual_max_nth; - if (nNeed > nWish) /* normalize the arguments */ - nWish = nNeed; #if KMP_OS_WINDOWS && !defined KMP_DYNAMIC_LIB /* only for Windows static library */ /* reclaim array entries for root threads that are already dead */ @@ -3527,13 +3521,8 @@ if (nNeed < 0) nNeed = 0; } - if (nWish) { - nWish -= added; - if (nWish < 0) - nWish = 0; - } #endif - if (nWish <= 0) + if (nNeed <= 0) return added; while (1) { @@ -3565,25 +3554,11 @@ old_tp_cached ? __kmp_tp_capacity : __kmp_sys_max_nth; KMP_DEBUG_ASSERT(__kmp_actual_max_nth >= __kmp_threads_capacity); - /* compute expansion headroom to check if we can expand and whether to aim - for nWish or nNeed */ - nTarget = nWish; + /* compute expansion headroom to check if we can expand */ + nTarget = nNeed; if (__kmp_actual_max_nth - __kmp_threads_capacity < nTarget) { - /* can't fulfil nWish, so try nNeed */ - if (nNeed) { - nTarget = nNeed; - if (__kmp_actual_max_nth - __kmp_threads_capacity < nTarget) { - /* possible expansion too small -- give up */ - break; - } - } else { - /* best-effort */ - nTarget = __kmp_actual_max_nth - __kmp_threads_capacity; - if (!nTarget) { - /* can expand at all -- give up */ - break; - } - } + /* possible expansion too small -- give up */ + break; } minimumRequiredCapacity = __kmp_threads_capacity + nTarget; @@ -3670,7 +3645,7 @@ } /* see if there are too many threads */ - if (__kmp_all_nth >= capacity && !__kmp_expand_threads(1, 1)) { + if (__kmp_all_nth >= capacity && !__kmp_expand_threads(1)) { if (__kmp_tp_cached) { __kmp_fatal(KMP_MSG(CantRegisterNewThread), KMP_HNT(Set_ALL_THREADPRIVATE, __kmp_tp_capacity),