TooManyCooks icon indicating copy to clipboard operation
TooManyCooks copied to clipboard

`tmc::spawn_group` - analogue to `tbb::task_group`

Open tzcnt opened this issue 9 months ago • 0 comments

OneAPI/Intel TBB has a type called tbb::task_group which can be used to create and wait for a group of tasks imperatively.

  tbb::task_group tg;
  for (size_t i = 0; i < N; ++i) {
    tg.run([=]() { do_something(); });
  }
  tg.wait();

This type would be useful to implement in TMC for two reasons:

  1. The current iterator-based approach provided by tmc::spawn_many() is very efficient, but can introduce friction in some use cases. The imperative approach may be more straightforward, and it would be a nice tool to have available.
  2. Simplifies the migration of TBB code to TMC by providing a similar interface.

The proposed API would have two constructors:

  • a default constructor which would require specifying the awaitable type
    • usage: tmc::spawn_group<tmc::task<int>> tg();
  • a constructor taking the first instance of the awaitable group, which can deduce the awaitable type
    • usage: tmc::spawn_group tg(first);

The group would be executed by co_await std::move(tg); or can be forked with .fork() which would produce a new awaitable type.

tzcnt avatar Apr 08 '25 01:04 tzcnt