HP Fortran Programmer's Guide HP-UX 11i v1, HP-UX 11i v2, and HP-UX 11i v3 Manufacturing Part Number: B3908-90031 September 2011
Print History Tenth Document Number B3908-90031 Released September 2011; document updates Ninth Document Number B3908-90030 Released March 2010; document updates Eighth Document Number B3909-90029 Released September 2007; document updates Seventh Document Number B3909-90027 Released February 2007; document updates Sixth Document Number B3909-90018 Released December 2004; document updates Fifth Document Number B3909-90014 Released September 2003; document updates Fourth Document Number B3909-90010 ii
Released June 2003; document updates Third Document Number B3909-90009 Released September 2001; document updates Second Document Number B3909-90005 Released June 2001. Added Itanium-based information First Document Number B3909-90002 Released October 1998.
Legal Notices Copyright 2010, 2011 Hewlett-Packard Development Company, L.P. Confidential computer software. Valid license from HP required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor's standard commercial license. The information contained in this document is subject to change without notice.
Contents 1. An overview of HP Fortran The HP Fortran compiler environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Driver. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 C preprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Front-end . . . . . . . . . . . .
Contents Creating shared libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Compiling with +pic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Linking with -b. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents Exceptions handled by the ON statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Actions specified by ON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Terminating program execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ignoring errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents 7. Writing HP-UX applications Accessing command-line arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Calling HP-UX system and library routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using HP-UX file I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stream I/O using FSTREAM . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents Controlling parallelization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Controlling dependence checks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Controlling checks for side effects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 10. Migrating to HP Fortran Incompatibilities with HP FORTRAN 77 . . . . . . . . . . . . . .
Contents Uninitialized variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Large word size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . One-trip DO loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Name conflicts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tables Table 1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii Table 1-1. Options for controlling the f90 driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Table 1-2. Options for controlling the C preprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Table 1-3. Options for controlling the front end . . . . . . . . . . . . . . . . . . . . . . . . . . .
Tables Table 9-2. Compatibility directives recognized by HP Fortran . . . . . . . . . . . . . . . . . . . . . . . . . Table 10-1. f77 options not supported by f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Table 10-2. f77 options replaced by f90 options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Table 10-3. HP FORTRAN 77 directives supported by f90 options. . . . . . . . . . . . . . . . . . . . . . Table 10-4.
Figures Figure 1-1. HP Fortran compiler environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Figure 3-1. Increasing default data sizes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .110 Figure 8-1. Memory layout of a two-dimensional array in Fortran and C . . . . . . . . . . . . . . . . .
Figures xiv
Preface The HP Fortran Programmer’s Guide describes how to use different features of HP Fortran to develop, compile, debug, and optimize programs in HP 9000 systems, and Integrity systems. It also describes how to migrate HP FORTRAN 77 programs to the current HP Fortran compiler and how to use the different compiler features for porting programs written for other vendors’ Fortran to HP Fortran.
If you have any problems with the software, please contact your local Hewlett-Packard Sales Office or Customer Service Center. You need not be familiar with the HP parallel architecture, programming models, or optimization concepts to understand the concepts introduced in this book. HP Fortran for Integrity systems is a part of the HP-UX PA-RISC Fortran product. HP Fortran is source compatible between HP 9000 and Integrity systems.
Scope This guide covers programming methods for the HP Fortran compiler on machines running: • HP-UX 11i v1 and higher on HP 9000 systems • HP-UX 11i v2 and higher on Integrity systems HP Fortran supports an extensive shared-memory programming model. HP-UX 11i v1 and higher includes the required assembler, linker, and libraries.
Notational conventions This section discusses notational conventions used in this book. Table 1 bold monospace In command examples, bold monospace identifies input that must be typed exactly as shown. monospace In paragraph text, monospace identifies command names, system calls, and data structures and types. In command examples, monospace identifies command output, including error messages. italic In paragraph text, italic identifies titles of documents.
The directives and pragmas described in this book can be used with the HP Fortran and C compilers, unless otherwise noted. The aC++ compiler does not support the pragmas, but does support the memory classes. In general discussion, these directives and pragmas are presented in lowercase type, but each compiler recognizes them regardless of their case.
Associated documents The following documents are listed as additional resources to help you use the compilers and associated tools: • HP aC++ Online Programmer’s Guide—Presents reference and tutorial information on aC++. This manual is only available in html format. • HP Fortran Programmer’s Reference — Provides language reference for HP Fortran and describes the language features and requirements.
1 An overview of HP Fortran When you use the f90 command to compile a Fortran program, the command invokes a number of components—and not just the compiler—to create the executable.
An overview of HP Fortran be required, and link all of the object code into an executable file that you run without further processing. For example, consider a program that consists of three source files: x.f90, y.f90, and z.f90. The following command line will process the source files and, if they are syntactically correct, produce an executable file with the default name a.out: $ f90 x.f90 y.f90 z.
An overview of HP Fortran The HP Fortran compiler environment The HP Fortran compiler environment Figure 1-1 illustrates the compilation process, showing the different components of the HP Fortran compiler environment; active processes are unshaded and data elements are shaded. With the exception of the performance analysis tools and the debugger (WDB), all components are invoked by the f90 command.
An overview of HP Fortran Driver Driver The driver parses the f90 command line by which you invoke the compiler, calls each subprocess as needed to complete the compilation, and retains control throughout the compilation process.
An overview of HP Fortran Driver Table 1-1 Options for controlling the f90 driver (Continued) Option -tx,name Function Substitute a private version (name) of one or more subprocesses (x) of the compilation. The values for x are: a Assembler c Compiler l Linker p C preprocessor s Startup file (crt0.o library) e Debug file (end.o library) If you compile and link separately and specify +tl on the compile line, you must also specify it on the link line.
An overview of HP Fortran C preprocessor C preprocessor HP Fortran source files can include directives that the C preprocessor (cpp) reads and expands before the program is passed to the compiler. Among other things, cpp directives enable you to code parts of your program for conditional compilation. By default, the f90 command passes source files ending in the.F extension to the C preprocessor.
An overview of HP Fortran Front-end Front-end The front-end is responsible for parsing the source code and issuing warning and error messages when the parse fails. Command-line options enable you to control the front end’s assumptions about the source code, including whether the source is in fixed or free format, uses implicit or explicit typing, and contains extensions.
An overview of HP Fortran Front-end Table 1-3 Options for controlling the front end (Continued) Option +[no]escape Function Treat the backslash character (\) as a C-like escape [literal] character. The default is +noescape. For information on using this option when porting, see “Escape sequences” on page 246. +[no]extend_source Allow [do not allow] up to 254 characters on a single source line. The default, +noextend_source, is 72 characters for fixed format and 132 for free format.
An overview of HP Fortran Front-end Table 1-3 Options for controlling the front end (Continued) Option +moddir=directory Function Write .mod files to directory. The default is to write .mod files to the current directory. For information about using this option, see “Managing .mod files” on page 87. +moduleoptimize Creates optimized module files by discarding redundant information. This reduces the compilation time and memory requirement of the compiler for nested or hierarchical modules..
An overview of HP Fortran Front-end Table 1-3 Options for controlling the front end (Continued) Option +source={fixed|free| default} Function Accept source files in fixed format (+source=fixed) or free format (+source=free). The default, +source=default, is free for .f90 files and fixed for .f and .F source files. For information about using this option, see “Source formats” on page 245. +[no]uppercase Use uppercase [lowercase] for all external names. The default is +nouppercase.
An ove rvie w of HP Fortran Back-end Back-end The two main functions of the back-end are: • To optimize your program for faster performance • To generate the code that goes into the object file Optimization is performed by two subcomponents of the compiler’s back end: • The High-Level Optimizer (HLO), which performs large-scale, high-semantic-level analyses and transformations to increase performance.
An overview of HP Fortran Back-end Table 1-4 Options for controlling optimization (Continued) Option Function +Ooptlevel This option has the same meaning as the -O[optlevel] option, except that optlevel must be specified. It is provided for compatibility with makefiles. +O[no]info Provide [do not provide] feedback information about the optimization process. This option is most useful at optimization level 3 and higher. The default is +Onoinfo.
An overview of HP Fortran Back-end Table 1-5 Options for controlling code generation (Continued) Option +DSmodel Function Perform instruction scheduling appropriate for a specific implementation of the PA-RISC architecture. model can be one of the following: • PA-RISC version number (1.1 or 2.0) • A model number (for example, 750 or 870). • One of the PA-RISC processor names (for example, PA7000, PA7100, or PA8000).
An overview of HP Fortran Back-end Table 1-5 Options for controlling code generation (Continued) Option +k Function Generate code for programs that reference a very large number of shared data items. The linker will issue a diagnostic message in the rare cases when this option is needed. NOTE: This option is only valid on the PA-RISC systems.
An overview of HP Fortran Linker Linker The linker (ld) builds an executable program from the object files produced by the back end and the libraries. An important group of options for controlling the linker specify what libraries the linker should search and where it should search for them.
An overview of HP Fortran Linker Table 1-6 Options for controlling the Linker (Continued) Option +[no]fp_exceptions Function Enable [disable] floating-point exceptions. Enabling floating-point exceptions also causes the running program to issue a procedure traceback for runtime errors. The default is +nofp_exceptions. For information using this option, see “Floating-point exceptions” on page 121. -Ldirectory Add directory to the front of the library search path.
An overview of HP Fortran Linker Table 1-6 Options for controlling the Linker (Continued) Option +[no]U77 Function Invoke [do not invoke] support for the libU77 library (BSD 3f). If you compile and link separately and specify +U77 on the compile line, you must also specify it on the link line. The default is +noU77. For information about the libU77 library, see “Additional HP Fortran libraries” on page 80 and the HP Fortran Programmer’s Reference.
An overview of HP Fortran Tools Tools The HP Fortran compiler environment includes a high-level language debugger and performance analysis tools. The debugger is HP WDB, which includes a graphical user interface. To prepare a program for debugging, you must compile it with the -g option. For information about this option, see “Using the HP WDB debugger” on page 118. The performance analysis tools include the standard UNIX utilities, prof and gprof.
An overview of HP Fortran HP-UX operating system HP-UX operating system Although the HP-UX operating system does not appear in Figure 1-1 on page 3, it provides a variety of resources for programs executing within HP-UX. For example, HP-UX captures the command line you use to invoke an executable program, breaks it up into arguments, and makes them available to your program. HP-UX also has many callable system routines that provide low-level access to kernel-level resources.
An overview of HP Fortran HP-UX operating system 20 Chapter 1
2 Compiling and linking This chapter discusses how to compile and link HP Fortran programs and covers the following topics: • Compiling with the f90 command Chapter 2 21
Compiling and linking • Linking HP Fortran programs • Special-purpose compilations • Using environment variables 22 Chapter 2
Compiling and linking Compiling with the f90 command Compiling with the f90 command The default behavior of the f90 command is to compile source files listed on the command line and, if the compilation is successful, to pass the resulting object files to the linker. If the link stage is successful, the linker produces an executable program with the default name a.out. Consider, for example, the program hello.f90: Example 2-1 hello.
Compiling and linking Compiling with the f90 command where options is a list of one or more command-line options and files is a list of one or more files containing HP Fortran source code to be compiled or object code to be linked. Items in options and files can be interspersed on the command line, separated by spaces. However, some options are order-sensitive. For example, the -l option, which is used to specify a library for linking, must follow the program file to which it will be linked.
Compiling and linking Compiling with the f90 command Commonly-used options Table 2-1 identifies commonly-used command-line options for when you want to change the compiler’s default behavior. For a complete and full description of all HP Fortran command-line options, see “Option descriptions” on page 27. Table 2-1 Commonly-used options Option Function -c Compile without linking. Use this option to compile and link in separate steps. -g Prepare program for debugging.
Compiling and linking Compiling with the f90 command Command-line options by category Table 2-2 categorizes the f90 command-line options. For detailed information about each of the options, see “Option descriptions” on page 27.
Compiling and linking Compiling with the f90 command Table 2-2 Options listed by category (Continued) Category Options Native language support +nls Performance and optimization +cat,+DA, +DC, +DO, +DS, +fastallocatable, +O, and-O +Oparallel_intrinsics Preprocessor +cpp, +cpp_keep, -D, and -U Profiling +gprof, +prof, +pa, +pal Miscellaneous +asm, -c, +getarg0, +getarg1, +noalign64bitpointers, -o, +pic, +pre_include, +ttybuf, and +usage, +Z, +z Option descriptions The following alphabetical list
Compiling and linking Compiling with the f90 command C$DIR IVDEP Rules and behavior: The IVDEP directive is an assertion to the compiler’s optimizer about the order of memory references inside a DO loop. The IVDEP directive tells the compiler to begin dependence analysis by assuming all dependences occur in the same forward direction as their appearance in the normal scalar execution order.
Compiling and linking Compiling with the f90 command 5. Store the results from Step 4 into the location indicated by A(INDARR(I)) from Step 1. IVDEP directs the compiler to initially assume that when Steps 1 and 5 access a common memory location, Step 1 always accesses the location first because Step 1 occurs earlier in the execution sequence. This approach lets the compiler reorder instructions, as long as it chooses an instruction schedule that maintains the relative order of the array references.
Compiling and linking Compiling with the f90 command Items promoted include constants, scalar variables, arrays, components of derived types, and record fields. This option also promotes intrinsics as well as the results and arguments of user-defined functions to the proper precision. Types specified in ON statements are also promoted. The entire program should be compiled with this option, not just selected files.
Compiling and linking Compiling with the f90 command The entire program should be compiled with this option, not just selected files. Use this option when you want to promote only the single-precision items. The default is +noautodbl4. NOTE The +autodbl4 option causes items declared as REAL, INTEGER, and DOUBLE PRECISION all to have the same size. This violates the Fortran Standard. -b This option can be specified to invoke ld with -b to create a shared library.
Compiling and linking Compiling with the f90 command bounds:array| bounds:pointer| bounds:all| bounds:none| globals| malloc| stack:frane| stack:variables| stack:none| stack| truncate:explicit| truncate:implicit| truncate|truncate:all| truncate:none| uninit| -check_bounds } +check=all enables compile-time range checking for array subscripts.
Compiling and linking Compiling with the f90 command +check=stack:variables enables run-time checks for illegal writes to the stack just before or after some variables on the stack. +check=stack:frame enables run-time checks for illegal writes from the current stack frame that overflow into the previous stack frame. +check=stack:variables enables run-time checks for illegal writes to the stack just before or after some variables on the stack. +check=stack:none disables all stack guard checking.
Compiling and linking Compiling with the f90 command If you want to keep the output from the C preprocessor, use the +cpp_keep option. +[no]cpp_keep +cpp_keep causes the compiler to retain the output from the C preprocessor. If the source filename is file.f or file.F, the output filename is file.i; if the source filename is file.f90, the output filename is file.i90. The compiler will accept source files with the .i and .i90 extensions. The default, +nocpp_keep, is to discard the output file.
Compiling and linking Compiling with the f90 command NOTE You must specify +DA2.OW to generate 64-bit code. At PA64, all data types remain the same size as at PA32 except for pointers. Fortran pointers are hidden from the user and cannot be directly manipulated. +DA2.0W Changes the default size of a Cray pointer. It will become the large of a default-sized integer and a C pointer (8-bytes), rather than the 4-byte default. +DC Specifies cache values to the compiler.
Compiling and linking Compiling with the f90 command This option is a synonym for +Oprofile=use: filename. This option is only valid on the Itanium processor family architecture. The default is flow.data if a name is not specified. +[no]dlines +dlines treats source lines with a “D” or “d” in column 1 as statements to be compiled. The default, +nodlines, treats lines beginning with “D” or “d” in column 1 as comments. The +dlines option must be used only with source files in fixed-format.
Compiling and linking Compiling with the f90 command On Itanium -based architectures, the defined values for model are: blended Tune for best performance on a combination of processors (i.e., Itanium or Itanium 2 processor). itanium Tune for best performance on an Itanium processor. itanium2 Tune for best performance on an Itanium 2 processor. native Tune for best performance on the processor on which the compiler is running. -dynamic -dynamic is used to generate dynamically-bound executables.
Compiling and linking Compiling with the f90 command +fastallocatable +fastallocatable enables a different representation for allocatable arrays in the object code produced by the compiler. This alternate representation avoids problems in optimizing code containing allocatable array references. Additionally, this alternate representation for allocatable arrays is binary compatible with the old representation. +fltconst_strict Uses a strict power table for converting floating constants with exponents.
Compiling and linking Compiling with the f90 command Enabling sudden underflow may cause the same program to compute different results on different implementations of the PA-RISC 1.1 and 2.0 architectures. This is because some hardware implementations have sudden underflow available, while others do not. The +FPD option enables the hardware to flush denormalized values to zero, but it does not require that it do so.
Compiling and linking Compiling with the f90 command Table 2-4 Values for the +FP option (Continued) Value Meaning D Enable sudden underflow (flush to zero) of denormalized values on those PA-RISC systems greater than version 1.0 that have implemented sudden underflow. (That is, +FPD enables sudden underflow only if it is available on the processor that is used at run time.) Denormalized values are those values whose absolute value is very close to zero.
Compiling and linking Compiling with the f90 command -g causes the compiler to generate information for use by the HP WDB debugger. The -g option can be used to prepare code for debugging that has been compiled with optimization options -O, -O1/+O1, and -O2/+O2, but not -O3/+O3 or higher. -G Generate code for gprof(1) profiling. This has the same functionality as +gprof. +getarg +getarg0 and +getarg1 control the behavior of the getarg intrinsic subroutine.
Compiling and linking Compiling with the f90 command +hugecommon is especially useful when a program contains several different COMMON blocks that together occupy more than two gigabytes but individually occupy less than two gigabytes. In this situation, the largest COMMON blocks could be placed in a huge data segment when the program is compiled by specifying their names in multiple +hugecommon options.
Compiling and linking Compiling with the f90 command +i8 changes 4-byte integer and logical constants, intrinsics, and user variables to 8-byte integers (rather than the 4-byte default). +ild Specifies incremental linking. This option is valid only for 64-bit links. If the output file does not exist, or if it was created without the +ild option, the linker performs an initial incremental link. The output file produced is suitable for subsequent incremental links.
Compiling and linking Compiling with the f90 command The common blocks listed in file (one per line, no enclosing ‘ / ‘s) are treated as shared common blocks, but are not attached. The user must attach or otherwise allocate storage for such common blocks before they are referenced. A C language program would typically be used to either attach a shared memory segment, or malloc a block of memory, and store that address into the external symbol for the common block.
Compiling and linking Compiling with the f90 command For libraries named in -l operands, look in directory before looking in the standard places. You can specify multiple directories; each directory must be preceded by its own -L option. Directories named in -L options are searched in the specified order. This option must precede the -l option on the command line. -lx -l causes the linker to search the library named by either /lib/libx.a (or .sl) or /usr/lib/libx.a (or .sl); the linker searches /lib first.
Compiling and linking Compiling with the f90 command Mark output from the linker unshared. For details and system defaults, see ld(1). +nls=lang +nls enables 16-bit Native Language Support processing in character strings and comments for the specified language lang. For details on Native Language Support, refer to Native Language Support User’s Guide. The -Y option can be used to perform the same function as +nls.
Compiling and linking Compiling with the f90 command -O invokes the optimizer, where n is the level of optimization, 0 - 4. The default is optimization level 2. This option is provided for compatibility and is functionally the same as the +On option. The only difference between the two is that the level number is optional for the -O option. For more information about the levels of optimization, see the +On option. +On +O invokes the optimizer, where n is the level of optimization, 0 - 4.
Compiling and linking Compiling with the f90 command Table 2-6 Levels of optimization (Continued) Level Optimizations 2 Optimizations performed at level 1, plus the following: 3 • Coloring register allocation • Induction variables and strength reduction • Common subexpression elimination • Loop invariant code motion • Store/copy optimization • Unused definition elimination • Dataflow analysis • Software pipelining • Scalar replacement • Sum reduction optimization Optimizations per
Compiling and linking Compiling with the f90 command Decrease the optimization to optlevel for one or more specified routines. This option can occur at optimization levels 1, 2, 3, or 4. The option cannot raise the optimization level above what was specified in the +Ooptlevel option. This option can occur multiple times, possibly with different values of optlevel. -o outfile -o names the executable file outfile rather than the default name of a.out. If not specified, a.
Compiling and linking Compiling with the f90 command +P Optimize the application based on profile data found in the database file flow.data, produced by compilation with +I ld(1), +I, and +df, for more details. The +P option is incompatible with the +I and -S options. It is incompatible with the -g option only during compile time. NOTE This option is only valid on Itanium-based systems. +pa +pa compiles an application for routine-level profiling. NOTE This option is only valid on the PA-RISC systems.
Compiling and linking Compiling with the f90 command +pic={short|long|no} +pic generates object code that can be added to a shared library. Object code generated with this option is position-independent code (PIC). All addresses are either pc-relative or indirect references. The argument—short or long—specifies the allocated size of the data linkage table. Normally you would specify +pic=short to generate PIC. Use +pic=long when the linker issues an error message indicating data linkage table overflow.
Compiling and linking Compiling with the f90 command Mark output from the linker demand load. This has the same functionality as the +demand_load option. The default is +nodemand_load. -Q Mark output from the linker no demand load. This has the same functionality as the +nodemand_load option (the default). +r8 +r8 changes 4-byte real constants, intrinsics, and user variables to 8-byte reals (rather than the 4-byte default). -R4 Set the precision of real and complex constants to single-precision.
Compiling and linking Compiling with the f90 command If you explicitly declare a variable with the AUTOMATIC attribute, the attribute overrides the +save option. The +save command-line option inhibits many of the optimizations performed by the compiler. Generally, you will get better performance with the +Oinitcheck option, which also sets uninitialized variables to zero but is more selective than +save; see “Using optimization options” on page 60.
Compiling and linking Compiling with the f90 command Control the generation of source position information for the Caliper analysis tool. When +srcpos is in effect (the default), the compiler generates this information. When +nosrcpos is in effect, the compiler does not generate this information, and the compiler will instruct the linker to discard any of this information encountered in object files. This option is only supported on Itanium platforms.
Compiling and linking Compiling with the f90 command Table 2-7 Values for the -t option x subprocesses (Continued) Value Subprocess Standard name s Start-up file crt0.o, gcrt0.o, mcrt0.o +trigdacc The compiler will use more accurate cosd, sind, and tand intrinsics, than the standard ones. While the standard ones have some accuracy problems with the boundary cases (i.e., cosd(90) needs to be 0.0), these new intrinsics get these cases right.
Compiling and linking Compiling with the f90 command of an unsatisfied symbol. If the libU77 name is the same as a libc name, the name might resolve to a libc name. This situation does not cause an error at compile time, but can produce unpredictable results. +[no]uppercase +uppercase uses uppercase for external names. The default, +nouppercase, is to convert external names to lowercase.
Compiling and linking Compiling with the f90 command The next example passes the -a shared option to the linker, causing it to select shared libraries for linking.
Compiling and linking Compiling with the f90 command -Y=lang Enable Native Language Support in the given language (lang). This has the same functionality as the +nls option. +z see +pic=short in this chapter. If +z is specified when creating 64-bit code, it instead maps to +Z. +Z see +pic=long in this chapter for a description. Note that when creating 64-bit shared executables (such as when +DA2.0W is specified), the +Z option is on by default. This is the only PIC option supported for 64-bit executables.
Compiling and linking Compiling with the f90 command -Bextern [=symbol [,symbol...]] The named symbols, or all undefined symbols if no list is provided, are assigned the default export class. Additionally, the compiler will inline the import stub for calls to these symbols. No compile-time binding of these symbols will be done.
Compiling and linking Compiling with the f90 command The named symbols, or all symbols if no symbols are specified, are assigned the protected export class. This means these symbols will not be preempted by symbols from other load modules, so the compiler may bypass the linkage table for both code and data references and bind them to locally-defined code and data symbols.
Compiling and linking Compiling with the f90 command NOTE You can insert (or remove) underscore characters in the names of any of the optimization options to improve their readability. The compiler will recognize the option name with or without underscores. Reviewing general optimization options The following options allow you to control how optimization affects code size, compilation time, runtime performance, and other user-visible effects.
Compiling and linking Compiling with the f90 command • +FPD +FPD is enabled only if +Oaggressive is used on the link line. NOTE The +Oaggressive option is incompatible with +Oconservative. The default is +Onoaggressive. NOTE This option is only valid on the PA-RISC systems. +O[no]all +Oall performs maximum optimization, including aggressive optimizations and optimizations that can significantly increase compile time and memory usage.
Compiling and linking Compiling with the f90 command +Oconservative causes the optimizer to make conservative assumptions about the code when optimizing it. This option is only effective at optimization level 2 or higher. The +Oconservative option sets the following options: • +Ofltacc • +Onofltacc • +Onomoveflops • +Oparmsoverlap Use +Oconservative when conservative assumptions are necessary due to the coding style, as with nonstandard-conforming programs.
Compiling and linking Compiling with the f90 command Fine-tuning optimization options The following options allow you to fine-tune the optimization process by providing control over the specific techniques that the optimizer applies to your program. The syntax for using these options is +O[no]optimization where optimization is a parameter that specifies an optimization technique to apply to your program. The different parameters are described below. The prefix no negates the effect of optimization.
Compiling and linking Compiling with the f90 command The default is +Onocxlimitedrange. +O[no]cross_region_addressing Enable [disable] the use of cross-region addressing. Cross-region addressing is required if a pointer (such as an array base) points to a different region than the data being addressed. This is usually due to an offset which results in a cross-over into another region. Standard-conforming applications do not require the use of cross-region addressing.
Compiling and linking Compiling with the f90 command system-wide default. This option applies only to executable files and shared libraries. chatr(1) can be used to change this setting, including restoration of the default setting, after the output file has been created. +O[no]entrysched +Oentrysched allows the optimizer to perform instruction scheduling on a subprogram’s entry and exit code sequences. This option is only effective at optimization level 1 or higher.
Compiling and linking Compiling with the f90 command The default is +Onofenvaccess. +O[no]fastaccess +Ofastaccess improves execution time by speeding up access to global data items. You can use this option at optimization level 1 or higher.. Note that the +Ofastaccess option may increase link time. The default is +Onofastaccess at optimization levels 1, 2, and 3; and +Ofastaccess at optimization level 4. NOTE This option is valid only on the PA-RISC systems.
Compiling and linking Compiling with the f90 command Table 2-9 Optimizations performed by +O[no]fltacc (Continued) +O[no]fltacc Expression reordering? FMA? +Onofltacc Yes Yes +O[no]fltacc=[strict|default|limited|relaxed] Control the level of floating point optimizations that the compiler may perform. The defined values for optlevel are: strict—disallow any floating point optimization that can result in numerical differences. This is the same as +Ofltacc.
Compiling and linking Compiling with the f90 command • Loop transformations to improve cache performance. • Vectorization. The default, +Onoinfo, disables the display of informational messages about optimization. +O[no]initcheck The initialization checking feature of the optimizer has three possible states: on, off, or unspecified.
Compiling and linking Compiling with the f90 command +Oinline_budget=n where n is an integer in the range 1 - 1000000 that specifies the level of aggressiveness, as listed in Table on page 70. The +Onolimit and +Osize options also affect inlining. Specifying the +Onolimit option has the same effect as specifying +Oinline_budget=200. The +Osize option has the same effect as +Oinline_budget=1. Note, however, that the +Oinline_budget option takes precedence over both of these options.
Compiling and linking Compiling with the f90 command Table 2-11 atan2 Millicode versions of intrinsic functions (Continued) log10 +o[no]libmerrno Enable [disable] support for errno in libm functions. The default is +Onolibmerrno. +O[no]loop_block +O[no]loop_block enables or disables blocking of eligible loops for improved cache performance. The +Onoloop_block option disables both automatic and directive-specified loop blocking.
Compiling and linking Compiling with the f90 command +loop_unroll_jam enables loop unrolling and jamming. +Onoloop_unroll_jam (the default) disables both automatic and directive-specified unroll and jam. Loop unrolling and jamming increases register exploitation. +O[no]moveflop +Omoveflops allows the optimizer to move conditional floating-point instructions, enabling other optimizations to occur. This option is only effective at optimization level 2 or higher.
Compiling and linking Compiling with the f90 command NOTE The +Oparallel option should not be used for programs that make explicit calls to the kernel threads library. +Oparallel_intrinsics +Oparallel_intrinsics links in the parallel version of many of the Fortran intrinsics located in libF90_parallel. +O[no]parmsoverlap +Oparmsoverlap causes the optimizer to assume that the actual arguments of function calls overlap in memory, thus preventing any optimizations that violate this assumption.
Compiling and linking Compiling with the f90 command Use +Oprocelim to reduce the size of the executable file, especially when optimizing at levels 3 and 4, when inlining can remove all calls to some routines. The default is +Onoprocelim at levels 0-3, and +Oprocelim at level 4. +Oprofile=use:filename Specify filname as the name of the profile database file. This option is a synonym for the +P, +dffilename options.The :filename argument is optional (the default filename is flow.data).
Compiling and linking Compiling with the f90 command +O[no]regreassoc +Onoregreassoc disables register reassociation. This option is only effective at optimization level 2 or higher. Use +Onoregreassoc to disable register reassociation in the rare case that this optimization degrades performance. +Oregreassoc is the default. NOTE +O[no]report This option is valid only on the PA-RISC systems. +Oreport specifies the contents of the Optimization Report.
Compiling and linking Compiling with the f90 command +O[no]static_prediction Enables [disables] the use of static branch prediction for decision on conditional branches. This is more applicable to large programs with poor locality. This option is available at optimization level 3 and above. NOTE This option is valid only on the PA-RISC systems. +O[no]store_ordering Preserve [do not preserve] the original program order for stores to memory that is potentially visible to multiple threads.
Compiling and linking Compiling with the f90 command Filenames The f90 command accepts files with any of the filename extensions listed in Table 2-12. The table also describes the meaning each name has for the f90 command. Files with names other than those listed in the table are passed to the linker. Table 2-12 Filenames Filenames recognized by f90 Meaning file.f90 Free-form Fortran source code; processed by the compiler. file.f Fixed-form Fortran source code; processed by the compiler. file.
Compiling and linking Linking HP Fortran programs Linking HP Fortran programs This section discusses how to link object files and covers the following topics: • The advantages of using the f90 command for linking as well as for compiling • How to link libraries, including shared libraries • How to establish the search rules used by the linker when it looks for libraries For more information about the linker, refer to Programming on HP-UX and to the ld(1) man page. Linking with f90 vs.
Compiling and linking Linking HP Fortran programs 8 /opt/fortran90/lib:/usr/lib:/opt/langtools/lib /usr/ccs/bin/ld -x /opt/langtools/lib/crt0.o hello.o /opt/fortran90/lib/libF90.a -lcl -lc -lisamstub Line 1 is the f90 command line. Line 2 is the information f90 passes to the compiler, including the full pathname of the compiler, the name of the source file (hello.f90), and the internal names of the option settings as determined by the defaults and the f90 command line.
Compiling and linking Linking HP Fortran programs The libisamstub library is provided as a tool for migrating HP FORTRAN 77 programs that call ISAM routines. The ISAM library is not available with HP Fortran, but the stub library allows the linker to resolve references to ISAM routines in HP FORTRAN 77 programs. Table 2-13 Libraries linked by default on PA-RISC Library Contents /usr/lib/libcl.a Archive version of HP Fortran runtime library /usr/lib/libcl.
Compiling and linking Linking HP Fortran programs Table 2-14 Libraries linked by default on Itanium (Continued) Library /opt/fortran90/lib/hpux[32|64]/li bF2003.a Contents Archive library for Fortran 2003 standard features When the linker finds a reference in your program to a name that is not defined in the program (for example, the DOT_PRODUCT intrinsic), it looks to resolve it in the default libraries.
Compiling and linking Linking HP Fortran programs • The names of the libraries that the linker is searching. This information can confirm that the linker is searching the correct libraries. • The names of the object files selected by the linker to resolve the references. The linker may have found the same name in another library and resolved the reference there. Many library-related problems are owing to a misplaced -l on the command line.
Compiling and linking Linking HP Fortran programs Linking to shared libraries Many HP Fortran libraries as well as HP-UX libraries exist in both shared and archive versions, as indicated by the library extension name (.sl or .a or .sl on Itanium ). For example, there are both shared and archive versions of the HP Fortran runtime library, /usr/lib/libcl.sl and /usr/lib/libcl.a.
Compiling and linking Linking HP Fortran programs Library search rules When you use the -l option to specify the name of a library, the linker searches for the library in the directories specified by the LPATH environment variable. The f90 command sets this variable so that the linker looks first in /opt/fortran90/lib, then in /usr/lib. You can specify another directory to search by setting LPATH yourself; see “LPATH environment variable” on page 98.
Compiling and linking Special-purpose compilations Special-purpose compilations The default behavior of the HP Fortran compiler has been designed to handle typical compilations. Most applications should require no more than a few of the f90 options to compile successfully (see Table on page 25 for a list of commonly used options). However, the compiler can also meet the needs of more specialized compilations.
Compiling and linking Special-purpose compilations • How to use the -I and +moddir options to manage .mod files Examples Consider, for example, a program that consists of three files: main.f90, code.f90, and data.f90. The main program unit is in main.f90, as follows. Example 2-2 main.
Compiling and linking Special-purpose compilations item(n_items) = new_item sum = sum + new_item END SUBROUTINE update_db ! get_avg: returns arithmetic mean INTEGER FUNCTION get_avg () get_avg = sum / n_items END FUNCTION get_avg END MODULE stats_code This program unit also begins with a USE statement, which identifies the module it uses as stats_db. This module is defined in data.f90, as follows: Example 2-4 data.
Compiling and linking Special-purpose compilations If instead of the preceding command line, the program had been compiled as follows: $ f90 -o do_stats main.f90 data.f90 code.f90 the compilation would fail and f90 would print the error message: Error FCE37 : Module STATS_CODE not found The compilation would fail because the compiler cannot process main.f90 without STATS_CODE.mod. But the order in which the program files appear on the command line prevents the compiler from processing code.
Compiling and linking Special-purpose compilations Managing .mod files By default, the compiler writes .mod files to the current working directory and looks there when it has to read them. The +moddir=directory and -I directory options enable you to specify different directories. The +moddir option causes the compiler to write .mod files in directory, and the -I option causes the compiler to search directory for .mod files to read. (The space character between -I and directory is optional.
Compiling and linking Special-purpose compilations • A PA-RISC processor name—for example, PA7100 or PA8000. • portable—code that is compatible across all models. Use +DAportable only if you want to ensure that your program will run on different models. Use the uname -m command to learn the model of your machine, as follows: $ uname -m 9000/879 Alternatively, you can use the grep command to look up the model number in the file /opt/langtools/lib/sched.
Compiling and linking Special-purpose compilations Although compiling with either +pic=short or +pic=long will generate PIC, in general you should use the +pic=short option. If the linker issues an error message saying that the number of referenced symbols in the shared library exceeds its limit, recompile with +pic=long, which will cause the compiler to allocate space for a longer symbol table.
Compiling and linking Special-purpose compilations Example 2-8 greet.f90 PROGRAM main CALL say_hi() CALL say_bye() END PROGRAM main The following command line creates the PIC object files (the -c option suppresses linking): $ f90 -c +pic=short bye.f90 hi.f90 The next command line links the object files into the shared library: $ ld -b -o my_lib.sl bye.o hi.o The last command line compiles the source file greet.f90 and links the object code with the shared library to produce the executable program a.
Compiling and linking Special-purpose compilations Processing cpp directives By default, the f90 command passes source files ending in the .F extension to cpp. Compiling with the +cpp=yes option enables you to override this default and cause the f90 driver to pass all source files to cpp. If you do not compile with the +cpp=yes option and if the source file does not have the .F extension, the compiler treats any cpp directives (but not any embedded Fortran statements) as comments and ignores them.
Compiling and linking Special-purpose compilations $ a.out Enter a real number: 3 The value of x in main: 3.0 The value of x in double_it: x = 6.0 3.0 The next command line does not use the -D option, so that DEBUG is undefined, causing cpp to remove the PRINT statements from the source text that is passed to the compiler: $ f90 +cpp=yes cpp_direct.f90 Here is the output from the nondebugging version of the program: $ a.out Enter a real number: 3.3 x = 6.
Compiling and linking Special-purpose compilations Creating demand-loadable executables By default, the loader loads the entire code for an executable program into virtual memory. For very large programs, this can increase startup time. You can override this default by causing the linker to mark your program demand load. A demand-loadable program is loaded into memory a page at a time, as it is accessed. Use the +demand_load option to make your program demand loadable, as follows: $ f90 +demand_load prog.
Compiling and linking Special-purpose compilations However, the C language has some differences in data type sizes. If your Fortran program calls functions written in C and is compiled in 64-bit mode, the size differences may require promoting the data items that are passed to or from the C functions. See Table on page 181 and Table on page 181 for the size differences between Fortran and C data types when compiled in 64-bit mode.
Compiling and linking Using environment variables Using environment variables Environment variables are variables that are defined in the operating environment of the system and are available to various system components. For example, when you run a program, the shell looks at the PATH variable to determine where the program is located. Table 2-15 lists and briefly describes the environment variables that control the way HP Fortran programs are compiled, linked, and run.
Compiling and linking Using environment variables The syntax of the HP_F90OPTS variable allows the bar (|) character to be used to specify that options appearing before | are to be recognized before any options on the command line and that options appearing after | are to be recognized after any options on the command line. For example, the commands: $ export HP_F90OPTS="-O|-lmylib" $ f90 -v hello.f90 are equivalent to: $ f90 -O -v hello.
Compiling and linking Using environment variables MP_NUMBER_OF_THREADS environment variable The MP_NUMBER_OF_THREADS environment variable sets the number of processors that are to execute a program that has been compiled for parallel execution. If you do not set this variable, it defaults to the number of processors on the executing machine.
Compiling and linking Using environment variables 100 Chapter 2
3 Controlling data storage This chapter describes the use of command-line options, directives, and other language features to control data in HP Fortran programs.
Controlling data storage • Automatic and static variables • Increasing the precision of constants • Increasing default data sizes • Sharing data among programs • Modules vs. common blocks NOTE 102 For information about how HP Fortran aligns data, refer to the HP Fortran Programmer's Reference.
Controlling data storage Disabling implicit typing Disabling implicit typing By default, HP Fortran uses implicit typing to determine the type of a variable or function that has not been declared with a type declaration statement. That is, the type of an undeclared entity is determined by the first letter of its name: if the letter is in the range I - N, the entity is of type integer; otherwise, it is of type real.
Controlling data storage Automatic and static variables Automatic and static variables By default, HP Fortran allocates stack storage for program variables. Such variables are called automatic variables because they are allocated at each invocation of the program unit in which they are declared. Static variables are allocated storage from static memory when the program is first loaded into memory. They remain allocated for the life of the program.
Controlling data storage Automatic and static variables CALL recurse CONTAINS ! This subroutine calls itself four times. ! Each time it is called, it adds 1 to the values in ! stat_val and auto_val and displays the result. ! stat_val has the SAVE attribute and therefore is ! pre-initialized and retains its value between calls. ! auto_val is an automatic variable and therefore has ! an unpredictable value (plus 1) at each call.
Controlling data storage Automatic and static variables NOTE HP Fortran provides the AUTOMATIC and STATIC statements as porting extensions. The STATIC statement is functionally the same as the SAVE statement, and the AUTOMATIC statement may be used to declare a variable as automatic. However, such a declaration is generally pointless because variables compiled under HP Fortran are automatic by default.
Controlling data storage Increasing the precision of constants Increasing the precision of constants By default, HP Fortran evaluates all floating-point constants as single-precision. For example, the compiler treats following constant 3.14159265358979323846 as though you had specified: 3.
Controlling data storage Increasing the precision of constants For information about increasing the precision of variables, see “Increasing default data sizes” on page 109. The HP Fortran Programmer’s Reference describes the syntax of the kind parameter and the exponent form and the +real_constant option. For detailed information about how floating-point arithmetic is implemented on HP 9000 computers and how floating-point behavior affects the programmer, refer to the HP-UX Floating-Point Guide.
Controlling data storage Increasing default data sizes Increasing default data sizes The +autodbl and +autodbl4 options enable you to increase the default sizes (that is, the number of storage bytes) for both constants and variables of default numeric and logical types. Unlike the +real_constant option, the +autodbl and +autodbl4 options affect both constants and variables of both real and integer types.
Controlling data storage Increasing default data sizes Figure 3-1 Increasing default data sizes Bytes 0 4 8 16 INTEGER: LOGICAL: REAL: DOUBLE PRECISION: COMPLEX: Key = +noautodbl and +noautodbl4 (the default) = +autodbl = +autodbl4 The following program illustrates the different effects of the +autodbl and +autodbl4 options.
Controlling data storage Increasing default data sizes Example 3-2 precision.f90 PROGRAM main REAL x REAL(KIND=16) y DOUBLE PRECISION z ! Assign a quad-precision constant to a default real: x = 3.14159265358979323846_16 PRINT 10, ‘Stored in x: ‘, x ! Assign a quad-precision constant to a variable that ! has been explicitly sized for quad-precision: y = 3.
Controlling data storage Increasing default data sizes $ f90 +autodbl4 precision2.f90 $ a.out Stored in x: 3.14159265358979310000 Stored in y: 3.14159265358979323846 Stored in z: 3.14159265358979310000 Though useful for increasing the range and precision of numerical data, the +autodbl and +autodbl4 options are especially useful when porting; see “Large word size” on page 242. For detailed information about these options, see the HP Fortran Programmer’s Reference.
Controlling data storage Sharing data among programs Sharing data among programs If you are designing an application that requires multiple threads of control that share the same data, the design can take either of two forms: • The program makes calls to the threads library: /usr/lib/libpthread.sl which creates multiple threads executing in a single process and therefore all sharing the same address space.
Controlling data storage Sharing data among programs The following two examples illustrate these concepts. Example 3-3 go_to_sleep.f90 PROGRAM main ! This program, go_to_sleep.f90, and its companion, wake_up.f90, ! share data in a common block, using the $HP$ SHARED_COMMON ! directive. Execute this program first. After it starts to ! execute, use ipcs(1) to confirm that a shared memory segment ! has been created. In a separate process, run wake.f90.
Controlling data storage Sharing data among programs CALL sleep (%VAL(1)) should instead read: CALL sleep (1) Example 3-4 wake_up.f90 PROGRAM main ! This program, wake_up.f90, should be run just after its ! companion, go_to_sleep.f90, starts to execute but in a ! separate process. The $HP$ SHARED_COMMON directive ! enables both programs to share the same memory. ! Directive puts the common block in shared memory.
Controlling data storage Sharing data among programs $ ipcs -m IPC status from /dev/kmem as of Fri Mar 21 15:55:29 1997 T ID KEY MODE OWNER GROUP Shared Memory: m 0 0x4119c72b --rw-rw-rwroot root m 1 0x4e180002 --rw-rw-rwroot root m 2 0x41187bf4 --rw-rw-rwroot root m 3 0x00000000 --rw------root sys m 7004 0x43186ea0 --rw-rw-rwdaemon daemon m 6005 0x73636231 --rw-rw-rwed lang Now run the second program in the second process: $ wake_up At this point, the program executing in the first process outputs the fo
Controlling data storage Modules vs. common blocks Modules vs. common blocks The common block has been a mainstay of Fortran programs throughout the evolution of the language, and it continues to be a part of Fortran. The common block provides a convenient means to share data among program units, especially when the program units sharing data do not otherwise communicate with each other.
Controlling data storage Modules vs. common blocks Another feature of the module is that it can include procedures. This feature provides a way to package data with the procedures needed to operate on the data. A program unit accesses module procedures in the same way it does module data, with the USE statement. The interface of module procedures is available to the compiler, which can perform compile-time checks on the actual arguments that are passed to a module procedure.
4 Debugging This chapter describes different HP Fortran features for debugging programs. These features include compile-line options, compiler directives, and programming tools that are useful for locating errors in your program.
Debugging • Using the HP WDB debugger • Stripping debugging information • Handling runtime exceptions • Using debugging lines 120 Chapter 4
Debugging Using the HP WDB debugger Using the HP WDB debugger The HP WDB debugger is the primary tool for debugging HP Fortran programs. The debugger provides such basic debugging functions as program control, process control, program and data monitoring, and expression evaluation. The debugger has both a graphical interface and a line-mode interface.
Debugging Stripping debugging information Stripping debugging information Programs compiled with HP Fortran include minimal debugging information in the executable program. This information consists of a symbol table—a list of all the symbols in your program and their offset addresses. The symbol table provides the information needed to produce a procedure traceback. It is also used by the debugger and by the CXperf performance analysis tool.
Debugging Handling runtime exceptions Handling runtime exceptions Broadly defined, an exception is an error or fault condition that affects a program’s results. Exceptions can range from the relatively benign inexact result condition that occurs in certain floating-point operations to the more severe segmentation violation that occurs when a runaway program attempts to access unallocated memory.
Debugging Handling runtime exceptions • The program aborts. The following sections discuss each of exceptions listed in Table 4-1. For more information about signals, refer to the signal(2) and signal(5) man pages. NOTE Standard Fortran 90 provides the IOSTAT= and ERR= specifiers for handling I/O runtime errors. For information about these specifiers, refer to the descriptions of the I/O statements (for example, OPEN and READ) in the HP Fortran Programmer’s Reference.
De bugging Handling runtime exceptions ❏ Division by zero ❏ Overflow ❏ Underflow The +FP option also enables the trap for the inexact operation exception. For detailed descriptions of these exceptions, refer to the HP-UX Floating-Point Guide. • Unlike the +fp_exception option, the +FP option includes a flags argument by which you can enable specific exceptions. • The +FP option can also be used to enable fast underflow on systems that support it (chiefly PA2.0 systems).
Debugging Handling runtime exceptions Any program that can generate address references outside its segment—for example, by indexing beyond the declared boundary of an array—may cause a segmentation violation. In C programs, bad pointers often result in this exception.
Debugging Using debugging lines Using debugging lines An HP Fortran program that has been written in fixed source form can contain debugging lines. These are statements that begin with the letter D or d in column 1. When compiled with the +dlines option, the debugging lines are treated as statements and compiled; otherwise, they are treated as comments and ignored. A program that contains debugging lines must also be compiled for fixed source form; that is, the filename extension must be either .f or .
Debugging Using debugging lines 128 Chapter 4
5 Using the ON statement Whenever a runtime error occurs, the default action of your program depends on the type of the error. If the error results from a floating-point exception, the program will continue to execute. Other errors will cause it to abort.
Using the ON statement As described in “Handling runtime exceptions” on page 120, the +fp_exception and +FP options provide control over how a program behaves when a runtime error occurs. The ON statement provides an additional level of control by enabling your program to handle floating-point and integer exceptions and +Ctrl-C interrupts.
Using the ON statement Exceptions handled by the ON statement Exceptions handled by the ON statement Like the +fp_exception option, the ON statement enables traps for floating-point exceptions (by default, traps for floating-point exceptions are disabled on HP 9000 computers).
Using the ON statement Exceptions handled by the ON statement Table 5-1 Exceptions handled by the ON statement (Continued) Exceptions Overflow Underflow Inexact result Invalid (illegal) operation +Ctrl-C interrupt 132 Exception keywords Alternate keywords INTEGER(2) DIV 0 INTEGER*2 DIV 0 INTEGER(4) DIV 0 INTEGER DIV 0 REAL(4) OVERFLOW REAL OVERFLOW REAL(8) OVERFLOW DOUBLE PRECISION OVERFLOW REAL(16) OVERFLOW (none) INTEGER(2) OVERFLOW INTEGER*2 OVERFLOW INTEGER(4) OVERFLOW INTEGER OV
Using the ON statement Actions specified by ON Actions specified by ON The action taken after an exception is trapped depends on the action specified by the most recently executed ON statement for that exception. To specify an action, the ON statement must include the keyword ABORT, IGNORE, or CALL. These keywords have the following meanings: • If ABORT is specified, a standard error message is generated and the program is aborted.
Using the ON statement Actions specified by ON z = x / y PRINT *, y END PROGRAM main Here is the command line and the output from a sample run: $ f90 abort.f90 $ a.out PROGRAM ABORTED : IEEE divide by zero PROCEDURE TRACEBACK: ( 0) 0x0000248c _start + 0x6c [./a.out] The program would have the same result if you were to comment out the ON statement and compile with the +fp_exception option. Ignoring errors You can use the ON statement to ignore an exception by specifying the IGNORE keyword.
Using the ON statement Actions specified by ON PRINT *, z END PROGRAM main As defined by the IEEE standard, a floating-point operation that results in a NaN is an exception known as an invalid operation. The example program performs an invalid operation when it passes a negative argument to the LOG intrinsic, causing the intrinsic to return a NaN. The following ON statement: ON REAL INVALID IGNORE causes the program to ignore this exception and continue execution.
Using the ON statement Actions specified by ON Example 5-3 call_fptrap.f90 PROGRAM main REAL :: x, y ON REAL ILLEGAL CALL trap_illegal x = -10.0 y = LOG(x) ! causes an invalid operation PRINT *, y END PROGRAM main SUBROUTINE trap_illegal(res) ! res is the result value of the invalid operation ! trapped by the ON statement REAL :: res res = 99.87 ! assign another value to the result argument END SUBROUTINE trap_illegal Here is the command line, followed by the output from a sample run: $ f90 call_fptrap.
Using the ON statement Actions specified by ON i = i + 1 PRINT *, i END PROGRAM main SUBROUTINE trap_oflow(n) INTEGER :: n ! write error message to standard error WRITE (7, *) 'integer overflow occurred, assigning 0 to result' n = 0 END SUBROUTINE trap_oflow Here is the command line, followed by the output from a sample run: $ f90 call_itrap.f90 $ a.
Using the ON statement Trapping +Ctrl-C trap interrupts Trapping +Ctrl-C trap interrupts A +Ctrl-C interrupt can occur during the following circumstances: • When the user enters the interrupt code from the terminal while the program is running or awaiting input • During the execution of a PAUSE statement The trap procedure for a +Ctrl-C interrupt must have no formal arguments. The interrupt code is the character defined by the HP-UX stty(1) command for the intr parameter.
Using the ON statement Allowing core dumps Allowing core dumps If a program includes the ON statement and takes an exception other than the one specified by the exception keywords, the program will abort with a procedure traceback but without a core dump. If you want to allow a core dump for one or more signals for a program that includes the ON statement, you must revise the program for each such signal.
Using the ON statement Allowing core dumps $ f90 +U77 allow_core.f90 $ a.
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 n represents the level of optimization to be applied to your program) or the -O option for the default level of optimization (level 2).
Performance and optimization for compatibility with the POSIX standard and has the same functionality as the +O2 option. The following command line compiles prog.f90, using the default level of optimization: $ f90 -O prog.f90 For most applications, -O provides 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.
Performance and optimization Using profilers 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.
Performance and optimization Using profilers HP Caliper automatically runs to generate the flow-data information in a file named flow.data in the current directory. You can repeat this step multiple times with different program_arguments to create aggregated profile information in the flow.data file to improve your program’s optimization. If the flow.data file already exists in the current directory when you run your program, then HP Caliper merges the results into the file.
Performance and optimization Using profilers 6. Run HP Caliper on your fully optimized executable from Step 5 with the same configuration file from Step 4 and compare the report results with the report from Step 4. Using Options to Control Data Collection You can use various options to specify how to collect profile information about your program. Some examples of the options you can use include: • Collecting information on specific load modules.
Performance and optimization Using profilers The file name used to log diagnostic messages. flow.log You can use the FLOW_DATA and FLOW_LOG environment variables to specify the file names. If the file you specify with the FLOW_DATA variable already exists when you run your program, then HP Caliper merges the results of the current run in into the file. CAUTION You cannot combine profile information from different programs into a single flow.data file.
Performance and optimization Using profilers 1. Compile the program with the +prof option. For example: $ f90 -o prog +prof prog.f90 2. Run the program. This creates a file named mon.out in the current directory. For example: $ prog $ ls mon.out mon.out 3. Run prof, giving the name of the program as an argument, as follows: $ prof prog prof produces a listing on standard output showing the time spent in each routine. For more information about prof, see the prof(1) man page.
Performance and optimization Using options to control optimization Using options to control optimization HP Fortran includes a rich set of command-line options for controlling optimization. For most applications, we recommend optimizing with -O, which enables the default level of optimization. (For information about the default level of optimization, refer to Table on page 149; look up +O2 in the first column.
Performance and optimization Using options to control optimization where opt-level is an integer in the range 0-2. If you use the -g option at a higher level of optimization, the compiler lowers the level to 2 and compiles for debugging. Table 6-1 Option Optimization levels Optimizations performed Advantages Disadvantages Recommended use +O0 default Constant folding and partial evaluation of test conditions. Compiles fastest; compatible with the debugger option -g. Does very little optimization.
Performance and optimization Using options to control optimization Table 6-1 Option Optimization levels (Continued) Optimizations performed Advantages Disadvantages Recommended use +O3 Level 2 optimizations, plus loop transforms, parallelization, vectorization, cloning, and inlining within a file. Some optimizations may require additional options; see “Using the optimization options” on page 150. Can significantly increase performance over level 2.
Performance and optimization Using options to control optimization Nearly all of the optimization options can be used to enable or disable an optimization or a package of optimizations. For example, the following command line requests aggressive level 4 optimizations that do not result in roundoff errors: $ f90 +O4 +Oaggressive +Ofltacc prog.f90 The f90.1 manpage fully describes all of the optimization options.
Performance and optimization Using options to control optimization Table 6-2 Packaged optimization options (Continued) Option Level +O[no]conservative +O2 or higher Function Suppress [do not suppress] optimizations that assume strict conformity to the Fortran 90 standard. The default is +Onoconservative. For more information about this option, see “Conservative vs. aggressive optimization” on page 162. NOTE: This option is valid only on the PA-RISC systems.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option Level Function +O[no]dynopt All Enable [disable] dynamic optimization for the output file, if the run-time environment supports this feature. Both forms of this option change the default setting, which allows the run-time environment to enable or disable dynamic optimization according to a system-wide default.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option +Ofast Level All Function Select a combination of optimization options for optimum execution speed and reasonable build times. Currently chosen options are: • +O2 • +Ofltacc=relaxed • +Onolimit • +DSnative • +FPD • -Wl,+pi,1M • -Wl,+pd,1M • -Wl,+mergeseg NOTE: Do not use this option for programs that depend on IEEE standard floating point denormalized numbers.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option Level Function +Ofrequently_called:file name All The file indicated by filename contains a list of functions, separated by spaces or newlines. These functions are assumed to be frequently called. This option overrides any information in a profile database. +O[no]info All Display [do not display] information about the optimization process.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option Level Function +O[no]loop_block +O3 or higher Loop blocking is a combination of strip mining and interchange that improves data cache locality. It is provided primarily to deal with nested loops that manipulate arrays that are too large to fit into the data cache.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option +O[no]parallel Level +O3 or higher Function Transform [do not transform] eligible loops for parallel execution. The default is +Onoparallel. This option is available only on HP 9000 systems. On Integrity systems, you can use the +Oautopar option instead to parallelize loops.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option Level Function +O[no]promote_indirect_c alls +O3 or higher Use profile data from profile-based optimization and other information to determine the most likely target of indirect calls and promotes them to direct calls. Indirect calls occur with pointers to functions and virtual calls.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option +O[no]recovery Level All Function This option generates [does not generate] recovery code for control speculation. For code that writes to uncacheable memory that may not be properly identified as volatile, the +Orecovery option reduces the risk of incorrect behavior. The default is +Orecovery.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option +[no]srcpos Level All Function This option controls the generation of source position information for HP Caliper. The default is +srcpos. When +srcpos, is in effect, the compiler generates source position information.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option +O[no]whole_program_mode Level +O4 or higher Function Enable the assertion that only the files that are compiled with this option directly reference any global variables and procedures that are defined in these files. In other words, this option asserts that there are no unseen accesses to the globals.
Performance and optimization Conservative vs. aggressive optimization Conservative vs. aggressive optimization At optimization level 2 or higher, the optimizer makes a number of assumptions about the program it is optimizing—for example, that re-ordering an expression for improved instruction scheduling will not change its results. In general, these assumptions relate to how closely the target program conforms to the Fortran 90 Standard.
Performance and optimization Conservative vs.
Performance and optimization Parallelizing HP Fortran programs Parallelizing HP Fortran programs The following sections discuss how to use the +Oparallel option and the parallel directives when preparing and compiling HP Fortran programs for parallel execution. Later sections also discuss reasons why the compiler may not have performed parallelization. The last section describes runtime warning and error messages unique to parallel-executing programs.
Performance and optimization Parallelizing HP Fortran programs Profiling parallelized programs You can profile a program that has been compiled for parallel execution in much the same way as for non-parallel programs: 1. Compile the program with the +gprof option. 2. Run the program to produce profiling data. 3. Run gprof against the program. 4. View the output from gprof. The differences are: • Step 2 produces a gmon.out file with the CPU times for all executing threads.
Performance and optimization Parallelizing HP Fortran programs You can use the DIR$ NO SIDE EFFECTS directive to force the compiler to ignore side effects when determining whether to parallelize the loop. For information about this directive, see . NOTE A subroutine (but not a function) is always expected to have side effects. If you apply this directive to a subroutine call, the optimizer assumes that the call has no effect on program results and can eliminate the call to improve performance.
Performance and optimization Parallelizing HP Fortran programs In this loop, the order of execution does matter. The data used in iteration I is dependent upon the data that was produced in the previous iteration (I-1). The array A would end up with very different data if the order of execution were any other than 2-3-4-5. The data dependence in this loop thus makes it ineligible for parallelization. Not all data dependences inhibit parallelization. The following paragraphs discuss some of the exceptions.
Performance and optimization Vectorization Vectorization When vectorization is enabled, the optimizer replaces eligible loops with calls to specially tuned routines in the math library. When you compile with the +Ovectorize option, the optimizer vectorizes wherever it determines that it is safe and feasible to do so. However, you can use directives to limit vectorization.
Performance and optimization Vectorization Table 6-5 Vector routines called by +Ovectorize (Continued) Vector routine Description vec_damax Find the maximum absolute value in a double-precision vector. vec_dmult_add Multiply a scalar by a vector and add the result to the result vector, using double-precision operands. vec_dsum Sum the elements of a double-precision vector. If your PA2.
Performance and optimization Vectorization Note that the *$* VECTORIZE directive does not force vectorization. The optimizer vectorizes only if: • The loop performs a vector operation recognized by the optimizer as in its repertoire. • The loop is safe to vectorize. The same conditions that can prevent parallelization—see, for example, “Data dependences” on page 166—can also prevent vectorization. • The optimizer can discover no other transformations that can result in better performance.
Performance and optimization Vectorization inc_x = 1 inc_y = 1 ! initialize the two arrays x and y DO i = 1, 5 y(i) = i x(i) = i + 3.0 END DO PRINT *, y ! add a scalar multiple of x to y DO i = 1, 5 y(i) = y(i) + b * x(i) END DO PRINT *, y END PROGRAM main The following command lines compile and execute the program, and show the output from a sample run: $ f90 saxpy.f90 $ a.out 1.0 2.0 3.0 4.0 5.0 13.0 17.0 21.0 25.0 29.
Performance and optimization Controlling code generation for performance Controlling code generation for performance For optimum performance, the executable program should consist of code that can take advantage of the hardware features of the machine on which the program will run. If your program will run on the same machine as you use to compile it, code generation is not an issue. By default, the HP Fortran compiler generates code for the model of the machine on which you are running the compiler.
7 Writing HP-UX applications This chapter discusses how HP Fortran applications running on the HP-UX operating system can use system resources to do the following: • Accessing command-line arguments Chapter 7 173
Writing HP-UX applications • Calling HP-UX system and library routines • Using HP-UX file I/O 174 Chapter 7
Writing HP-UX applications Accessing command-line arguments Accessing command-line arguments When invoking an HP Fortran executable program, you can include one or more arguments on the command line. The operating system will make these available to your program.
Writing HP-UX applications Accessing command-line arguments $ f90 get_args.f90 $ a.out perambulation of a different sort this program produces the following output: 13 perambulation 5 For more information about the IGETARG and IARGC intrinsics, see the HP Fortran Programmer's Reference. GETARGC is also available as a libU77 routine; see the HP Fortran Programmer's Reference.
Writing HP-UX applications Calling HP-UX system and library routines Calling HP-UX system and library routines System calls provide low-level access to kernel-level resources, such as the write system routine. or example, see “File handling” on page 198 for an example of a program that calls the write routine. For information about system calls, refer to the HP-UX Reference. HP-UX library routines provide many capabilities, such as getting system information and file stream processing.
Writing HP-UX applications Using HP-UX file I/O Using HP-UX file I/O HP-UX file-processing routines can be used as an alternative to Fortran file I/O routines. This section discusses HP-UX stream I/O routines and I/O system calls. Stream I/O using FSTREAM The HP-UX operating system uses the term stream to refer to a file as a contiguous set of bytes. There are a number of HP-UX subroutines for performing stream I/O; see stdio(3S) in the HP-UX Reference.
Writing HP-UX applications Using HP-UX file I/O Establishing a connection to a file HP-UX I/O system calls require an HP-UX file descriptor, which establishes a connection to the file being accessed. A file descriptor is an integer whose function is similar to a Fortran logical unit number. For example, the following open system call (called from a C-language program) opens a file named DATA.DAT for reading and writing, and returns the value of an HP-UX file descriptor: #include
Writing HP-UX applications Using HP-UX file I/O 180 Chapter 7
8 Calling C routines from HP Fortran This section describes language differences between C and HP Fortran that affect calling C routines from an HP Fortran program.
Calling C routines from HP Fortran • Argument-passing conventions • Case sensitivity • Arrays • C strings • File handling • Sharing data 182 Chapter 8
Calling C routines from HP Fortran Data types Data types Table 8-1 lists the corresponding data types for HP Fortran and C when compiled as 32-bit applications.
Calling C routines from HP Fortran Data types Table 8-2 shows the differences between the corresponding data types in HP Fortran and C when compiling in 32-bit mode and in 64-bit mode. Table 8-3 shows the differences when the Fortran program is compiled with the +autodbl option. Notice that Fortran data items that are explicitly sized (for example, INTEGER*4) stay the same size regardless of whether they are compiled in 32-bit mode, in 64-bit mode, or with the +autodbl option.
Calling C routines from HP Fortran Data types • Unsigned integers • Logicals • Complex numbers • Derived types Unsigned integers Unlike Fortran, C allows integer data types (char, int, short, and long) to be declared as either signed or unsigned. If a Fortran program passes a signed integer to a C function that expects an unsigned integer argument, C will interpret the bit pattern as an unsigned value.
Calling C routines from HP Fortran Data types The Fortran source file for such a scenario is shown below in the example pass_complex.f90. Example 8-1 pass_complex.f90 PROGRAM main ! This program passes a complex number to a C function ! that squares it and returns the result. The C ! function has the following declaration prototype: ! ! complex sqr_complex(complex cmx_val); ! ! "complex" is not an intrinsic type for C but it ! creates a typedef for one, using a struct. COMPLEX :: result, cmx_num = (2.
Calling C routines from HP Fortran Data types { COMPLEX result; float a, b; /* copy both parts of the complex number into locals */ a = cmx_val.real; b = cmx_val.imag; /* square the * the return */ result.imag = a = a * a; b = b * b; result.real = complex number and store the results into variable 2 * (a * b); a - b; return result; } Below are the command lines to compile, link, and execute the program, followed by the output from a sample run. $ cc -Aa -c sqr_complex.c $ f90 pass_complex.
Calling C routines from HP Fortran Argument-passing conventions Argument-passing conventions The important difference between the argument-passing conventions of HP C and HP Fortran is that Fortran passes arguments by reference — that is, it passes the address of the argument — whereas C passes non-array and non-pointer arguments by value — that is, it passes a copy of the argument.
Calling C routines from HP Fortran Case sensitivity Case sensitivity Unlike HP Fortran, C is a case-sensitive language. HP Fortran converts all external names to lowercase, and it disregards the case of internal names. Thus, for example, the names foo and FOO are the same in Fortran. C, however, is a case-sensitive language: foo and FOO are different in C.
Calling C routines from HP Fortran Case sensitivity 2. The function expects its second argument (the size of the array) to be passed by value. The following $HP$ ALIAS directive handles both issues: !$HP$ ALIAS bubblesort = 'BubbleSort'(%REF, %VAL) The name bubblesort is the alias that Fortran will use to refer to the C function, and the %REF and %VAL built-in functions change Fortran’s argument-passing conventions to conform to how the C function expects the arguments to be passed.
Calling C routines from HP Fortran Case sensitivity See “File handling” on page 199 for another example of a program that uses the $HP$ ALIAS directive. The HP Fortran Programmer's Reference fully describes the %VAL and %REF built-in functions, the +uppercase and +pre_include options. Th e $HP$ ALIAS directive is discussed in “$HP$ ALIAS” on page 208.
Calling C routines from HP Fortran Arrays Arrays There are two differences between HP Fortran and C to consider when passing arrays from Fortran to C: • In HP Fortran, array subscripts start by default at 1, whereas in C they always start at 0 • In HP Fortran, multi-dimensional arrays are laid out differently in memory than they are in C. The difference in subscript-numbering does not result in any size discrepancies: an array of 10 elements in Fortran has 10 elements in C, too.
Calling C routines from HP Fortran Arrays You can change the array declaration in either language, whichever is more convenient. The important point is that, to be conformable, the dimensions must be in reverse order. Below is an example for a three-dimensional array, the first being for a Fortran declaration. REAL, DIMENSION(2,3,4) :: x Below is the same declaration as declared in C. int x[4][3][2]; Example 8-5 pass_array.
Calling C routines from HP Fortran Arrays printf("\nHere is the same array as accessed from C:\n\n"); for (i = 0; i < 4; i++) for (j = 0; j < 2; j++) printf(“a[%d][%d] = %d\n”, i, j, a[i][j]); } Here are the command lines to compile, link, and execute the program, followed by the output from a sample run: $ cc -Aa -c get_array.c $ f90 pass_array.f90 get_array.o $ a.
Calling C routines from HP Fortran C strings C strings C strings differ from Fortran character variables in two important respects: • C expects strings to be null-terminated. • For each character variable or character constant that Fortran passes to a C routine, it also passes a hidden length argument. The following sections discuss these differences and explain how to code for them. The last section includes an example program.
Calling C routines from HP Fortran C strings Note that both C and Fortran both pass strings by reference. This means that, if Fortran passes only string arguments to C, you need not use the %VAL and %REF built-in functions to indicate how the arguments are to be passed. For information about these functions, see “Argument-passing conventions” on page 188.
Calling C routines from HP Fortran C strings 20 FORMAT(/, 'The names passed back to Fortran: ', A, 1X, A) END PROGRAM main Example 8-8 get_string.c #include #include void fix_string_for_f90(char s[], int len); /* get_string: overwrites the string arguments fname and lname; * fname_len and lname_len are the hidden length arguments, which * are implicitly passed by Fortran with each string argument.
Calling C routines from HP Fortran C strings The names passed back to Fortran: 198 Wade Ward Chapter 8
Calling C routines from HP Fortran File handling File handling A Fortran unit number cannot be passed to a C routine to perform I/O on the associated file; nor can a C file pointer be used by a Fortran routine. However, a file created by a program written in either language can be used by a program in the other language if the file is declared and opened within the program that uses it. C accesses files using HP-UX I/O subroutines and intrinsics.
Calling C routines from HP Fortran File handling ! written; if the write was successful, it should be 10 status=IWRITE(fd, a, 10) CLOSE (1, STATUS=’KEEP’) ! open the file for reading; we want to see if the write was ! successful OPEN (1, FILE='file1', STATUS='UNKNOWN') READ (1, 4) (a(i), i = 1, 10) 4 FORMAT (10A1) CLOSE (1, STATUS='DELETE') DO i = 1, 10 ! if we find anything other than x's, the write failed IF (a(i) .NE.
Calling C routines from HP Fortran Sharing data Sharing data Fortran programmers have traditionally relied on the common block to share large amounts of data among different program units. The convenience offered by the common block is that it can give storage access to program units that don’t otherwise communicate with each other, even when they reside in separate files.
Calling C routines from HP Fortran Sharing data The common block to be shared with a C function can contain more than one data item. To do so, the C source file must declare a structure whose members match the data items in common. Any C function needing access to an item in common uses the extern statement to declare a variable of the structure type. The name of the variable is that of the common block.
Calling C routines from HP Fortran Sharing data Example 8-11 shared_struct.c #include #include /* declare a structure whose members match the data items * in the Fortran common block */ struct glob { double num; double nlog_of_num; } globals; /* get_nlog: reads the value in globals.num, passes it * to log() in the math library, and writes the write the * return value to globals.
Calling C routines from HP Fortran Sharing data 204 Chapter 8
9 Using Fortran directives Compiler directives are commands within the source program that affect how the program is compiled. They are similar in function to command-line options, but generally provide more local control. The directives provided by HP Fortran use a syntax that causes them to be treated as comments (and so ignored) when ported to another processor or when incorrectly formatted.
Using Fortran directives Fortran directives. HP Fortran also recognizes C Preprocessor (cpp) directives. If you compile with the +cpp=yes option or if the name of the source ends in the .F extension, the source files are first passed to the C preprocessor for processing. For information about the C preprocessor, refer to cpp(1).
Using Fortran directives Directive syntax Directive syntax The syntax for specifying directives in HP Fortran source files varies according to the type of directive: C preprocessor directives take the form: #[line]cpp-directive where cpp-directive is ANSI C-conforming except that the line keyword is optional, making it compatible with the HP C compiler.
Using Fortran directives Using HP Fortran directives Using HP Fortran directives HP Fortran provides a number of compiler directives that are useful for controlling certain functions (for example, optimization) within the source file. Table 9-1 lists and briefly describes these directives; they are listed in the order in which they appear in the sections below.
Using Fortran directives Using HP Fortran directives The following sections describe each of the HP Fortran directives. $HP$ ALIAS The ALIAS directive associates the name of a subroutine, function, entry, or common block with an external name and specifies the parameter-passing conventions of routines written in other languages.
Using Fortran directives Using HP Fortran directives external-name should never conflict with the name of an HP-UX system routine (described in sections 2 and 3 of the HP-UX Reference) or with a Fortran library routine (for example, OPEN, READ, or CLOSE). The $HP$ ALIAS directive applies to subroutines, entries, and functions that are used externally. It does not apply to the main program unit.
Using Fortran directives Using HP Fortran directives Case sensitivity Names in HP Fortran are not case sensitive; that is, the compiler converts all names to lowercase.
Using Fortran directives Using HP Fortran directives ! Append a null to the string so that C can handle it properly CALL c_rout(name//char(0)) END PROGRAM main Here are the command lines to compile and link both files, and to execute the program, along with the output from a sample run: $ cc -Aa -c pr_str.c $ f90 pass_str.f90 pr_str.o $ a.out Charlie For more information For detailed information about the %REF and %VAL built-in functions, see the HP Fortran Programmer’s Reference.
Using Fortran directives Using HP Fortran directives Syntax !$HP$ LIST [ON | OFF] ON enables the inclusion of source lines in the listing file. OFF disables the inclusion of source lines in the listing file. Description and restrictions The $HP$ LIST directive controls which source lines are output to the listing file. This directive is effective only when the source files are compiled with the +list option. It may appear anywhere in the source file.
Using Fortran directives Using HP Fortran directives Description and restrictions The $HP$ OPTIMIZE directive allows you to determine which areas of your program that the optimizer will process. Specifying $HP$ OPTIMIZE OFF causes the following source lines not to be optimized. $HP$ OPTIMIZE ON re-enables optimization for the following source lines. This directive is effective only if you have used either the -On or +On option when you compiled the program.
Using Fortran directives Compatibility directives Compatibility directives HP Fortran supports the compiler directives listed in Table 9-2. These directives are provided for compatibility with programs developed on the platforms listed in the table.
Using Fortran directives Compatibility directives NOTE The + Ovectorize option is valid only on the PA-RISC systems. Controlling parallelization HP Fortran can parallelize eligible program loops by distributing different iterations of the loop to different processors for parallel execution on a multiprocessor machine.
Using Fortran directives Compatibility directives Other conditions may limit the compiler's efforts to parallelize, such as the presence of the VD$ NOCONCUR directive. Such conditions may prevent parallelization even if you use a directive to disable dependence checking. Controlling checks for side effects The compiler will not parallelize a loop with an embedded call to a routine if the compiler finds that the routine has side effects.
Using Fortran directives Compatibility directives 218 Chapter 9
10 Migrating to HP Fortran A major feature of HP Fortran is its compatibility with standard-conforming HP FORTRAN 77. Both source files and object files from existing HP FORTRAN 77 applications can be migrated to HP Fortran with comparatively little effort.
Migrating to HP Fortran HP Fortran. To smooth the migration path, HP Fortran includes a number of extensions that are compatible with HP FORTRAN 77. HP Fortran also includes extensions that are designed to ease the job of porting applications from other vendors' Fortran dialects. For a summary list of all HP Fortran extensions, see the HP Fortran Programmer's Reference. For information about porting other vendors’ Fortran programs to HP Fortran, see “Porting to HP Fortran” on page 235.
Migrating to HP Fortran Incompatibilities with HP FORTRAN 77 Incompatibilities with HP FORTRAN 77 The following sections describe known incompatibilities between HP Fortran and HP FORTRAN 77. These incompatibilities include both source-level and object-code incompatibilities. A subset of these are detected by the HP fid tool, which is described in “Fortran incompatibilities detector” on page 234. Compiler limits HP Fortran supports format field widths up to 32767.
Migrating to HP Fortran Incompatibilities with HP FORTRAN 77 Table 10-2 f77 options replaced by f90 options (Continued) f77 option f90 replacement +B +escape -D +dlines +es +extend_source -F +cpp_keep -L +list -onetrip +onetrip +Q +pre_include +s +langlvla +T +fp_exception +ttyunbuf +nottybuf -U +uppercase -u +implicit_none -V +lista a. Does not fully replace. Format field widths HP Fortran 90 supports format field widths up to 32767.
Migrating to HP Fortran Incompatibilities with HP FORTRAN 77 DOUBLE PRECISION x = 3.1415926535 will initialize x to only 32 bits worth of the constant because it interprets the constant as single precision. Under HP Fortran, a constant must have a D exponent or a KIND suffix to be interpreted as double precision. In programs that use double precision exclusively, you should consider using the +real_constant=double option, which causes real constants to default to double precision.
Migrating to HP Fortran Incompatibilities with HP FORTRAN 77 Data types and constants The following HP FORTRAN 77 extensions for data types and constants are not supported by HP Fortran: • Double precision as the default storage for floating-point constants; see “Floating-point constants” on page 222. • I and J integer suffixes. To express the HP FORTRAN 77 constant 10I (or I*2) in HP Fortran, use 10_2; for 10J (or J*4), use 10_4. • Use of the 8#n and 16#n for octal and hex constants, respectively.
Migrating to HP Fortran Incompatibilities with HP FORTRAN 77 ACCESS=expr1, where expr1 is a constant expression other than DIRECT or SEQUENTIAL. • IOSTAT= • KEY= • NAME= • READONLY • STATUS=expr2, where expr2 is a constant expression other than OLD, NEW, UNKNOWN, REPLACE, or SCRATCH. • TYPE= In general, HP FORTRAN 77 allows more specifiers (and more options to specifiers) than does HP Fortran.
Migrating to HP Fortran Incompatibilities with HP FORTRAN 77 • The syntax and functionality of the HP Fortran version of the ON statement is different from the HP FORTRAN 77 version. For example, ON EXTERNAL and ON INTERNAL are not supported in HP Fortran. For information about using the ON statement, see the “Using the ON statement” on page 127. • HP FORTRAN 77 accepts statement functions that convert arguments; HP Fortran does not.
Migrating to HP Fortran Migration issues Migration issues Migration issues fall into four general categories: • Source code issues • Command-line option issues • Object code issues • Data file issues Source code issues For standard-conforming HP FORTRAN 77 code, migration to HP Fortran can be as simple as recompiling with the f90 command. The f90 command accepts source files with the extensions .f and .F (among others).
Migrating to HP Fortran Migration issues Although most of the HP FORTRAN 77 directives are not supported by HP Fortran, some of their functionality is available through command-line options; see Table 10-3.
Migrating to HP Fortran Migration issues Table 10-3 HP FORTRAN 77 directives supported by f90 options (Continued) HP FORTRAN 77 directive HP Fortran option Remarks SAVE_LOCALS (ON) +save SAVE_LOCALS OFF +nosave SET -D or -U Use the C preprocessor #define directive. STANDARD_LEVEL ANSI +langlvl=f90 Applies to Fortran 90 instead of FORTRAN 77. SYMDEBUG -g UPPERCASE +[no]uppercase WARNINGS -w Lowercase is the default.
Migrating to HP Fortran Migration issues Command-line option issues Command-line options can become a migration issue in two ways: • When you compile a program with the HP Fortran compiler, using an f77 command line. If the command line contains an unsupported f77 option, f90 will flag the option with an error message. Table 10-5 lists the f77 and f90 that have the same functionality but different names.
Migrating to HP Fortran Migration issues Table 10-5 f77 options supported by f90 (Continued) f77 option f90 option function -Y +nls Enable Native Language Support +Z +pic=long Generate position-independent code (large model) +z +pic=short Generate position-independent code (small model) Object code issues Some migration problems do not manifest themselves until runtime, when the program behaves unexpectedly or produces incorrect results.
Migrating to HP Fortran Migration issues To resolve problems with incompatible data files, examine the source file of the program that generated the data file as well as the command line that was used to compile the source file, following the suggestions discussed in “Object code issues” on page 231.
Migrating to HP Fortran Approaches to migration Approaches to migration The most direct (and painstaking) approach to migrating an HP FORTRAN 77 program so that it will compile and execute correctly under HP Fortran is to make a clean sweep through the original source code, removing all extensions and rewriting all nonstandard programming practices to conform to the Fortran 90 standard. The result will be a highly portable program.
Migrating to HP Fortran Approaches to migration In addition, the f90 command sometimes reports incompatibilities — especially in syntax—one at a time. Needless to say, fixing incompatibilities one at a time and recompiling after each fix may not be the most cost-effective approach to migrating a large FORTRAN 77 program to HP Fortran. Lintfor The lintfor tool can be used on HP FORTRAN 77 code to detect semantic assumptions that may not be valid for HP Fortran code.
Migrating to HP Fortran Approaches to migration specifier in OPEN statement: Minor differences exist between F90 and F77 IOSTAT error numbers The incompatibilities currently detected by fid are: • The I/O specifiers to the OPEN statement listed in “Input/output” on page 224. • The HP FORTRAN 77 forms of ON EXTERNAL and ON INTERNAL. • LOGICAL types used as operands to the .EQ. and .NE. operators. • All HP FORTRAN 77 compiler directives except those listed in “Directives” on page 225.
Migrating to HP Fortran Approaches to migration 236 Chapter 10
11 Porting to HP Fortran The goal of portability is to make it possible to compile and execute a program on different vendors’ platforms, regardless of the platform on which it was written. A portable Fortran 90 program contains no language elements except those mandated by the Standard and adheres to generally accepted coding practices.
Porting to HP Fortran In practice, however, programming is rarely so simple. Many Fortran programs have a long history and were originally coded at a time when portability was not a concern because many programs were written to execute on one platform only. Older Fortran programs—so-called dusty-deck programs—are likely to have passed through different dialects of Fortran, picking up features from each, even after those features have become outmoded.
Porting to HP Fortran Compatibility extensions Compatibility extensions HP Fortran includes a variety of extensions to the Fortran 90 language. Most of these are compatibility extensions—statements, intrinsic routines, and compiler directives that are specific to nonstandard implementations of Fortran 90.
Porting to HP Fortran Compatibility extensions Table 11-1 Compatibility statements (Continued) Statement Implementation Description POINTER (Cray-style) Cray Declares Cray-style pointers and their objects. RECORD DEC Declares a record of a previously defined structure. STATIC Sun Allocates storage in static memory. STRUCTURE DEC Defines a named structure. TYPE (I/O) DEC Writes to standard output. UNION DEC Defines a union within a structure. VIRTUAL DEC Declares an array.
Porting to HP Fortran Compatibility extensions As noted in the table, some of the compatibility directives are effective only if the source file is compiled with either the +Oparallel or the +Ovectorize option; otherwise, the directive is treated as a comment and ignored. For information about using these options, see “Using the +Ovectorize option” on page 167. Table 11-2 Vendor Cray KAI VAST Compatibility directives Directive Function Option dependency DIR$ IVDEP Disables dependency checks.
Porting to HP Fortran Compatibility extensions not recognize the directive name, it issues a warning and ignores the directive. A directive takes effect only if the compiler recognizes both its prefix and name—that is, it must be either one of HP’s own directives or one of those listed in Table 11-2.
Porting to HP Fortran Compatibility extensions Table 11-4 Nonstandard intrinsic procedures in HP Fortran (Continued) ATAND FREE INT2 MCLOCK SRAND ATANH FSET INT4 OR SYSTEM BADDRESS FSTREAM INT8 QCOTAN TAND COSD GETARG INUM QCOTAND TIME COTAN GETENV IOMSG QEXT XOR COTAND GRAN IQINT QFLOAT ZEXT DATE HFIX IRAND QNUM DCMPLX IACHAR IRANP QPROD DCOTAN IADDR ISIGN RAN HP Fortran also provides nonstandard specific intrinsics that derive from standard generic intrinsics; t
Porting to HP Fortran Using porting options Using porting options HP Fortran provides a number of compile-line options for porting programs. The most important of these is the +langlvl=90 option. Compiling your program with this option will cause the compiler to issue warning messages for all nonstandard features.
Porting to HP Fortran Using porting options Instead, it causes the compiler to search for all local, nonarray, nonstatic variables that have not been defined before being used. Any that it finds are initialized to 0 on the stack each time the procedure in which they are declared is invoked. For detailed information about the +save and +Oinitcheck options, see HP Fortran Programmer’s Reference. Large word size The word size of default integers, reals, and logicals in HP Fortran is 4 bytes.
Porting to HP Fortran Using porting options the PRINT statement will never execute because the initial loop count is higher than the final loop count. To force the loop to execute at least once, compile it with the command line: $ f90 +onetrip test_loop.f90 When you run the program now, it produces the output: $ a.out Should never happen in standard Fortran 90.
Porting to HP Fortran Using porting options 11 Lines Compiled $ a.out j = 4 If the program is recompiled with the +langlvl=90 option, the compiler flags the name of what it assumes to be a nonstandard intrinsic as well as the nonstandard source format: $ f90 +langlvl=90 clash.f90 program CLASH i = 4 ^ Warning 4 at (3:clash.f90) : Tab characters are an extension to standard Fortran-90 j = int1(i) ^ Warning 39 at (5:clash.
Porting to HP Fortran Using porting options If you are not sure if your program references libU77 routines, compile it with the +langlvl=90 option, which will cause the compiler to issue warnings for references to nonstandard routines. For problems that can occur when migrating HP FORTRAN 77 programs that reference libU77 routines, see *** 'Intrinsic functions' on page 222 ***.
Porting to HP Fortran Using porting options • If the file is compiled with the +extend_source option, the compiler allows lines as long as 254 characters in either fixed or free form. The default line length is 72 characters for fixed form and 132 characters for free form. See the HP Fortran Programmer’s Reference for detailed information about the different source and the +langlvl=90, +source, and +extend_source options.
Porting to HP Fortran Using porting options It is important to note that +cfc requires the following runtime library patches to function properly: • PHSS_31970—liblO77 11.22/11.23 0409 • PHSS_31971—libcl 11.11 • PHSS_31972—libcl 11.23 0409 (also pa-sharelibs for use through aries) • PHSS_31973—libF90 11.22/11.23 0409 • PHSS_31974—libF90 11.11 NOTE +cfc will not work without the patches listed above.
Porting to HP Fortran Using porting options • -check_bounds (alternate for -C) • -[no]cpp flags • -fixed/-free flags • -d_lines (synonym for +dlines) • -integer_size (16|32|64) flag • -i2, -i4, -i8 flags • -1, -66, -f66, -nof77, -onetrip (alternate for +onetrip) • -nof66 (alternate for +noonetrip) • -static, -noautomatic, -norecursive flags (all alternate spellings of +save) • -automatic and -recursive (alternates for +nosave) • -show [no]code (alternate for +[no]asm) • -[no]machine_c
Porting to HP Fortran Using porting options • support for ‘-inline {all|none|speed}’ options (‘all’ and ‘speed’ map to +Oinline; ‘none’ maps to +Onoinline) • support for ‘-speculate {all|none}’ options (‘all’ maps to +Ostatic_prediction, ‘none’ maps to +Onostatic_prediction) • -[no_]fp_reorder (inverse of ‘-assume [no]accuracy_sensitive’) • -[no]omp (maps to +O[no]openmp) • -[no]pipeline (maps to +O[no]pipeline) • -nospeculate (alternate of ‘-speculate none’) • -[no]transform_loops (maps to +O[
12 Fortran 2003 Features HP Fortran partly supports the Fortran standards 2003 as defined by ISO/IEC 1539-1:2004(E). This chapter explains the supported fortran 2003 features.
Fortran 2003 Features Interoperability with C Interoperability with C HP-UX fortran compiler supports the fortran 2003 standard mechanism to allow communication between fortran code and C code. The intrinsic module ISO_C_BINDING contains named constants that hold kind type parameter values for intrinsic types for interoperability between C and Fortran. Interoperability of Intrinsic types, C pointers, Derived types, Variables, global data and procedures are supported in the HP-UX fortran compiler.
Fortran 2003 Features Input/output enhancements Input/output enhancements Input/output fortran 2003 enhancements are partially supported in HP-UX fortran compiler. The following features are supported. • IOMSG= specifier • ROUND= specifier • DECIMAL= specifier • SIGN= specifier • Intrinsic function for newline character • Input and output of IEEE exceptional values • Comma after a P edit descriptor Currently, the following features are not supported.
Fortran 2003 Features Miscellaneous enhancements Miscellaneous enhancements HP-UX fortran compiler supports following miscellaneous fortran 2003 features.
Fortran 2003 Features Data enhancements Data enhancements HP-UX fortran compiler supports following data enhancement features of fortran 2003. 1. Procedure pointers 2. The PASS attribute HP-UX fortran compiler also supports following ISO Technical reports.
Fortran 2003 Features Object orientation features Object orientation features HP-UX fortran compiler doesnt support object orientation features. For more information on these features, refer the Fortran standards 2003 as defined by ISO/IEC 1539-1:2004(E).
Glossary A-B See also static variable.. archive library A library of routines that can be linked to an executable program at link-time. The names of archive libraries have the .a extension. back-end The component of the compiler that optimizes and generates object code. See also front-end.. See also shared library. Basic Linear Algebra Subroutine library A library of de facto standard routines for performing low-level vector and matrix operations.
Glossary core dump given the array a(3,4), element a(1,1) would be stored in the first location, a(2,1) in the second, a(3,1) in the third, and so on. See also row-major order. core dump A core image of an executing program that is deposited in a file after the program aborted execution. The core dump (also called a core file) may contain information that is useful in debugging the aborted program. data dependence The relationship that can obtain between the definition of data and its use.
Glossary porting invalid operation The floating-point exception that occurs whenever the system attempts to perform an operation that has no numerically meaningful interpretation, such as a NaN. L-N language extension A feature of a programming language that has been added by a vendor and is not defined in (or is in violation of) the language standard. The ON statement is an HP language extension to the Fortran 90 Standard. See also filename extension..
Glossary position-independent code position-independent code Object code that contains no absolute addresses. Position-independent code (PIC) has linkage tables that contain pointers to code and data. This table is filled in by the loader at runtime. Object code that consists of PIC can be used to create shared libraries. precision The number of digits to which floating-point numbers are represented. Double-precision numbers can have greater precision than single-precision numbers.
Glossary HP WDB stream I/O A type of I/O that is based on the concept of a stream—a flow of data to or from a file or I/O device. Streams are managed by the HP-UX operating system. Access to a stream is provided by a stream pointer, which is the address of a C-like structure that contains information about a stream. When the Fortran 90 intrinsic FSTREAM is given a logical unit number, it returns a stream pointer, providing Fortran programs with access to stream-based system routines.
Glossary tty buffering 264 Glossary
Index Symbols # comment character, 93 #define directive (cpp), 93 #endif directive (cpp), 93 #ifdef directive (cpp), 93 #include directive, 43 $HP$ ALIAS directive, 209 $HP$ CHECK_OVERFLOW directive, 212 $HP$ LIST directive, 212 $HP$ OPTIMIZE directive, 213 %REF built-in function, 126, 190 ALIAS directive, 209 defined, 259 %VAL built-in function, 126, 190 ALIAS directive, 209 defined, 259 +asm option, 12, 27, 29, 228, 230 +autodbl option, 7, 29, 109, 110, 112, 183, 184, 228, 245 +autodbl4 option, 7, 30, 10
Index +Ooptimization option, 12, 150 +Oparallel, 72 +Oparallel option, 72, 113, 157 directives, 241 +Oparmsoverlap option, 73, 157 +Oconservative option, 63 +Opipeline option, 73, 157 +Oprocelim option, 73, 157 +Orarely_called, 158 +Oregreassoc option, 74, 75, 159 +Oreport, 75 +Oshortdata, 159 +Osize option, 63, 152 inlining, 70 +Ovectorize option, 73, 76, 160, 168 +Oaggressive option, 62 directives, 241 +pa option, 50 +pal option, 50 +pic option, 14, 51, 90, 230 +ppu option, 9, 51, 228, 248 ALIAS directive
Index example, 190 aliasing, 259 alignment data, 102 defined, 259 packing, 202 allocatable arrays passing to C, 187 allowing core dumps, 139 analyzing performance, 18 AND intrinsic, 242 ANSI directive (f77), 228 appending underscores +ppu option, 51 architecture generating code for, 12 performance, 172 archive libraries, 83 defined, 259 -l option, 45 argument lists, 223 argument passing arrays, 192 C and Fortran, 187, 188 complex numbers, 185 conventions, 188 strings, 196 arguments C vs.
Index file handling, 199 hidden length argument, 195 logicals, 185 null-termination, 195 opening a file, 179 pointers, 187 sharing data, 201 stream I/O, 178 strings, 195 structures, 187 subscripts, 192 unsigned integers, 185 -C option, 32 -c option, 4, 15, 31, 78, 92 -C option (f77), 230 C preprocessor +cpp option, 31, 33 +cpp_keep option, 34 -D option, 34 directives, 206 -I option, 43 -U option, 55 cache optimizations, 64 CALL clause, 133 calling BLAS routines, 170 C functions, 126 C routines, 181 libU77 r
Index prof, 18, 146 setenv, 79 strip, 122 stty, 138 uname, 90 comments # as extension, 93 compiler directives as, 205 directives as, 93, 240 incompatibilities, 226 common blocks C, 201 C’s extern specifier, 201 placing in shared memory, 113 pros and cons, 117 sharing data, 113 COMMON statement, 104, 201 compatibility, 220 Cray, 215 KAP, 215 VAST, 215 compatibility directives, 215 compatibility features, 239 +autodbl option, 245 +autodbl4 option, 245 +escape option, 249 +extend_source option, 249 +langlvl=90
Index +Oregreassoc, 74, 75, 159 +Oreport, 72, 75 +Osize, 63, 152 +Ovectorize, 73, 76, 160, 168 +pa, 50 +pal, 50 +pic, 14, 51, 90, 230 +ppu, 9, 51, 228, 248 +pre_include, 4, 51, 190, 221 +prof, 14, 18, 51, 147, 230 +real_constant, 9, 52, 107, 109, 230 +save, 14, 52, 104, 228, 230, 244 +shared, 16, 53, 95, 230 +source, 10, 53, 248 +strip, 16, 54, 122, 230 +traceback, 139 +ttybuf, 16, 55, 221 +U77, 17, 55, 82, 139, 229 +uppercase, 10, 56, 189, 221, 228 +usage, 2, 5, 24, 56 +version, 5, 56 +Z, 51, 58 +z, 51, 58
Index CHECK_OVERFLOW, 136, 137, 212, 225 compatibility, 215, 240 CONCUR, 216, 241 CONCURRENTIZE, 216, 241 incompatibilities, 225 incompatible directives, 223 IVDEP, 167, 216 LIST, 212, 225 listed, 208 NO SIDE EFFECTS, 166, 170, 217, 241 NO_SIDE_EFFECTS, 217 NODEPCHK, 167, 216, 241 OPTIMIZE, 213, 225 recognized prefixes, 241 replaced by options, 228 SHARED_COMMON, 113, 225 syntax, 207 VECTOR, 241 VECTORIZE, 169, 215, 241 compiling +strip option, 122 defaults, 1 for debugging and optimization, 148 for optimiz
Index shared, 113 storage, 101 data dependence defined, 260 data files migrating, 231 data prefetch instructions, 65 DATA statement incompatibilities, 224 DATA statements, 104 data types, 224 C and Fortran, 183 COMPLEX, 185, 224 derived types, 187 LOGICAL, 185, 235 pointers, 187 DATE intrinsic, 242 daxpy routine, 168 DCMPLX intrinsic, 242 dde command, 121 ddot routine, 168 DEBUG directive (f77), 228 debugger, 3, 18 defined, 260 -g option, 121 overview, 121 using, 121 debugging, 119 +dlines option, 36, 127 +
Index ellipses, vertical, xviii ELSE directive (f77), 228 enabling traps +FP option, 38 ENCODE statement, 239 endif directive (cpp), 93 ENDIF directive (f77), 228 environment variables, 97 HP_F90OPTS, 97 LPATH, 79, 97, 98 MP_NUMBER_OF_THREADS, 97, 99 TTYUNBUF, 97 EQUIVALENCE statement, 104 equivalencing, 117 ERR= specifier, 124 error handling ON statement, 129 escape sequences, 249 establishing traps, 129 example programs abort.f90, 133 allow_core.f90, 139 bye.f90, 91 call_fptrap.f90, 136 call_itrap.
Index compatibility with f77, 227 cpp input file, 94 cpp output file, 94 defined, 260 fixed form, 77 free form, 77 object code, 77 extensions, language +langlvl option, 238 compatibility, 220, 239 Cray pointers, 124 defined, 261 intrinsics, 242 migrating aids, 220 ON statement, 125, 129 porting aids, 239 statements, 239 warnings about, 8, 238 extern storage class specifier (C), 201 external names +uppercase option, 56 ALIAS directive, 210 EXTERNAL statement, 171, 229, 246 resolving name conflicts, 229 using
Index FORTRAN 66 DO loop, 49 Fortran Incompatibilities Detector, 234 fpsetdefaults routine, 38 fpsetmask routine, 38 FREE intrinsic, 229, 242 libU77 routine, 229 free form, 10, 248 filename extension, 77 line length, 249 free source form +source option, 53 front end compiler environment, 3 controlling, 7 defined, 260 options, 7 FSET intrinsic, 242 FSTREAM intrinsic, 178, 199, 242 functions built-in, 209 functions, built-in %REF, 126, 188, 190 %VAL, 126, 188, 190 defined, 259 fusing and optimization, 67 G -G
Index exceptions, 131 IF directive (f77), 228 ifdef directive (cpp), 93 IGETARG intrinsic, 175, 242 IGNORE clause, 133, 134 ignoring errors, 133, 134 IJINT intrinsic, 242 illegal instruction exception, 123, 125 IMAG intrinsic, 242 IMPLICIT NONE statement, 103 IMPLICIT statement +implicit_none option, 42, 43 implicit typing, 103 +implicit_none option, 42, 43, 103 functions, 171 overriding, 8 rules, 103 INCLUDE line -I option, 43 including source text +pre_include option, 190 INCLUDE directive (f77), 228 INCL
Index incompatibilities, 223 porting issue, 244 variables, 14, 104 inlining +O3 option, 48 +Oinline option, 69 +Oinline_budget option, 69 inlining options +Oinline, 155 +Oinline_budget, 155 +Oprocelim, 157 inserting text in source +pre_include option, 51 instruction scheduler, 13, 90 instruction scheduling, 66 +DS option, 36 INT1 intrinsic, 242 INT2 intrinsic, 242 INT4 intrinsic, 242 INT8 intrinsic, 242 integer changing default size, 29, 30 overflow, 32, 212 integers data type, 183 incompatibilities, 226 in
Index QPROD, 242 RAN, 242 RAND, 242 REAL, 224 RNUM, 242 RSHFT, 242 RSHIFT, 242 SECNDS, 242 SIND, 242 SIZEOF, 242 SRAND, 242 SYSTEM, 229, 242 TAND, 242 TIME, 223, 229, 242 XOR, 242 ZEXT, 242 INUM intrinsic, 242 invalid floating-point operations, trapping, 39 invalid operation, 124 defined, 261 invoking C preprocessor, 6, 93 compiler, 1, 23 linker, 78 IOMSG intrinsic, 242 IOSTAT= specifier, 124, 225 ipcs command, 113 IQINT intrinsic, 242 IRAND intrinsic, 242 IRANP intrinsic, 242 ISAM stub library, 80 ISIGN in
Index defined, 261 FLUSH routine, 229 FREE routine, 229 GETARG routine, 229 GETARGC routine, 176 GETENV routine, 229 IARGC routine, 229 IDATE routine, 229 LOC routine, 229 MALLOC routine, 229 name conflicts, 229 porting issues, 247 SIGNAL routine, 139 system calls, 177 SYSTEM routine, 229 TIME routine, 229 libU77 routines +U77 option, 55 line length, 249 linker +strip option, 122 -a option, 83 -b option, 91 compiler environment, 3 controlling, 15 ld command, 78, 79 -lm option, 203 options, 5, 15 passing arg
Index ld, 3, 79 malloc system routine, 211 prof, 18, 147 signal, 124 stdio, 178 stty, 138 ttv, 18 write, 200 managing .
In d ex NLS directive (f77), 228 +, 33, 160 +O, 156, 157, 158, 159, 160, 161 NO CONCUR directive, 241 NO SIDE EFFECTS directive, 166, 170, 217, 241 NO VECTOR directive, 241 NO_SIDE_EFFECTS directive, 217 NOCONCUR directive, 217 NOCONCURRENTIZE directive, 241 NODEPCHK compiler directive, 167, 216 NODEPCHK directive, 216, 241 nondefault libraries, 81 Not-a-Number, 261 notational conventions, xviii ntrinsic procedures millicode routines, 155 null character, defined, 261 null-terminated strings, 195 numeric pr
Index fine-tuning options, 64 floating-point traps, 72 Fortran 90 standard, 162 -g option, 41 initialization, 69 inlining, 69, 155 instruction scheduling, 66 intrinsic functions, 70 invoking, 148 levels, 12, 47, 148 limiting, 63 loop unrolling, 71 maximum optimization, 62 memory consumption, 63 memory hierarchy, 35 millicode routines, 70 nonstandard-conforming programs, 63 -O option, 44, 46, 47 ON statement, 130 OPTIMIZE directive, 213 optimizing library calls, 155 options, 11, 60, 148, 150 overlapping argu
Index parminit, 157 passing allocatable arrays to C, 187 arguments in C and Fortran, 126, 187, 188 arguments to subprocesses, 5 pointers to C, 187 strings to C, 195 PBO compiler environment, 3 performance, 141 code generation, 172 optimization options, 60 options for increasing, 11 profilers, 143 profiling options, 41, 51 tools for analyzing, 18 performance issues large word sizes, 245 names, 248 static storage, 244 PIC, 14 +pic option, 90 defined, 262 object code, 90 shared libraries, 90 PIC code, 51 pipel
Index program listing source, 45, 212 program listing, 8 PROGRAM statement incompatibilities, 226 unsupported extensions, 226 promote_indirect_calls, 158 promoting, 7 constants, 107 promoting data sizes +autodbl option, 29 +autodbl4 option, 30 PUBLIC statement, 117 Q -Q option, 35 -q option, 35 -q option (f77), 230 QEXT intrinsic, 242 QFLOAT intrinsic, 242 QNUM intrinsic, 242 QPROD intrinsic, 242 quad-precision variables, 109 R -R4 option, 52 -R4 option (f77), 230 -R8 option, 52 -R8 option (f77), 230 RAN in
Index defined, 262 serial execution defined, 262 SET directive (f77), 228 setenv command HP_F90OPTS, 98 LPATH, 79, 98 MP_NUMBER_OF_THREADS, 99 shared data +k option, 44 shared data items, 14 shared executables, 16 creating, 95 defined, 262 shared libraries +pic option, 51 creating, 90 default, 79 defined, 262 -l option, 45 linking, 83 PIC code, 51 shared memory, 113 SHARED_COMMON directive, 113, 225 sharing data, C and Fortran, 201 short-displacement code, 44 side effects defined, 262 side effects and data
Index POINTER (Cray-style), 240 PRIVATE, 117 PROGRAM, 226 PUBLIC, 117 RECORD, 240 SAVE, 104, 106 STATIC, 104, 106, 240 STRUCTURE, 240 TYPE (I/O), 240 UNION, 240 USE, 86, 117 VIRTUAL, 240 VOLATILE, 240 WRITE, 199 static memory, 104 STATIC statement, 104, 106, 240 static storage +save option, 52 static variables, 104 defined, 262 optimization, 104 performance, 104 recursion, 104 vs.
Index threads defined, 263 library, 113 multiple, 113 threads library +Oparallel option, 72 TIME intrinsic, 223, 229, 242 libU77 routine, 229 TMPDIR, 97 tools debugger, 18 migration, 233 performance analysis, 18 traceback, 122, 123, 126 traceback, requesting, 40 transferring control to trap procedure, 133 trap handling +FP option, 38 +fp_exception option, 40 traps, 133 arithmetic errors, 135 Control-C interrupts, 138 core dumps, 139 defined, 263 examples, 138, 139 floating-point exceptions, 15, 16 integer o
Index calling BLAS routines, 170 defined, 263 directives, 169 local control, 169 vectorization, controlling, 215 VECTORIZE directive, 169, 215, 241 verbose mode compiling, 78 linking, 81 -v option, 5, 81 verbose mode, enabling, 56 version information, 5, 56 vertical ellipses, xviii VIRTUAL statement, 240 VOLATILE statement, 240 W -w, 10 -W option, 5, 56 -w option, 10, 56, 228 wall-clock time profiling defined, 263 warnings about extensions, 8, 45 suppressing, 10 -w option, 56 WARNINGS directive (f77), 228 w