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