CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Parallel Tasking Library (PTL)
Lightweight C++11 multithreading tasking system featuring thread-pool, task-groups, and lock-free task queue
Basic Interface
#include "PTL/PTL.hh"
#include <cassert>
inline long
fibonacci(long n)
{
return (n < 2) ? n : (fibonacci(n - 1) + fibonacci(n - 2));
}
int main()
{
bool use_tbb = false;
auto num_threads = 4;
auto run_manager = PTL::TaskRunManager(use_tbb);
run_manager.Initialize(num_threads);
auto* task_manager = run_manager.GetTaskManager();
// add a task via the task manager
auto baz = task_manager->async<long>(fibonacci, 40);
// functor to combine results
auto join = [](long& lhs, long rhs) { return lhs += rhs; };
// create a task group for 10 fibonacci calculations
PTL::TaskGroup<long> foo(join);
for(uint64_t i = 0; i < 10; ++i)
foo.exec(fibonacci, 40);
// create a task group for 10 fibonacci calculations
PTL::TaskGroup<void> bar{};
long ret_bar = 0;
auto run = [&ret_bar](long n) { ret_bar += fibonacci(n); };
for(uint64_t i = 0; i < 10; ++i)
bar.exec(run, 40);
auto ret_baz = baz->get();
auto ret_foo = foo.join();
bar.join();
assert(ret_baz * 10 == ret_foo);
assert(ret_baz * 10 == ret_bar);
assert(ret_foo == ret_bar);
}
Explicit Thread-Pool
Using PTL::TaskRunManager is not necessary with task-groups.
You can create new thread-pools directly and pass them to task-groups:
long example()
{
// create a new thread-pool explicitly
PTL::ThreadPool tp(4);
// combines results
auto join = [](long& lhs, long rhs) { return lhs += rhs; };
// specify thread-pool explicitly
PTL::TaskGroup<long> foo(join, &tp);
for(int i = 0; i < 10; ++i)
foo.exec(fibonacci, 40);
// blocks until tasks in group are completed
// thread-pool is destroyed after function returns
return foo.get();
}