HP Fortran Programmer Guide HP-UX 11i v1, HP-UX 11i v2, and HP-UX 11i v3 Abstract The HP Fortran Programmer Guide describes how to use the 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.
© Copyright 2010, 2014 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 HP secure development lifecycle......................................................................7 1 An overview of HP Fortran...........................................................................8 The HP Fortran compiler environment...........................................................................................8 Driver......................................................................................................................................9 C preprocessor............
LPATH environment variable.................................................................................................65 MP_NUMBER_OF_THREADS environment variable.................................................................65 Floating installation.................................................................................................................65 Setting up floating installation..............................................................................................
Vectorization........................................................................................................................103 Using the +Ovectorize option............................................................................................103 Controlling vectorization locally.........................................................................................104 Calling BLAS library routines.............................................................................................
Miscellaneous ................................................................................................................135 Migration issues...................................................................................................................135 Source code issues...........................................................................................................135 Directives............................................................................................................
HP secure development lifecycle Starting with HP-UX 11i v3 March 2013 update release, HP secure development lifecycle provides the ability to authenticate HP-UX software. Software delivered through this release has been digitally signed using HP's private key. You can now verify the authenticity of the software before installing the products, delivered through this release. To verify the software signatures in signed depot, the following products must be installed on your system: • B.11.31.
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.
Figure 1 HP Fortran compiler environment 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.
Table 1 Options for controlling the f90 driver (continued) Option Function If you compile and link separately and specify +tl on the compile line, you must also specify it on the link line. +usage List and briefly describe all f90 options. -v Print verbose information to standard output as program is compiled. +version Write compiler version information to standard output, without compiling. -Wx,name] Pass arg1 through argN to a subprocess of the compilation, identified by x.
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. Other front-end options control the level of error messages and their language (Native Language Support), default data sizes, and search rules for .mod files.
Table 3 Options for controlling the front end (continued) Option +[no]implicit_none Function Cause the types of identifiers to be implicitly undefined [defined]. The default is implicit typing (+noimplicit_none). For information about using this option, see “Disabling implicit typing” (page 67). nl +langlvl={90|default} Issue warnings for all extensions to the Fortran standard (+langlvl=90). The default, +langlvl=default, allows extensions.
Table 3 Options for controlling the front end (continued) Option Function -w Suppress warning messages. +w Warn about all questionable constructs and issue remarks about coding styles and performance. Without the +w option, the compiler issues warnings only about constructs that are almost certainly problems.
Table 4 Options for controlling optimization (continued) Option Function +O[no]info Provide [do not provide] feedback information about the optimization process. This option is most useful at optimization level 3 and higher. The default is +Onoinfo. +O[no]optimization Enable [disable] optimization, a predefined string that indicates a category of optimizations (for example, those that do not increase code size) or a specific optimization technology (for example, inlining).
Table 5 Options for controlling code generation (continued) Option Function -g 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” (page 76).
Table 6 Options for controlling the Linker (continued) Option Function +demand_load on the command line, you must also specify it on the link line. The default is +nodemand_load. For information about using this option, see “Creating demand-loadable executables” (page 62). nl +FPflags Specify how the runtime environment for trapping floating-point exceptions should be initialized at program startup.
Table 6 Options for controlling the Linker (continued) Option Function For information about the libU77 library, see “Additional HP Fortran libraries” (page 53)and the HP Fortran Programmer’s Reference. -Wl,options Pass a comma-separated list of options to the linker. For information about options supported by the linker, see the ld(1) manpage. nl Tools The HP Fortran compiler environment includes a high-level language debugger and performance analysis tools.
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 • Linking HP Fortran programs • Special-purpose compilations • Using environment variables 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.
Example 2 hello.f90 PROGRAM main CALL hello() END PROGRAM main SUBROUTINE hello() PRINT *, 'Hello, I must be going.' END SUBROUTINE hello When compiled with the command line: $ f90 hello.f90 f90 produces two files, hello.o (object code) and a.out(the executable program). If the command line contains only an object file, as in the following: $ f90 hello.o f90passes the object file to the linker, which (if successful produces the executable program a.out. Here is a sample run of the executable program: $ a.
form +option=arg. You can cause f90 to list the values for arg on stderr by specifying just the option name without an argument. For example, given the command line: $ f90 +langlvl= prog.f90 f90 will issue the following message: f90: The '+langlvl=' option requires one of s Still other options take a name as an argument. For example, the -oname option specifies the name you want to give to the output file.
Table 8 Options listed by category Category Options Compatibility and porting +autodbl, +autodbl4, +charlit77 +[no]es, +extend_source, gformat77, +i8, +io77, +langlvl, +multi_open, +nocheckuf, +nopadsharedcommon, +onetrip, +ppu, +r8, +save, +[no]signedzero, and +U77 Compiler configuration -t and -W Data storage +autodbl, +autodbl4, +hugecommon, +hugesize, +i8, +indirectcommonlist=file, +nopadsharedcommon, +r8, +real_constant, and +save Directory, module, and library search path +U77, -I, -L, -l, an
C$DIR IVDEP Rules and behavior: The IVDEPdirective is an assertion to the compiler’s optimizer about the order of memory references inside a DOloop. The IVDEPdirective 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. This contrasts with normal compiler behavior, which is for the dependence analysis to make no initial assumptions about the direction of a dependence.
3.1416_4, 113_4 Note, however, that constants specified with an exponent—for example, 4.0E0and 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 ONstatements are also promoted. The entire program should be compiled with this option, not just selected files.
-C Performs run-time error checking of array subscripts. This option is deprecated and replaced by the +check=alloption. +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. +check={ all| none| uninit| bounds| bounds:array| bounds:all| bounds:none| -check_bounds } +check=all enables compile-time range checking for array subscripts.
Note that this option does not pass source files to the C preprocessor. To do that, you must also specify the +cpp=yes option. -D name[=def] -Ddefines a symbol name (name)to the C preprocessor. If you do not provide a definition (def) for the symbol name, name is defined as 1. This option applies only to files that are passed to the C preprocessor. +DAmodel +DA generates object code for a particular version of the PA-RISC architecture.
+[no]dlines +dlines treats source lines with a “D” or “d” in column 1 as statements to be compiled. The default, +nodlines, treats lines beginning with “D” or “d” in column 1 as comments. The +dlines option must be used only with source files in fixed-format. +DOosname +DOosname sets the target operating system for the compiler, and is intended for enabling optimizations that are not backward compatible. PA-RISC— based system recognized values for osnameare 11.0 and 11.0EP9806.
+[no]extend_source +extend_source allows extended source lines, which may contain up to 254 characters. The default, +noextend_source, restricts fixed-format source lines to 72 characters and free-format source lines to 132 characters. Programs that depend on the compiler’s ignoring characters past column 72 will not compile correctly with the +extend_source option. +externals=file Specifies a file that contains a list of procedure names to be considered external as opposed to intrinsic.
Table 10 Values for the +FP option (continued) Value Meaning I Trap on floating-point operations that produce inexact results. Inexact result traps may occur whenever roundoff is necessary to produce the result. For example, the fraction 1.0/3.0 produces an inexact trap because there is no exact floating-point representation for this fraction. 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.
Example 4 % f90 +hugecommon=results pcvals.f90 places the COMMON block named results into a huge data segment. +hugecommonis especially useful when a program contains several different COMMON blocks that together occupy more than two gigabytes but individually occupy less than two gigabytes. In this situation, the largest COMMON blocks could be placed in a huge data segment when the program is compiled by specifying their names in multiple +hugecommon options.
• 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. The default, +noimplicit_none, allows identifiers to be implicitly defined.
Table 14 (continued) none none of the heap variables save variables having save attribute A combination of different type of heap variables can be specified by colon separated values, like +initheap_set=common:module:save The default is +initheap_set=none +io77 Suppresses the generation of the optional leading “0” before the decimal point for real numbers printed with the E and F edit descriptors. Fortran 77 suppressed these leading zeros unless the NOSTANDARDIOflag was used.
Table 15 Levels of optimization Level Optimizations 0 Local optimizations, including constant folding and partial evaluation of test conditions.
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. In accordance with the language standard, HP Fortran will not execute a DO loop if either of the following conditions is true: • The increment value is greater than zero, and the initial value is greater than the limit.
-q Mark output from the linker demand load. This has the same functionality as the +demand_load option. The default is +nodemand_load. -Q Mark output from the linker no demand load. This has the same functionality as the +nodemand_load (the default). +r8 +r8 changes 4-byte real constants, intrinsics, and user variables to 8-byte reals (rather than the 4-byte default). -R4 Set the precision of real and complex constants to single-precision.
+[no]strip +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 -soption can be used to perform the same function as+strip . tx,path- -t looks in path for the subprocess identified by xand substitutes it for the default subprocess. x can be one or more identifiers indicating the subprocesses.
libc name. This situation does not cause an error at compile time, but can produce unpredictable results. +uppercase uses uppercase for external names. The default, +nouppercase, is to convert external names to lowercase. +[no]uppercase If you need to control the case of specific names, use the$HP$ ALIAS directive, as described in “$HP$ ALIAS” (page 124). +usage +usage lists and briefly describes all of the command-line options currently supported by the HP Fortran compiler. No compile occurs.
+DA2.0W is specified), the +Zoption is on by default. This is the only PIC option supported for 64-bit executables.
-Bhidden:filename The file indicated by filename contains a list of symbols, separated by spaces or newlines. These symbols are assigned the hidden export class. -Bprotected_data Marks only data symbols as having the protected export class. -Bprotected_def This is the same as-Bprotected, but only locally-defined (non-tentative) symbols are assigned the protected export class. -Bsymbolic All symbols are assigned the protected export class. This is equivalent to -Bprotected with no symbol list.
a program’s behavior. This option is only effective at optimization level 2 or higher. The +Oaggressive option performs optimizations invoked by the following options: • +Oentrysched • +Olibcalls • +Onofltacc • +Onoinitcheck • +FPD +FPD is enabled only if +Oaggressiveis used on the link line. NOTE: The +Oaggressive option is incompatible with +Oconservative. The default is +Onoaggressive. NOTE: +O[no]all This option is only valid on the PA-RISC systems.
The +Onoconservative option relaxes the optimizer’s assumptions about the target program. The +Onoconservative option relaxes the optimizer’s assumptions about the target program. The default is +Onoconservative. This option has been deprecated starting with HP-UX version 11i and later. +O[no]limit +Olimit suppresses optimizations that significantly increase compilation time or that can consume large amounts of memory at compile time. This option is only effective at optimization level 2 or higher.
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.
+O[no]entrysched +Oentrysched allows the optimizer to perform instruction scheduling on a subprogram’s entry and exit code sequences. This option is only effective at optimization level 1 or higher. The option can change the behavior of programs that perform exception-handling or that handle asynchronous interrupts. The default is +Onoentrysched. NOTE: This option is valid only on the PA-RISC systems. +O[no]failsafe Enable [disable] failsafe optimization.
+Ofltacc disables optimizations that change the order of expression evaluation and therefore may affect the accuracy of the result. The +Ofltaccoption also disables fusing. NOTE: +Ofltacc is the same as +Ofltacc=strict. +Onofltacc is the same as +Ofltacc=relaxed. 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.
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. Currently, this option provides feedback for the following optimizations: • Cloning, the replacement of a call to a routine by a call to a clone, which is a copy of the routine with changes specific to that call site. • Inlining. • Loop transformations to improve cache performance.
inlining. This option has the following syntax: +Oinline_budget=n where n is an integer in the range 1 1000000 that specifies the level of aggressiveness, as listed in Table on page 70. The +Onolimit and +Osize options also affect inlining. Specifying the +Onolimitoption has the same effect as specifying +Oinline_budget=200. The +Osize option has the same effect as +Oinline_budget=1. Note, however, that the +Oinline_budget option takes precedence over both of these options.
+O[no]loop_transform +Oloop_transformenables 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. +inline_level num This option controls inlining in fortran.
on Itanium®-based systems for HP Fortran Version 3.2 and later. You can use the +Oautopar option instead of +Oparallel on Itanium® based systems. NOTE: The +Oparallel option should not be used for programs that make explicit calls to the kernel threads library. +Oparallel_intrinsics +Oparallel_intrinsics links in the parallel version of many of the Fortran intrinsics located in libF90_parallel.
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:arc,stride +Oprofile=collectinstruments 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. Indirect calls occur with pointers to functions.
+O[no]sideeffects=name1, name2,...nameN Optimize with the assumption that the specified subprograms do [do not] modify global variables. This option can be used at optimization level 2 or higher. The default is to assume that all subprograms have side effects unless the optimizer can determine that there are none. +O[no]static_prediction Enables [disables] the use of static branch prediction for decision on conditional branches. This is more applicable to large programs with poor locality.
NOTE: The compiler generates a.modfile for each file that defines a Fortran module. It also reads the .modfiles 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” (page 54).
Line 8 is the command line thatf90 passes to the linker (ld). If you use the ld command to link hello.f90, the command line should be similar to the one shown here. As noted in the comments on lines 7 and 8, compiling and linking hello.f90successfully using both the f90and ldcommands requires three command lines: $ f90 -c hello.f90 # compile $ export LPATH=/opt/fortran90/lib/pa1.1:/usr/lib/pa1.1:\ /opt/fortran90/lib:/usr/lib:/opt/langtools/lib# set LPATH $ ld -x /opt/langtools/lib/crt0.o hello.
Table 23 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 Linking to nondefault libraries The -loption enables you to specify other libraries for linking, in addition to the default libraries listed in Table 2-14.
-L/opt/fortran90/lib/pa20_64/ -lF90 -lisamstub NOTE: For more information on Itanium library paths corresponding to the above examples, see Table 23 (page 51). When the linker finds a reference in your program to a name that is not defined in the program (for example, the DOT_PRODUCTintrinsic), it looks to resolve it in the default libraries. If it cannot find the name in the default libraries, the link will fail unless the command line specifies additional, non default libraries.
NOTE: For libF90, libU77, and libIO77(Itanium® only), archive libraries are selected by default (see +sharedlibF90, +sharedlibU77, and +sharedlibIO77options). To force the linker to select archive libraries, specify the -Wl,-a,archiveoption on the f90command line. f90passes 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.
To make the .modfiles available to the compiler, you must therefore compile the files that define modules before the files that use modules. Likewise, if you make changes to a file that defines a module, you must recompile that file as well as any files that use the module, in that order. Also, if a module is defined and used in the same file, the definition must lexically precede anyUSEstatements that reference the module. This requirement allows the compiler to generate the .
Examples Example 5 Consider, for example, a program that consists of three files: main.f90, code.f90, anddata.f90 . The main program unit is in main.f90, as follows. Example 6 Example 2-2 main.f90 PROGRAM keep_stats ! stats_code contains module procedures for operating ! on statistical database USE stats_code INTEGER :: n ! print prompt, using nonadvancing I/O WRITE (*, FMT='(A)', ADVANCE='NO') 'Enter an integer '// & '(hint: 77 is current average): ' READ *, n IF (n == 0) THEN PRINT *, 'But not that one.
Example 8 Example 2-4 data.
Example 9 Example 2-5 makefile makefile # description for building do_stats do_stats : main.o code.o data.o f90 -o do_stats main.o code.o data.o # main.o is dependent on main.f90 and code.f90 main.o : main.f90 code.o f90 -c main.f90 # code.o is dependent on code.f90 and data.f90 code.o : code.f90 data.o f90 -c code.f90 # data.o is dependent only its source, data.f90 data.o : data.f90 f90 -c data.
• A PA-RISC processor name—for example, PA7100or PA8000. • portable—code that is compatible across all models. Use +DAportableonly if you want to ensure that your program will run on different models. Use the uname -mcommand to learn the model of your machine, as follows: $ uname -m 9000/879 Alternatively, you can use the grep command to look up the model number in the file /opt/ langtools/lib/sched.modelsand find its architecture type, as follows: $ grep 879 /opt/langtools/lib/sched.models 879 2.
Linking with -b The -boption is a linker option. It causes the linker to bind PIC object files into a shared library, instead of creating a normal executable file. The-b option must be used with the ldcommand; you cannot use thef90 command to create a shared library. Also, the object files specified on theld command line must consist of PIC; that is, they must have been created with either +pic=shortor +pic=long. The following command line links the object filesx.o , y.o, and z.
cppdirectives are similar to debugging lines, a feature of many Fortran implementations see, “Using debugging lines” (page 80). Like cppdirectives, debugging lines enable the compiler to treat source lines as either compilable statements or comments to be removed before compilation. But debugging lines are nonstandard, available only in fixed-form source, and not nearly as powerful as the cpp directives.
The value of x in double_it: 3.0 x = 6.0 The next command line does not use the-D option, so that DEBUGis undefined, causing cpp to remove the PRINTstatements from the source text that is passed to the compiler: $ f90 +cpp=yes cpp_direct.f90 Here is the output from the nondebugging version of the program: $ a.out Enter a real number: 3.3 x = 6.6 Saving the cpp output file By default, the f90command discards the source text as processed by cpp after compilation.
You can override this default with the +nosharedoption, which causes the linker to mark the executable as unshared, making the program’s code nonshareable. The following command line causes the linker to mark prog.f90as unshared: $ f90 +noshared prog.f90 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.
Table 24 HP Fortran environment variables (continued) Environment variable Description TMPDIR Specifies a directory for temporary files; used in place of the default directory /var/tmp. TTYUNBUF Controls tty buffering. To enable tty buffering, set TTYUNBUFto 0; to disable tty buffering, set it to a nonzero value. The following sections describe how to use the HP_F90_OPTS, LPATH, and MP_NUMBER_OF_THREADSenvironment variables.
$ export HP_F90OPTS="-O|-lmylib" $ f90 -v hello.f90 LPATH environment variable The LPATHenvironment variable is read by the linker to determine where to look for libraries to link with a program’s object file. Depending on whetherLPATH is set or not, one of the following actions occurs: • If LPATHis already set, only the directories listed in LPATHare searched. This happens, for example, whenLPATH is set in a user’s .kshrcor .cshrcfile, or after LPATHis defined from the command line.
Setting up floating installation You may want to install the most recent compiler version and keep the prior version on one system. If there are problems with the most recent version, you can easily switch to the prior one. Following is an example of how to set up the floating installation feature for this purpose. Assume that your system will have two versions of the compiler, both floating install enabled. In this case, 3.6.1 is the prior version, and 3.6.2 or 3.7 is the more recent version.
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. In particular, it discusses the following topics: • Disabling implicit typing • Automatic and static variables • Increasing the precision of constants • Sharing data among programs • Modules vs. common blocks NOTE: For information about how HP Fortran aligns data, see HP Fortran Programmer's Reference.
HP Fortran allocates static storage for the following variables: • Variables specified in a COMMON or EQUIVALENCE statement. • Variables initialized in a type declaration statement or in a DATA statement. • Variables specified in a SAVE or STATIC statement. A SAVE statement without a variable list specifies static storage for all variables in the scoping unit. • Variables in program files that have been compiled with the +saveor +Oinitcheckcommand-line option.
stat_val auto_val stat_val auto_val stat_val auto_val stat_val auto_val = = = = = = = = 1 124 2 1 3 65 4 65 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.
floating-point arithmetic is implemented on HP 9000 computers and how floating-point behavior affects the programmer, see the HP-UX Floating-Point Guide. Increasing default data sizes The +autodbland +autodbl4options 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 +autodbland +autodbl4options affect both constants and variables of both real and integer types.
The following program illustrates the different effects of the +autodbl and +autodbl4 options. The program assigns the same quad-precision constant to three variables: • x, a default (that is, single-precision) real • y, a real that is declared as double-precision with the kind parameter • z, a double-precision real that is declared with the DOUBLE PRECISION statement Example 3-2 precision.
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.
! when alarm is set by wake_up.f90, this program breaks out ! of the DO loop, prints message (which wake_up.f90 has ! written to), and exits. COMMON /shared_data/ alarm, message alarm = .FALSE. ! Wait for alarm to be set... DO WHILE (alarm .EQ. .FALSE.) ! sleep(1) is an HP-UX system call that suspends a process ! for the number of seconds specified by the argument. ! The %VAL function tells Fortran that sleep expects its ! argument to be passed by value. CALL sleep(%VAL(1)) END DO ! Message from wake.
Now run the second program in the second process: $ wake_up At this point, the program executing in the first process outputs the following and completes execution: I'm up! The following command line confirms that the shared memory segment was released: $ 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-rw- root root m 1 0x4e180002 --rw-rw-rw- root root m 2 0x41187bf4 --rw-rw-rw- root root m 3 0x00000000 --rw------- root sys m 7
In addition, the module provides the following controls on access to module data: • The PUBLIC and PRIVATEstatements declare which module variables are accessible outside the module and which are not. • The USE statement has an ONLYclause 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.
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.
If the size of executable is critical to your application, you can use the +stripoption to remove symbol table information from the production version of your program. If you compile and link on separate command lines, you must use the +stripoption on both command lines. Instead of recompiling with +strip, you can use the strip utility, which removes all debugging information, including the symbol table.
The following sections discuss each of exceptions listed in Table4-1. For more information about signals, refer to the signal((2))) and signal((5))man pages. NOTE: Standard Fortran90 provides the IOSTAT=and ERR=specifiers for handling I/O runtime errors. For information about these specifiers, refer to the descriptions of the I/O statements (for example, OPENand READ) in the HPFortran Programmer’s Reference.
See the HPFortran Programmer’s Reference, for detailed information about the +FPand +fp_exceptionoptions. Also, the HP-UX Floating-Point Guide has a useful discussion of both options and includes detailed information on floating-point exceptions and how to handle them. Illegal instruction exception An illegal instruction exception occurs when a program attempts to execute a bit pattern that is not an op-code. A common cause of this exception is an overwritten stack.
Bad argument exception This exception occurs when a bad argument (for example, an out-of-range argument) is passed to a kernel system routine. This exception can also occur in programs that make explicit calls to the kernel threads library, /usr/lib/libpthread.sl, and pass bad arguments. Using debugging lines An HPFortran 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.
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. As described in “Handling runtime exceptions” (page 77), the +fp_exception and +FPoptions provide control over how a program behaves when a runtime error occurs.
The next example ONstatement does the same as the first but uses the alternate keywords from the third column of the table: ON DOUBLE PRECISION DIV 0 CALL div_zero_trap Table 26 Exceptions handled by the ON statement Exceptions Exception keywords Alternate keywords Division by zero REAL(4) DIV 0 REAL DIV 0 REAL(8) DIV 0 DOUBLE PRECISION DIV 0 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
Terminating program execution Use the ABORTform of the CALLstatement to terminate the program when an exception occurs. In the following example, the log is taken of a negative number. The ABORTclause causes the program immediately after the exception is detected and to issue a procedure traceback: Example 14 Example5-1 abort.f90 PROGRAM main REAL :: x, y, z ! The next statement enables traps for floating-point exceptions ! and specifies the action to take for divide by zero. ! ON REAL DIV 0 ABORT x = 10.
The program also attempts to divide by zero. Although the ONstatement enables the trap triggered by a divide-by-zero exception, the statement has no other effect. As a result, the exception will cause the program to abort. To ignore the divide-by-zero exception would require an additional ONstatement: ON REAL DIV 0 IGNORE Here is command line to compile the program, followed by the output from a sample run: $ f90 ignore.f90 $ a.
Example 17 Example5-4 call_itrap.
program uses the ON statement to handle floating-point exceptions, but allows a core dump when a bus error occurs: Example 18 Example 5-5 allow_core.
6 Performance and optimization This chapter describes how to use different features of HP Fortran to tune your program for optimum performance. The most important of these features is the optimizer. You invoke the optimizer when compiling your program by specifying either +On(where nrepresents the level of optimization to be applied to your program) or the -Ooption for the default level of optimization (level 2).
Invoking HP Caliper with the compiler to optimize your program The simplest way to use HP Caliper is to use the PBO mode to create a flow-data file that the compiler can use to further optimize your program. Step 1. Compile your program with the +Oprofile=collectoption. /opt/ansic/bin/cc -Aa +O3 -o program +Oprofile=collect program.c The loader sets a run-time flag on the program to automatically invoke HP Caliper. HP Caliper supports programs compiled with any compiler option.
Using Options to Control Data Collection You can use various options to specify how to collect profile information about your program. • Collecting information on specific load modules. • Improving HP Caliper performance by excluding load modules you don’t want to profile. • Collecting information on specific processes. You can specify HP Caliper data collection options by using the CALIPER_OPTSenvironment variable.
prof The profprofiler can also be used for profiling. Unlike the gprofprofiler, 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.out in the current directory. For example: $ prog$ ls mon.outmon.out 3.
Table 27 Optimization levels (continued) Option Optimizations performed Advantages Disadvantages Recommended use branch optimization, dead code elimination, more efficient use of registers, instruction scheduling, and peephole optimization. compiles faster than level 2; compatible with the debugger option -g.
Table6-2 lists the “packaged” options. These options enable or disable a set of related optimizations, such as optimizations that do not increase code size. Table6-3 lists options that enable or disable specific optimizations. 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.
Table 29 Fine-tuning optimization options (continued) Level Level Function 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. +O[no]dynopt All Enable [disable] dynamic optimization for the output file, if the run-time environment supports this feature.
Table 29 Fine-tuning optimization options (continued) Level Level Function NOTE: Do not use this option for programs that depend on IEEE standard floating point denormalized numbers. Otherwise, different numerical results may occur. See +Ofltacc=relaxed. This option is a synonym for -fast. 94 +Ofaster All This option is equivalent to +Ofastwith an increased optimization level. The definition of +Ofastermay change or it may be deprecated in future releases.
Table 29 Fine-tuning optimization options (continued) Level Level Function +O[no]inline +O3or higher Enable [disable] inlining. The default is +Oinline. +Oinline_level num All 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.
Table 29 Fine-tuning optimization options (continued) Level Level Function compiler can be reduced by using this option. +O[no]moveflops +O2or higher Enable [disable] moving conditional floating-point instructions out of loops. The default is +Omoveflops. +O[no]parallel +O3or higher Transform [do not transform] eligible loops for parallel execution. The default is +Onoparallel. This option is available only on HP 9000 systems.
Table 29 Fine-tuning optimization options (continued) Level Level Function NOTE: The optimizer tries to determine the most likely target of indirect calls. If the profile data is incomplete or ambiguous, the optimizer may not select the best target. If this happens, your code’s performance may decrease. This option can be used at optimization levels 3 and 4. At +O3, it is only effective if indirect calls from functions within a file are mostly to target functions within the same file.
Table 29 Fine-tuning optimization options (continued) Level Level Function +O[no]regreassoc +O2or higher +O2or higher Enable [disable] register association. The default is +Oregreassoc. NOTE: This option is valid only on the PA-RISC systems. +Ono_return All This option provides a hint to the optimizer that the named functions never return to the call site. If the +Ono_return:filenameform is used, the file filename contains a list of function names separated by spaces or newlines.
Table 29 Fine-tuning optimization options (continued) Level Level Function NOTE: This option is valid only on the PA-RISC systems. +O[no]whole_program_mode +O4or higher 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.
Table on page160 lists the assumptions that the optimizer makes about your program when you compile with +Oconservative, +Oaggressive, or neither option (the default). The table also lists the fine-tuning options that are invoked by +Oconservativeand +Oaggressive. The options listed for the default case are the subset of the ones invoked by +Oconservative and +Oaggressive. For information about the fine-tuning options listed in the third column, see Table on page 152.
As this command line implies, if you link and compile separately, you must use f90, notld. The command line to link must also include the +Oparallel and +O3options in order to link in the parallel runtime support. Performance and parallelization To ensure the best runtime performance from programs compiled for parallel execution on a multiprocessor machine, do not run more than one parallel program on a multiprocessor machine at the same time.
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. Indeterminate iteration counts If the compiler finds that a runtime determination of a loop's iteration count cannot be made before the loop starts to execute, the compiler will not parallelize the loop.
But no such data dependence appears in the outer loop: each column access is independent of every other column access. Consequently, the compiler can safely distribute entire columns of the matrix to execute on different processors; the data assignments will be the same regardless of the order in which the columns are executed, so long as the rows execute in serial order.
Table 31 Vector routines called by +Ovectorize (continued) Vector routine Description saxpy Add a scalar multiple of a vector to a vector, using single-precision operands. sdot Compute the dot product of two single-precision vectors. sdot 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.
For a detailed description of the *$* [NO]VECTORIZE directive, see the HP Fortran Programmer's Reference. NOTE: The + Ovectorizeoption is valid only on the PA-RISC systems. Calling BLAS library routines The HP Fortran compiler is bundled with the Basic Linear Algebra Subroutine (BLAS) library. This library consists of specially tuned routines that perform low-level vector and matrix operations that conform to a de facto, 1.
Controlling code generation for performance For optimum performance, the executable program should consist of code that can take advantage of the hardware features of the machine on which the program will run. If your program will run on the same machine as you use to compile it, code generation is not an issue. By default, the HP Fortran compiler generates code for the model of the machine on which you are running the compiler.
7 Writing HP-UX applications This chapter discusses how HP Fortran applications running on the HP-UX operating system can use system resources to do the following: • Accessing command-line arguments • Calling HP-UX system and library routines • Using HP-UX file I/O 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.
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. Calling HP-UX system and library routines System calls provide low-level access to kernel-level resources, such as thewrite system routine. or example, see “File handling” (page 120) for an example of a program that calls the write routine. For information about system calls, see the HP-UX Reference.
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 /* definition of O_RDWR contained here */ fildes = open("DATA.DAT", O_RDWR) Obtaining an HP-UX file descriptor The Fortran intrinsic FNUMreturns the HP-UX file descriptor for a given logical unit. See the program in “File handling” (page 120) for an example of how to call the FNUMintrinsic.
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. This includes the following topics: • Data types Calling C routines from HP Fortran 182 Chapter 8 • Argument-passing conventions • Case sensitivity • Arrays • C strings • File handling • Sharing data Data types Table 8-1 lists the corresponding data types for HP Fortran and C when compiled as 32-bit applications.
Table 33 Size differences between HP Fortran and C data types C data types HP Fortran data types 32-bit mode 64-bit mode Sizes (in bits) INTEGER intor long int 32 INTEGER*4 intor long int 32 INTEGER*8 longlong longor long long 64 REAL float float 32 DOUBLE PRECISION double double 64 REAL*16 long double long double 128 Table 34 Size differences after compiling with +autodbl C data types HP Fortran data types 32-bit mode 64-bit mode Sizes (in bits) INTEGER longor long long 64
Complex numbers C has no complex numbers, but they are easy to simulate. To illustrate this, create a struct type containing two floating-point members of the correct size — two floatsfor the complex type, and two doublesfor the double complex type.
Example 22 Example 8-2 sqr_complex.c #include <stdio.h> /* simulate Fortran’s complex number */ typedef struct { 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 complex number and store the results into * the return variable */ result.imag = 2 * (a * b); a = a * a; b = b * b; result.
directive. The %REFfunction tells Fortran that its argument is to be passed by reference (as when passing an array or pointer in C), and the %VALfunction tells Fortran that its argument is to be passed by value (the default case in C).
Example 23 Example 8-3 sort_em.c #include <stdio.h> void BubbleSort(int a[], int size) void BubbleSort(int a[], int size) { int i, j, temp; for (i = 0; i < size - 1; i++) for (j = i + 1; j < size; j++) if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } 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 name of the file you want to include. All text in file is prepended to each of the source files specified on the command line, before being passed to the compiler. See “File handling” (page 120) for another example of a program that uses the $HP$ ALIAS directive. The HP Fortran Programmer's Reference fully describes the %VALand %REFbuilt-in functions, the +uppercase and +pre_includeoptions. The $HP$ ALIAS directive is discussed in “$HP$ ALIAS”.
Example 25 Example 8-5 pass_array.f90 PROGRAM main ! This program initializes a multi-dimensional array, ! displays its contents, then passes it to a C function, ! which displays its contents. The C function has the ! following declaration prototype: ! ! void get_array(int a[4][2]); ! ! Note that the dimensions are declared in reverse order ! in C from the way they are declared in Fortran.
In this example, it is assumed that the C routine has the array size information already coded into it. If that is not the case, then the Fortran program must also pass the size as a separate argument, and the C routine must be changed to accept a second argument. For an example of a Fortran program that passes an array and its size as arguments to a C function, see “Case sensitivity” (page 114).
The program consists of two source files: • The Fortran source file, which consists of a main program unit that declares two initialized character variables and passes them to a C function.
Example 27 Example 8-7 pass_chars.f90 PROGRAM main ! This program passes to character variables to a C routine, ! which overwrites them. This program displays the ! character variables before and after the call. ! Initialize the character variables and append null ! characters so that C can process them. CHARACTER(LEN=10) :: first_name = "Pete"//CHAR(0) CHARACTER(LEN=15) :: last_name = "Seeger"//CHAR(0) ! Note that character variables, like arrays, are passed by ! reference in both languages.
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. This method of file access can also be used from Fortran instead of Fortran I/O. You can pass file units and file pointers from Fortran to C with the FNUMand FSTREAMintrinsics.
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 2. Although C has no common blocks, it does provide external variables, which can also be used to share data among different parts of a C program.
9 Using Fortran directives Compiler directives are commands within the source program that affect how the program is compiled. They are similar in function to command-line options, but generally provide more local control. The directives provided by HP Fortran use a syntax that causes them to be treated as comments (and so ignored) when ported to another processor or when incorrectly formatted. The following sections describe the 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. Keywords and any arguments must be delimited by at least one space character, as in the following: !$HP$ OPTIMIZE ON Using the comment character as the directive prefix ensures that, unless the compiler is specifically looking for the directive, it is otherwise treated as a comment and ignored.
Note the following restrictions: • Attempts to redefine $HP$ ALIAS names generate warning messages. • The compiler always uses external-name exactly as it is entered. No case transformations occur, and no underscore is appended. The +ppu and +uppercasecommand-line options do not apply to external names specified by the $HP$ ALIAS directive.
Strings Programs written in C expect strings to be terminated with the null character ('\0'). But HP Fortran programs pass a hidden length parameter to indicate the end of a string argument. Thus, if you want to pass a string from HP Fortran to a C language function, you must explicitly append the null to the string and suppress the hidden length parameter. The $HP$ ALIAS directive enables you to pass the string from Fortran to C. For example, consider the following routine: Example 31 Example 9-1 pr_str.
For more information For more information about the ONstatement see the HP Fortran Programmer’s Reference. $HP$ LIST The $HP$ LIST directive turns on or off the inclusion of subsequent source lines in the listing output. Syntax !$HP$ LIST [ON | OFF] ON enables the inclusion of source lines in the listing file. OFF disables the inclusion of source lines in the listing file. OFF disables the inclusion of source lines in the listing file.
Description and restrictions The $HP$ OPTIMIZEdirective allows you to determine which areas of your program that the optimizer will process. Specifying $HP$ OPTIMIZE OFFcauses the following source lines not to be optimized. $HP$ OPTIMIZE ONre-enables optimization for the following source lines. This directive is effective only if you have used either the -Onor +Onoption when you compiled 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. NOTE: The + Ovectorizeoption is valid only on the PA-RISC systems. Controlling parallelization HP Fortran can parallelize eligible program loops by distributing different iterations of the loop to different processors for parallel execution on a multiprocessor machine.
NOTE: Using this directive to incorrectly assert that a routine has no side effects can result in wrong answers when a call to the routine is embedded in a loop. Cray's implementation of this directive requires that it precede any executable statement or statement function. HP Fortran does not enforce this requirement.
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. However, some command-line options and nonstandard extensions in HP FORTRAN 77 programs may have to be changed to compile and execute correctly under HP Fortran.
Table 38 f77 options replaced by f90 options (continued) f77 option f90 replacement -D +dlines +es +extend_source -F +cpp_keep -L +list -onetrip +onetrip +Q +pre_include +s a +T +fp_exception +ttyunbuf +nottybuf -U +uppercase -u +implicit_none -V +lista +langlvla a Does not fully replace. Format field widths HP Fortran 90 supports format field widths up to 32767. In contrast, HP FORTRAN 77 allows format field widths up to 2147483639, which is close to 2**31.
The HP Fortran version of the TIMEintrinsic takes a CHARACTER* argument; it will not accept an integer. Other intrinsics are similarly affected. Procedure calls and definitions When defining a procedure or making a procedure call, HP Fortran makes the following requirements, which HP FORTRAN 77™ overlooks: • Function references must include the parentheses for the argument list, even when no arguments are supplied.
the expression foo**baris legal in HP FORTRAN 77™but not in HP Fortran™. (HP FORTRAN 77 ™coerces COMPLEX(16)entities to COMPLEX(8)in order to continue the computation.) Given the previous declarations, the following is acceptable in HP Fortran™: foo**REAL(bar, 8) ! foo**bar See the HP Fortran Programmer's Reference for information about theREAL intrinsic.
Miscellaneous Following are miscellaneous incompatibilities between HP Fortran and HP FORTRAN 77: • The syntax and functionality of the HP Fortran version of the ON statement is different from the HP FORTRAN 77™version. For example, ON EXTERNALand ON INTERNAL are not supported in HP Fortran™. For information about using theONstatement, see the “Using the ON statement” (page 81). • HP FORTRAN 77™ accepts statement functions that convert arguments; HP Fortran™ does not.
Directives HP FORTRAN 77™supports more than seventy directives; of these, only a handful are supported by HP Fortran; see “Directives” (page 134), for the directives that are supported and for the new directive syntax. Note that, except for the LISTdirective, the HP Fortran directives have more limited functionality than their HP FORTRAN 77™counterparts; see the HP Fortran Programmer's Reference.
Intrinsic functions HP Fortran supports most of the intrinsics that HP FORTRAN 77 ™offers, and more. In addition, most of these intrinsics are available in HP Fortran without having to activate them with compiler directives or command-line options (as with HP FORTRAN 77™). With the larger number of available intrinsics in HP Fortran, there is the risk of name collisions with user-defined functions in existing HP FORTRAN 77™source code. Use of the EXTERNALstatement can prevent such collisions.
Table 41 f77 options supported by f90 (continued) f77 option f90 option function -Q +nodemand_load Do not mark linker output demand load -q +demand_load Mark linker output demand load -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
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.
fidsearches the target source-code file for various HP FORTRAN 77™ extensions that are known to be incompatible with HP Fortran. It also detects incompatible command-line options when given anf77 command line. fid reports both source-code and object-code incompatibilities between HP FORTRAN 77™ and HP Fortran. Furthermore, if fiddetects an incompatible extension whose functionality is enabled by some other means in HP Fortran, it will suggest a fix.
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. In practice, however, programming is rarely so simple.
Table 42 Compatibility statements (continued) Statement 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. VIRTUAL DEC Declares an array.
Table 43 Compatibility directives (continued) Vendor Directive Function Option dependency KAI *$* [NO]CONCURRENTIZE Enables [disables] code generation for parallel execution. +Oparallel *$* [NO]VECTORIZE Enables [disables] vectorization. +Ovectorize VD$ [NO]VECTOR Enables [disables] vectorization. +Ovectorize VD$ NODEPCHK Disables dependency checks. +Oparallelor +Ovectorize VAST HP Fortran also recognizes several directive prefixes.
Table 45 Nonstandard intrinsic procedures in HP Fortran (continued) ATANH FSET INT4 OR SYSTEM BADDRESS FSTREAM INT8 QCOTAN TAND COSD GETARG INUM QCOTAND TIME COTAN GETENV IOMSG QEXT XOR COTAND GRAN IQINT QFLOAT ZEXT DATE HFIX IRAND QNUM DCMPLX IACHAR IRANP QPROD DCOTAN IADDR ISIGN RAN HP Fortran also provides nonstandard specific intrinsics that derive from standard generic intrinsics; these nonstandard specific intrinsics are not listed in Table 11-4.
compatible with implementations that allocate static storage, compile with the +saveoption. This option causes the compiler to act as though all local variables had the SAVEattribute. As mentioned in “Automatic and static variables” (page 67), saving all variables in static storage can degrade performance. If performance is an issue, consider using the +Oinitcheck option. Unlike the +save option, +Oinitcheckdoes not “save” variables—it does not move variables into static storage.
Name conflicts A common problem in porting Fortran programs is name conflicts: a user-written procedure may have the same name as an intrinsic procedure on the implementation to which you are porting, and the compiler selects the name of the intrinsic when you are expecting it to call the user-written procedure. For example, HP Fortran provides the nonstandard intrinsic FLUSH.
$ f90 clash.f90 clash.f90 program CLASH external function INT1 11 Lines Compiled $ a.out j = 5 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.
• If the file is compiled with the +source=free option, the compiler assumes free form, regardless of the extension. • If the file is compiled with the +extend_source option, the compiler allows lines as long as 254 characters in either fixed or free form. The default line length is 72 characters for fixed form and 132 characters for free form. See the HP Fortran Programmer’s Reference for detailed information about the different source and the +langlvl=90, +source, and +extend_source options.
Enhancements The following enhancements have been made to support the addition of new Tru64 Fortran options: • AddedCLF_TRU64 bit to command-line flags, used to distinguish migration options from ‘regular’ options. • Added support forCLF_DETACHED_SUB_OPT bit in command-line flags, used to indicate flags with a space-delimited sub-option (-foo bar), not to be confused with flags that take a space-separated argument. • Added TRU64DRIVERas new (pseudo-) phase in the f90 driver.
• -check [no]boundsoptions (for example, -[no]check_bounds) • -assume [no]backslash options (opposite of +[no]escape; Tru64 default different from HP) • -assume [no]{buffered_io, recl, minus0}options (new functionality) • -assume [no]underscopeoptions (for example, +[no]ppu) • -check [no]{format, output_conversion}options (new functionality) • -convert {big_endian, cray, fdx, fgx, ibm, little_endian, native, vaxd, vaxg}options (new functionality) • support for '-assume [no]accuracy_sensitive’ (
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. 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_BINDINGcontains named constants that hold kind type parameter values for intrinsic types for interoperability between C and Fortran.
• Controlling IEEE underflow • Another IEEE class value 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.
13 Documentation Feedback HP is committed to providing documentation that meets your needs. To help us improve the documentation, send any errors, suggestions, or comments to Documentation Feedback (docsfeedback@hp.com). Include the document title and part number, version number, or the URL when submitting your feedback.
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. • Passing a common variable as an actual argument.
be stored in the first location, a (2,1)in the second, a (3,1)in the third, and so on. See also row-major order. core dump A core image of an executing program that is deposited in a file after the program aborted execution. The core dump (also called a core file) may contain information that is useful in debugging the aborted program. data dependence The relationship that can obtain between the definition of data and its use.
language extension A feature of a programming language that has been added by a vendor and is not defined in (or is in violation of) the language standard. The ONstatement is an HP language extension to the Fortran 90 Standard. See also filename extension.. libU77 routines Routines in the BSD 3f library (libU77.a) that provide a Fortran 90 interface to selected system calls in libc.a. The libU77.alibrary is part of HP Fortran 90 and is accessed with the +U77option.
profiler Programming tools that determine where a program spends its execution time. Profilers that come with HP Fortran 90 include prof, gprof, and CXperf. R-S roundoff error The loss of precision that can occur as a result of floating-point arithmetic. Different orders of evaluating a floating-point expression can produce different accumulations of roundoff errors, which in turn can sometimes cause the expression to yield significantly different results.
Glossary T-Z thread An independent flow of control within a single process, having its own register set and program counter. The HP-UX operating system supports multiple-executing threads within the same process. Thread Trace Visualizer See ttv trap A change in system state that is caused by an exception and that may be detected by the executing program that took the exception. Traps are hardware features that may be enabled or disabled.
Index Symbols # character, 61 $HP$ ALIAS, 124 $HP$ CHECK_OVERFLOW, 126 $HP$ LIST directive, 127 $HP$ OPTIMIZE $HP$ OPTIMIZE directive, 127 %REF built-in function, 115, 118 +asm, 21, 22, 34, 136, 138 +autodbl, 11, 12, 21, 22, 23, 70, 71, 110, 111, 145 +autodbl14, 11, 12, 21, 23, 70, 71, 145 +autodbl4, 70 +autodblpad, 131 +B, 131 +check, 11, 24, 79, 85, 136, 137 +check, +dlines,+fp_exception, -g, , +initheap_complex, +initheap_integer, +initheap_real and +initheap_set, 21 +cpp, 10, 20, 21, 24, 61, 62, 123 +cp