# Parallel windowing

**URL:** <https://discourse.julialang.org/t/parallel-windowing/10170>\
**Category:** Performance\
**Tags:** parallel, smoothing\
**Created:** [April 5, 2018, 5:01am UTC](https://discourse.julialang.org/t/parallel-windowing/10170 "2018-04-05T05:01:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [April 5, 2018, 5:01am UTC](https://discourse.julialang.org/t/parallel-windowing/10170/1 "2018-04-05T05:01:39Z")

</div>

To determine the values of a simple moving average, where the length of the MA window is much smaller than the length of the data vector, one may … and usually does … run through the data sequentially, moving the window in unit increments (as it were).

With a window of 10, and a data source of 49 sequential values (where the first nine are used only to contribute to the first MA value), it is possible to run more than one MA over apportionings of the data and to recombine these tasks’ results to obtain the same result as above.

What way does this happen well using Julia?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 5, 2018, 5:12am UTC](https://discourse.julialang.org/t/parallel-windowing/10170/2 "2018-04-05T05:12:22Z")

</div>

Frankly, with a vector of length 49, I doubt you would gain anything from parallelization; I expect the overhead would dominate the computational cost.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [April 5, 2018, 6:02am UTC](https://discourse.julialang.org/t/parallel-windowing/10170/3 "2018-04-05T06:02:42Z")

</div>

the 49 was just for easy math – the actual vectors have 100s of 1000s of values

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 5, 2018, 7:07am UTC](https://discourse.julialang.org/t/parallel-windowing/10170/4 "2018-04-05T07:07:21Z")

</div>

You can experiment with `pmap` (see the [manual](https://docs.julialang.org/en/latest/manual/parallel-computing/)), but note that MA is usually cheap for the CPU and thus the bottleneck may be memory access.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [April 5, 2018, 7:12am UTC](https://discourse.julialang.org/t/parallel-windowing/10170/5 "2018-04-05T07:12:38Z")

</div>

I was hoping for a SIMDy way. The distributed processing would be too heavy for this (and not all vectors are that long, some are 750).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 5, 2018, 7:21am UTC](https://discourse.julialang.org/t/parallel-windowing/10170/6 "2018-04-05T07:21:04Z")

</div>

If you have a type which does not suffer from floating point error (eg `Int`), you can do a “rolling sum”, adding and subtracting as you work through the vector. This may be amenable to SIMD. But for floats, this may not be accurate (again, depending on dimension and distribution of the actual data).

Also, you may get better help if you provide an MWE that roughly matches your dimensions (both for vector and window length). So far you talked about 10/49, ?/750, and ?/10^5, so I m confused about this. If you have really long windows, you could sum subsequences and then use those with a clever algorithm, but it would only be worth it for long windows.

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [April 5, 2018, 7:22am UTC](https://discourse.julialang.org/t/parallel-windowing/10170/7 "2018-04-05T07:22:24Z")

</div>

ok – thank you for that
