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, 2011 Hewlett-Packard Development Company, L.P. Confidential computer software. Valid license from HP required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial Computer Software, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor's standard commercial license. The information contained in this document is subject to change without notice.
Contents 1 An overview of HP Fortran...........................................................................7 The HP Fortran compiler environment...........................................................................................7 Driver......................................................................................................................................8 C preprocessor...................................................................................................................
Floating Installation.................................................................................................................63 Setting up Floating Installation.............................................................................................64 3 Controlling data storage............................................................................65 Disabling implicit typing..........................................................................................................
Controlling vectorization locally.........................................................................................102 Calling BLAS library routines.............................................................................................103 Controlling code generation for performance...........................................................................104 7 Writing HP-UX applications......................................................................105 Accessing command-line arguments...
Source code issues...........................................................................................................133 Directives...................................................................................................................134 Intrinsic functions.........................................................................................................135 Command-line option issues..............................................................................................
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 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 +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 Function For information about using this option, see “Disabling implicit typing” on page 100. +langlvl={90|default} Issue warnings for all extensions to the Fortran standard (+langlvl=90). The default, +langlvl=default, allows extensions. For information about using this option, see Chapter 11, “Porting to HP Fortran,” on page 235. nl +[no]list Write [suppress] a program listing to standard output during compilation.
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.
Table 5 Options for controlling code generation Option Function +[no]asm Compile the named source files and leave [do not leave] the assembly language output in corresponding files whose names are suffixed with .s. The default is +noasm. +DAmodel 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).
Table 5 Options for controlling code generation (continued) Option Function +pic={short|long|no} Generate Position Independent Code (PIC) with short displacements (+pic=short) or long displacements (+pic=long) for use in shared libraries. The default is +pic=no. For information about using this option when creating shared libraries, see “Compiling with +pic” on page 89. nl +[no]prof Prepare [do not prepare] object files for profiling with prof; see the prof(1) manpage. The default is +noprof.
Table 6 Options for controlling the Linker (continued) Option Function -Ldirectory Add directory to the front of the library search path. This option applies only to libraries specified by the -l option (see below). If you compile and link separately and specify -L on the command line, you must also specify it on the link line. For information about using this option, see “Library search rules” on page 82. nl -lx Link the library libx.a or libx.sl to the executable program.
HP-UX operating system Although the HP-UX operating system does not appear 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.
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 +charlit77causes 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| 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=yesoption. -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 +DAgenerates object code for a particular version of the PA-RISC architecture.
+[no]dlines +dlinestreats 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 +dlinesoption must be used only with source files in fixed-format. +DOosname +DOosnamesets 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.
+f2003 +f2003enables FORTRAN 2003 features supported by the compiler. +fastallocatable +fastallocatableenables a different representation for allocatable arrays in the object code produced by the compiler. This alternate representation avoids problems in optimizing code containing allocatable array references. Additionally, this alternate representation for allocatable arrays is binary compatible with the old representation.
For a description of these signals, see signal(2)and signal(5)in the HP-UX Reference. For information about floating-point exceptions and error handling, see the HP-UX Floating-Point Guide. You can also use the ON statement to write your own trap procedures. For information about the syntax of the ON statement, see “Using the ON statement” on page 127. The default,+nofp_exception , disables traceback information.
The default is to place COMMON blocks larger than two gigabytes (2147483648 bytes) into huge data segments; that is, +hugesize=2097152is the default. For example: % f90 +hugesize=1024 hello.f90 specifies that COMMON blocks larger than 1048576 bytes (1 megabyte) should be placed into a huge data segment. If a common block is specified as huge in one object file, it must be specified huge in all object files. If it is not, the program will fail to link. PA2.
All source files that reference variables in such a common block must be compiled with the +indirectcommonlist flag, and that common block name must appear in the named file. +initheap_complex=rval:ival Default initialization of heap variables (mentioned in +initheap_set option) of type complex. rval is real part and ival is imaginary part of complex number. Valid values for rval and ival are normal real numbers, nan , snan. The numbers represented by rval/ival are mentioned in below table.
levels +O1and +O2. It is enabled by default when +O4 or+O faster are used. +kgenerates 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. +k NOTE: +koption is not valid on HP Itanium®-based systems.
Table 15 Levels of optimization (continued) Level Optimizations • Scalar replacement • Sum reduction optimization Optimizations performed at levels 1 and 2, plus the following: 3 • Interprocedural optimizations, including cloning and inlining • Loop transformations to improve memory performance, including fusion and interchange Level 4 optimizations are not currently supported by the PA-RISC compiler. If +O4is specified, the compiler will issue a warning message and compile at optimization level 3.
+pais ignored when the HP Fortran compiler generates position-independent code (PIC). The following options cause+pa to be ignored: +pic=short, +pic=long, +zand +Z. NOTE: +palis ignored when the HP Fortran compiler generates position-independent code (PIC). The following options cause +pato be ignored: +pic=short, +pic=long, +zand +Z. +[no]parallel_intrinsics Link with the parallel version of some intrinsics in the libF90_parallel library. The default is +Onoparallel_intrinsics.
in which they are declared). The +saveoption causes all uninitialized variables to be initialized to zero. The default is +nosave. If you explicitly declare a variable with theAUTOMATIC attribute, the attribute overrides the +saveoption. The +savecommand-line option inhibits many of the optimizations performed by the compiler.
Table 16 (continued) Value Subprocess Standard name e Debug file end.o l Linker ld p C preprocessor cpp s Start-up file crt0.o, gcrt0.o, mcrt0.o +trigdacc The compiler will use more accurate cosd,sind , andtand 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: +trigdaccoption is not valid on HP Itanium®-based systems.
+what +whatprints the whatstring for the Fortran 90 driver, providing version and patch numbers. -Wx,arg1,arg2,...,argN -Wcauses arg1through argNto be handed off to subprocess x. Each arg takes the form: -option[,value] where optionis the name of an option recognized by the subprocess and value is a separate argument to option, where necessary. The values that xcan assume are listed in Table 2-8.
have the default on a per-symbol basis to specify exceptions to global -Bprotected, -Bhidden, or-Bexternoptions. -Bdefault:filename The file indicated by filenamecontains 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.
+O[no]infooption, which provides compile-time information about the optimization process, is described in the same section. NOTE: You can insert (or remove) underscore characters in the names of any of the optimization options to improve their readability. The compiler will recognize the option name with or without underscores.
The +Oalloption automatically invokes the highest level of optimization. The default is +Onoall. This option has been deprecated on version HP-UX 11i and later. +O[no]autopar +O[no]autoparcontrols automatic parallelization of loops that are deemed safe and profitable by the loop parallelizer.
Fine-tuning optimization options The following options allow you to fine-tune the optimization process by providing control over the specific techniques that the optimizer applies to your program. The syntax for using these options is +O[no]optimization where optimizationis a parameter that specifies an optimization technique to apply to your program. The different parameters are described below. The prefix nonegates the effect of optimization.
data from memory into the data cache. Data prefetch instructions will be inserted only for data structures referenced within innermost loops using simple loop varying addresses—that is, in a simple arithmetic progression. It is not available for PA-RISC 1.1 targets. Use this option for applications that have high data cache miss overhead. The default is +Onodataprefetch.
+Ofaster Selects the +Ofastoption at optimization level +O3for PA-RISC based architectures. For Itanium processor family architectures, +Ofasterruns at +O4and 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.
perform. The defined values for optlevel are: strict—disallow any floating point optimization that can result in numerical differences. This is the same as +Ofltacc. default—allow contractions, such as fused multiply-add (FMA), but disallows any other floating point optimization that can result in numerical differences. limited—like default, but also allows floating point optimizations which may affect the generation and propogation of infinities, NaNs, and the sign of zero. Also implies +Ocxlimitedrange.
uninitialized with respect to at least one path leading to a use of the variable. When +Onoinitcheckis specified, the optimizer issues warning messages when it discovers definitely uninitialized variables, but does not initialize them. When this option is unspecified, the optimizer initializes to zero any local, scalar, nonstatic variables that are definitely uninitialized with respect to all paths leading to a use of the variable. This option is only effective at optimization level 2 or higher.
Table 19 Values for the +Oinline_budget option Values for n Meaning = 100 Default level of inlining. > 100 More aggressive inlining. The optimizer is less restricted by compilation time and code size when searching for eligible routines to inline. 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.
Loop unrolling and jamming increases register exploitation. +O[no]moveflop +Omoveflopsallows the optimizer to move conditional floating-point instructions, enabling other optimizations to occur. This option is only effective at optimization level 2 or higher. The behavior of floating-point exception handling may be altered by this option.
NOTE: This option is valid only on the PA-RISC systems. +Oprefetch_latency=num option Applies to loops for which the compiler generates data prefetch instructions. For a given loop, the compiler divides “cycles” by the estimated loop length to arrive at the number of loop iterations for which to generate advance prefetches. The default value is 480 cycles for loops containing floating-point accesses and 150 cycles for loops that do not contain any floating-point accesses.
are assumed to be infrequently called. This option overrides any information in a profile database. +O[no]recovery Generate [do not generate] recovery code for control speculation. The default is +Onorecovery +O[no]regreassoc +Onoregreassocdisables register reassociation. This option is only effective at optimization level 2 or higher. Use +Onoregreassocto disable register reassociation in the rare case that this optimization degrades performance. +Oregreassocis the default.
procedures that are defined in these files. This option enables optimizations that assume that there are no unseen accesses to the globals. This option can be used at optimization level 4. The default is +Onowhole_program_mode . Filenames The f90command accepts files with any of the filename extensions listed in Table 2-12. The table also describes the meaning each name has for the f90command. Files with names other than those listed in the table are passed to the linker.
When you use the f90command to compile and link in the same command line, the driver passes certain information—search paths, library names, and options—to the linker. If you use the ld command to link separately, you must specify this same information on theld command line. Not doing so can cause the link to fail. Using the samef90 command line to link as you use to compile avoids the problem of passing insufficient or incorrect information to the linker.
The libisamstublibrary is provided as a tool for migrating HP FORTRAN77™programs that call ISAMroutines. 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 22 Libraries linked by default on PA-RISC Library Contents /usr/lib/libcl.a Archive version of HP Fortran runtime library /usr/lib/libcl.sl Shared version of HP Fortran runtime library /opt/fortran90/lib/libF90.
This form of the command line is useful for linking libraries that do not conform to the naming convention required by the-l option or that reside in a directory other than /lib or /usr/lib. As with the -l option, the library name must follow the name of the source file that references it. For example, the following command line links prog.f90with the my_routineslibrary , both of which reside in the current working directory: $ f90 prog.
Linking to shared libraries Many HP Fortran libraries as well as HP-UX libraries exist in both shared and archive versions, as indicated by the library extension name (.sl or.aor .slon Itanium). For example, there are both shared and archive versions of the HP Fortran runtime library, /usr/lib/libcl.sl and /usr/lib/libcl.a. The difference between a shared library and an archive library is that the linker does not actually link the code in a shared library with your program.
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 f90options 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. This section explains how to use the f90command for the following purposes: • To compile programs that contain Fortran modules.
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” on page 125). 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 cppdirectives.
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, refer to the 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 AUTOMATICand STATICstatements as porting extensions. The STATICstatement is functionally the same as the SAVEstatement, and the AUTOMATICstatement 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, refer to 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 PUBLICand 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 USEstatement 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.
Refer to 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” on page120, the +fp_exceptionand +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 Example5-5 allow_core.
6 Performance and optimization This chapter describes how to use different features of HPFortranto 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. 92 +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 page152.
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]VECTORIZEdirective, 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 IGETARGand IARGC intrinsics, see the HP Fortran Programmer's Reference. GETARGCis also available as a libU77routine; 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” 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.
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” on page 198 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.
ALIASdirective. 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” on page 199 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. Th e $HP$ ALIASdirective is discussed in “$HP$ ALIAS”on page 208.
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” on page 189.
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$ ALIASnames 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$ ALIASdirective.
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$ ALIASdirective 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 ONstatement is different from the HP FORTRAN 77™version. For example, ON EXTERNALand ON INTERNALare not supported in HP Fortran™. For information about using theONstatement, see the “Using the ON statement” on page 127. • 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” on page 225, 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 END (structure definition) DEC Description Terminates the definition of a structure or union. 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.
Table 43 Compatibility directives (continued) Vendor Directive Function Option dependency FPP$ NODEPCHK Disables dependency checks +Oparallel or +Ovectorize KAI VAST *$* [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.
Table 45 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 from standard generic intrinsics; these nonstandar
implementations that allocate stack storage can have disastrous results. To make HP Fortran 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” on page 101, saving all variables in static storage can degrade performance. If performance is an issue, consider using the +Oinitcheckoption.
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.alibrary. Some implementations link libU77.aby default. HP Fortran does not; to link in this library, you must compile your program with the +U77option.
• If the file is compiled with the +source=freeoption, the compiler assumes free form, regardless of the extension. • If the file is compiled with the +extend_sourceoption, 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.
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.
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, 59 $HP$ ALIAS, 122 $HP$ CHECK_OVERFLOW, 124 $HP$ LIST directive, 125 $HP$ OPTIMIZE $HP$ OPTIMIZE directive, 125 %REF built-in function, 113, 116 +asm, 20, 21, 32, 134, 136 +autodbl, 10, 11, 20, 21, 22, 68, 69, 108, 109, 143 +autodbl14, 10, 11, 20, 22, 68, 69, 143 +autodbl4, 68 +autodblpad, 129 +B, 129 +check, 10, 23, 77, 83, 134, 135 +check, +dlines,+fp_exception, -g, , +initheap_complex, +initheap_integer, +initheap_real and +initheap_set, 20 +cpp, 9, 19, 20, 23, 59, 60, 121 +cpp