# Define macros depending on optimization level

**URL:** <https://discourse.julialang.org/t/define-macros-depending-on-optimization-level/105714>\
**Category:** General Usage\
**Tags:** macros, command-line-options\
**Created:** [November 2, 2023, 5:43pm UTC](https://discourse.julialang.org/t/define-macros-depending-on-optimization-level/105714 "2023-11-02T17:43:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mancolric](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mancolric/32/21799_2.png) [@mancolric](https://discourse.julialang.org/u/mancolric)\
**Post date:** [November 2, 2023, 5:43pm UTC](https://discourse.julialang.org/t/define-macros-depending-on-optimization-level/105714/1 "2023-11-02T17:43:36Z")

</div>

I would like to define the macro `const var"@lvec" = const var"@turbo @."` if Julia is started with optimization levels 2 or 3, and `const var"@lvec" = const var"@."` otherwise.

My main motivation is that I use `@tturbo @.` very often. However, sometimes it fails to throw an error if the dimensions of the involved arrays are not consistent, whereas `@.` does not fail. So, I would like to define a single macro that is either any of them depending on the optimization level.

I am facing two problems:

1. I do not know what command I should use to get the current optimization level – I need this to define an `if` sentence.
2. If I type `const var"@lvec" = var"@."` in the REPL, I get the error ` `@.` not defined`, something that does not happen, e.g., if I type `const var"@lvec" = var"@warn"`.

Any help will be appreciated.

---

<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:** [November 2, 2023, 6:31pm UTC](https://discourse.julialang.org/t/define-macros-depending-on-optimization-level/105714/2 "2023-11-02T18:31:10Z")

</div>

You could also PR LV to check broadcast bounds.

---

<div class="post-metadata">

**Author:** ![mancolric](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mancolric/32/21799_2.png) [@mancolric](https://discourse.julialang.org/u/mancolric)\
**Post date:** [November 2, 2023, 7:41pm UTC](https://discourse.julialang.org/t/define-macros-depending-on-optimization-level/105714/3 "2023-11-02T19:41:33Z")

</div>

What do you mean by PR LV?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [November 2, 2023, 7:45pm UTC](https://discourse.julialang.org/t/define-macros-depending-on-optimization-level/105714/4 "2023-11-02T19:45:45Z")

</div>

I’d think, “make a pull request (PR) for LoopVectorization.jl (LV)”.
