# Vectorization Advice

**URL:** <https://discourse.julialang.org/t/vectorization-advice/457>\
**Category:** General Usage\
**Created:** [November 21, 2016, 12:33am UTC](https://discourse.julialang.org/t/vectorization-advice/457 "2016-11-21T00:33:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JaredCrean2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaredcrean2/32/3574_2.png) [@JaredCrean2](https://discourse.julialang.org/u/JaredCrean2)\
**Post date:** [November 21, 2016, 12:33am UTC](https://discourse.julialang.org/t/vectorization-advice/457/1 "2016-11-21T00:33:25Z")

</div>

I have a sample code [here](https://github.com/JaredCrean2/wave6d/blob/master/src/vectorization_sample.jl), where `blockedLoop_5_2_16` vectorizes but `hilbertLoop_5_2_16` doesn’t (using julia 0.4, neither vectorize on 0.6, issue filed [here](https://github.com/JuliaLang/julia/issues/19369)). Any advise on how to get it to vectorize? What I have tried so far:

- running julia with --check-bounds=no --math-mode=fast (needed to get `blockedLoop` to vectorize
- Sprinkling `@simd` on all the loops (I think it only makes a difference on the innermost loop?) (needed to get `blockedLoop` to vectorize)
- updating the kernel to `+=` into the output array (in case the problem is that the compiler can’t prove each index is visited only once, hence can’t reorder assignments) (no effect)
- lifting the `16*(di - 1)` into the outermost loop and combining with `dioffset` (no effect)

For a performance comparison:

```julia
blockLoop timing:
  0.111497 seconds (1.70 k allocations: 93.875 KB)
  0.095680 seconds
hilbertLoop timing:
  0.218142 seconds (1.43 k allocations: 81.031 KB)
  0.191973 seconds

```

I ran this on a Ivy Bridge i7 processor (supports AVX instructions)
