Browse Source

Use environment variable LIBIGL_NUM_THREADS as a hint.

Former-commit-id: 22662eed96b6fd031cd40bd4b4dda4b6ac0ad88d
Qingnan Zhou 9 years ago
parent
commit
417c9dd205
1 changed files with 9 additions and 1 deletions
  1. 9 1
      include/igl/copyleft/cgal/SelfIntersectMesh.h

+ 9 - 1
include/igl/copyleft/cgal/SelfIntersectMesh.h

@@ -962,7 +962,15 @@ inline void igl::copyleft::cgal::SelfIntersectMesh<
       }
     }
   };
-  const size_t num_threads = std::thread::hardware_concurrency();
+  size_t num_threads=0;
+  const size_t hardware_limit = std::thread::hardware_concurrency();
+  if (const char* igl_num_threads = std::getenv("LIBIGL_NUM_THREADS")) {
+    num_threads = atoi(igl_num_threads);
+  }
+  if (num_threads == 0 || num_threads > hardware_limit) {
+    num_threads = hardware_limit;
+  }
+  assert(num_threads > 0);
   const size_t num_pairs = candidate_box_pairs.size();
   const size_t chunk_size = num_pairs / num_threads;
   std::vector<std::thread> threads;