# Error when trying the first example for LoopVectorization

**URL:** <https://discourse.julialang.org/t/error-when-trying-the-first-example-for-loopvectorization/33586>\
**Category:** New to Julia\
**Created:** [January 20, 2020, 2:14pm UTC](https://discourse.julialang.org/t/error-when-trying-the-first-example-for-loopvectorization/33586 "2020-01-20T14:14:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![lesshaste](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lesshaste/32/12302_2.png) [@lesshaste](https://discourse.julialang.org/u/lesshaste)\
**Post date:** [January 20, 2020, 2:14pm UTC](https://discourse.julialang.org/t/error-when-trying-the-first-example-for-loopvectorization/33586/1 "2020-01-20T14:14:33Z")

</div>

I am trying the first example from [GitHub - JuliaSIMD/LoopVectorization.jl: Macro(s) for vectorizing loops.](https://github.com/chriselrod/LoopVectorization.jl) . That is:

```julia
using LoopVectorization, BenchmarkTools
function mydot(a, b)
    s = 0.0
    @inbounds @simd for i ∈ eachindex(a,b)
        s += a[i]*b[i]
    end
    s
end
function mydotavx(a, b)
    s = 0.0
    @avx for i ∈ eachindex(a,b)
        s += a[i]*b[i]
    end
    s
end
a = rand(256); b = rand(256);
@btime mydot($a, $b)
@btime mydotavx($a, $b)
a = rand(43); b = rand(43);
@btime mydot($a, $b)
@btime mydotavx($a, $b)

```

I get an error from “s += a[i]\*b[i]” which is

> **ERROR:** LoadError: “Don’t know how to handle expression:\ns += a[i] \* b[i]”
> 
> Stacktrace:
> 
> [1] **push!(** ::LoopVectorization.LoopSet, ::Expr, ::Int64 **)** at **/Users/user/.julia/packages/LoopVectorization/WdP5f/src/graphs.jl:539**
> 
> [2] **add\_block!(** ::LoopVectorization.LoopSet, ::Expr, ::Int64 **)** at **/Users/user/.julia/packages/LoopVectorization/WdP5f/src/graphs.jl:310**
> 
> [3] **add\_loop!(** ::LoopVectorization.LoopSet, ::Expr, ::Int64 **)** at **/Users/user/.julia/packages/LoopVectorization/WdP5f/src/graphs.jl:401**
> 
> [4] **add\_loop!** at **/Users/user/.julia/packages/LoopVectorization/WdP5f/src/graphs.jl:398** [inlined]
> 
> [5] **copyto!** at **/Users/user/.julia/packages/LoopVectorization/WdP5f/src/constructors.jl:6** [inlined]
> 
> [6] **LoopVectorization.LoopSet(** ::Expr **)** at **/Users/user/.julia/packages/LoopVectorization/WdP5f/src/constructors.jl:45**
> 
> [7] **@avx(** ::LineNumberNode, ::Module, ::Any **)** at **/Users/user/.julia/packages/LoopVectorization/WdP5f/src/constructors.jl:93**
> 
> in expression starting at REPL[25]:3

Am I doing something dim or is this a bug?

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [January 20, 2020, 2:35pm UTC](https://discourse.julialang.org/t/error-when-trying-the-first-example-for-loopvectorization/33586/2 "2020-01-20T14:35:32Z")

</div>

My apologies.  
I messed up and tagged a bad commit. As soon as [CI passes on the latest commit](https://travis-ci.com/chriselrod/LoopVectorization.jl/builds/145226050), I will tag a new one (which will take another few minutes to merge).

EDIT: [PR on general registry](https://github.com/JuliaRegistries/General/pull/8208).

---

<div class="post-metadata">

**Author:** ![lesshaste](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lesshaste/32/12302_2.png) [@lesshaste](https://discourse.julialang.org/u/lesshaste)\
**Post date:** [January 20, 2020, 3:04pm UTC](https://discourse.julialang.org/t/error-when-trying-the-first-example-for-loopvectorization/33586/3 "2020-01-20T15:04:04Z")

</div>

Thank you. It looks like that process has finished but it can’t register the version number (which I guess should be 0.3.11?). I see: " **[JuliaRegistrator](https://github.com/JuliaRegistrator)** commented on `4192003`[14 minutes ago](https://github.com/chriselrod/LoopVectorization.jl/compare/3ec56c4d584e...41920031cddc#commitcomment-36878707)

Error while trying to register: “Tag with name `0.3.10` already exists and points to a different commit”"

When I do “update LoopVectorization” I still get 0.3.10.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [January 20, 2020, 3:05pm UTC](https://discourse.julialang.org/t/error-when-trying-the-first-example-for-loopvectorization/33586/4 "2020-01-20T15:05:45Z")

</div>

Yes. Tests passed, but I forgot to bump the version number. I edited my earlier post to add a link to the PR on the general registry with 0.3.11.

EDIT: To clarify, you need to wait until that PR merges before it is available. It has now.  
@JeffreySarnoff also recommended loosening version bounds, which I did for now. This is despite the fact that they do have lower bounds. This means you may need to make sure you’re on `SIMDPirates 0.1.8`.  
I’ll go back to micromanaging versions, and wait until CI passes before tagging so that this does not happen again.

---

<div class="post-metadata">

**Author:** ![lesshaste](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lesshaste/32/12302_2.png) [@lesshaste](https://discourse.julialang.org/u/lesshaste)\
**Post date:** [January 20, 2020, 3:25pm UTC](https://discourse.julialang.org/t/error-when-trying-the-first-example-for-loopvectorization/33586/5 "2020-01-20T15:25:23Z")

</div>

It works perfectly now. Just for interest, I get:

> **julia\>** a = rand(256); b = rand(256);  
> **julia\>** @btime mydot($a, $b)
> 
> 20.066 ns (0 allocations: 0 bytes)
> 
> 70.72502598935759
> 
> **julia\>** @btime mydotavx($a, $b)
> 
> 19.365 ns (0 allocations: 0 bytes)
> 
> 70.72502598935759
> 
> **julia\>** a = rand(43); b = rand(43);
> 
> **julia\>** @btime mydot($a, $b)
> 
> 10.704 ns (0 allocations: 0 bytes)
> 
> 10.22360436556094
> 
> **julia\>** @btime mydotavx($a, $b)
> 
> 7.602 ns (0 allocations: 0 bytes)
> 
> 10.22360436556094

This is on an OS X iMac (Retina 5K, 27-inch, Late 2015)

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [January 20, 2020, 3:32pm UTC](https://discourse.julialang.org/t/error-when-trying-the-first-example-for-loopvectorization/33586/6 "2020-01-20T15:32:45Z")

</div>

For simple loops like `mydot`, the main optimization is calculating the remainder faster than LLVM normally does.

On CPUs with the avx(2) instruction set, like your laptop, performance should be similar at multiples of 16. However, `mydot` will slow down more on average for each extra length you add. By the time `length(a) % 16 == 15`, `mydot` will probably be be a few nanoseconds slower than `mydotavx`.
