Squeeze - Parallel loops and sections with JUCE



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
    [&]() { 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,


Minor feature request: ThreadPool::getNumThreads() const