Mipsprotm Fortran 77 Programmer's Guide
Total Page:16
File Type:pdf, Size:1020Kb
MIPSproTM Fortran 77 Programmer’s Guide 007–2361–009 COPYRIGHT Copyright © 1994, 1999, 2002 - 2003 Silicon Graphics, Inc. All rights reserved; provided portions may be copyright in third parties, as indicated elsewhere herein. No permission is granted to copy, distribute, or create derivative works from the contents of this electronic documentation in any manner, in whole or in part, without the prior written permission of Silicon Graphics, Inc. LIMITED RIGHTS LEGEND The electronic (software) version of this document was developed at private expense; if acquired under an agreement with the USA government or any contractor thereto, it is acquired as "commercial computer software" subject to the provisions of its applicable license agreement, as specified in (a) 48 CFR 12.212 of the FAR; or, if acquired for Department of Defense units, (b) 48 CFR 227-7202 of the DoD FAR Supplement; or sections succeeding thereto. Contractor/manufacturer is Silicon Graphics, Inc., 1600 Amphitheatre Pkwy 2E, Mountain View, CA 94043-1351. TRADEMARKS AND ATTRIBUTIONS Silicon Graphics, SGI, the Silicon Graphics logo, IRIS, IRIX, and Origin are registered trademarks and OpenMP, IRIS 4D, IRIS Power Series, and POWER CHALLENGE are trademarks of Silicon Graphics, Inc. in the United States and other countries worldwide. MIPS, R4000, R4400, R8000, R10000 are registered trademarks and MIPSpro and R12000 are trademarks of MIPS Technologies, Inc. MIPSpro is used under license by Silicon Graphics, Inc. UNIX is a registered trademark of the Open Group in the United States and other countries. VMS and VAX are trademarks of Compaq. Portions of this product and document are derived from material copyrighted by Kuck and Associates, Inc. Portions of this product/publication may have been derived from the OpenMP Language Application Program Interface Specification. Cover Design By Sarah Bolles, Sarah Bolles Design, and Danny Galgani, SGI Technical Publications. Record of Revision Version Description 7.3 March 1999. Printing to support the MIPSpro 7.3 release. 008 September 2002 Revision to support the MIPSpro 7.4 release which runs on IRIX version 6.5 and later. 009 June 2003 Revision to support the MIPSpro 7.4.1m release which runs on IRIX version 6.5 and later. 007–2361–009 iii Contents About This Guide ..................... xix Related Compiler Publications ................... xix Compiler Messages ....................... xx Compiler Man Pages . ................... xx Obtaining Publications . ................... xx Conventions . ........................ xxi Reader Comments ....................... xxi 1. Compiling, Linking, and Running Programs .......... 1 Compiling and Linking . ................... 1 Compilation ........................ 2 Compiling in C/C++ . ................... 3 Linking Objects ....................... 4 Specifying Link Libraries . ................... 6 Compiler Options: an Overview ................... 6 Compiling Simple Programs ................... 7 Using a Defaults Specification File . .............. 7 Specifying Features to the Compiler .................. 8 Specifying the Buffer Size for Direct Unformatted I/O . ......... 14 Object File Tools ........................ 14 Archiver . ........................ 15 Run-Time Considerations . ................... 15 Invoking a Program . ................... 16 Maximum Memory Allocations .................. 16 007–2361–009 v Contents Arrays Larger Than 2 Gigabytes . .............. 16 Local Variable (Stack Frame) Sizes . .............. 18 Static and Common Sizes ................... 18 Pointer-based Memory . ................... 19 File Formats ........................ 19 Preconnected Files . ................... 20 File Positions ........................ 20 Unknown File Status . ................... 20 Quad-Precision Operations ................... 21 Run-Time Error Handling . ................... 21 Floating Point Exceptions . ................... 21 2. Data Types and Mapping ................. 23 Alignment, Size, and Value Ranges .................. 23 Access of Misaligned Data . ................... 27 Accessing Small Amounts of Misaligned Data .............. 27 Accessing Misaligned Data Without Modifying Source Code ......... 28 3. Fortran Program Interfaces ................. 29 Subprogram Names . ................... 29 Mixed-Case Names . ................... 30 Preventing a Suffix Underscore with $ . .............. 30 Naming Fortran Subprograms from C . .............. 31 Naming C Functions from Fortran . .............. 31 Verifying Spelling Using nm ................... 31 Correspondence of Fortran and C Data Types . .............. 32 Corresponding Scalar Types ................... 32 Corresponding Character Types .................. 33 vi 007–2361–009 MIPSproTM Fortran 77 Programmer’s Guide Corresponding Array Elements .................. 33 Passing Subprogram Parameters ................... 35 Normal Treatment of Parameters .................. 35 Calling Fortran from C . ................... 36 Calling Fortran Subroutines from C . .............. 36 Alternate Subroutine Returns .................. 38 Calling Fortran Functions from C . .............. 39 Calling C from Fortran . ................... 41 Normal Calls to C Functions ................... 41 Using Fortran COMMON in C Code . .............. 43 Using Fortran Arrays in C Code .................. 44 Calls to C Using LOC%, REF% and VAL% ............... 44 Using %VAL ....................... 45 Using %REF ....................... 46 Using %LOC ....................... 46 Making C Wrappers with mkf2c .................. 46 Parameter Assumptions by mkf2c ................ 47 Character String Treatment by mkf2c ............... 48 Restrictions of mkf2c .................... 49 Using mkf2c and extcentry .................. 50 Makefile Considerations . ................... 51 4. System Functions and Subroutines . .......... 53 Library Functions ....................... 53 Extended Intrinsic Subroutines ................... 60 DATE .......................... 60 IDATE .......................... 61 ERRSNS ......................... 61 007–2361–009 vii Contents EXIT .......................... 62 TIME .......................... 62 MVBITS ......................... 62 Extended Intrinsic Functions . ................... 63 SECNDS ......................... 63 RAN ........................... 63 5. OpenMP Fortran API Multiprocessing Directives . ...... 65 Using Directives ........................ 65 Conditional Compilation . ................... 66 Parallel Region Constructs . ................... 66 Work-sharing Constructs . ................... 67 Combined Parallel Work-sharing Constructs . .............. 68 Synchronization Constructs . ................... 69 Data Environment Constructs ................... 70 Directive Binding ....................... 71 Directive Nesting ....................... 72 6. Compiling and Debugging Parallel Fortran . .......... 75 Compiling and Running Parallel Fortran . .............. 75 Using the -static Option ................... 75 Examples of Compiling . ................... 76 Profiling a Parallel Fortran Program .................. 77 Debugging Parallel Fortran . ................... 77 General Debugging Hints . ................... 77 EQUIVALENCE Statements and Storage of Local Variables . ......... 80 Appendix A. Run-Time Error Messages . .......... 81 viii 007–2361–009 MIPSproTM Fortran 77 Programmer’s Guide Appendix B. Multiprocessing Directives (Outmoded) . ...... 89 Overview . ........................ 90 Parallel Loops ........................ 90 Writing Parallel Fortran . ................... 91 C$DOACROSS ....................... 91 IF .......................... 92 LOCAL, SHARE, LASTLOCAL .................. 92 REDUCTION ....................... 93 CHUNK, MP_SCHEDTYPE .................... 94 C$& ........................... 97 C$ ........................... 97 C$MP_SCHEDTYPE and C$CHUNK .................. 98 C$COPYIN ......................... 98 Nesting C$DOACROSS ..................... 98 Analyzing Data Dependencies for Multiprocessing ............. 99 Breaking Data Dependencies . ................... 104 Work Quantum ........................ 109 Cache Effects . ........................ 111 Performing a Matrix Multiply ................... 111 Understanding Trade-Offs . ................... 112 Load Balancing ....................... 113 Reorganizing Common Blocks To Improve Cache Behavior . ......... 115 Advanced Features ....................... 115 mp_block and mp_unblock ................... 116 mp_setup, mp_create, and mp_destroy .............. 116 mp_blocktime ....................... 116 mp_numthreads, mp_set_numthreads ............... 117 mp_suggested_numthreads .................. 117 007–2361–009 ix Contents mp_my_threadnum ...................... 118 mp_setlock, mp_unsetlock, mp_barrier .............. 118 Environment Variables for Origin Systems . .............. 118 Using the MP_SET_NUMTHREADS, MP_BLOCKTIME, MP_SETUP environment variables . 119 Setting the _DSM_WAIT Environment Variable ............. 119 Using Dynamic Threads ................... 120 Controlling the Stacksize of Slave Processes ............. 120 Specifying Page Sizes for Stack, Data, and Text . ......... 121 Specifying Run-Time Scheduling . .............. 121 Specifying Gang Scheduling .................. 121 Local COMMON Blocks . ................... 121 Compatibility With sproc .................... 122 DOACROSS Implementation . ................... 123 Loop Transformation . ................... 123 Executing Spooled Routines ................... 124 PCF Directives ........................ 125 Parallel