The sections in this topic provide examples of the three basic PGO phases, or steps:
When you use PGO, consider the following guidelines:
Minimize the changes to your program after instrumented execution and before feedback compilation. During feedback compilation, the compiler ignores dynamic information for functions modified after that information was generated.
The compiler issues a warning that the dynamic information does not correspond to a modified function.
Repeat the instrumentation compilation if you make many changes to your source files after execution and before feedback compilation.
Specify the name of the profile summary file using the -prof-file (Linux*) or /Qprof-file (Windows*) option.
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 if the application includes the source files located in multiple directories. -prof-dir (Linux) or /Qprof-dir (Windows) insures 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.
The compiler gathers extra information when you use the -prof-genx (Linux) or /Qprof-genx (Windows) qualifier; however, the additional static information gathered using the option can be used by specific tools only. See Basic PGO Options.
Run your instrumented program with a representative set of data to create one or more dynamic information files. 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.
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 |
In addition to the optimized executable, 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.
The compiler ignores the -ipo (Linux) or /Qipo (Windows) option with -prof-gen (Linux) or /Qprof-gen (Windows).
See Basic PGO Options.