Chapter 3. Optimizing & Parallelizing scheduling, and vectorization. By default, the PGI compilers produce code specifically targeted to the type of processor on which the compilation is performed. That is, the default is to use all supported instructions wherever possible when compiling on a given system. As a result, executables created on a given system may not be usable on previous generation systems. For example, executables created on a Pentium 4 may fail to execute on a Pentium III or Pentium II.
All PGI compilers have the capability of generating
unified binaries
, which provide a low-overhead means for generating a single executable that is compatible with and has good performance on more than one hardware platform.
You can use the
–tp
option to control compilation behavior by specifying the processor or processors with which the generated code is compatible. The compilers generate and combine into one executable multiple binary code streams, each optimized for a specific platform. At run-time, the one executable senses the environment and dynamically selects the appropriate code stream. For specific information on the
–tp
option,
refer to –tp <target> [,target...]
.
Executable size is automatically controlled via unified binary culling. Only those functions and subroutines where the target affects the generated code have unique binary images, resulting in a code-size savings of from
10% to 90% compared to generating full copies of code for each target.
Programs can use the PGI Unified Binary even if all of the object files and libraries are not compiled as unified binaries. Like any other object file, you can use PGI Unified Binary object files to create programs or libraries.
No special start up code is needed; support is linked in from the PGI libraries.
The
–Mipa
option disables generation of PGI Unified Binary. Instead, the default target auto-detect rules for the host are used to select the target processor.
Interprocedural Analysis and Optimization using –Mipa
The PGI Fortran, C and C++ compilers use interprocedural analysis (IPA) that results in minimal changes to makefiles and the standard edit-build-run application development cycle. Other than adding
–Mipa
to the command line, no other changes are required. For reference and background, the process of building a program without IPA is described later in this section, followed by the minor modifications required to use
IPA with the PGI compilers. While the PGCC compiler is used here to show how IPA works, similar capabilities apply to each of the PGI Fortran, C and C++ compilers.
Note
The examples use Linux file naming conventions. On Windows, ‘.o’ files would be ‘.obj’ files, and
‘a.out’ files would be ‘.exe’ files.
Building a Program Without IPA – Single Step
Using the pgcc command-level compiler driver, multiple source files can be compiled and linked into a single executable with one command. The following example compiles and links three source files:
% pgcc -o a.out file1.c file2.c file3.c
In actuality, the pgcc driver executes several steps to produce the assembly code and object files corresponding to each source file, and subsequently to link the object files together into a single executable file. This command is roughly equivalent to the following commands performed individually:
39