HP Fortran Programmer Guide
Abstract
Page
Contents
Debugging
Using the on statement
Controlling data storage
Performance and optimization
Calling C routines from HP Fortran 110
Using Fortran directives 123
Writing HP-UX applications 107
Migrating to HP Fortran 131
Porting to HP Fortran 141
Fortran 2003 Features 151
Documentation Feedback 153 Glossary 154 Index 159
HP secure development lifecycle
HP Fortran compiler environment
An overview of HP Fortran
An overview of HP Fortran
+dryrun
Driver
Options for controlling the f90 driver
+preinclude= file
Preprocessor
Options for controlling the C preprocessor
Front-end
Options for controlling the front end
+moddir=directory
Back-end
Options for controlling optimization
Optimization
Options for controlling code generation
+Onooptimization
+DAmodel
Linker
Options for controlling the Linker
Ldirectory
+FPflags
Ooutfile
HP-UX operating system
Tools
Wl ,options
Compiling and linking
Compiling with the f90 command
F90 command syntax
$ f90 hello.f90
Command-line options
Command-line options
F90 command syntax
Example 2 hello.f90
Commonly-used options
Command-line options by category
Commonly-used options
+save
Option descriptions
Options listed by category
Do I+1, N
Example 3 Example
+allowunaligned
+autodbl +autodbl4
Data type sizes and +autodbl4
14164
Boption
+check=bounds
+cpp=default
+charlit77
+nocfc
+DDdatamodel
Name=def
+DAmodel
Datamodelare
Itanium2
Blended
Itanium
Native
Values for the +FP option
Gformat77
Signals recognized by the +fpexception option
+hugecommon
Example 4 % f90 +hugecommon=results pcvals.f90
+initheapcomplex=rvalival
/usr/include directory +noimplicitnone
+indirectcommonlist=file
+initheapinteger=ival
+nocheckuf
+io77
Ipo
+nolibs
With different values of optlevel
Levels of optimization
Requires concurrent use of the +Oprofile=use option
+noobjdebug
+pa1
+r8
+demandload option. The default is +nodemandload
+nodemandload the default
+realconstant=single
F90com
Tx,path
Tp,/usr/ccs/lbin/cpp
End.o
Wx,arg1,arg2,...,argN
Bextern =symbol ,symbol
Symbol binding options
Bdefault=symbol,symbol
Bhidden =symbol ,symbol
Reviewing general optimization options
Using optimization options
F90 +O3 +Osize myprog.f90
+Onoautopar
+Oconservative
+Onoall
+Oautopar and omit +Oparallel
Fine-tuning optimization options
F90 +O3 +Onomoveflops +Ofltacc myprog.f90
+Ocachepadcommon option
Default is +Onocxlimitedrange
Default is +Odataprefetch
+Onocxlimitedrange
+Onoentrysched
+Onofenvaccess
+Onofastaccess
+Onofailsafe
Optimizations performed by +Onofltacc
+Onoinlinefilename
+Oinlinebudget=n +Oinlinebudget enables
+Onoinline
+Onoinline=function1,function2
Values for the +Oinlinebudget option
Millicode versions of intrinsic functions
+Oloopunroll=4
+inlinelevel num
+Onoloopunroll=factor
+Onoloopunrolljam
+Onoparmsoverlap
Default is+Onoparmsoverlap
+Oparallelintrinsics
+Onopipeline
Default is +Oshortdata=8
Default is +Onopromoteindirectcalls
+Onorecovery
For +Oprofile=collectarc,stride
Filenames
Filenames recognized by f90
Linking HP Fortran programs
Linking with f90 vs. ld
Linking to libraries
Libraries linked by default on PA-RISC
Libraries linked by default on Itanium
$ f90 -c hello.f90 # compile
Linking to nondefault libraries
Linking HP Fortran 90 routines
Linking to shared libraries
Additional HP Fortran libraries
Opt/fortran90/lib/pa2064/ -lF90 -lisamstub
Library search rules
Special-purpose compilations
Compiling programs with modules
$ f90 -Wl,-a,archive prog.f90 -lm
Special-purpose compilations
Example 6 Example 2-2 main.f90
Examples
Example
Example 7 Example 2-3 code.f90
$ f90 -o dostats data.f90 code.f90 main.f90
Compiling with make
Example 8 Example 2-4 data.f90
$ dostats
Example 9 Example 2-5 makefile
Compiling for different PA-RISC machines
Managing .mod files
$ make
Creating shared libraries
Compiling with +pic
Using the C preprocessor
Linking with -b
Example 13 Example 2-9 cppdirect.f90
Using the C preprocessor
Processing cpp directives
$ f90 +cpp=yes -D Debug cppdirect.f90
Creating shared executables
Creating demand-loadable executables
Saving the cpp output file
$ f90 +noshared prog.f90
Compiling in 64-bit mode
Using environment variables
HP Fortran environment variables
HPF90OPTS environment variable
F90ROOT environment variable
STF90COM64 environment variable
$ f90 +list hello.f90
Lpath environment variable
Floating installation
Floating installation
Mpnumberofthreads environment variable
Setting up floating installation
Alternate-path/opt/fortran90.3.6.1
Automatic and static variables
Controlling data storage
Disabling implicit typing
Disabling implicit typing
Contains
Controlling data storage
Increasing the precision of constants
Increasing default data sizes
Increasing default data sizes
Increasing default data sizes
Usr/lib/libpthread.sl
Sharing data among programs
Which creates multiple threads
$ gotosleep
Sharing data among programs
$ wakeup
Modules vs. common blocks
Im up
Modules vs. common blocks
Debugging
Using the HP WDB debugger
Stripping debugging information
Handling runtime exceptions
Signals recognized by +fpexception
Signal
Floating-point exceptions
Floating-point exceptions
Bus error exception
= 1.0/0.0
Illegal instruction exception
Segmentation violation exception
Using debugging lines
Bad argument exception
On REAL8 DIV 0 Call divzerotrap
Using the on statement
Exceptions handled by the on statement
Exceptions handled by the on statement
On Double Precision DIV 0 Call divzerotrap
Actions specified by on
Exceptions handled by the on statement
Example 14 Example5-1 abort.f90
Ignoring errors
Terminating program execution
Example 15 Example5-2 ignore.f90
Trapping integer overflow exceptions
Calling a trap procedure
Trapping floating-point exceptions
On Double Precision Overflow Call trap
Allowing core dumps
Trapping +Ctrl-C trap interrupts
Example 17 Example5-4 callitrap.f90
Example 18 Example 5-5 allowcore.f90
On Real Overflow Ignore
Performance and optimization
Using profilers
Using profilers
HP Caliper
Program.c
Comparing Program Performance
Opt/ansic/bin/cc -Aa +O3 -o program +Oprofile=collect
Programprogramarguments
Specifying PBO file names and locations
Using Options to Control Data Collection
Gprof
$ gprof prog gprof.out
Prof
Using options to control optimization
Using +O to set optimization levels
$ f90 +O4 file.f90
+O3
Using the optimization options
+O2, -O
+O4
$ f90 +O4 +Oaggressive +Ofltacc prog.f90
Fine-tuning optimization options
$ f90 +02 +Oaggressive +Osize prog.f90
Packaged optimization options
+O2
Is +Onofastaccess at
+Ofastaccess at level
+Ofltacc=relaxed
Fast
+Ofltacc=relaxed . This
+Onoinitcheck
+Olibcalls
+Oinlinelevel num
+Onolibcalls
+Onoloopunroll=n
+Onoparminit
+Opipeline
+Orecovery
+Oshortdata=8
+Oregreassoc
+Onoreturn
+Ovectorize option on
+Onowholeprogrammode
Conservative vs. aggressive optimization
+Owholeprogrammode
Compiling for parallel execution
Conservative, aggressive, and default optimizations
Parallelizing HP Fortran programs
F90 +O3 +Oparallel -c x.f90 y.f90 F90 +O3 -c z.f90
Conditions inhibiting loop parallelization
Performance and parallelization
Profiling parallelized programs
Calling routines with side effects parallellization
Indeterminate iteration counts
Data dependences
F90 +O3 +Ovectorize prog.f90
Using the +Ovectorize option
Vectorization
Vector routines called by +Ovectorize
Sdot
Controlling vectorization locally
Saxpy
Vecdmultadd
REAL, External sdot
Calling Blas library routines
Example 19 Example 6-1 axpy.f90
Industry-wide standard Vectorization
Controlling code generation for performance
$ fprog arg1 another arg
Accessing command-line arguments
Writing HP-UX applications
Example 20 Example 7-1 getargs.f90
Performing I/O using HP-UX system calls
Using HP-UX file I/O
Stream I/O using Fstream
Calling HP-UX system and library routines
Using HP-UX file I/O
Obtaining an HP-UX file descriptor
Data types
Calling C routines from HP Fortran
Data type correspondence for HP Fortran and C
Size differences between HP Fortran and C data types
Unsigned integers
Logicals
Size differences after compiling with +autodbl
Complex sqrcomplexCOMPLEX cmxval
Complex numbers
Example 21 Example 8-1 passcomplex.f90
Pointers
Argument-passing conventions
Derived types
Example 22 Example 8-2 sqrcomplex.c
Void fooint *ptr, int iarray100, int
Integer ptr INTEGER, DIMENSION100 iarray
Case sensitivity
Call foo%REFptr, %REFiarray, %VALi
Example 24 Example 8-4 testsort.f90
Example 23 Example 8-3 sortem.c
$HP$ Alias bubblesort = BubbleSort%REF,%VAL
Case sensitivity
Arrays
Memory layout of a two-dimensional array in Fortran and C
REAL, DIMENSION2,3,4
Int
Example 25 Example 8-5 passarray.f90
Example 26 Example 8-6 getarray.c
Fortran hidden length argument
Strings
Null-terminated string
Passing a string
Following are example C and Fortran programs
Strings
Example 27 Example 8-7 passchars.f90
File handling
Example 28 Example 8-8 getstring.c
Example 29 Example 8-9 fnumtest.f90
File handling
Extern int somedata
Sharing data
Int somedata
Extern int globals100
Directive syntax
Using Fortran directives
Using HP Fortran directives
HP Fortran directives
$HP$ Alias name = external-name arg-pass-mode-list
Syntax
Description and restrictions
Name
Case sensitivity
Local and global usage
Argument-passing conventions
Example 31 Example 9-1 prstr.c
Strings
For more information
Example 32 Example 9-2 passstr.f90
Example 33 Example
Disables the inclusion of source lines in the listing file
Specified on the command line
Listing file
Compatibility directives recognized by HP Fortran
Compatibility directives
Controlling vectorization
Vendor Directive Cray
Controlling checks for side effects
Controlling parallelization
Controlling dependence checks
Compatibility directives
Using Fortran directives
Incompatibilities with HP Fortran
Command-line options not supported
Migrating to HP Fortran
Compiler limits
Intrinsic functions
Format field widths
Floating-point constants
Double Precision x =
Procedure calls and definitions
Data types and constants
Foo**REALbar, 8 ! foo**bar
Input/output
Directives
KEY=
Migration issues
Migration issues
Source code issues
Miscellaneous
Directives
HP Fortran 77 directives supported by f90 options
Conflicting intrinsics and libU77 routine names
Command-line option issues
Intrinsic functions
F77 options supported by f90
Object code issues
Data file issues
Approaches to migration
HP-supplied migration tools
$ fid +800 file.f $ fid +es program.f
Compatibility statements
Porting to HP Fortran
Compatibility extensions
END structure definition
Pointer Cray-style
Compiler directives
Compatibility directives
+Oparallel or
Directive prefixes recognized by HP Fortran
Intrinsic procedures
Nonstandard intrinsic procedures in HP Fortran
+Oparallel or +Ovectorize
Using porting options
Uninitialized variables
One-trip do loops
Using porting options
Large word size
$ f90 testloop.f90
Example 34 Example 11-1 clash.f90
Name conflicts
External int1
Names with appended underscores
Source formats
Escape sequences
Porting from Tru64 to HP Fortran
+cfc
Nof66alternate for +noonetrip
Enhancements
New options
Porting from Tru64 to HP Fortran
Check noboundsoptions for example, -nocheckbounds
+nopadsrc Altparam
Input/output enhancements
Fortran 2003 Features
Interoperability with C
Miscellaneous enhancements
Fortran 2003 Features
Object orientation features
Data enhancements
Documentation Feedback
153
Glossary
Glossary
So on. See also row-major order
155
Also filename extension
Memory fault
157
See ttv
Index
Symbols
159