Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

optimization with debug symbols. is that "-g -O3" or "-O3 -g" ?

Rene_S_1
Beginner
1,765 Views

 

Just wanted to verify what the precedence order is on compiler flags for the intel compilers is.

is the precedence that the last flag specified on the command line the one that wins?

I simply want to generate a binary that optimization level 3 "-O3" but that also includes debug symbols. "-g"

Will "-g -O3" do the trick?

Thanks

Rene

 

 

 

 

 

 

 

 

0 Kudos
9 Replies
Kevin_D_Intel
Employee
1,765 Views

Either order would do the trick. -g implies -O0 but the explicit -O3 overrides the implicit level 0.

You may want/need to include -debug extended. Refer to Debugging and Optimizations in the User Guide for more.

0 Kudos
Rene_S_1
Beginner
1,765 Views

 

 

Thank you for clearing that up for me and the link to the documentation. Exactly what I was looking for.

Rene

0 Kudos
Kevin_D_Intel
Employee
1,765 Views

You're welcome Rene. Glad to hear that.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,765 Views

Kevin,

Then what would -O3 -O0 produce?

The greater of, or last one issued?

What I am getting at is -g may have no implication or effect as to what the optimization level is to be used. (meaning default)

Jim Dempsey

0 Kudos
Kevin_D_Intel
Employee
1,765 Views

Hi Jim,

Here are some details/examples our compiler driver developer provided in the past regarding what we term "left-most/right-most wins", where the idea of left-most and right-most wins is how the command line is interpreted when dealing with options of the same family - or options that can be specified multiple times on the command line.

Here are some examples (same applies to C/C++):

ifort -opt1 -opt2 file.f90
// Above -opt1 and -opt2 are not of the same type or family both -opt1 and -opt2 get set, and ordering has no impact on behavior

ifort -opt1 -opt2 file.f90
// Above -opt1 and -opt2 are of the same type (i.e. -I<dir>)  -opt1 gets precedence over -opt2.  For -I<dir>, -opt1 will be searched first  for headers, then -opt2 will be searched.

ifort -opt1 -opt2 file.f90
// Above -opt1 and -opt2 are of the same family (i.e. -O2, -O3)  -opt2 wins over -opt1.  -opt2 will actually override the behavior the -opt1 behavior.

So -O0 “wins” in the -O3 -O0 scenario.

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,765 Views

Thanks Kevin,

I was more interested in having this clarified on this forum for others to read. It is best not to have a half answered question....

Thanks for going to an extra effort on your response above.

Jim Dempsey

0 Kudos
mecej4
Honored Contributor III
1,765 Views

The question regarding -On -g versus -g -On, where n=2, 3, etc., is one that Kevin's classification scheme in #6 does not cover: 

ifort -opt1 -opt2 file.f90

where opt1 has the effect of setting some of the switches that opt2 sets. I am not sure how to decide whether two options are of the same type or in the same family, especially when an "umbrella" option such as -g is concerned, or one option implies other (possibly unspecified but default) options. Should one do two passes, expanding umbrella options to "atomic" options in the first pass, and then apply the family/type rules?

0 Kudos
Steven_L_Intel1
Employee
1,765 Views

Lorri could probably explain better, but as I understand it: options are processed left-to-right. Group options, such as -standard-semantics, make their changes when they appear - individual options can be then changed again further to the right, (I may not have this exactly right - I will ask Lorri to comment.)

0 Kudos
Lorri_M_Intel
Employee
1,765 Views

I'm waving my hands a little bit here (which makes it interesting to type) but ...

Most of the time, options are processed left-to-right.

Some of the exceptions are, as mecj4 notes, ones that I call meta-options that tend to set multiple other options, such as "-fast" or "-standard-semantics".  And yes, individual command line switches from the meta-options can be overwritten by adding the negation of the individual command line *after* the meta-option.

Using -g is yet-another weird exception because, well, it's debug and it's everywhere.  By default, -g sets -O0 if you had not previously already explicitly set a different optimization.

So.  -O3 -g still sets optimization, even though the "-g" happens after the "-O3", and that's why this case works.

There are likely other special cases, but these are what comes to mind right now.

     I hope this helps --

                   --Lorri

 

0 Kudos
Reply