[Openmp-commits] [openmp] r322204 - Simplify __kmp_expand_threads

Jonathan Peyton via Openmp-commits openmp-commits at lists.llvm.org
Wed Jan 10 10:27:01 PST 2018


Author: jlpeyton
Date: Wed Jan 10 10:27:01 2018
New Revision: 322204

URL: http://llvm.org/viewvc/llvm-project?rev=322204&view=rev
Log:
Simplify __kmp_expand_threads

This change simplifies __kmp_expand_threads to take a single argument.
Previously, it allowed two arguments and had logic to decide on different
potential expansion sizes. However, no calls to __kmp_expand_threads in the
runtime make use of this extra logic. Thus the extra argument and logic is
removed here.

Patch by Terry Wilmarth

Differential Revision: https://reviews.llvm.org/D41836

Modified:
    openmp/trunk/runtime/src/kmp_runtime.cpp

Modified: openmp/trunk/runtime/src/kmp_runtime.cpp
URL: http://llvm.org/viewvc/llvm-project/openmp/trunk/runtime/src/kmp_runtime.cpp?rev=322204&r1=322203&r2=322204&view=diff
==============================================================================
--- openmp/trunk/runtime/src/kmp_runtime.cpp (original)
+++ openmp/trunk/runtime/src/kmp_runtime.cpp Wed Jan 10 10:27:01 2018
@@ -88,7 +88,7 @@ void __kmp_setup_icv_copy(kmp_team_t *te
 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 @@ static int __kmp_reserve_threads(kmp_roo
     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 @@ static int __kmp_reclaim_dead_roots(void
    __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 @@ static int __kmp_expand_threads(int nWis
     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 @@ static int __kmp_expand_threads(int nWis
         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 @@ int __kmp_register_root(int initial_thre
   }
 
   /* 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),




More information about the Openmp-commits mailing list