Squeeze - Parallel loops and sections with JUCE

Hi,

I’ve implemented a small single-header “library” providing parallel for loops and sections using the ThreadPool class of JUCE:

A short example how it looks like:

void Example()
{
  std::vector<float> data(...);

  // Grab some thread pool
  // (try to reuse thread pool as much as possible to mitigate
  // the quite expensive thread creation)
  juce::ThreadPool& threadPool = GetThreadPool();

  // Loop using iterators
  squeeze::ParallelFor(threadPool, begin(data), end(data), [&](std::vector<float>::iterator it)
  {
    (*it) = SomeCalculation(*it);
  });

  // Loop using indices
  squeeze::ParallelFor(threadPool, size_t(0), data.size(), [&](size_t i)
  {
    data[i] = AnotherCalculation(i);
  });

  // Performing three different calculations in parallel
  squeeze::ParallelInvoke(threadPool,
    [&]() { SomeCalculation(data); },
    [&]() { AnotherCalculation(data); },
    [&]() { YetAnotherCalculation(data); });
}

Please have a look at the README.md for further information.

It is published using the quite liberal MIT license.

Maybe it is useful for some people. :slight_smile:

Regards and have a nice weekend,

Uli

6 Likes

Am i nuts for wanting to use this in a synthesizer voice class to process 3 oscillators and 3 samplers?

Or am I missing the point, is this suppose to be more of a supportive role to the main threads?

Either way this is really cool, just like your convolution, and FFT classes!