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:
-O2
flag tells the compiler to perform significant optimizations (which for Fortran, includes function inlining). -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.) -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....
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....)
I then link the object files together and create the executable:
ifort -O2 -finline-functions -ipo myProgram.o function.o subroutine.o -o MyProgram
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?
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 ...
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.
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.
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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With