# Eigvals() results being slightly different when Distributed.jl are used

**URL:** <https://discourse.julialang.org/t/eigvals-results-being-slightly-different-when-distributed-jl-are-used/49516>\
**Category:** Numerics\
**Tags:** linearalgebra\
**Created:** [November 3, 2020, 12:23pm UTC](https://discourse.julialang.org/t/eigvals-results-being-slightly-different-when-distributed-jl-are-used/49516 "2020-11-03T12:23:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zhaiyusci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zhaiyusci/32/13125_2.png) [@zhaiyusci](https://discourse.julialang.org/u/zhaiyusci)\
**Post date:** [November 3, 2020, 12:23pm UTC](https://discourse.julialang.org/t/eigvals-results-being-slightly-different-when-distributed-jl-are-used/49516/1 "2020-11-03T12:23:16Z")

</div>

Hi friends, recently I am working on some eigen problems in quantum physics. I need to construct and diagonalize quite a few symmetric real matrices so I am using Distributed, the standard library.

See a minimal example.

```julia
using Distributed
@everywhere using LinearAlgebra

function symrand(n)
  A=rand(n,n)
  A+=transpose(A)
  A
end

mats=[symrand(10) for _ in 1:1]

# distributed version
function exec1()
  temp=[]
  for (p, m) in Iterators.zip(Iterators.cycle(workers()), mats)
    push!(temp,remotecall(eigvals, p, m))
  end
  for j in temp
    @show fetch(j)
  end
end

# series version
function exec2()
  for m in mats
    @show eigvals(m)
  end
end

@time exec1() # ...1
@time exec1() # ...2
@time exec1()

@time exec2() # ...3
@time exec2()
@time exec2()

```

We can then save the codes above in `eigs.jl` and run with `julia -p2 eigs.jl`.

I find the distributed results of `eigvals()` (also `eigvecs`, `eigen`) returns differently (i.e., `1` and `3` differ slightly), while I can also run the same function several times and always gives same result (I.e., `1` and `2` give exactly same output).

It should be mentioned that the difference is very small. I read something about floating number arithmetic, but I am not sure about it here. Did I wrote something wrong or it is a possible bug in the library or it cannot be avoided?

---

<div class="post-metadata">

**Author:** ![Noel\_Araujo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noel_araujo/32/4862_2.png) [@Noel\_Araujo](https://discourse.julialang.org/u/Noel_Araujo)\
**Post date:** [November 3, 2020, 4:24pm UTC](https://discourse.julialang.org/t/eigvals-results-being-slightly-different-when-distributed-jl-are-used/49516/2 "2020-11-03T16:24:42Z")

</div>

The error is around 10e-15, for sure is a floating point fault; I just don’t know “where”.

Unless you need high precision results, this difference is small enough to be ignored 😀

---

<div class="post-metadata">

**Author:** ![fph](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fph/32/17159_2.png) [@fph](https://discourse.julialang.org/u/fph)\
**Post date:** [November 3, 2020, 4:51pm UTC](https://discourse.julialang.org/t/eigvals-results-being-slightly-different-when-distributed-jl-are-used/49516/3 "2020-11-03T16:51:30Z")

</div>

Usually there is no guarantee that linear algebra operations behave in the same way on all machines and implementations. For instance, even on the same machine and with the same compiler optimizations, changing the BLAS library you use will alter slightly your results. You can look into projects such as [Reproblas](https://bebop.cs.berkeley.edu/reproblas/) if you wish to have exact reproducibility (warning: that may come at a large performance cost).
