# Performance gotcha in linear algebra lu()

**URL:** <https://discourse.julialang.org/t/performance-gotcha-in-linear-algebra-lu/18128>\
**Category:** General Usage\
**Tags:** performance, linearalgebra\
**Created:** [November 29, 2018, 5:14am UTC](https://discourse.julialang.org/t/performance-gotcha-in-linear-algebra-lu/18128 "2018-11-29T05:14:59Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 30, 2018, 4:30pm UTC](https://discourse.julialang.org/t/performance-gotcha-in-linear-algebra-lu/18128/11 "2018-11-30T16:30:59Z")

</div>

> [@stevengj](#):
>
> The `pivot=false` option is basically only useful for pedagogy (comparing to hand calculations or toy code for tiny matrices), and should never be used in real problems because it can make the calculation numerically unstable. Improving its performance would serve no practical purpose.

That is a fair point. But we shouldn’t miss the important part of the story: the performance of the BLAS-supported LU factorization is erratic for smaller matrix sizes, and in fact it is outperformed by the generic Julia version (both WITH PIVOTING).

With just a small change to the code (the “better” implementation of the generic LU factorization), the performance can be improved further.

![image](https://global.discourse-cdn.com/julialang/original/3X/b/7/b7eda50c4a101ca766f96b8d5f3a8633cbea2756.png)

The break-even point between `lu!` and `generic_lufact!` is around 200 equations. NB: For 10 equations or less, the static-array solver implementation may provide further improvements in speed with the generic version of the factorization. (I don’t know if the static array can be passed to the BLAS-supported solver.)

I think it might be of interest to compare with the MKL solver. If anyone has access to it, would you please run the code in [Testing LU · GitHub](https://gist.github.com/PetrKryslUCSD/758d19f03ee2f643bf1f76fe9f5c40ac) and post the generated graph?

EDIT: Additional results for complex matrices. Same computer as above.  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/4/9/49517f2aad7e6a19a5383131b467a8a44450b184.png)

---

_[View the full topic](https://discourse.julialang.org/t/performance-gotcha-in-linear-algebra-lu/18128)._
