
Chapter 5. Fortran programming 45
You can improve the performance by padding the arrays so that the
corresponding elements do not map to the same cache lines:
INTEGER, PARAMETER :: n = 4096, pad = 8
REAL, DIMENSION(n+pad) :: a, b
REAL, DIMENSION(n) :: c
COMMON /my_block/ a, b, c
The rest of the code is identical. The padding can also be done using
extra arrays:
INTEGER, PARAMETER :: n = 4096, pad = 8
REAL, DIMENSION(n) :: a, b, c
REAL, DIMENSION(pad) :: temp1, temp2
COMMON /my_block/ a, temp1, b, temp2, c
After this, the read operations for arrays a and b do not map to the
same DCACHE and SCACHE lines, and the write operations of the c(i)
elements do not map to these cache lines. This makes the code run a lot
faster!
Similar techniques can also be used with arrays of two or more dimen-
sions.
5.7 Compiler directives
In addition to using compiler options, you can use the so-called compiler
directives to control the compilation process. There are directives which
help in code optimization, memory usage, checking array bounds etc.
Table 5.4 lists the most useful compiler directives.
Directive Explanation
free, fixed Specifying source form
[no]bounds [array] Array bounds checking
integer=n Specifying integer length
name (fortran_name="ext_name") Naming external routines
[no]bl Bottom loading operands
[no]split Loop splitting
[no]unroll [n] Loop unrolling (n copies)
cache_align var Align on cache line boundaries
symmetric [var, ...] Declaring local addressing
Table 5.4: Some compiler directives for the f90 command.
Directives are written into the source code as special comments, and the
CF90 compiler interprets them in the compilation phase.
Here is a short example:
Kommentare zu diesen Handbüchern