| 273 | /** @brief Use n_threads as the number of blocks. */ |
| 274 | template <typename Index, typename Func> |
| 275 | void ParallelForBlock(Index size, std::int32_t n_threads, Func&& fn) { |
| 276 | static_assert(std::is_void_v<std::invoke_result_t<Func, common::Range1d>>); |
| 277 | std::size_t blk_size = size / n_threads + (size % n_threads > 0); |
| 278 | ParallelFor(n_threads, n_threads, [&](auto tid) { |
| 279 | auto blk_beg = tid * blk_size; |
| 280 | auto blk_end = std::min((tid + 1) * blk_size, static_cast<std::size_t>(size)); |
| 281 | if (blk_end <= blk_beg) { |
| 282 | return; |
| 283 | } |
| 284 | fn(common::Range1d{blk_beg, blk_end}); |
| 285 | }); |
| 286 | } |
| 287 | |
| 288 | inline std::int32_t OmpGetThreadLimit() { |
| 289 | std::int32_t limit = omp_get_thread_limit(); |
no test coverage detected