Add some parallel algorithms to JUCE?

Wouldn’t it be useful to have at least these 3 algorithms available with thread parallel implementations in JUCE :

  1. parallel_for_each. Just conveniently goes through a container’s elements.
  2. parallel_for. for loop with an integer index.
  3. parallel_reduce. Reduces a container to a single value, starting from a given initial value, using some operation to combine the elements. (std::accumulate is the C++ standard library equivalent of this.)

Microsoft’s PPL has these and these probably can be made with help from Apple’s Grand Central Dispatch functions too, but a cross platform solution available from JUCE would be nice…(I realize that the C++ standard library itself is in the works to have parallel versions of some its algorithms but of course it will take time before those new versions are available for every platform…)


To do this I highly recommend Intel’s Thread Building Blocks libraries. They’re Apache licensed, cross platform and can elegantly handle exactly what you’re trying to do.

Part of the issue with creating generalized parallel algorithms like this in an environment like JUCE is there is a lot of assumptions that have to be made which can have major performance implications. Some of the biggest being thread creation/deletion overhead vs. thread re-use, efficiently sharing resources, etc. which would crop up when an OS-provided asynchronous dispatcher like GCD or PPL isn’t available.

Intel TBB takes care of this by maintaining a global thread pool it uses for all dispatch operations, sort of like an application-level GCD. Theoretically this could also be accomplished with JUCE in a cross-platform way, but why reinvent the wheel?

1 Like

I know of TBB of course. Having this stuff in JUCE would mainly be for convenience of use. TBB is somewhat annoying to set up as it depends on adding prebuilt lib etc files into the build process.

1 Like