Example of Profile-Guided Optimization

The following is an example of the basic PGO phases:

1.  Instrumentation Compilation and Linking—Use -prof_gen to produce an executable with instrumented information. Use also the -prof_dir option as recommended for most programs, especially if the application includes the source files located in multiple directories. -prof_dir ensures that the profile information is generated in one consistent place. For example:

ifort -prof_gen -prof_dir/usr/profdata -c a1.f a2.f a3.f

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

In place of the second command, you could use the linker (ld) directly to produce the instrumented program. If you do this, make sure you link with the libirc.a library.

2.  Instrumented Execution—Run your instrumented program with a representative set of data to create a dynamic information file.

prompt>a1

The resulting dynamic information file has a unique name and .dyn suffix every time you run a1. 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.

3.  Feedback Compilation—Compile and link the source files with -prof_use to use the dynamic information to optimize your program according to its profile:

ifort -prof_use -prof_dir/usr/profdata -ipo a1.f a2.f a3.f

Besides the optimization, the compiler produces a pgopti.dpi file. You typically specify the default optimizations (-O2) for phase 1, and specify more advanced optimizations (-ip or -ipo) for phase 3. This example used -O2 in phase 1 and the -ipo in phase 3.

Note   
The compiler ignores the -ip or the -ipo options with -prof_gen.

See Basic PGO Options.