next up previous contents
Next: Advanced Numerical Experiments Up: Examples and Exercises Previous: Optional and Keyword Arguments

Achieving Portability

Portability refers to the ease with which source code can be moved from machine to machine. A portable program requires little or no change to the source code when compiled and run on a different machine. Portability of numerical code is important for several reasons.

Fortran 90 introduces several new mechanisms to aid in porting numerical code to other machines. The most difficult problem in porting numerical programs is in the portable selection of precision. Selecting the precision of a computation in a portable way was impossible with Fortran 77. However, with the introduction of kind values as well as intrinsic environmental inquiry functions for selecting and inquiring about precision, Fortran 90 programs should be much easier to port to other machines.

Kind values are integer constants that can be used to further specify the characteristics of an intrinsic type, such as integer or real. For example, real( 2 ) selects a real type with kind value 2. Unfortunately, kind values are processor-dependent and are therefore not standardized. However, there are several portable ways to select kind values based on the precision desired. Two such functions are selected_int_kind and selected_real_kind. The following Precision module illustrates a portable means of selecting precision parametrically.

module Precision
   integer, parameter :: Q = selected_real_kind( 10, 10 )
end module Precision

The selected_real_kind function above selects the kind value corresponding to a real number with at least 10 decimal digits of precision and a decimal exponent range of at least 10 in magnitude. The selected_int_kind function is similar, and an expression such as selected_int_kind( 10 ) selects the kind value corresponding to a integer number with magnitude in the range exercise366 Other environmental inquiry and manipulation functions are described in tables 1 and 2 in section 1. Advanced uses of these functions and other portability issues are described in section 3.

exercise 2.17


next up previous contents
Next: Advanced Numerical Experiments Up: Examples and Exercises Previous: Optional and Keyword Arguments