HP Fortran Programmer's Guide HP-UX 11i v1, HP-UX 11i v2, and HP-UX 11i v3 Manufacturing Part Number: B3908-90030 March 2010
Print History 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 Released June 2003; document updates ii
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 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Compiling with +pic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Linking with -b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents 5. Using the ON statement Exceptions handled by the ON statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Actions specified by ON . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Terminating program execution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Ignoring errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents Controlling code generation for performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 7. Writing HP-UX applications Accessing command-line arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Calling HP-UX system and library routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using HP-UX file I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents Compatibility directives. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Controlling vectorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Controlling parallelization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Controlling dependence checks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents Intrinsic procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Using porting options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Uninitialized variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Large word size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 Table 1-4.
Tables Table 9-2. Compatibility directives recognized by HP Fortran . . . . . . . . . . . . . . . . .224 Table 10-1. f77 options not supported by f90 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .229 Table 10-2. f77 options replaced by f90 options . . . . . . . . . . . . . . . . . . . . . . . . . . . . .229 Table 10-3. HP FORTRAN 77 directives supported by f90 options. . . . . . . . . . . . . .236 Table 10-4. Conflicting intrinsics and libU77 routine names . . . . . . . . . . . . . . . . . .
Figures Figure 1-1. HP Fortran compiler environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Figure 3-1. Increasing default data sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112 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.
Table 1 (Continued) Vertical ellipses Vertical ellipses show that lines of code have been left out of an example. Keycap Keycap indicates the keyboard keys you must press to execute the command example. 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.
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 intermediate code, optimize the intermediate code, produce object code, search a set of library files for any additional object code that may 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.
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 overview 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 -O[optlevel] Optimize program, where optlevel is 0 (no optimization), 1, 2, 3, or 4(the highest level). If optlevel is not specified, the program is optimized at level 2 (-O2). +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.
An overview of HP Fortran Back-end Table 1-5 Options for controlling code generation (Continued) Option +DAmodel Function Generate code for a specific version 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). • The word portable to generate code compatible across all PA-RISC 1.1 and 2.0 workstations and servers.
An overview of HP Fortran Back-end Table 1-5 Options for controlling code generation (Continued) Option -g Function Generate debugging information needed by the debugger. This option is compatible with optimization levels 0, 1, and 2. If you compile and link separately and specify -g on the command line, you must also specify it on the link line. For information about using this option to prepare programs for the debugger, see “Using the HP WDB debugger” on page 118.
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 Option +[no]strip Options for controlling the Linker (Continued) Function Strip [do not strip] symbol table information from the linker output. For more information, see the ld(1) and strip(1) man pages. This option is not compatible with -g. If you compile and link separately and specify +strip on the command line, you must also specify it on the link line. The default is +nostrip.
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 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 3. Retrieve B(I); 4. Add the results from Steps 2 and 3 ; 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.
Compiling and linking Compiling with the f90 command 3.1416_4, 113_4 Note, however, that constants specified with an exponent—for example, 4.0E0 and 2.3D0—are doubled. 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.
Compiling and linking Compiling with the f90 command Note, however, that constants specified with an exponent—for example, 4.0E0 and 2.3D0—are doubled. 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.
Compiling and linking Compiling with the f90 command Concatenates all source files of the same source form together, then compiles the concatenated source all at once. This enables inlining at +O3 within the concatenated file. +charlit77 +charlit77 causes character literals to be placed in writable static storage. This allows character strings passed as actual arguments to be modified by the called routine.
Compiling and linking Compiling with the f90 command +check=bounds:arrary enables run-time checks for out-of-bounds references to array variables. +check=bounds:pointer enables run-time checks for out-of-bounds references to buffer through pointer or reference access. +check=bounds:all enables run-time checks for both +check=bounds:array and +check=bounds:pointers. +check=bounds:none disables out-of-bounds run-time check. +check=globals enables run-time checks to detect corruption of global variables.
Compiling and linking Compiling with the f90 command -check_bounds performs run-time error checking; promote compile-time bound violations to errors. +[no]cfc Enable or Disable Compaq/DEC F90 language mode. +cpp={yes|no|default} +cpp=yes tells the compiler to pass the source files specified on the command line to the C preprocessor before passing them on to the compiler. This option does not apply to .i and .i90 files. The default, +cpp=default, is to apply the C preprocessor to files that end in the .
Compiling and linking Compiling with the f90 command • A model number (for example, 750 or 870) • One of the PA-RISC processor names (for example, PA7000, PA7100, or PA8000) • The word portable, which causes the compiler to generate code that is compatible across all PA-RISC 1.1 and 2.0 systems For best performance, use +DA with the model number or architecture of the machine on which you plan to execute the program. The +DA option also specifies the appropriate search path for HP-UX math libraries.
Compiling and linking Compiling with the f90 command Generate code using either the ILP32 or LP64 data model. Defined values for datamodel are: 32 Use the ILP32 data model. The sizes of the int, long, and pointer data types are 32-bits. 64 Use the LP64 data model. The size of the int data type is 32-bits, and the sizes of the long and pointer data types are 64-bits. Defines LP64 to the preprocessor. The default is +DD32.
Compiling and linking Compiling with the f90 command Itanium— based system recognized values for osname are 11.20, 11.22, and 11.23. +DOosname can be used at any level of optimization. The default value for osname is the operating system version of the computer on which the compiler is invoked.. +DSmodel +DS specifies an instruction scheduling algorithm for a particular implementation of the PA-RISC architecture, as specified by model. model can be one of the following: • A PA-RISC version number (1.
Compiling and linking Compiling with the f90 command +[no]escape +escape treats the backslash character (\) as a C-like escape character. The default, +noescape, treats the backslash character as a literal character. +[no]es +[no]es is similar to +[no]extend_source except that character literals and hollerith constants continued across a line boundary are not padded. This option provides compatibility with FORTRAN 77’s +es option.
Compiling and linking Compiling with the f90 command Uses a strict power table for converting floating constants with exponents. Use of strict power table provides a more accurate floating point representation. +FPflags +FP initializes the flags that specify how runtime floating-point exceptions should be trapped; uppercase flags enable traps, lowercase flags disable traps. flags can be concatenated to specify a desired behavior and may not contain spaces or tabs.
Compiling and linking Compiling with the f90 command 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. Table 2-4 Values for the +FP option Value Meaning V Trap on invalid floating-point operations.
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 Table 2-5 Signals recognized by the +fp_exception option (Continued) Signal Meaning SIGSYS Bad argument to system call -g -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.
Compiling and linking Compiling with the f90 command +hugecommon=name where name is the name of a COMMON block. By default, only COMMON blocks larger than 2 gigabytes are placed into huge data segments. For example: % f90 +hugecommon=results pcvals.f90 places the COMMON block named results into a huge data segment. +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.
Compiling and linking Compiling with the f90 command PA2.0W objects cannot be combined with 32-bit object files. 64-bit applications will only execute on PA8000-based systems. NOTE +hugesize and +hugecommon options are not valid on HP Itanium-based systems. +i2 +i2 changes 4-byte integer and logical constants, intrinsics, and user variables to 2-byte integers (rather than the 4-byte default).
Compiling and linking Compiling with the f90 command • Directories specified by the -I option, in the order specified • The current working directory • The /usr/include directory +[no]implicit_none +implicit_none forces the types of identifiers to be implicitly undefined. This is equivalent to specifying IMPLICIT NONE for each program unit in each file in the files list. The source code that is to be compiled with this option may contain other IMPLICIT statements; the statements will be honored.
Compiling and linking Compiling with the f90 command +k generates code for programs that reference a very large number of shared data items. The linker will issue a diagnostic message in the rare case when this option is needed. By default, the compiler generates short-displacement code sequences for programs that reference global data in shared libraries. For nearly all programs, this is sufficient. NOTE +k option is not valid on HP Itanium-based systems.
Compiling and linking Compiling with the f90 command +moddir directs the compiler to write .mod files to directory. If this option is not specified, the compiler writes modules in the current directory. +multi_open Enables attaching multiple FORTRAN UNITs to the same file by allowing the file to be opened in multiple Fortran OPEN statements. -n Mark output from the linker shared. For details and system defaults, see ld(1). -N Mark output from the linker unshared. For details and system defaults, see ld(1).
Compiling and linking Compiling with the f90 command Disables the passing of libraries to the linker. This is useful when symbols are resolved at runtime through dynamically loaded libraries. +nopadsharedcommon Do not pad shared common blocks to a multiple of 8 bytes. This option is useful when sharing shared common blocks between f77-generated programs and f90-generated programs. All source files referencing the same shared common block must be compiled with the same setting of this flag.
Compiling and linking Compiling with the f90 command Table 2-6 Levels of optimization (Continued) Level Optimizations 1 Peephole optimizations, including: 2 3 Chapter 2 • Basic block optimizations • Branch optimizations • Instruction scheduling Optimizations performed at level 1, plus the following: • Coloring register allocation • Induction variables and strength reduction • Common subexpression elimination • Loop invariant code motion • Store/copy optimization • Unused definition
Compiling and linking Compiling with the f90 command Table 2-6 Level Levels of optimization (Continued) Optimizations 4 Level 4 optimizations are not currently supported by the PA-RISC compiler. If +O4 is specified, the compiler will issue a warning message and compile at optimization level 3. For Itanium applications, performs level 3 as well as doing interprocedural optimizations across translation units (link time optimizations).
Compiling and linking Compiling with the f90 command +noobjdebug can be used at link time to continue to place the debug info into the a.out, even if some objects were compiled with +objdebug. NOTE Object files and archive libraries must be accessible to the debugger if the +objdebug method of storing debug information is used. +[no]onetrip +onetrip generates code that executes any DO loop at least once.
Compiling and linking Compiling with the f90 command NOTE +pa is ignored when the HP Fortran compiler generates position-independent code (PIC). The following options cause +pa to be ignored: +pic=short, +pic=long, +z and +Z. +[no]padsrc Specifies that source records shorter than the statement field width are [are not] to be padded with spaces on the right, out to the end of the statement field. This affects the interpretation of character and Hollerith literals that are continued across source records.
Compiling and linking Compiling with the f90 command The +z option performs the same function as +pic=short, and the +Z option performs the same function as +pic=long. +[no]ppu +ppu appends underscores to external names, including subroutines, functions, and common blocks (for example, int_sum_ rather than the default int_sum). For Itanium and PA-RISC 64-bit architectures,the default is +ppu. For PA-RISC 32-bit architecture, the default is +noppu.
Compiling and linking Compiling with the f90 command Set the precision of real and complex constants to single-precision. This has the same functionality as the +real_constant=single option (the default). -R8 Set the precision of real and complex constants to double-precision. This has the same functionality as the +real_constant=double option. The default is +real_constant=single.
Compiling and linking Compiling with the f90 command +noshared causes the output file from the linker to be marked unshared. The default, +shared, is to mark the output file as shared. The -n option performs the same function as +shared, and the -N option performs the same function as +noshared. +[no]sharedlibF90 +sharedlibF90 allows users to link the shared version of libF90 or libF90_parallel from /usr/lib.
Compiling and linking Compiling with the f90 command +strip causes the linker to strip symbol table information from the executable program. This option is incompatible with the -g option. The default is +nostrip. The -s option can be used to perform the same function as +strip. -tx,path -t looks in path for the subprocess identified by x and substitutes it for the default subprocess. x can be one or more identifiers indicating the subprocesses.
Compiling and linking Compiling with the f90 command 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. NOTE +trigdacc option is not valid on HP Itanium-based systems. +[no]ttybuf +ttybuf controls tty buffering, using buffered output. +nottybuf uses unbuffered output. The default is buffered output (+ttybuf).
Compiling and linking Compiling with the f90 command +uppercase uses uppercase for external names. The default, +nouppercase, is to convert external names to lowercase. If you need to control the case of specific names, use the $HP$ ALIAS directive, as described in “$HP$ ALIAS” on page 208. +usage +usage lists and briefly describes all of the command-line options currently supported by the HP Fortran compiler. No compile occurs.
Compiling and linking Compiling with the f90 command -Wl,-a,shared Table 2-8 Values for the -W option Value Meaning a Assembler c Compiler l Linker p C preprocessor Chapter 2 59
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 The file indicated by filename contains a list of symbols, separated by spaces or newlines. These symbols are assigned the default export class. -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 file indicated by filename contains a list of symbols, separated by spaces or newlines. These symbols are assigned the hidden export class. -Bprotected [=symbol [,symbol...]] The named symbols, or all symbols if no symbols are specified, are assigned the protected export class.
Compiling and linking Compiling with the f90 command The following subsections describe the options in both categories. For information about the options that control levels of optimization, see the description of the +On option in the “Option descriptions” on page 27. The +O[no]info option, which provides compile-time information about the optimization process, is described in the same section.
Compiling and linking Compiling with the f90 command The +Oaggressive option performs optimizations invoked by the following options: • +Oentrysched • +Olibcalls • +Onofltacc • +Onoinitcheck • +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.
Compiling and linking Compiling with the f90 command On HP 9000 systems, when +Oautopar is used with the +Oparallel option, +O4 is inhibited. If automatic parallelization is desired along with +O4, then use +Oautopar and omit +Oparallel. To compile a program with +Oautopar support, the libcps, libomp , and libpthreads runtime support libraries must be present at compile-time and runtime. This feature is available on Itanium-based systems and HP 9000 systems.
Compiling and linking Compiling with the f90 command The default is +Oloop_transform. +O[no]size +Osize suppresses optimizations that significantly increase code size. This option is only effective at optimization level 2 or higher. The +Onosize option permits optimizations that can increase code size. The default is +Onosize.
Compiling and linking Compiling with the f90 command Note the following precautions when using this option: • All program modules that reference the common block must be compiled with the +Ocache_pad_common option. • Each common block in the program should have the same layout in all program units within which it is declared. If the layouts are different, they must be fully independent—that is, they must not pass values between them. The default, +Onocache_pad_common, disables padding.
Compiling and linking Compiling with the f90 command direct—enable generation of data prefetch instructions for the benefit of direct memory accesses, but not indirect memory accesses. indirect—enable generation of data prefetch instructions for the benefit of both direct and indirect memory accesses. This is the default at optimization levels +O2 and above. none—disable generation of data prefetch instructions. This is the default at optimization levels +O1 and below.
Compiling and linking Compiling with the f90 command +Ofaster Selects the +Ofast option at optimization level +O3 for PA-RISC based architectures. For Itanium processor family architectures, +Ofaster runs at +O4 and implies -ipo. +O[no]fenvaccess Inform the compiler that the program accesses [does not access] the floating point environment to test flags or run under non-default modes.
Compiling and linking Compiling with the f90 command Table 2-9 identifies the different actions taken by the optimizer, according to whether you specify +Ofltacc, +Onofltacc, or neither option. In all cases, the table assumes that you are compiling at optimization level 2 (+O2) or higher.
Compiling and linking Compiling with the f90 command +O[no]info +Oinfo causes the compiler to display informational messages about the optimization process. The +Oinfo option provides feedback that can help you to determine whether the compiler optimized time-critical sections of your program. It can be used at any level of optimization but is most useful at level 3.
Compiling and linking Compiling with the f90 command +O[no]inline:filename The file indicated by filename contains a list of function names, separated by spaces or newlines. This option enables [disables] optimizer inlining for the named functions. This optimization can occur at optimization levels 3 and 4. The default is +Oinline. +O[no]inline=function1[,function2...] Enable [disable] optimizer inlining for the named functions. This optimization can occur at optimization levels 3 and 4.
Compiling and linking Compiling with the f90 command Table 2-10 Values for the +Oinline_budget option (Continued) Values for n Meaning 2 - 99 Less aggressive inlining. The optimizer gives more weight to compilation time and code size when determining whether to inline. =1 Only inline if it reduces code size. +O[no]libcalls invokes millicode versions of a number of frequently called intrinsic functions; see Table on page 73.
Compiling and linking Compiling with the f90 command +Oloop_transform enables transformation of eligible loops for improved cache performance. The most important transformation is the interchange of nested loops to make the inner loop unit stride, resulting in fewer cache misses. +Onoloop_transform disables transformation of eligible loops. The default is +Oloop_transform. NOTE This option is deprecated and not supported in future releases. Use +inline_level.
Compiling and linking Compiling with the f90 command +O[no]multiprocessor +Omultiprocessor tells the compiler to appropriately optimize several different processes on multiprocessor machines. The optimizations are those appropriate for executables and or shared libraries. +Onomultiprocessor, the default, disables the optimization of more than one process running on a multiprocessor machine. +O[no]openmp +Oopenmp allows users to enable the OpenMP directives. +Onoopenmp will disable the OpenMP directives.
Compiling and linking Compiling with the f90 command The default is +Onoparmsoverlap. +O[no]pipeline +Opipeline enables software pipelining. This option is only effective at optimization level 2 or higher. Use +Onopipeline (disable software pipelining) to conserve code space. The default is +Opipeline. +Oprefetch_latency=num option Applies to loops for which the compiler generates data prefetch instructions.
Compiling and linking Compiling with the f90 command arc—collect arc counts (synonym to +Oprofile=collect). This is the default value. stride—collect stride data. all—collect all types of profile data. This is a synonym for +Oprofile=collect:arc,stride +Oprofile=collect instruments the application for profile-based optimization. This option is only valid for Itanium-based applications. +O[no]promote_indirect_calls Enable [disable} the promotion of indirect calls to direct calls.
Compiling and linking Compiling with the f90 command All objects of size bytes or smaller will be placed in the short data area, and references to such data will assume it resides in the short data area. Valid values of n are 0, or a decimal number between 8 and 4,194,304 (4MB). If no size is specified, all data is placed in the short data area. If size is 0, no data will be placed in the short data area, and all data references will use long offsets. The default is +Oshortdata=8.
Compiling and linking Compiling with the f90 command If you link separately from the command line and you compiled with the +Ovectorize option, you must ensure that the link line causes the math library to be searched. +Onovectorize is the default. +O[no]whole_program_mode Assert [do not assert] that only files compiled with this option directly reference any global variables and procedures that are defined in these files.
Compiling and linking Compiling with the f90 command NOTE 80 The compiler generates a .mod file for each file that defines a Fortran module. It also reads the .mod files when compiling source files that use modules. Do not specify .mod files on the command line. If you do, the compiler will pass them to the linker, which will try (and fail) to link them into the executable. For more information about .mod files, see “Compiling programs with modules” on page 88.
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 7 8 LPATH is: /opt/fortran90/lib/pa1.1:/usr/lib/pa1.1: /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.
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 Contents /usr/lib/hpux[32|64]/libc.so Shared library for intrinsic procedures and system routines /opt/fortran90/lib/hpux[32|64]/li bF2003.a 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 If your program calls routines in a library but the linker is unable to resolve the references, compile with the -Wl,-v option. The f90 command passes -v to the linker, causing it to process in verbose mode. The verbose information includes: • The names of the libraries that the linker is searching. This information can confirm that the linker is searching the correct libraries.
Compiling and linking Linking HP Fortran programs • /opt/fortran90/lib/libblas.a: The Basic Linear Algebra Subroutine (BLAS) library, which provides routines that perform common vector and matrix operations. Programs that reference routines in this library must be compiled with the +lblas option. For more information, see “Calling BLAS library routines” on page 169. (PA-RISC only) Both the libU77 and BLAS libraries are described in the HP Fortran Programmer’s Reference.
Compiling and linking Linking HP Fortran programs To force the linker to select archive libraries, specify the -Wl,-a,archive option on the f90 command line. f90 passes the arguments to the -Wl option (-a and archive) to the linker. This option must appear before the names of any libraries also specified on the command line. The following command line compiles prog.
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 compile a program that uses modules • How to design makefiles to work with modules • 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 INTEGER :: new_item n_items = n_items +1 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 $ do_stats Enter an integer (hint: Average or better. 77 is current average): 77 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.
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 version number—1.1, 2.0, or 2.0W. Use +DA2.0W to compile in 64-bit mode; see “Compiling in 64-bit mode” on page 99. • A model number—for example, 750 or 870. • 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.
Compiling and linking Special-purpose compilations Compiling with +pic The +pic option causes the compiler to generate Position- Independent Code (PIC) for use in a shared library. PIC contains no absolute addresses and can therefore be placed anywhere in a process’s address space without addresses having to be relocated. This characteristic of PIC makes it shareable by multiple processes.
Compiling and linking Special-purpose compilations Example 2-6 hi.f90 SUBROUTINE say_hi() PRINT *, 'Hi!' END SUBROUTINE say_hi Example 2-7 bye.f90 SUBROUTINE say_bye() PRINT *, 'Bye!' END SUBROUTINE say_bye 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.
Compiling and linking Special-purpose compilations before compilation. But debugging lines are nonstandard, available only in fixed-form source, and not nearly as powerful as the cpp directives. Although cpp directives are not a standard feature of Fortran, cpp is a de facto standard feature of UNIX systems. This section discusses how to do the following: • Invoke cpp from the f90 command line. • Use the -D option to define cpp macros. • Save the preprocessed output generated by cpp.
Compiling and linking Special-purpose compilations The program uses the #ifdef and #endif directives around PRINT statements. If the macro DEBUG is defined, cpp will leave the PRINT statements in the source text that is passed to the compiler; if it is not defined, cpp will remove the statements. You can define the macro in the source text, using the #define directive; or you can define it on the command line, using the -D command-line option.
Compiling and linking Special-purpose compilations WRITE (6, FMT='(A)', ADVANCE='NO') 'Enter a real number:' READ *, x PRINT *, 'x =', double_it(x) END PROGRAM main REAL FUNCTION double_it(arg) REAL :: arg double_it = 2.0 * arg END FUNCTION double_it 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.
Compiling and linking Special-purpose compilations In some circumstances, it may help to debug a program or to improve its runtime performance by making it nonshareable. In general, however, it is not desirable because nonshareable executables place greater demands on memory resources. Compiling in 64-bit mode Compiling HP Fortran programs with the +DA2.0W option (PA-RISC only; for Itanium, use +DD64) causes f90 to produce 64-bit executable programs.
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 $ f90 +list hello.f90 is equivalent to: $ f90 -v +list hello.f90 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 To see how f90 sets LPATH before calling the linker, compile with the -v option for verbose output. For an example, see “Linking with f90 vs. ld” on page 81. 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.
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 • Disabling implicit typing • Automatic and static variables • Increasing the precision of constants • Increasing default data sizes • Sharing data among programs • Modules vs. common blocks NOTE 104 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 Example 3-1 recursive.f90 PROGRAM main ! This program calls a recursive internal subroutine. 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.
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 111. 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 Finally, the program is compiled with the +autodbl4 option. As shown in the output, x is promoted, but z is not: $ 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.
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 $HP$ SHARED_COMMON directive must appear at the beginning of the specification part of the main program unit of each program sharing the memory segment. Also, the common block specified for sharing must have the same layout in all files in which it is declared. You can use the ipcs -m command both to determine that HP-UX has created a shared memory segment and, after the programs complete execution, to confirm that it has been released.
Controlling data storage Sharing data among programs ! The shared memory segment is destroyed when this program halts. END IMPORTANT In the example above, you must use +U77 to access the correct sleep in the Fortran library. If you use +U77, the line above: 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.
Controlling data storage Sharing data among programs Run the first program in any process by doing the following: $ go_to_sleep In another process, use the following command line to confirm that a shared memory segment has been created for the program (the last in the list is the newly created one): $ 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 ro
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 • The USE statement has an ONLY clause that specifies which module variables are accessible to a particular program unit. • The USE statement also has a renaming feature to resolve name clashes between local variables and module variables. 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.
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 122 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 • A procedure traceback is displayed on standard error. A procedure traceback lists routine names and their offsets that are helpful in locating the code that triggered the exception. • 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.
Debugging Handling runtime exceptions HP Fortran provides two compile-line options, +FP and +fp_exception, which enable traps for floating-point exceptions. The differences between the two options are: • The +fp_exception option enables traps for the following IEEE floating-point exceptions: ❏ Invalid operation ❏ Division by zero ❏ Overflow ❏ Underflow The +FP option also enables the trap for the inexact operation exception.
Debugging Handling runtime exceptions This exception may indicate a compiler error. If you cannot find the cause of this exception in your code, contact your HP support representative. Segmentation violation exception Before a program starts to execute, it is allocated a memory segment, which defines the area of memory that it can use.
Debugging Handling runtime exceptions If you suspect that an out-of-bounds array reference is causing the segmentation violation, you can use the +check=all option instead of the +fp_exception option. When compiled with the +check=all option, a program that attempts to reference an array element that is outside the declared array boundary will abort with an error message that gives the line number of where the reference was detected.
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 .
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 134 Exception keywords Alternate keywords REAL(16) DIV 0 (none) 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
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 ! ON REAL DIV 0 ABORT x = 10.0 y = 0.0 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.
Using the ON statement Actions specified by ON z = x/y 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 Trapping floating-point exceptions The following program, call_fptrap.f90, causes an invalid operation exception and includes an ON statement to handle the exception. The ON statement calls the trap procedure trap_illegal, which assigns a different value to the result argument. The program prints the result. Here is the program listing: Example 5-3 call_fptrap.f90 PROGRAM main REAL :: x, y ON REAL ILLEGAL CALL trap_illegal x = -10.
Using the ON statement Actions specified by ON Example 5-4 call_itrap.
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.
Performance and optimization of optimization to be applied to your program) or the -O option for the default level of optimization (level 2). The -O option is provided 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.
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 program [program_arguments] 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 4. Run HP Caliper on your +O3 executable with a configuration file such as total_cpu to measure performance. 5. Recompile your program with +O3 optimization and +Oprofile=use to use the profile data collected in Step 2 as input. 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.
Performance and optimization Using profilers For example, if you only want to measure wordplay, you would use these settings: --module-default=none --module-include=wordplay Specifying PBO file names and locations HP Caliper creates two files when doing profile-based optimization: flow.data The file name used to store profile data. flow.log The file name used to log diagnostic messages. You can use the FLOW_DATA and FLOW_LOG environment variables to specify the file names.
Performance and optimization Using profilers 4. Once gprof is finished, you can view the output tables using an ASCII editor. For more information about gprof, see the gprof(1) man page. prof The prof profiler can also be used for profiling. Unlike the gprof profiler, prof does not generate the call graph profile. To use prof, do the following: 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.
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 151; 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 152. Can significantly increase performance over level 2.
Performance and optimization Using options to control optimization The options in both tables can be combined on the same command line, except as noted. For example, the following command line requests aggressive optimizations at level 2 that do not increase code size: $ f90 +02 +Oaggressive +Osize prog.f90 Nearly all of the optimization options can be used to enable or disable an optimization or a package of optimizations.
Performance and optimization Using options to control optimization Table 6-2 Packaged optimization options (Continued) Option Level Function Do [do not] automatically parallelize loops that are deemed safe and profitable by the loop parallelizer. The default is +Onoautopar. The +Oautopar option can be used for programs at optimization levels, +O3 and above. +O[no]autopar If both +Oopenmp and +Oautopar are specified on the command line, the OpenMP directives gain precedence over the +Oautopar option.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options Option Level Function +O[no]cache_pad_common +O3 or higher Pad [do not pad] common blocks to avoid cache collisions. The default is +Onocache_pad_common. +O[no]dataprefetch +O2 or higher Insert [do not insert] instructions within innermost loops to explicitly prefetch data from memory into the data cache. The default is +Onodataprefetch.
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=func tion1[,function2...] All The named functions are assumed to be frequently called. This option overrides any information in a profile database. +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.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option +inline_level num Level All Function This option controls inlining in fortran. The format for num is N[.n], where num is either an integral value from 0 to 9 or a value with a single decimal place from 0.0 to 9.0. For more information on this option, see F90(1) manpage. +O[no]libcalls All Substitute [do not substitute] millicode versions of specific intrinsics.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option Level Function +O[no]loop_unroll_jam +O3 or higher Loop unroll-and-jam involves partially unrolling one or more loops higher in the nest than the innermost loop, and fusing ("jamming") the resulting loops back together. This transformation is primarily intended to increase register reuse and decrease memory loads and stores per operation within an iteration of a nested loop.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option Level Function +O[no]parmsoverlap +O2 or higher Suppress optimizations that assume [do not assume] that arguments may refer to the same memory locations. The default is +Onoparmsoverlap. +O[no]pipeline +O2 or higher Enable [disable] software pipelining. The default is +Opipeline. +O[no]procelim All Remove [do not remove] unreferenced procedures from the executable.
Performance and optimization Using options to control optimization Table 6-3 Fine-tuning optimization options (Continued) Option +O[no]promote_indirect_c alls Level +O3 or higher Function 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 Level The file indicated by filename contains a list of functions, separated by spaces or newlines. These functions are assumed to be rarely called. This option overrides any information in a profile database. +Orarely_called:filename +O[no]recovery Function All This option generates [does not generate] recovery code for control speculation.
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 Parallelizing HP Fortran programs • FPP$ NODEPCHK • VD$ NODEPCHK For more information about these directives, see “Compatibility directives” on page 215.
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 sdot Compute the dot product of two single-precision vectors. 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 END DO !*$* NOVECTORIZE . . . 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 169—can also prevent vectorization.
Performance and optimization Vectorization INTEGER :: i, inc_x, inc_y, dim_num REAL, DIMENSION(5) :: x, y REAL :: b b = 3.0 dim_num = 5 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.
Performance and optimization Vectorization Fortran uses implicit typing by default. Unless a function is explicitly declared as having a certain type, the type is determined by the first character of the BLAS routine. If that character implies a type other than that of the returned value, the result will be meaningless. See the HP Fortran Programmer's Reference for information about the BLAS library.
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.
Performance and optimization Controlling code generation for performance 178 Chapter 6
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 179
Writing HP-UX applications • Calling HP-UX system and library routines • Using HP-UX file I/O 180 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 186 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 188 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 main subprogram calls sqr_complex, passing in a complex number. The C function squares the number and returns the result. There is no complex data type in C, but this example uses C’s typedef feature to create one. 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.
Calling C routines from HP Fortran Data types float real; float imag; }COMPLEX; /* returns the square of the complex argument */ COMPLEX sqr_complex(COMPLEX cmx_val) { 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.
Calling C routines from HP Fortran Data types Allocatable arrays may be passed from Fortran to C like any other array, with the precaution about array differences between the two languages. Strings (an array of characters in C) are a different matter; see “C strings” on page 203 for information about passing strings from Fortran to C.
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 Argument-passing conventions For detailed information about the $HP$ ALIAS directive and the %VAL and %REF built-in functions, see the HP Fortran Programmer's Reference.
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 Before a Fortran program can call this function correctly, it must resolve two issues: 1. The name of the C function contains both uppercase and lowercase letters. 2. The function expects its second argument (the size of the array) to be passed by value.
Calling C routines from HP Fortran Case sensitivity If you use the $HP$ ALIAS directive in many of the Fortran source files in your program, you may find it convenient to define all of the directives in one file and include that file in all of the Fortran source files with the +pre_include=file option. This option takes one argument, file, which is the name of the file you want to include.
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 INTEGER, DIMENSION(3,6) :: my_array then the array should be declared in C as follows: int my_array[6][3]; 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.
Calling C routines from HP Fortran Arrays Example 8-6 get_array.c #include /* get_array: displays the contents of the array argument */ void get_array(int a[4][2]) { int i, j; 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.
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 arguments, however, will come at the end of the list. If more than one string argument is passed, the length arguments will follow the same order as the address arguments, but at the end of the C’s argument list. 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.
Calling C routines from HP Fortran C strings ! reference in both languages. There’s no need to use the ! %REF built-in function, so long as the C routine ! provides an extra argument for the "hidden" length ! parameter. To suppress passing that parameter, use %REF. CALL get_string(first_name, last_name) PRINT 20, first_name, last_name 20 FORMAT(/, 'The names passed back to Fortran: ', A, 1X, A) END PROGRAM main Example 8-8 get_string.c #include #include
Calling C routines from HP Fortran C strings $ cc -Aa -c get_string.c $ f90 pass_chars.f90 get_string.o $ a.
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 ! a = the character array to write ! 10 = the number of elements (bytes) to write ! the return value, status, is the number of bytes actually ! 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 a
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 Note that the extern specifier references the name of the common block, globals, not the name of the array. From C’s point of view, the common block is treated as though it were the array. 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.
Calling C routines from HP Fortran Sharing data 10 FORMAT(3X, F3.0, 2X, A, 8X, F5.2) END PROGRAM main 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 See the HP Fortran Programmer's Reference for a full description of the COMMON statement.
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.
Using Fortran directives formatted. The following sections describe the HP 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 In files that use free format, directives must start with the comment character !. In fixed format, they must start with the comment character C, *, or ! in column 1.
Using Fortran directives Using HP Fortran directives • It provides a way to associate the name used by your program when referring to a subroutine, function, entry, or common block with a distinct external name. This feature is especially useful when you want to access a variety of different graphics device drivers from the same source code so that different hardware configurations can be supported.
Using Fortran directives Using HP Fortran directives Examples The $HP$ ALIAS directive is especially useful when calling a routine in a language that uses different conventions than Fortran. The following examples illustrate how to use the $HP$ ALIAS directive to resolve differences with: • Case sensitivity • Argument-passing conventions • Strings 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 Example 9-1 pr_str.c void c_rout(char *s) { printf(“%s\n”, s); } The ALIAS directive in the following program enables the string to be passed to c_rout: Example 9-2 pass_str.
Using Fortran directives Using HP Fortran directives Description and restrictions If you use $HP$ CHECK_OVERFLOW with the ON statement, you can cause your program to ignore the overflow, abort on the overflow, or branch to a trap subroutine. If this directive is not used, the ON statement has no effect on integer overflow errors. This directive can appear anywhere in your program. It stays in effect until a subsequent $HP$ CHECK_OVERFLOW directive changes the status.
Using Fortran directives Using HP Fortran directives For more information See “Incompatibilities with HP FORTRAN 77” on page 220 for information about the +list option. $HP$ OPTIMIZE The $HP$ OPTIMIZE directive enables or disables the level of optimization that was specified on the command line. Syntax !$HP$ OPTIMIZE [ON | OFF] ON enables the level of optimization specified on the command line. OFF disables the level of optimization specified on the command line.
Using Fortran directives Using HP Fortran directives !HP$ OPTIMIZE level 1 off !HP$ OPTIMIZE level 0 off !HP$ OPTIMIZE level 2 off !HP$ optimize assume_no_parameters_overlaps on !HP$ optimize assume_no_parameters_overlaps off Chapter 9 223
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 To use the vectorization directive, you must compile and link with the +Ovectorize option. The directive applies to the beginning of the next loop and remains in effect for the rest of the program unit or until superseded by a later directive. For more information about this option, see the Parallel Programming Guide for HP-UX Systems.
Using Fortran directives Compatibility directives NOTE Using these directives to incorrectly assert that a loop has no data dependences can result in the loop producing wrong answers. 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.
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 to be changed to compile and execute correctly under 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.
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 242. 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 • In HP Fortran, recursive procedures must be so declared with the RECURSIVE keyword; HP FORTRAN 77 allows recursive procedures by default. 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 230. • I and J integer suffixes.
Migrating to HP Fortran Incompatibilities with HP FORTRAN 77 See the HP Fortran Programmer's Reference for information about the REAL intrinsic. Input/output The following I/O specifiers are recognized by the OPEN statement and by other I/O statements in HP FORTRAN 77 but are not supported in HP Fortran: ACCESS=expr1, where expr1 is a constant expression other than DIRECT or SEQUENTIAL.
Migrating to HP Fortran Incompatibilities with HP FORTRAN 77 The syntax and functionality of individual directives has also changed; for detailed information about the HP Fortran directives, see the HP Fortran Programmer's Reference. All unsupported directives should be deleted or replaced by HP Fortran code that results in the same functionality (see Table on page 236).
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 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 Table 10-4 GETENV Conflicting intrinsics and libU77 routine names (Continued) LOC TIME Refer to the HP Fortran Programmer's Reference for information about all of the HP Fortran intrinsics and the libU77 routines. 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.
Migrating to HP Fortran Migration issues Table 10-5 f77 options supported by f90 (Continued) f77 option f90 option function -R4 +real_constant=single Make single precision the default for all single-precision constants -R8 +real_constant=double Make double precision the default for all single-precision constants -S +asm Generate assembly listing -s +strip Strip symbol table information from linker output -Y +nls Enable Native Language Support +Z +pic=long Generate position-independent
Migrating to HP Fortran Migration issues If you find object-code incompatibilities, you should change the source code and recompile with the f90 command. Data file issues In general, data files are the easiest files to migrate because the data files produced by the two Fortrans are compatible. However, problems can occur because of misaligned data and data types that are not supported under HP Fortran. For example, HP FORTRAN 77 permits misaligned data, especially when working with the structure extension.
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 The main drawback of f90 as a migration tool is that a clean compilation under f90 does not guarantee that all incompatibilities have been found; some do not manifest themselves until runtime. Also, linking under f90 with f77-generated object files may yield unexpected behavior or incorrect results; see “Object code issues” on page 239 and “Data file issues” on page 240.
Migrating to HP Fortran Approaches to migration Following are examples of the warning messages fid issues when it detects an incompatibility: fid Warning: The command-line option, +800, is both source incompatible and .o incompatible with F90 fid Warning on line 8 of file.f: ON EXTERNAL not supported by F90 fid Warning on line 9 of file.
Migrating to HP Fortran Approaches to migration 244 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 Statement Compatibility statements (Continued) Implementation Description MAP DEC Defines a union within a structure. 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.
Porting to HP Fortran Compatibility extensions the HP Fortran Programmer’s Reference for detailed descriptions of the directives to check the level of compatibility. For usage information about these directives, see “Controlling vectorization locally” on page 168. 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.
Porting to HP Fortran Compatibility extensions that begins with one of these prefixes but does 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) ATAN2D FNUM INT1 MALLOC SIZEOF 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
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 As mentioned in “Automatic and static variables” on page 101, saving all variables in static storage can degrade performance. If performance is an issue, consider using the +Oinitcheck option. Unlike the +save option, +Oinitcheck does not “save” variables—it does not move variables into static storage. Instead, it causes the compiler to search for all local, nonarray, nonstatic variables that have not been defined before being used.
Porting to HP Fortran Using porting options PRINT *, 'Should never happen in standard Fortran 90.' 10 CONTINUE END PROGRAM main When compiled with the command line: $ f90 test_loop.f90 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 If this is compiled as coded and without the +langlvl=90 option, the compiler will assume that the reference is to the HP intrinsic named INT1 and not to the external function. Executing the program will produce unexpected results, as appears in the following sample run: $ f90 clash.f90 clash.f90 program CLASH external function INT1 11 Lines Compiled $ a.
Porting to HP Fortran Using porting options NOTE The name-conflict problem can occur in Fortran programs that call routines in the libU77.a library. Some implementations link libU77.a by default. HP Fortran does not; to link in this library, you must compile your program with the +U77 option.
Porting to HP Fortran Using porting options • If the name of the source file ends with the .f90 extension, the file is compiled as free form. The compiler accepts tab characters in the source. • If the name of the source file ends with the .f or .F extension, the file is compiled as fixed form. • If the file is compiled with the +langlvl=90 option, the interprets the format as either fixed or free form, depending on the filename extension (as described above).
Porting to HP Fortran Using porting options Porting from Tru64 to HP Fortran Support has been added for options that will assist users in porting applications from Tru64 to HP Fortran. Wherever possible, these options mimic the behavior of their counterparts in the Tru64 Fortran compiler. +cfc The +cfc flag has been added to the Fortran compiler. +cfc allows you access to the newly-implemented Tru64 Fortran options.
Porting to HP Fortran Using porting options • Added/updated Compaq-mode determination code in driver. Now done early in main(), in case other driver components need to know the state of compaq_flag prior to standard options processing. • Added support for Compaq-mode defaults to be emitted, when they differ from HP-mode. • Added ‘-align’ option to main table; created tru64_align_flags table for sub-options. • Made all new -align options conflict with existing +A and +allow_unaligned options.
Porting to HP Fortran Using porting options • -[no]altparam (-Wc, -dps) • -what (alternate for +what) • +[no]padsrc flag (not restricted to Tru64 mode).
Porting to HP Fortran Using porting options • -[no]pad_source options (alternate spelling of +[no]padsrc) • -r8 option (same as +r8) • -fpe0 and -fpe options (maps to ‘+fp_exception -W1,+FPD’) • -fpel option (maps to +fp_exception) Additionally, the following defaults for Tru64 mode were changed: • +U77 always on • locals on stack (+save) • +nopadsrc • -altparam For a complete list of the Tru64 options, please refer to the f90(1) man page.
Porting to HP Fortran Using porting options 262 Chapter 11
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 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. See also shared library. aliasing Referencing a variable by more than one name. Examples of aliasing include: • Passing the same variable as two or more actual arguments. • Using the EQUIVALENCE statement. • Referencing an element of an array declared in common with an out-of-bounds subscript.
Glossary column-major order HP Fortran 90 can pass source files to the C preprocessor (cpp) for preprocessing and then send the output to the compiler. column-major order The method of storing Fortran 90 arrays in memory. Column-major order requires the columns of a two-dimensional array to be in contiguous memory locations. For example, 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.
Glossary optimization HP DDE See HP Distributed Debugging Environment. memory fault See segmentation violation. HP Distributed Debugging Environment. The source-level debugger for HP Fortran 90 programs. See also dde.. millicode routines Millicode versions of frequently called intrinsics, having very low call overhead and little error-handling. One of the optimizations performed by HP Fortran 90 is to replace calls to eligible intrinsics with millicode versions.
Glossary overflow overflow An exception condition that occurs when the result of a floating-point operation is greater than the largest normalized number. See also integer overflow.. profilers Programming tools that determine where a program spends its execution time. Profilers that come with HP Fortran 90 include prof, gprof, and CXperf. parallel execution Program execution on multiple processors at the same time.
Glossary ttv shared library A library of routines that can be linked to an executable program at runtime and shared by several programs simultaneously. The names of shared libraries have the .sl extension. See also archive library.. 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 tty buffering A method for efficiently processing data that is directed to standard output by capturing it in a buffer before sending it to the screen. underflow An exception condition that occurs when the result of a floating-point operation is smaller than the smallest normalized number. On systems that support it, fast underflow is an efficient method of handling this exception.
Index Symbols # comment character, 96 #define directive (cpp), 97 #endif directive (cpp), 97 #ifdef directive (cpp), 97 #include directive, 44 $HP$ ALIAS directive, 217 $HP$ CHECK_OVERFLOW directive, 220 $HP$ LIST directive, 221 $HP$ OPTIMIZE directive, 222 %REF built-in function, 128, 198 ALIAS directive, 218 defined, 269 %VAL built-in function, 128, 198 ALIAS directive, 218 defined, 269 +asm option, 12, 27, 29, 236, 238 +autodbl option, 7, 29, 111, 112, 114, 189, 190, 236, 253 +autodbl4 option, 7, 30, 11
Index +Oopt_level option, 12 +Ooptimization option, 12, 152 +Oparallel, 75 +Oparallel option, 75, 115, 159 directives, 249 +Oparmsoverlap option, 75, 160 +Oconservative option, 65 +Opipeline option, 76, 160 +Oprocelim option, 76, 160 +Orarely_called, 161 +Oregreassoc option, 77, 162 +Oreport, 77 +Oshortdata, 162 +Osize option, 66, 154 inlining, 72 +Ovectorize option, 75, 78, 163, 172 +Oaggressive option, 64 directives, 249 +pa option, 51 +pal option, 52 +pic option, 14, 52, 94, 238 +ppu option, 9, 53, 236,
Index %REF function, 198 %VAL function, 198 example, 198 aliasing, 269 alignment data, 104 defined, 269 packing, 210 allocatable arrays passing to C, 194 allowing core dumps, 141 analyzing performance, 18 AND intrinsic, 250 ANSI directive (f77), 236 appending underscores +ppu option, 53 architecture generating code for, 13 performance, 177 archive libraries, 86 defined, 269 -l option, 46 argument lists, 231 argument passing arrays, 200 C and Fortran, 193, 195 complex numbers, 191 conventions, 195 strings, 2
Index derived types, 193 escape sequences, 37, 38 extern specifier, 209 file handling, 207 hidden length argument, 203 logicals, 191 null-termination, 203 opening a file, 185 pointers, 193 sharing data, 209 stream I/O, 184 strings, 203 structures, 193 subscripts, 200 unsigned integers, 191 -C option, 32 -c option, 4, 15, 31, 81, 95 -C option (f77), 238 C preprocessor +cpp option, 32, 34 +cpp_keep option, 34 -D option, 34 directives, 214 -I option, 44 -U option, 57 cache optimizations, 66 CALL clause, 135 ca
Index gprof, 18, 148 grep, 93 ipcs, 115, 116 ld, 3, 82, 94 prof, 18, 149 setenv, 82 strip, 124 stty, 140 uname, 93 comments # as extension, 96 compiler directives as, 213 directives as, 96, 248 incompatibilities, 234 common blocks C, 209 C’s extern specifier, 209 placing in shared memory, 115 pros and cons, 119 sharing data, 115 COMMON statement, 106, 209 compatibility, 228 Cray, 224 KAP, 224 VAST, 224 compatibility directives, 224 compatibility features, 247 +autodbl option, 253 +autodbl4 option, 253 +esca
Index +Oparallel, 75, 115, 159, 249 +Oparmsoverlap, 75, 160 +Opipeline, 76, 160 +Oprocelim, 76, 160 +Oregreassoc, 77, 162 +Oreport, 75, 77 +Osize, 66, 154 +Ovectorize, 75, 78, 163, 172 +pa, 51 +pal, 52 +pic, 14, 52, 94, 238 +ppu, 9, 53, 236, 256 +pre_include, 4, 53, 199, 229 +prof, 14, 18, 53, 149, 238 +real_constant, 9, 54, 109, 111, 238 +save, 14, 54, 106, 236, 238, 252 +shared, 16, 55, 98, 238 +source, 10, 55, 257 +strip, 17, 56, 124, 238 +traceback, 141 +ttybuf, 17, 57, 229 +U77, 17, 57, 85, 141, 237 +u
Index NOCONCUR, 226 compiler directives, 213, 235, 243 ALIAS, 184, 195, 197, 207, 217, 233 and comments, 217 C preprocessor, 214 CHECK_OVERFLOW, 138, 139, 220, 233 compatibility, 224, 248 CONCUR, 225, 249 CONCURRENTIZE, 225, 249 incompatibilities, 233 incompatible directives, 231 IVDEP, 170, 225 LIST, 221, 233 listed, 216 NO SIDE EFFECTS, 169, 226, 249 NO_SIDE_EFFECTS, 226 NODEPCHK, 170, 225, 249 OPTIMIZE, 222, 233 recognized prefixes, 249 replaced by options, 236 SHARED_COMMON, 115, 233 syntax, 215 VECTOR,
Index alignment, 104, 269 controlling access, 119 implicit typing, 105 initialization, 14 promotion, 7 shared, 115 storage, 103 data dependence defined, 270 data files migrating, 240 data prefetch instructions, 67 DATA statement incompatibilities, 232 DATA statements, 106 data types, 232 C and Fortran, 189 COMPLEX, 191, 232 derived types, 193 LOGICAL, 191, 243 pointers, 193 DATE intrinsic, 250 daxpy routine, 172 DCMPLX intrinsic, 250 dde command, 123 ddot routine, 172 DEBUG directive (f77), 236 debugger, 3,
Index E ecape characters, 8 eliminating procedures, 76 ellipses, vertical, xix ELSE directive (f77), 236 enabling traps +FP option, 39 ENCODE statement, 247 endif directive (cpp), 97 ENDIF directive (f77), 236 environment variables, 100 HP_F90OPTS, 100 LPATH, 82, 100, 101 MP_NUMBER_OF_THREADS, 100, 102 TTYUNBUF, 100 EQUIVALENCE statement, 106 equivalencing, 119 ERR= specifier, 126 error handling ON statement, 131 escape sequences, 257 establishing traps, 131 example programs abort.f90, 135 allow_core.
Index .
Index FNUM intrinsic, 185, 207, 250 file descriptor, 185 format of source code, 10, 256 FORTRAN 66 DO loop, 51 Fortran Incompatibilities Detector, 242 fpsetdefaults routine, 39 fpsetmask routine, 39 FREE intrinsic, 237, 250 libU77 routine, 237 free form, 10, 256 filename extension, 79 line length, 257 free source form +source option, 55 front end compiler environment, 3 controlling, 7 defined, 270 options, 7 FSET intrinsic, 250 FSTREAM intrinsic, 184, 207, 250 functions built-in, 218 functions, built-in %RE
Index -Idirectory, 25 IEEE floating-point standard, 126 exceptions, 133 IF directive (f77), 236 ifdef directive (cpp), 97 IGETARG intrinsic, 181, 250 IGNORE clause, 135, 136 ignoring errors, 135, 136 IJINT intrinsic, 250 illegal instruction exception, 125, 127 IMAG intrinsic, 250 IMPLICIT NONE statement, 105 IMPLICIT statement +implicit_none option, 44, 45 implicit typing, 105 +implicit_none option, 44, 45, 105 functions, 175 overriding, 8 rules, 105 INCLUDE line -I option, 44 including source text +pre_inc
Index initialization +Oinitcheck option, 71, 157 +save option, 54 incompatibilities, 231 porting issue, 252 variables, 14, 106 inlining +O3 option, 49 +Oinline option, 71 +Oinline_budget option, 72 inlining options +Oinline, 157 +Oinline_budget, 157 +Oprocelim, 160 inserting text in source +pre_include option, 53 instruction scheduler, 13, 93 instruction scheduling, 68 +DS option, 37 INT1 intrinsic, 250 INT2 intrinsic, 250 INT4 intrinsic, 250 INT8 intrinsic, 250 integer changing default size, 29, 30 overflo
Index QEXT, 250 QFLOAT, 250 QNUM, 250 QPROD, 250 RAN, 250 RAND, 250 REAL, 233 RNUM, 250 RSHFT, 250 RSHIFT, 250 SECNDS, 250 SIND, 250 SIZEOF, 250 SRAND, 250 SYSTEM, 237, 250 TAND, 250 TIME, 231, 237, 250 XOR, 250 ZEXT, 250 INUM intrinsic, 250 invalid floating-point operations, trapping, 40 invalid operation, 127 defined, 271 invoking C preprocessor, 6, 96 compiler, 1, 23 linker, 81 IOMSG intrinsic, 250 IOSTAT= specifier, 126, 233 ipcs command, 115, 116 IQINT intrinsic, 250 IRAND intrinsic, 250 IRANP intrins
Index search path, 15, 87, 101 shared, 86, 93, 273 system routines, 183 threads, 115 vectorization, 75, 78, 172 libU77 library, 17, 85 accessing, 183 defined, 271 FLUSH routine, 237 FREE routine, 237 GETARG routine, 237 GETARGC routine, 182 GETENV routine, 237 IARGC routine, 237 IDATE routine, 237 LOC routine, 237 MALLOC routine, 237 name conflicts, 237 porting issues, 256 SIGNAL routine, 141 system calls, 183 SYSTEM routine, 237 TIME routine, 237 libU77 routines +U77 option, 57 line length, 257 linker +str
Index man pages, xix cpp, 3, 6, 130 CXperf, 18 dynamic memory, 219 f90, 2 gprof, 18 ld, 3, 82 malloc system routine, 219 prof, 18, 149 signal, 126 stdio, 184 stty, 140 ttv, 18 write, 208 managing .
Index naming conflicts resolving, 58 NaN, 136 defined, 271 Native Language Support, 47 Native Language Support, enabling, 9 NLS directive (f77), 236 +, 34, 163 +O, 158, 159, 161, 162, 163, 164 NO CONCUR directive, 249 NO SIDE EFFECTS directive, 169, 226, 249 NO VECTOR directive, 249 NO_SIDE_EFFECTS directive, 226 NOCONCUR directive, 226 NOCONCURRENTIZE directive, 249 NODEPCHK compiler directive, 170, 225 NODEPCHK directive, 225, 249 nondefault libraries, 84 Not-a-Number, 271 notational conventions, xviii nt
Index directives, 173 documentation, 150 eliminating inlined procedures, 76 feedback, 71 feedback option, 12 fine-tuning, 152 fine-tuning options, 66 floating-point traps, 74 Fortran 90 standard, 165 -g option, 42 initialization, 71 inlining, 71, 72, 157 instruction scheduling, 68 intrinsic functions, 73 invoking, 150 levels, 12, 48, 150 limiting, 65 loop unrolling, 74 maximum optimization, 64 memory consumption, 65 memory hierarchy, 35 millicode routines, 73 nonstandard-conforming programs, 65 -O option, 4
Index code generation option, 34 compiling for a model, 92 enabling floating-point traps, 39 instruction scheduling option, 37 listing model information, 93 version numbers, 92, 177 parminit, 159 passing allocatable arrays to C, 194 arguments in C and Fortran, 128, 193, 195 arguments to subprocesses, 5 pointers to C, 193 strings to C, 203 PBO compiler environment, 3 performance, 143 code generation, 177 optimization options, 62 options for increasing, 11 profilers, 145 profiling options, 42, 53 tools for an
Index profiling compile-line options, 26 profiling options +gprof option, 42 +prof option, 53 profiling parallel-executing programs, 168 program listing source, 46, 221 program listing, 8 PROGRAM statement incompatibilities, 234 unsupported extensions, 234 promote_indirect_calls, 161 promoting, 7 constants, 109 promoting data sizes +autodbl option, 29 +autodbl4 option, 30 PUBLIC statement, 119 Q -Q option, 36 -q option, 36 -q option (f77), 238 QEXT intrinsic, 250 QFLOAT intrinsic, 250 QNUM intrinsic, 250 QP
Index -L option, 46 -l option, 46 math libraries, 35 SECNDS intrinsic, 250 segmentation violation, 125, 128 defined, 272 serial execution defined, 272 SET directive (f77), 236 setenv command HP_F90OPTS, 101 LPATH, 82, 101 MP_NUMBER_OF_THREADS, 102 shared data +k option, 46 shared data items, 14 shared executables, 16 creating, 98 defined, 272 shared libraries +pic option, 52 creating, 93 default, 82 defined, 273 -l option, 46 linking, 86 PIC code, 52 shared memory, 115 SHARED_COMMON directive, 115, 233 shar
Index ON, 127, 131, 138, 234 OPEN, 233, 243 OPTIONAL, 231 PARAMETER, 232 POINTER (Cray-style), 248 PRIVATE, 119 PROGRAM, 234 PUBLIC, 119 RECORD, 248 SAVE, 106, 108 STATIC, 106, 108, 248 STRUCTURE, 248 TYPE (I/O), 248 UNION, 248 USE, 89, 119 VIRTUAL, 248 VOLATILE, 248 WRITE, 207 static memory, 106 STATIC statement, 106, 108, 248 static storage +save option, 54 static variables, 106 defined, 273 optimization, 106 performance, 106 recursion, 106 vs.
Index tab formatting, 256 Table 9-3, 236 TAND intrinsic, 250 temporary files, 100 terminating execution, 135 threads defined, 273 library, 115 multiple, 115 threads library +Oparallel option, 75 TIME intrinsic, 231, 237, 250 libU77 routine, 237 TMPDIR, 100 tools debugger, 18 migration, 241 performance analysis, 18 traceback, 124, 125, 128 traceback, requesting, 41 transferring control to trap procedure, 135 trap handling +FP option, 39 +fp_exception option, 41 traps, 135 arithmetic errors, 137 Control-C int
Index vec_dsum routine, 173 VECTOR directive, 249 vector operations and BLAS, 183 vectorization, 172, 173, 224 +Ovectorize option, 75, 78, 163 calling BLAS routines, 174 defined, 274 directives, 173 local control, 173 vectorization, controlling, 224 VECTORIZE directive, 173, 224, 249 verbose mode compiling, 81 linking, 85 -v option, 5, 85 verbose mode, enabling, 58 version information, 5, 58 vertical ellipses, xix VIRTUAL statement, 248 VOLATILE statement, 248 W -w, 10 -W option, 5, 58 -w option, 10, 58, 23