MCPcopy Create free account
hub / github.com/dmlc/xgboost / ParallelForBlock

Function ParallelForBlock

src/common/threading_utils.h:275–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

273/** @brief Use n_threads as the number of blocks. */
274template <typename Index, typename Func>
275void 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
288inline std::int32_t OmpGetThreadLimit() {
289 std::int32_t limit = omp_get_thread_limit();

Callers 3

EvalMethod · 0.85
MakeFixedVecWithMallocFunction · 0.85
IotaFunction · 0.85

Calls 2

ParallelForFunction · 0.85
fnFunction · 0.85

Tested by

no test coverage detected