# How to tell VS Code to use the fast math option?

**URL:** <https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257>\
**Category:** VS Code\
**Tags:** fast-math\
**Created:** [December 3, 2018, 5:49pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257 "2018-12-03T17:49:21Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 6, 2018, 3:03pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257/21 "2018-12-06T15:03:47Z")

</div>

> [@antoine-levitt](#):
>
> Talking about “at least having a comprehensive test suite” in this context is a non-starter. That has never stopped anybody from including a -ffast-math in their makefiles, **usually without any problems.**

Sorry for the somewhat epistemological question, but **how did they know** without a test suite?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 6, 2018, 3:50pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257/22 "2018-12-06T15:50:12Z")

</div>

> [@antoine-levitt](#):
>
> If in two years nobody has bothered to, then that’s the answer - nobody is using that feature and it can be removed. But removing it at this stage of the language development seems premature.

We could just leave it, but it’s a hard sell to implement the `@nofastmath` feature just to support a global flag that we probably shouldn’t have in the first place. I do think that users deserve some warning when they use an option that could quite possible render their computations into total nonsense in very unexpected ways. So maybe @Tamas_Papp’s banner should be added.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 6, 2018, 4:23pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257/23 "2018-12-06T16:23:33Z")

</div>

I must insist on the cow’s eyes being red.

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [December 6, 2018, 7:34pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257/24 "2018-12-06T19:34:07Z")

</div>

The option `--math-mode=fast` is “dangerous” but what about “-O3”? Is it also dangerous to use it?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 6, 2018, 7:34pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257/25 "2018-12-06T19:34:49Z")

</div>

No. (also since SLP is included in O2 I haven’t seen any benchmark where O3 is better than the default)

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [December 6, 2018, 7:40pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257/26 "2018-12-06T19:40:18Z")

</div>

> [@kristoffer.carlsson](#):
>
> SLP is included in O2

How can I know what option is being used from within my Julia session?  
What optimization option is used if I launch Julia from VS Code?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 6, 2018, 7:45pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257/27 "2018-12-06T19:45:20Z")

</div>

`Base.JLOptions().opt_level`

---

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [December 6, 2018, 7:59pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257/28 "2018-12-06T19:59:26Z")

</div>

> [@kristoffer.carlsson](#):
>
> Base.JLOptions().opt\_level

OK, thanks, VS Code says it’s using -O 2.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [December 6, 2018, 8:31pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257/29 "2018-12-06T20:31:58Z")

</div>

That’s the default.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 7, 2018, 4:10pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257/30 "2018-12-07T16:10:15Z")

</div>

Based on this thread [and others](https://discourse.julialang.org/t/how-to-know-what-optimization-options-are-been-used-how-to-change-it-on-vs-code-o-3/18368), I have a feeling you may be fixating a bit too much on compiler flags. Julia already defaults to good performance—you should not need to mess around with optimization flags unless you are doing something pretty unusual. Frankly, the `--math-mode=fast` flag is a bad idea and you shouldn’t use it at all (sorry, @antoine-levitt, but that’s my honest opinion) and `-O3` is basically the same as `-O2` which is already the default. These options are not some magic wand to make your code faster—even if they do, it will only be by a very small margin. If your code is not fast enough, instead of messing with compiler flags, you should: profile it, look at allocation stats, make sure it’s type stable, make sure you don’t use non-constant globals, and put `@inline` and `@simd` annotations where appropriate. Or better still, use better algorithms—that’s where the most dramatic speed improvements come from. In all my time doing Julia consulting work helping people speed up their code, I have never once changed any compiler flags.

---

<div class="post-metadata">

**Author:** ![antoine-levitt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/antoine-levitt/32/4008_2.png) [@antoine-levitt](https://discourse.julialang.org/u/antoine-levitt)\
**Post date:** [December 7, 2018, 5:03pm UTC](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257/31 "2018-12-07T17:03:10Z")

</div>

FWIW, I almost completely agree: `--math-mode=fast` is the last resort of the last resort, after thinking about the problem, the algorithm, the structure of the code, the code itself, and then the micro optimizations, all that with copious profiling. It’s just that sometimes, you’ve done all that (or decided you’ve done enough and further improvements would be too much of a bother), you play around with flags for 5 minutes (either of the safe variety like O3 or of the frankly dangerous variety with math-mode), you’ve made sure it doesn’t significantly change the result and it gives you an extra 10% with no modification to your code. Seems a shame to let that go.

[Previous page](https://discourse.julialang.org/t/how-to-tell-vs-code-to-use-the-fast-math-option/18257.md?page=1)
