Efficient Compilation

Efficient compilation contributes to performance improvement. Before you analyze your program for performance improvement, and improve program performance, you should think of efficient compilation itself.

Based on the analysis of your application, you can decide which compiler optimizations and command-line options can improve the run-time performance of your application.

Efficient Compilation Techniques

The efficient compilation techniques can be used during the earlier stages and later stages of program development. During the earlier stages of program development, you can use incremental compilation without optimization. For example:

Linux* and Mac OS* X

Example

ifort -c -g -O0 sub2.f90

ifort -c -g -O0 sub3.f90

ifort -o main -g -O0 main.f90 sub2.o sub3.o

Windows*

Example

ifort /c /Zi /Od sub2.f90

ifort /c /Zi /Od sub3.f90

ifort /exe:main.exe /Zi /Od main.f90 sub2.obj sub3.obj

The above commands turn off all compiler default optimizations, for example, -O2 (Linux* and Mac OS* X) or /O2 (Windows*), with -O0 (Linux and Mac OS X) or /Od (Windows). You can use the -g (Linux) or /Zi or /debug:full (Windows) option to generate symbolic debugging information and line numbers in the object code for all routines in the program for use by a source-level debugger. The main file created in the third command above contains symbolic debugging information as well.

During the later stages of program development, you should specify multiple source files together and use an optimization level of at least -O2 (Linux and Mac OS X) or /O2 (Windows) to allow more optimizations to occur. For instance, the following command compiles all three source files together using the default level of optimization:

Linux and Mac OS X

Example

ifort -o main main.f90 sub2.f90 sub3.f90

Windows

Example

ifort /exe:main.exe main.f90 sub2.f90 sub3.f90

Compiling multiple source files lets the compiler examine more code for possible optimizations, which results in:

For very large programs, compiling all source files together may not be practical. In such instances, consider compiling source files containing related routines together using multiple ifort commands, rather than compiling source files individually.