# Squeeze - Parallel loops and sections with JUCE

**URL:** <https://forum.juce.com/t/squeeze-parallel-loops-and-sections-with-juce/19579>\
**Category:** Useful Tools and Components\
**Created:** [October 21, 2016, 9:06pm UTC](https://forum.juce.com/t/squeeze-parallel-loops-and-sections-with-juce/19579 "2016-10-21T21:06:46Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![hifi-lofi](https://avatars.discourse-cdn.com/v4/letter/h/5daacb/32.png) [@hifi-lofi](https://forum.juce.com/u/hifi-lofi)\
**Post date:** [October 21, 2016, 9:06pm UTC](https://forum.juce.com/t/squeeze-parallel-loops-and-sections-with-juce/19579/1 "2016-10-21T21:06:46Z")

</div>

Hi,

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

> **[HiFi-LoFi/Squeeze](https://github.com/HiFi-LoFi/Squeeze)**
>
> Squeeze - Single-header library for parallel programming in 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](https://github.com/HiFi-LoFi/Squeeze/blob/master/README.md) for further information.

It is published using the quite liberal MIT license.

Maybe it is useful for some people. 🙂

Regards and have a nice weekend,

Uli

---

_[View the full topic](https://forum.juce.com/t/squeeze-parallel-loops-and-sections-with-juce/19579)._
