MCPcopy Create free account
hub / github.com/cactus-compute/cactus / enqueue_batch

Method enqueue_batch

cactus/kernel/kernel_utils.h:359–377  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

357
358 template<typename F>
359 void enqueue_batch(size_t total_work, F task_func) {
360 if (total_work == 0) return;
361
362 const size_t num_tasks = std::min(num_workers_, total_work);
363 const size_t per_worker = total_work / num_tasks;
364 const size_t remainder = total_work % num_tasks;
365
366 {
367 std::lock_guard<std::mutex> lock(mutex);
368 pending_tasks.fetch_add(num_tasks, std::memory_order_relaxed);
369
370 for (size_t w = 0; w < num_tasks; ++w) {
371 size_t start = w * per_worker + std::min(w, remainder);
372 size_t end = start + per_worker + (w < remainder ? 1 : 0);
373 tasks.emplace_back([=]() { task_func(start, end); });
374 }
375 }
376 work_available.notify_all();
377 }
378
379 void wait_all() {
380 std::unique_lock<std::mutex> lock(mutex);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected