fortran programming guide fortran 77 5.0 — fortran 90 isd/_course_fortran_90/_docs/sun_c... ·...

Download Fortran Programming Guide FORTRAN 77 5.0 — Fortran 90 isd/_course_fortran_90/_docs/Sun_C... · and

Post on 30-Jul-2018




11 download

Embed Size (px)


  • Fortran Programming Guide

    FORTRAN 77 5.0 Fortran 902.0

    901 San Antonio RoadPalo Alto, , CA 94303-4900

    USA 650 960-1300 fax 650 969-9131

    Part No: 805-4940Revision A, February 1999

  • Copyright Copyright 1999 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California 94303-4900 U.S.A. All rights reserved.All rights reserved. This product or document is protected by copyright and distributed under licenses restricting its use, copying,distribution, and decompilation. No part of this product or document may be reproduced in any form by any means without prior writtenauthorization of Sun and its licensors, if any.Portions of this product may be derived from the UNIX system, licensed from Novell, Inc., and from the Berkeley 4.3 BSD system,licensed from the University of California. UNIX is a registered trademark in the United States and in other countries and is exclusivelylicensed by X/Open Company Ltd. Third-party software, including font technology in this product, is protected by copyright and licensedfrom Suns suppliers. RESTRICTED RIGHTS: Use, duplication, or disclosure by the U.S. Government is subject to restrictions of FAR52.227-14(g)(2)(6/87) and FAR 52.227-19(6/87), or DFAR 252.227-7015(b)(6/95) and DFAR 227.7202-3(a).Sun, Sun Microsystems, the Sun logo, SunDocs, SunExpress, Solaris, Sun Performance Library, Sun Performance WorkShop Fortran, SunVisual WorkShop C++, Sun WorkShop, and Sun WorkShop Professional are trademarks or registered trademarks of Sun Microsystems, the United States and in other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks ofSPARC International, Inc. in the United States and in other countries. Products bearing SPARC trademarks are based upon an architecturedeveloped by Sun Microsystems, Inc.The OPEN LOOK and Sun


    Graphical User Interfaces were developed by Sun Microsystems, Inc. for its users and licensees. Sunacknowledges the pioneering efforts of Xerox Corporation in researching and developing the concept of visual or graphical user interfacesfor the computer industry. Sun holds a nonexclusive license from Xerox to the Xerox Graphical User Interface, which license also coversSuns licensees who implement OPEN LOOK GUIs and otherwise comply with Suns written license agreements.f90 is derived from Cray CF90


    , a product of Silicon Graphics, Inc.THIS PUBLICATION IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING,BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, ORNON-INFRINGEMENT.Copyright 1999 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, Californie 94303-4900 U.S.A. Tous droits rservs.Ce produit ou document est protg par un copyright et distribu avec des licences qui en restreignent lutilisation, la copie et ladcompilation. Aucune partie de ce produit ou de sa documentation associe ne peut tre reproduite sous aucune forme, par quelquemoyen que ce soit, sans lautorisation pralable et crite de Sun et de ses bailleurs de licence, sil y en a.Des parties de ce produit pourront tre derives du systme UNIX licenci par Novell, Inc. et du systme Berkeley 4.3 BSD licenci parlUniversit de Californie. UNIX est une marque enregistre aux Etats-Unis et dans dautres pays, et licencie exclusivement par X/OpenCompany Ltd. Le logiciel dtenu par des tiers, et qui comprend la technologie relative aux polices de caractres, est protg par uncopyright et licenci par des fournisseurs de Sun.Sun, Sun Microsystems, le logo Sun, SunDocs, SunExpress, Solaris, Sun Performance Library, Sun Performance WorkShop Fortran, SunVisual WorkShop C++, Sun WorkShop, et Sun WorkShop Professional sont des marques dposes ou enregistres de Sun Microsystems,Inc. aux Etats-Unis et dans dautres pays. Toutes les marques SPARC, utilises sous licence, sont des marques dposes ou enregistres deSPARC International, Inc. aux Etats-Unis et dans dautres pays. Les produits portant les marques SPARC sont bass sur une architecturedveloppe par Sun Microsystems, Inc.Les utilisateurs dinterfaces graphiques OPEN LOOK et Sun


    ont t dvelopps de Sun Microsystems, Inc. pour ses utilisateurs etlicencis. Sun reconnat les efforts de pionniers de Xerox Corporation pour la recherche et le dveloppement du concept des interfacesdutilisation visuelle ou graphique pour lindustrie de linformatique. Sun dtient une licence non exclusive de Xerox sur linterfacedutilisation graphique, cette licence couvrant aussi les licencis de Sun qui mettent en place les utilisateurs dinterfaces graphiques OPENLOOK et qui en outre se conforment aux licences crites de Sun.f90 est deriv de CRAY CF90




  • Contents

    Preface xi

    1. Introduction 11

    Standards Conformance 11

    Features of the Fortran Compilers 12

    2. Fortran Input/Output 21

    Accessing Files From Within Fortran Programs 21

    Accessing Named Files 21

    Opening Files Without a Name 23

    Preconnected Units 23

    Opening Files Without an OPEN Statement 23

    Passing File Names to Programs 24

    f77: VAX / VMS Logical File Names 27

    Direct I/O 28

    Internal Files 29

    Tape I/O (f77 Only) 211

    Using TOPEN Routines 211

    Fortran Formatted I/O for Tape 211

    Fortran Unformatted I/O for Tape 211

    Tape File Representation 212

    Contents iii

  • End-of-File 212

    Multifile Tapes 213

    Fortran 90 I/O Considerations 213

    3. Program Development 31

    Facilitating Program Builds With the make Utility 31

    The Makefile 32

    make Command 33

    Macros 33

    Overriding of Macro Values 34

    Suffix Rules in make 34

    Version Tracking and Control With SCCS 35

    Controlling Files With SCCS 35

    Checking Files Out and In 37

    4. Libraries 41

    Understanding Libraries 41

    Specifying Linker Debugging Options 42

    Generating a Load Map 42

    Listing Other Information 43

    Consistent Compiling and Linking 44

    Setting Library Search Paths and Order 44

    Search Order for Standard Library Paths 44

    LD_LIBRARY_PATH Environment Variable 45

    Library Search Path and OrderStatic Linking 46

    Library Search Path and OrderDynamic Linking 47

    Creating Static Libraries 48

    Tradeoffs for Static Libraries 48

    Creation of a Simple Static Library 49

    Creating Dynamic Libraries 412

    iv Fortran Programming Guide Revision A, February 1999

  • Tradeoffs for Dynamic Libraries 412

    Position-Independent Code and -pic 413

    Binding Options 413

    Naming Conventions 414

    A Simple Dynamic Library 415

    Libraries Provided with Sun Fortran Compilers 416

    VMS Library 417

    POSIX Library 417

    Shippable Libraries 418

    5. Program Analysis and Debugging 51

    Global Program Checking 51

    GPC Overview 51

    How to Invoke Global Program Checking 52

    Some Examples of -Xlist and Global Program Checking 54

    Suboptions for Global Checking Across Routines 57

    -Xlist Suboption Reference 59

    Some Examples Using Suboptions 512

    Special Compiler Options 514

    Subscript Bounds (-C) 514

    f77: Undeclared Variable Types (-u) 514

    Version Checking (-V) 515

    Interactive Debugging With dbx and Sun WorkShop 515

    f77: Viewing Compiler Listing Diagnostics 516

    6. Floating-Point Arithmetic 61

    Introduction 61

    IEEE Floating-Point Arithmetic 62

    -ftrap=mode Compiler Options 63

    Floating-Point Exceptions and Fortran 63

    Contents v

  • Handling Exceptions 64

    Trapping a Floating-Point Exception 64

    SPARC: Nonstandard Arithmetic 64

    IEEE Routines 65

    Flags and ieee_flags() 66

    IEEE Extreme Value Functions 610

    Exception Handlers and ieee_handler() 611

    Retrospective Summary 615

    Debugging IEEE Exceptions 616

    Further Numerical Adventures 617

    Avoiding Simple Underflow 618

    Continuing With the Wrong Answer 619

    SPARC: Excessive Underflow 619

    7. Porting 71

    Time and Date Functions 71

    Formats 74

    Carriage-Control 74

    Working With Files 75

    Porting From Scientific Mainframes 75

    Data Representation 76

    Hollerith Data 77

    Nonstandard Coding Practices 79

    Uninitialized Variables 79

    Aliasing Across Calls 710

    Obscure Optimizations 710

    Troubleshooting 711

    Results Are Close, but Not Close Enough 712

    Program Fails Without Warning 713

    vi Fortran Programming Guide Revision A, February 1999

  • 8. Performance Profiling 81

    The time Command 81

    Multiprocessor Interpretation of time Output 82

    The gprof Profiling Command 82

    Overhead Considerations 85

    The tcov Profiling Command 85

    Old Style tcov Coverage Analysis 85

    New Style Enhanced tcov Analysis 86

    f77 I/O Profiling 87

    9. Performance and Optimization 91

    Choice of Compiler Options 91

    Performance Option Reference 92

    Other Performance Strategies 97

    Using Optimized Libraries 97

    Eliminating Performance Inhibitors 98

    Further Reading 99

    10. SPARC: Parallelization 101

    Essential Concepts 101

    SpeedupsWhat to Expect 102

    Steps to Parallelizing a Program 103

    Data Dependency Issues 103

    Parallel Options and Directives Summary 105

    Number of Processors 106

    Stacks, Stack Sizes, and Paralleli


View more >