6 Performance and optimization

This chapter describes how to use different features of HP Fortran to tune your program for optimum performance. The most important of these features is the optimizer. You invoke the optimizer when compiling your program by specifying either +On(where nrepresents the level of optimization to be applied to your program) or the -Ooption for the default level of optimization (level 2). The -Ooption is provided for compatibility with the POSIX standard and has the same functionality as the

+O2 option.The following command line compiles , usingprog.f90 the default level of optimization:

$ f90 -O prog.f90

For most applications, -Oprovides effective optimization. However, some applications can realize significant increases in performance at higher levels of optimization or when you use other features of the optimizer to boost performance. This chapter discusses these features as well as the following topics:

Using profilers

Using options to control optimization

Conservative vs. aggressive optimization

Parallelizing HP Fortran programs

Vectorization

Controlling code generation for performance

For information about getting the best performance from floating-point intensive applications running on HP-UX, see the HP-UXFloating-Point Guide.

Using profilers

A profiler is a tool for sampling a program during execution so that you can determine where your program spends most of its time. After examining the data provided by a profiler, you can decide whether to redesign parts of the program to improve their performance or to re-compile the program with optimization options. For example, if your program contains a loop with an embedded call and profiling reveals that the program spends much of its time in the loop, you may decide to inline the embedded call.

The following sections describe the HP Caliper performance analysis tool, which is bundled with HPFortranas well as the two UNIX profilers,gprof and prof.

NOTE: As described in “Stripping debugging information” (page 76), all programs compiled by HP Fortran include symbol table information in the executable file, unless you compile with the +stripoption or have removed the symbol table with the strip utility. This information must be present in the executable in order to use the profiling tools.

HP Caliper

HP Caliper works with your compiler to perform Profile Based Optimization (PBO).

The compiler option +Oprofile=collectuses HP Caliper in the background to collect profile information for your entire application. This is equivalent to the +Ioption on HP PA-RISC systems.

Using profilers 87