Example of Profile-Guided Optimization

The sections in this topic provide examples of the three basic phases of PGO, which are:

Profile-guided Optimization (PGO) Phases

Instrumentation Compilation and Linking

Use -prof-gen (Linux*) or /Qprof-gen (Windows*) to produce an executable with instrumented information included.

Use the -prof-dir (Linux) or /Qprof-dir (Windows) option for most programs, especially if the application includes the source files located in multiple directories. -prof-dir (Linux) or /Qprof-dir (Windows) ensures that the profile information is generated in one consistent place. The following example commands demonstrate how to combine these options:

Platform

Commands

Linux

ifort -prof-gen -prof-dir/usr/profdata -c a1.f a2.f a3.f

ifort -oa1 a1.o a2.o a3.o

Windows

ifort /Qprof-gen /Qprof-dirc:\profdata /c a1.f a2.f a3.f

ifort a1.obj a2.obj a3.obj

In place of the second command, you can use the linker directly to produce the instrumented program.

Instrumented Execution

Run your instrumented program with a representative set of data to create a dynamic information file. The following examples demonstrate the command lines for running the executable generated by the example commands (listed above):

Platform

Command

Linux

a1

Windows

a1.exe

Executing the instrumented applications generates dynamic information file that has a unique name and .dyn suffix. A new .dyn file is created every time you execute the instrumented executable.

The instrumented file helps predict how the program runs with a particular set of data. You can run the program more than once with different input data.

Feedback Compilation

The final phase compiles and links the sources files using the dynamic information generated in the instrumented execution phase. Compile and link the source files with -prof-use (Linux) or /Qprof-use (Windows) to use the dynamic information to guide the optimization of your program, according to its profile:

Platform

Examples

Linux

ifort -prof-use -prof-dir/usr/profdata -ipo a1.f a2.f a3.f

Windows

ifort /Qprof-use /Qprof-dirc:\profdata /Qipo a1.f a2.f a3.f

Besides the optimization, the compiler produces a pgopti.dpi file.

You typically specify the default optimizations, -02 (Linux) or /O2 (Windows) , for phase 1, and specify more advanced optimizations, -ipo (Linux) or /Qipo (Windows), for phase 3. For example, the example shown above used -O2 (Linux) or /O2 (Windows) in phase 1 and -ipo (Linux) or /Qipo (Windows) in phase 3.

Note

The compiler ignores the -ipo (Linux) or /Qipo (Windows) option with -prof-gen (Linux) or /Qprof-gen (Windows). However, the compiler gathers extra information when you use the -prof-genX (Linux) or /Qprof-genX (Windows) qualifier.

See Basic PGO Options.