You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by cj...@apache.org on 2018/11/15 01:21:37 UTC

[incubator-mxnet] branch master updated: Manually track num_max_thread (#12380)

This is an automated email from the ASF dual-hosted git repository.

cjolivier01 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/master by this push:
     new 7541021  Manually track num_max_thread (#12380)
7541021 is described below

commit 75410210e07a5fab5e044348aee276d578d5857e
Author: Alexander Zai <az...@gmail.com>
AuthorDate: Wed Nov 14 17:21:25 2018 -0800

    Manually track num_max_thread (#12380)
    
    * use cached version of get thread max
    
    * reserve core affects omp singleton
    
    * omp_thread_max_ updated in one line
    
    * remove enabled block
    
    * add brackets
    
    * re-add excluded reserved
    
    * add missing var
    
    * refactor macro
---
 src/engine/openmp.cc | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/engine/openmp.cc b/src/engine/openmp.cc
index 8fe3939..64899b0 100644
--- a/src/engine/openmp.cc
+++ b/src/engine/openmp.cc
@@ -73,18 +73,14 @@ void OpenMP::set_reserve_cores(int cores) {
   CHECK_GE(cores, 0);
   reserve_cores_ = cores;
 #ifdef _OPENMP
-  if (reserve_cores_ >= omp_thread_max_) {
-    omp_set_num_threads(1);
-  } else {
-    omp_set_num_threads(omp_thread_max_ - reserve_cores_);
-  }
+  omp_thread_max_ = std::max(omp_thread_max_ - reserve_cores_, 1);
 #endif
 }
 
 int OpenMP::GetRecommendedOMPThreadCount(bool exclude_reserved) const {
 #ifdef _OPENMP
   if (omp_num_threads_set_in_environment_) {
-    return omp_get_max_threads();
+    return omp_thread_max_;
   }
   if (enabled_) {
     int thread_count = omp_get_max_threads();
@@ -101,10 +97,8 @@ int OpenMP::GetRecommendedOMPThreadCount(bool exclude_reserved) const {
     }
     return omp_thread_max_;
   }
-  return 1;
-#else
-  return 1;
 #endif
+  return 1;
 }
 
 OpenMP *__init_omp__ = OpenMP::Get();