# Is it possible to use @simd with multiple variable loop?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-use-simd-with-multiple-variable-loop/5701>\
**Category:** Julia at Scale\
**Tags:** question, simd, parallel\
**Created:** [September 3, 2017, 8:32pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-simd-with-multiple-variable-loop/5701 "2017-09-03T20:32:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 3, 2017, 8:32pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-simd-with-multiple-variable-loop/5701/1 "2017-09-03T20:32:34Z")

</div>

Any chance of something like the following work?

```julia
@simd for i=1:10000, j=1:10000
  # do something
end

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [September 3, 2017, 11:55pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-simd-with-multiple-variable-loop/5701/2 "2017-09-03T23:55:47Z")

</div>

I don’t see any reason why `@simd` couldn’t work in this case by interpreting it exactly like this:

```julia
for i=1:10000
  @simd for j=1:10000
      # do something
  end
end

```

which does work. I think that capability just needs to be added.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 3, 2017, 11:57pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-simd-with-multiple-variable-loop/5701/3 "2017-09-03T23:57:20Z")

</div>

I discarded that option for now, in my case @simd is taking more time than the raw for loop.

Thanks for sharing your thoughts, I have the same feeling, that this could be implemented at some point.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [September 3, 2017, 11:59pm UTC](https://discourse.julialang.org/t/is-it-possible-to-use-simd-with-multiple-variable-loop/5701/4 "2017-09-03T23:59:11Z")

</div>

> [@juliohm](#):
>
> I discarded that option for now, in my case @simd is taking more time than the raw for loop.

Yeah, that’s pretty common. If you’re using the `-O3` setting for the compiler, it’ll add SIMD when it’s a good idea anyways, and its choice tends to be better than yours, or at least mine 🙂.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 4, 2017, 12:03am UTC](https://discourse.julialang.org/t/is-it-possible-to-use-simd-with-multiple-variable-loop/5701/5 "2017-09-04T00:03:48Z")

</div>

So we have to pass in an option to Clang somewhere?

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [September 4, 2017, 12:05am UTC](https://discourse.julialang.org/t/is-it-possible-to-use-simd-with-multiple-variable-loop/5701/6 "2017-09-04T00:05:12Z")

</div>

Oh, Julia has an option there, I will try later. Thanks!
