Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does ifort use optimization flags?

Introduction

I understand that Intel's Fortran compiler ifort performs some amount of function inlining and interprocedural optimization (IPO), as well as other, standard optimizations. This can be done as in the following example:

ifort -O2 -finline-functions -ipo myProgram.f function.f subroutine.f -o MyProgram

Compiler Option Explanations:

  • The -O2 flag tells the compiler to perform significant optimizations (which for Fortran, includes function inlining).
  • The -finline-functions flag tells the compiler to allow function inlining. (This is the default behavior; I include the flag here for the sake of explicitness.)
  • The -ipo flag tells the compiler to perform IPO.

Suppose I break up the compilation process into two steps, as is often done when using a Makefile....

Step 1

I compile and assemble a bunch of files separately, turning source code into object files:

ifort -O2 -ipo -c   function.f -o   function.o
ifort -O2 -ipo -c subroutine.f -o subroutine.o
ifort -O2 -ipo -c  myProgram.f -o  myProgram.o

(I'm guessing no inlining is done at this step because the files are compiled independently....)

Step 2

I then link the object files together and create the executable:

  • ifort -O2 -finline-functions -ipo myProgram.o function.o subroutine.o -o MyProgram

My Question

If I do compile files individually, which of these optimization flags should be passed to the compiler at which stages? During which step are inlining and IPO performed?

like image 309
jvriesem Avatar asked Mar 09 '18 21:03

jvriesem


People also ask

What are the different flags in compiler optimization?

General Compiler Optimization Flags Flag Description -O Optimized compile. -O2 More extensive optimization. Recommended ... -O3 More aggressive than -O2 with longer com ... -Ofast -O3 plus some extras. 2 more rows ...

How to check which target architecture optimization flags are being used?

Currently, using --optarch=GENERIC will result in the following target architecture optimization flags being used, (on a Linux x86-64 system): for toolchains using GCC compilers: -march=x86-64 -mtune=generic On other systems or for other compilers, you can check which compiler flags will be used via Extended dry run.

What is ifort compiler?

Intel's traditional Fortran compiler that has a long history we will informally call ifort. Officially it is called the Intel® Fortran Compiler Classic and is part of the Intel® oneAPI HPC Toolkit beginning with the 2021.1 release.

Why can't I use ifort with IFX?

If you compile using the -ipocompiler option, there is no compatibility between the object files created by ifort and ifx. Intel linker xi* tools removed Intel tools xilink, xild, and xiar are removed from ifx as they serve no purpose – they are specific to the proprietary object file formats used by the Intel® Compilers.


1 Answers

When you compile with -ipo, the compiler generates intermediate code but does no optimization or inlining at all. You have .o files but they don't contain any machine instructions. When you then call ifort again to create the executable, the compiler then sucks up all the intermediate code and optimizes it as if you had compiled everything in one big source file. It can then see which routines are referenced and where and can do more optimization and inlining.

You should pass the same optimization options for each compile - they are recorded along with the intermediate code.

I'm pretty sure that other compilers with a similar feature do it much the same way. (I'm a former Intel compiler dev/support engineer.)

like image 188
Steve Lionel Avatar answered Sep 22 '22 22:09

Steve Lionel