# Compiling options for speed optimization

**URL:** <https://fortran-lang.discourse.group/t/compiling-options-for-speed-optimization/472>\
**Category:** Help\
**Created:** [December 9, 2020, 3:30pm UTC](https://fortran-lang.discourse.group/t/compiling-options-for-speed-optimization/472 "2020-12-09T15:30:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CConde](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@CConde](https://fortran-lang.discourse.group/u/CConde)\
**Post date:** [December 9, 2020, 3:30pm UTC](https://fortran-lang.discourse.group/t/compiling-options-for-speed-optimization/472/1 "2020-12-09T15:30:01Z")

</div>

Dear friends,

Please, I would like to ask for your recommendations on the best compiling options for optimizing code speed performance. I use the last version of GFortran.

Tipically, I use -Ofast, but I don’t know if this is enough. The website of GFortran states that adding  
-fcoarray = simple, -lcaf\_single improves speed. I’ve tested it, but the result was the opposite, it was slower.

Many thanks for your help.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [December 9, 2020, 5:37pm UTC](https://fortran-lang.discourse.group/t/compiling-options-for-speed-optimization/472/3 "2020-12-09T17:37:17Z")

</div>

With `gfortran` I use `-O3 -march=native -ffast-math -funroll-loops` with good results. I believe the `-Ofast` enables all those.

---

<div class="post-metadata">

**Author:** ![certik](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/certik/32/4_2.png) [@certik](https://fortran-lang.discourse.group/u/certik)\
**Post date:** [December 9, 2020, 5:54pm UTC](https://fortran-lang.discourse.group/t/compiling-options-for-speed-optimization/472/5 "2020-12-09T17:54:23Z")

</div>

Yes, what @kargl said is correct. I develop in Debug mode with the options `-Wall -Wextra -Wimplicit-interface -fPIC -g -fcheck=all -fbacktrace`. Then in Release mode with the options I suggested above, I always test that the numerical results are acceptable in terms of accuracy against the Debug mode results.

---

<div class="post-metadata">

**Author:** ![CConde](https://avatars.discourse-cdn.com/v4/letter/c/d6d6ee/32.png) [@CConde](https://fortran-lang.discourse.group/u/CConde)\
**Post date:** [December 9, 2020, 7:02pm UTC](https://fortran-lang.discourse.group/t/compiling-options-for-speed-optimization/472/6 "2020-12-09T19:02:13Z")

</div>

@kargl, @certik, many thanks for your help.

---

<div class="post-metadata">

**Author:** ![septc](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/septc/32/77_2.png) [@septc](https://fortran-lang.discourse.group/u/septc)\
**Post date:** [December 15, 2020, 7:24pm UTC](https://fortran-lang.discourse.group/t/compiling-options-for-speed-optimization/472/7 "2020-12-15T19:24:29Z")

</div>

> [@kargl](#):
>
> If you have well-written code, then `-ftree-vectorize` may be of help.

I’ve never used this `-ftree-vectorize` (which I found on the gcc man page), which seems interesting 🙂 (but I am not sure what “tree” means here so need to read man pages more…)
