# How to use LoopVectorization.jl?

**URL:** https://discourse.julialang.org/t/how-to-use-loopvectorization-jl/103858
**Category:** General Usage
**Tags:** parallel, loopvectorization
**Created:** [September 14, 2023, 4:48pm UTC](https://discourse.julialang.org/t/how-to-use-loopvectorization-jl/103858 "2023-09-14T16:48:19Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)
#### Post date: [September 14, 2023, 5:02pm UTC](https://discourse.julialang.org/t/how-to-use-loopvectorization-jl/103858/2 "2023-09-14T17:02:55Z")

</div>

I can’t tell you how to fix it, but you might be hitting a (current) limitation of LoopVectorization. From the  
[README](https://github.com/JuliaSIMD/LoopVectorization.jl#usage)

> The macro assumes that loop iterations can be reordered. It also currently supports simple nested loops, **where loop bounds of inner loops are constant across iterations of the outer loop, and only a single loop at each level of loop nest.** These limitations should be removed in a future version.

Also, “thread-local state”, i.e. indexing arrays by thread id, is bound to break. Please see

> [@PSA: Thread-local state is no longer recommended; Common misconceptions about threadid() and nthreads()](https://discourse.julialang.org/t/psa-thread-local-state-is-no-longer-recommended-common-misconceptions-about-threadid-and-nthreads/101274):
>
> Here’s a new blogpost we’ve been working on for some weeks now intended to explain and help fix a common and incorrect pattern that has been showing up in multithreaded julia code The TL;DR is that if you’ve written code with things like state[Threads.threadid()] you’ve probably created a race condition and you should fix it immediately Shout out to @jling for pointing out the scale of this problem, and for encouraging us to think hard about how it should be approached and fixed.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-use-loopvectorization-jl/103858)._
