Profile-guided Optimizations Methodology and Usage Model

PGO works best for code with many frequently executed branches that are difficult to predict at compile time. An example is the code with intensive error-checking in which the error conditions are false most of the time. The "cold" error-handling code can be placed such that the branch is hardly ever mispredicted. Minimizing "cold" code interleaved into the "hot" code improves instruction cache behavior.

PGO Phases

The PGO methodology requires three phases and options:

  1. Instrumentation compilation and linking with -prof_gen

  2. Instrumented execution by running the executable; as a result, the dynamic-information files (.dyn) are produced.

  3. Feedback compilation with -prof_use

The flowcharts below illustrate this process for IA-32 compilation and ItaniumŪ-based compilation . A key factor in deciding whether you want to use PGO lies in knowing which sections of your code are the most heavily used. If the data set provided to your program is very consistent and it elicits a similar behavior on every execution, then PGO can probably help optimize your program execution. However, different data sets can elicit different algorithms to be called. This can cause the behavior of your program to vary from one execution to the next.

Phases of Basic Profile-Guided Optimization

PGO Usage Model

The chart that follows presents PGO usage model.  

Here are the steps for a simple example (myApp.f90) for IA-32 systems.

  1. Set the following:


  2. Issue the following command:

    ifort -prof_genx myApp.f90

    This command compiles the program and generates instrumented binary myApp.exe as well as the corresponding static profile information pgopti.spi.

  3. Execute myApp.

    Each invocation of myApp runs the instrumented application and generates one or more new dynamic profile information files that have an extension .dyn in the directory specified by PROF_DIR.

  4. Issue the following command:

    ifort -prof_use myApp.f90

    At this step, the compiler merges all the .dyn files into one .dpi file representing the total profile information of the application and generates the optimized binary. The default name of the .dpi file is pgopti.dpi.