The three basic phases of PGO are:
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:
prompt>icpc -prof_gen -prof_dir /profdata -c
a1.cpp a2.cpp a3.cpp
prompt>icpc a1.o a2.o a3.o
In place of the second command, you could use the linker directly to produce the instrumented program.
prompt>./a.out
The resulting dynamic information file has a unique name and .dyn suffix every time you run a.o. 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.
Compile and link the source files with -prof_use to use the dynamic information to optimize your program according to its profile:
prompt>icpc -prof_use -ipo a1.cpp a2.cpp a3.cppBesides the optimization, the compiler produces a pgopti.dpi file. You typically specify the default optimizations (-O2) for phase 1, and specify more advanced optimizations with -ipo for phase 3. This example used -O2 in phase 1 and -O2 -ipo in phase 3.
Note
The compiler ignores the -ipo options with -prof_gen[x]. With the x qualifier, extra information is gathered.