Sun Logo


Fortran Programming Guide

Suntrademark Studio 11

819-3685-10



Contents

Tables

Before You Begin

Typographic Conventions

Shell Prompts

Supported Platforms

Accessing Sun Studio Software and Man Pages

Accessing Compilers and Tools Documentation

Accessing Related Solaris Documentation

Resources for Developers

Contacting Sun Technical Support

Sending Your Comments

1. Introduction

1.1 Standards Conformance

1.2 Features of the Fortran 95 Compiler

1.3 Other Fortran Utilities

1.4 Debugging Utilities

1.5 Sun Performance Library

1.6 Interval Arithmetic

1.7 Man Pages

1.8 README Files

1.9 Command-Line Help

2. Fortran Input/Output

2.1 Accessing Files From Within Fortran Programs

2.1.1 Accessing Named Files

2.1.2 Opening Files Without a Name

2.1.3 Opening Files Without an OPEN Statement

2.1.4 Passing File Names to Programs

2.2 Direct I/O

2.3 Binary I/O

2.4 Stream I/O

2.5 Internal Files

2.6 Binary I/O Between Big-Endian and Little-Endian Platforms

2.7 Legacy I/O Considerations

3. Program Development

3.1 Facilitating Program Builds With the make Utility

3.1.1 The Makefile

3.1.2 make Command

3.1.3 Macros

3.1.4 Overriding of Macro Values

3.1.5 Suffix Rules in make

3.1.6 .KEEP_STATE and Special Dependency Checking

3.2 Version Tracking and Control With SCCS

3.2.1 Controlling Files With SCCS

3.2.2 Checking Files Out and In

4. Libraries

4.1 Understanding Libraries

4.2 Specifying Linker Debugging Options

4.2.1 Generating a Load Map

4.2.2 Listing Other Information

4.2.3 Consistent Compiling and Linking

4.3 Setting Library Search Paths and Order

4.3.1 Search Order for Standard Library Paths

4.3.2 LD_LIBRARY_PATH Environment Variable

4.3.3 Library Search Path and Order--Static Linking

4.3.4 Library Search Path and Order--Dynamic Linking

4.4 Creating Static Libraries

4.4.1 Tradeoffs for Static Libraries

4.4.2 Creation of a Simple Static Library

4.5 Creating Dynamic Libraries

4.5.1 Tradeoffs for Dynamic Libraries

4.5.2 Position-Independent Code and -xcode

4.5.3 Binding Options

4.5.4 Naming Conventions

4.5.5 A Simple Dynamic Library

4.5.6 Initializing Common Blocks

4.6 Libraries Provided With Sun Fortran Compilers

4.7 Shippable Libraries

5. Program Analysis and Debugging

5.1 Global Program Checking (-Xlist)

5.1.1 GPC Overview

5.1.2 How to Invoke Global Program Checking

5.1.3 Some Examples of -Xlist and Global Program Checking

5.1.4 Suboptions for Global Checking Across Routines

5.2 Special Compiler Options

5.2.1 Subscript Bounds (-C)

5.2.2 Undeclared Variable Types (-u)

5.2.3 Compiler Version Checking (-V)

5.3 Debugging With dbx

6. Floating-Point Arithmetic

6.1 Introduction

6.2 IEEE Floating-Point Arithmetic

6.2.1 -ftrap=mode Compiler Options

6.2.2 Floating-Point Exceptions

6.2.3 Handling Exceptions

6.2.4 Trapping a Floating-Point Exception

6.2.5 Nonstandard Arithmetic

6.3 IEEE Routines

6.3.1 Flags and ieee_flags()

6.3.2 IEEE Extreme Value Functions

6.3.3 Exception Handlers and ieee_handler()

6.4 Debugging IEEE Exceptions

6.5 Further Numerical Adventures

6.5.1 Avoiding Simple Underflow

6.5.2 Continuing With the Wrong Answer

6.5.3 Excessive Underflow

6.6 Interval Arithmetic

7. Porting

7.1 Carriage-Control

7.2 Working With Files

7.3 Porting From Scientific Mainframes

7.4 Data Representation

7.5 Hollerith Data

7.6 Nonstandard Coding Practices

7.6.1 Uninitialized Variables

7.6.2 Aliasing and the -xalias Option

7.6.3 Obscure Optimizations

7.7 Time and Date Functions

7.8 Troubleshooting

7.8.1 Results Are Close, but Not Close Enough

7.8.2 Program Fails Without Warning

8. Performance Profiling

8.1 Sun Studio Performance Analyzer

8.2 The time Command

8.2.1 Multiprocessor Interpretation of time Output

8.3 The tcov Profiling Command

8.3.1 Enhanced tcov Analysis

9. Performance and Optimization

9.1 Choice of Compiler Options

9.1.1 Performance Options

9.1.2 Other Performance Strategies

9.1.3 Using Optimized Libraries

9.1.4 Eliminating Performance Inhibitors

9.1.5 Viewing Compiler Commentary

9.2 Further Reading

10. Parallelization

10.1 Essential Concepts

10.1.1 Speedups--What to Expect

10.1.2 Steps to Parallelizing a Program

10.1.3 Data Dependence Issues

10.1.4 Compiling for Parallelization

10.1.5 Number of Threads

10.1.6 Stacks, Stack Sizes, and Parallelization

10.2 Automatic Parallelization

10.2.1 Loop Parallelization

10.2.2 Arrays, Scalars, and Pure Scalars

10.2.3 Automatic Parallelization Criteria

10.2.4 Automatic Parallelization With Reduction Operations

10.3 Explicit Parallelization

10.3.1 Parallelizable Loops

10.3.2 OpenMP Parallelization Directives

10.3.3 Sun-Style Parallelization Directives

10.3.4 Cray-Style Parallelization Directives

10.4 Environment Variables

10.5 Debugging Parallelized Programs

10.5.1 First Steps at Debugging

10.5.2 Debugging Parallel Code With dbx

10.6 Further Reading

11. C-Fortran Interface

11.1 Compatibility Issues

11.1.1 Function or Subroutine?

11.1.2 Data Type Compatibility

11.1.3 Case Sensitivity

11.1.4 Underscores in Routine Names

11.1.5 Argument-Passing by Reference or Value

11.1.6 Argument Order

11.1.7 Array Indexing and Order

11.1.8 File Descriptors and stdio

11.1.9 Libraries and Linking With the f95 Command

11.2 Fortran Initialization Routines

11.3 Passing Data Arguments by Reference

11.3.1 Simple Data Types

11.3.2 COMPLEX Data

11.3.3 Character Strings

11.3.4 One-Dimensional Arrays

11.3.5 Two-Dimensional Arrays

11.3.6 Structures

11.3.7 Pointers

11.4 Passing Data Arguments by Value

11.5 Functions That Return a Value

11.5.1 Returning a Simple Data Type

11.5.2 Returning COMPLEX Data

11.5.3 Returning a CHARACTER String

11.6 Labeled COMMON

11.7 Sharing I/O Between Fortran and C

11.8 Alternate Returns

11.9 Fortran 2000 Interoperability With C

Index