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

icpc -prof-gen -prof-dir /profdata -c a1.cpp a2.cpp a3.cpp

icpc a1.o a2.o a3.o

Windows

icl /Qprof-gen /Qprof-dirc:\profdata /c a1.cpp a2.cpp a3.cpp

icl 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

./a.out

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

icpc -prof-use -ipo a1.cpp a2.cpp a3.cpp

Windows

icl /Qprof-use /Qipo a1.cpp a2.cpp a3.cpp

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.