| 106 | } |
| 107 | |
| 108 | std::int32_t OmpGetNumThreads(std::int32_t n_threads) noexcept(true) { |
| 109 | // Don't use parallel if we are in a parallel region. |
| 110 | if (omp_in_parallel()) { |
| 111 | return 1; |
| 112 | } |
| 113 | // Honor the openmp thread limit, which can be set via environment variable. |
| 114 | auto max_n_threads = std::min({omp_get_num_procs(), omp_get_max_threads(), OmpGetThreadLimit()}); |
| 115 | // If -1 or 0 is specified by the user, we default to maximum number of threads. |
| 116 | if (n_threads <= 0) { |
| 117 | n_threads = max_n_threads; |
| 118 | } |
| 119 | n_threads = std::min(n_threads, max_n_threads); |
| 120 | n_threads = std::max(n_threads, 1); |
| 121 | return n_threads; |
| 122 | } |
| 123 | |
| 124 | void NameThread(std::thread* t, StringView name) { |
| 125 | #if defined(__linux__) && (!defined(__ANDROID__) || __ANDROID_API__ >= 26) |