Compiler-friendly programming idioms can be as useful to performance as any
of the options or directives. Here are some suggestions.
- General
-
- Where possible, use command invocations like xlf90 or
xlf95 to enhance standards conformance and code portability. If this is not
possible, consider using the -qnosave option to have all local
variables be automatic; doing this provides more opportunities for
optimization.
- Use modules to group related subroutines and functions.
- Consider using the highly tuned MASS and ESSL libraries rather than custom implementations or generic libraries.
- Hand-tuning
-
- Do not excessively hand-optimize your code. Unusual constructs can
confuse the compiler (and other programmers), and make your application
difficult to optimize for new machines.
- Do limited hand tuning of small functions by inlining.
- Avoid breaking your program into too many small functions as this can increase the percentage of time the program spends in
dealing with call overhead. If you choose to use many small functions, seriously consider using -qipa.
- Variables
-
- Avoid unnecessary use of global variables and pointers. When using
them in a loop, load them into a local variable before the loop and store them
back after.
- Use the INTENT statement to describe usage of parameters.
- Conserving storage
-
- Use register-sized integers (INTEGER(4) or INTEGER(8) data type) for scalars.
- Use the smallest floating-point precision appropriate to your
computation.
- When writing new code, use module variables rather than common blocks for
global storage.
- Use the CONTAINS statement only to share thread local
storage.
- Pointers
-
- Obey all language aliasing rules. Try to avoid using
-qalias=nostd.
- Limit the use of ALLOCATABLE arrays and POINTER
variables to situations which demand dynamic allocation.
- Arrays
-
- Use local variables wherever possible for loop index variables and
bounds.
- Keep array index expressions as simple as possible. Where indexing
needs to be indirect, consider using the PERMUTATION
directive.
- When using array assignment or WHERE statements, pay close
attention to the generated code with -qlist or
-qreport. If performance is inadequate, consider using -qhot
or rewriting array language in loop form.
- Related Information:
-
