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