Home
Fortran 90 User's Guide - Space monitoring data center
Contents
1. E wH JU UHH Jj z iw 212 Fortran 90 User s Guide Index Symbols DIRS in directives 180 MICS in directives 183 M files 23 usr ccs 1lib error to specify it 22 usr 1lib error to specify it 22 Numerics 132 column lines e 17 A a out file 10 abrupt underflow 112 access named files 42 unnamed files 43 accrued exceptions do not warn 106 actions actions options sorted by action 13 and what options invoke them 13 frequently used actions options 13 addenda for manuals read me file xxi agreement across routines Xlist 69 alias 50 many options short commands 33 align data types 125 126 double word dalign 17 errors across routines Xlist 69 allocated array 91 ANSI conformance check Xlist 70 X3 198 1992 Fortran standard 163 ansi extensions 15 AnswerBook documents in xix ar 58 create static library 60 arithmetic nonstandard 111 standard 111 array allocated 91 bounds exceeding 81 C FORTRAN differences 130 dbx 92 93 slices in dbx 93 asa FORTRAN print 3 audience xvii 213 214 automatic parallelization definition 197 exceptions 198 overview 190 usage 195 what the compiler does 196 automatic variables 29 autovectorizing compiler comparison 192 B Bdynamic 15 62 best floating point native 23 performance 25 binding dynamic 15 17 62 static 15 62 boldface font con
2. What You Do page 201 What the Compiler Does page 202 Parallel Directives page 203 DOALL Loops page 206 Exceptions for Explicit Parallelizing page 208 Risk with Explicit Nondeterministic Results page 209 Signals page 211 This appendix shows an advanced way to parallelize programs for multiple processors This is called explicit parallelizing It may be faster with some risk of incorrect results This is a how to guide To parallelize explicit loops do the following Analyze loops to detect those with no order dependence This requires far more analysis and sophistication than using automatic parallelization Insert a special directive just before each loop that you want parallelized Use the explicitpar option on the 90 command line Check results very carefully 201 lll v The special directive is described later but first it is illustrated in the following example Example Parallelize the DO 1 1 N loop explicitly MIC DOALL IMIC amp SHARED a b c n The MIC DOALL is IMICS amp PRIVATE i explained later DO i 1 n This loop gets parallelized a i Dia Se a END DO DO k 1 m This loop does not get parallelized x k y k z k END DO demo 90 explicitpar t1 f90 D 2 What the Compiler Does For explicit parallelization the compiler parallelizes those loops that you have specified This is similar to the t
3. This opens a file for direct access formatted I O with a record length of 20 characters then reads the thirteenth record and converts it according to the format 110 F10 3 File System and File I O 45 E 46 4 9 Internal Files An internal file is a variable of type default character This means that an internal file can be one of the following Scalar Array Element of an array Section of an array Component of a structure Substring To use an internal file give the name or the designator of the character variable in place of the unit number This is called I O because you use READ and WRITE statements to deal with internal files although I O is not a precise term to use here 90 extends what can be an internal file if you are reading from an internal file the internal file can be a literal constant character string Rules and Restrictions The variable must not be an array section with a vector subscript e For a constant there is a single record in the file For a variable or substring there is a single record in the file For an array each array element is a record Each sequential READ or WRITE starts at the beginning of an internal file Fortran 90 User s Guide Example Scalar for internal file sequential formatted read demo cat internl f90 CHARACTER x 80 WRITE Enter two numbers READ A x Readsa character string from standard
4. SAVELAST MAXCPUS n At runtime if the expression expr is true use multiprocessing If this parameter is not specified and the loop was not called from a parallel region then use multiprocessing Share the variables v1 72 between parallel processes That is they are accessible to all the tasks Do not share the variables x1 x2 between parallel processes That is each task has its own private copy of these variables Save the values of private variables from the last DO iteration Use no more than n CPUs Table D 2 DOALL Scheduling Parameters Parameter Action SINGLE Distribute one iteration to each available processor CHUNKSIZE n NUMCHUNKS m GUIDED VECTOR Distribute n iterations to each available processor e n is an expression For best performance n must be an integer constant Example With 100 iterations and CHUNKSIZE 4 distribute 4 iterations to each CPU If there are i iterations then distribute i m iterations to each available processor There can be one smaller residual chunk m is an expression For best performance m must be an integer constant Example With 100 iterations and NUMCHUNKS 4 distribute 25 iterations to each CPU Distribute the iterations by use of guided self scheduling This minimizes synchronization overhead with acceptable dynamic load balancing Distribute 64 iterations to each available processor If
5. 127 Character Strings and Order os cx genes cee m cce 129 Array Indexing and Order iios eres 130 Libraries and Linking with the 90 Command 131 File Descriptors and Stdioc sis cxx pae ex ri aae sity 132 File Parnussiofis 2083 nse a axecesuips XV rape ev edd 133 94 Fortran Calls C 4442s rr Ree EROR ERERERE S Yes 134 Arguments Passed by Reference 90 Calls C 134 Arguments Passed by Value 90 Calls C 141 Function Return Values 90 Calls C 141 Labeled Common 90 Calls C eue m e 147 Alternate Returns 90 Calls C N A esses 148 9 5 C Calls Fortran ub Ex oe ee PR CES ERREUR e dien 149 Arguments Passed by Reference C Calls 90 149 Arguments Passed by Value C Calls 90 N A 155 Function Return Values C Calls 90 155 Labeled Common C Calls E90 decer rwr 160 Alternate Returns C Calls 90 161 Contents ix A Features and Differences 0 cc cece eee e eee eee 163 Ae ucc CPP 163 A 2 Extensions eee 164 Tabs in the SOULE LL LU VRVERE REISEN XE oriri PY de ERA 164 Continuation Line Limits ux pr x Eu RR RREPEEEEE 165 Fixed Form Source of 96 Characters 005 165 Dit ctiVes ur ERE EEG Rees d ue CES ERE EE Es 165 Source Form Assumed sis epe 6 Lex EEXERERRRRECCHERERRS 165 boblean IVpOL ai nna ow dba not S Cais eS L
6. For function return values a Fortran function of type BYTE INTEGER LOGICAL DOUBLE PRECISION or REAL 16 quadruple precision is equivalent to a C function that returns the corresponding type INTEGER Function Return Value C Calls 90 Example A Fortran function with an INTEGER function return value RetInt f90 FUNCTION RetInt k INTEGER k RetInt RetInt k 1 END FUNCTION RetInt Example A C program uses a Fortran function that returns an INTEGER RetIntmain c int retint int Declare function interface void main int k m k 8 m 100 retint_ amp k printf Sd d n k m C Fortran Interface 155 lll Ko Compile Link Execute RetFloat f90 RetFloatmain c Compile Link Execute 156 Example Fortran and C with an INTEGER function return value demo f90 c RetInt f demo cc c RetIntmain c demoS 90 RetInt o RetIntmain o demo a out 8 109 demos M REAL Function Return Value C Calls 90 Example Fortran returns a REAL to a C float FUNCTION RetFloat x REAL x RetFloat RetFloat x 1 0 END FUNCTION RetFloat Example A C program uses a Fortran function that returns a REAL float retfloat float Declare function interface main float r 8 r 8 0 s 100 0 retfloat_ amp r printf 8 6f
7. float r4 90 4 byte REAL double d8 90 8 byte DOUBLE PRECISION extern simref int int float double simref amp b4 amp i4 amp r4 amp d8 printf 080 d 3 1f 3 1f n b4 i4 r4 d8 Example Simple arguments C and Fortran Compile Link Execute demo f90 c SimRef f90 demo cc c SimRefmain c demo 90 SimRef o SimRefmain o lt This does the linking demo a out 00000001 9 9 9 9 9 demos M C Fortran Interface 149 lll Ko CmplxRef f90 CmplxRefmain c Compile Link Execute 150 Complex Arguments Passed by Reference C Calls 90 Example Complex arguments Fortran 90 expects a simple structure SUBROUTINE CmplxRef w z f90 gets passed complex arguments from C C calls f90 INTEGER PARAMETER doublecomplex 8 COMPLEX w COMPLEX KIND doublecomplex z w 6 7 z 8 9 END SUBROUTINE CmplxRef Example Complex arguments C passes pointers to structures main struct complex float r i struct complex dl struct complex w amp dl struct dcomplex double r i struct dcomplex d2 struct dcomplex z amp d2 extern cmplxref struct complex struct dcomplex cmplxref w z wand zare pointers printf 3 1f 3 1f n 3 1f 3 1f Mn W r w gt i z r z gt i Example
8. Optimization and Cray Pointers For purposes of optimization 90 assumes the storage of a pointee is never overlaid on the storage of another variable it assumes that a pointee is not associated with another variable Such association could occur in either of two ways A Cray pointer has two pointees or Two Cray pointers are given the same value Note You are responsible for preventing such association These kinds of association are sometimes done deliberately such as for equivalencing arrays but then results can differ depending on whether optimization is turned on or off Example b and c have the same pointer POINTER p b p c REAL x b c p LOC x b 1 0 c 2 0 PRINT b Above because b and c have the same pointer assigning 2 0 to c gives the same value to b Therefore b prints out as 2 0 even though it was assigned 1 0 Features and Differences 175 176 Cray Character Pointers If a pointee is declared as a character type its Cray pointer is a Cray character pointer Purpose of Cray Character Pointers A Cray character pointer is a special data type that allows 90 to maintain character strings by keeping track of the following Byte address of the first character of the string Length Offset An assignment to a Cray character pointer alters all three That is when you change what it points to all three change Declaration of Cray Characte
9. f makefile1 184 03 01 OBJ pattern o computepts o startupcore o pattern OBJ 90 S OBJ Fxview o pattern pattern o pattern f90 commonblock computepts o computepts f90 commonblock startupcore o startupcore f90 Checking Files Out and In Out Once your source code is under SCCS control you use SCCS for two main tasks to check out a file so that you can edit it and to check in a file you are done editing A file is checked out using the SCCS edit command Example Check out a file using SCCS demo sccs edit computepts f90 demos In this example SCCS makes a writable copy of computepts 90 in the current directory and records your login name Other users cannot check it out while you have it checked out but they can find who checked out which files In Check in the file with the sccs delget command when you have completed your current editing Example Check in a file using SCCS demo sccs delget computepts f90 demos M This causes the SCCS system to do the following 1 Make sure that you are the user who checked it out compares login names 2 Solicit a descriptive comment from the user on the changes 3 Make a record of what was changed in this editing session 4 Delete the writable copy of computepts 90 from the current directory 5 Replace it by a read only copy with the SCCS keywords expanded Fortran 90 User s Guide O1 lll The SCCS comma
10. Inserting SCCS ID Keywords Some people put one or more SCCS ID keywords into each file but that is optional These will later be filled in with a version number each time the file is checked in with a get or delget SCCS command There are three likely places to put such strings Comment lines parameter statements nitialized data The advantage of the last is that the version information appears in the compiled object program and can be printed using the what command Included header files containing only parameter and data definition statements do not generate any initialized data so the keywords for those files usually are put in comments or in parameter statements Finally in the case of some files like ASCII data files or make files the source is all there is so the SCCS information can go in comments if anywhere Identify the make file with a make comment containing the keywords T SLSOMS SI SE oo The source files startupcore f90 and computepts f90and pattern f90 can be identified to SCCS by initialized data of the form CHARACTER LEN 50 sccsid Z M I E n Creating SCCS Files Example Put files under control of SCCS with an SCCS create command demo sccs create makefile commonblock startupcore f90 computepts f90 pattern f90 demos M Program Development 53 54 The make file looks like this after SCCS keyword expansion
11. reduction conflicts with g Before you use reduction see Appendix C iMPact Multiple Processors and Appendix D iMPact Automatic Parallelization Reduction works only during parallelization If you specify reduction without parallel the compiler does no reduction If you have a directive explicitly specifying a loop then there will be no reduction for that loop Example Automatically parallelize with reduction demo 90 parallel reduction any f90 Library paths store paths into object file While building the executable file store a list of library search paths into it e Is is a colon separated list of directories for library search paths The blank between R and Is is optional Multiple instances of this option are concatenated together with each list being separated by a colon How this list is used The list will be used at runtime by the runtime linker ld so At runtime dynamic libraries in the listed paths are scanned to satisfy any unresolved references Why You would want to use it Use this option to let your users run your executables without a special path option to find your dynamic libraries LD RUN PATHand R For 90 R and the environment variable LD RUN PATH are not identical for the runtime linker 1d so they are Fortran 90 User s Guide Qo lll S stackvar If you build a out with R then only the paths of R are put in a out So R i
12. PROGRAM StructureRef TYPE IntChr INTEGER n CHARACTER str 15 Define the derived type IntChr END TYPE IntChr TYPE IntChr vls Make vls an item of type IntChr vis n 40 Initialize components vis str 123456789012345 CALL StruRef vls Change components WRITE 1 vls n vls str Print components i FORMAT n E I2 w Str t A wee END PROGRAM StructureRef Example A structure argument Fortran 90 and C demo cc c StruRef c demo 90 StruRef o StruRefmain f90 demo a out n 5 str oyvay6789012345 demos M Pointer Arguments Passed by Reference 90 Calls C N A These two kinds of pointers are not compatible Fortran 90 User s Guide Ko lll Arguments Passed by Value 90 Calls C In general if an existing C function passes arguments by value using no pointers then Fortran 90 cannot use that function Function Return Values 90 Calls C In general for a C function return value If it has no pointer then Fortran 90 can use it as is If it returns a pointer then Fortran 90 needs an interface block See Pointer to a REAL Function Return Value f90 Calls C on page 143 INTEGER Function Return Value 90 Calls C Example A C function with an int function return value not a pointer RetInt c int retint_ int r int s S r Stt return s Example A Fortran progra
13. The above command places the executable code in the maven file Fortran 90 User s Guide No lll Either way run the program by typing the name of the executable file demo maven Real programmers hack Fortran 90 demos M At this point read Chapter 3 Using the Compiler for the compiler options and the summary of performance optimization If you are not familiar with a UNIX file system read Chapter 4 File System and File I O or refer to any introductory UNIX book Getting Started Z Fortran 90 User s Guide Using the Compiler 3 This chapter is organized into the following sections Compile Command page 9 Compiler Options page 12 Miscellaneous Tips page 33 3 1 Compile Command The syntax of a simple compiler command is as follows Before you use this release of 90 it must be installed and 90 options sfn licensed Read Installing a Developer Products on where sfn is a Fortran 90 source file name and options is one or more of the olaris compiler options Example A compile command with two files demo f90 growth f90 fft f90 Example A compile command same files with some options demo f90 g P growth f90 fft f90 10 A more general form of the compiler command is as follows 90 options fn m 1x The fn is a file name not necessarily of a Fortran 90 source file See Command line File Names on
14. nonstop 19 dynamic binding Bdynamic 15 62 dy 17 62 executable file name the o outfil 25 explicit parallelization explicitpar 18 extend lines to 132 columns e 17 fast execution fast 19 feedback to Sun help 20 fixed form source ixed 19 floating point best native 23 free form source free 19 generate a CIF file db 17 generate code for generic SPARC cg89 16 SPARC V8 cg92 16 generate double load store instructions dalign 17 global program checking xX1ist 32 library add to search path for Ldir 22 build shared library G 20 name a shared dynamic hname 20 license do not queue request noqueue 24 information xlicinfo 31 link with library x 1x 21 list of options help 20 multi thread safe libraries mt 22 no automatic libraries nolib 24 no run path norunpath 24 optimize object code On 25 parallelize parallel 26 pass option to other program Qoption 27 paths store into object file R Is 28 Index compile action continued print name of each pass as compiler executes v 30 version id of each pass as compiler executes V 30 profile by procedure p 26 procedure pg 27 reduction analyze loops for reduction reduction 27 report execution times for compilation passes time 30 reset fast so that it does not use xlibmopt 31 set directory for temporary files temp dir 30 INCLUDE path Ipath 21 module files path Mdir 23
15. u v W CALL UseCom u v w WRITE u v w END PROGRAM TryUseCom Example Fortran and C share a labeled common Compile Link Execute demo cc c CUseCom c demo 90 CUseCom o FUseCommain f90 demo a out 7 0000000 8 0000000 9 0000000 1 0000000 2 0000000 3 0000000 demos M Note Any of the options that change size or alignment or any equivalences that change alignment might invalidate such sharing C Fortran Interface 147 148 Alternate Returns 90 Calls C N A C does not have an alternate return The work around is to pass an argument and branch on that Fortran 90 User s Guide Ko lll 9 5 C Calls Fortran Arguments Passed by Reference C Calls 90 Simple Arguments Passed by Reference C Calls 90 Example Simple arguments Fortran arguments by reference SimRef 90 SUBROUTINE SimRef b4 i4 r4 d8 90 gets passed some simple types by reference from C C calls f90 LOGICAL b4 Default kind is 4 byte INTEGER i4 Default kind is 4 byte REAL r4 Default kind is 4 byte DOUBLE PRECISION d8 This is 8 byte b4 TRUE i4 9 r4 90 9 de 9 9 END SUBROUTINE SimRef Example Simple arguments C passes the address of each SimRefmain c void main Simple types passed by reference to f90 C calls f90 int b4 90 4 byte LOGICAL int i4 90 4 byte INTEGER
16. 9 9f d8 9 9F Example Simple arguments Fortran default way PROGRAM SimpleRef Pass some simple types by reference to C f90 calls C LOGICAL b4 Default kind is 4 byte INTEGER i4 Default kind is 4 byte REAL r4 Default kind is 4 byte DOUBLE PRECISION d8 This is 8 byte CALL SimRef b4 i4 r4 d8 WRITE L4 I4 F6 1 F6 1 b4 i4 r4 d8 END PROGRAM SimpleRef Example Simple arguments with Fortran and C demo cc c SimRef c demo f90 SimRef o SimRefmain f90 demo a out T 9 9 9 9279 demos M Fortran 90 User s Guide CmplxRef c CmplxRefmain f90 Compile Link Execute Complex Arguments Passed by Reference 90 Calls C Example Complex arguments C function pointers to structures void cmplxref_ struct complex float r i w struct dcomplex double r i z w gt r 6 w gt i 7 zZz gt r 8 z gt i 9 Example Complex arguments Fortran main program calls C function PROGRAM ComplexRef Pass complex types by reference to C f90 calls C INTEGER PARAMETER doublecomplex 8 COMPLEX w COMPLEX KIND doublecomplex z CALL CmplxRef w z WRITE w WRITE z END PROGRAM ComplexRef Example Complex arguments demo cc c CmplxRef c demo 90 CmplxRef o CmplxRefmain 90 demo a out 6 00
17. Add dir at the start of the list of object library search directories While building the executable file 1d 1 searches dir for archive libraries a files and shared libraries so files A space between L and dir is optional The directory dir is not built in to the a out file See also Ix 1d searches dir before the default directories See Building Executables ld Search order on page 66 For the relative order between LD_LIBRARY_PATH and 1dir see 1d 1 Example Use 1dir to specify a library search directory demo 90 Ldirl any f90 Example Use Ldir again to add more directories demo 90 Ldirl Ldir2 any f90 Restrictions No L usr lib Do not use 1dir to specify usr 1ib It is searched by default Including it here may prevent using the unbundled 1ibm No L usr ccs 1ib In Solaris 2 x do not use 1dir to specify usr ccs 1ib It is searched by default Including it here may prevent using the unbundled 1ibm Multithread safe libraries use for low level threads Use multithread safe libraries If you do your own low level thread management this helps prevent conflicts between threads Use mt if you mix C and Fortran 90 and you do your own thread management of multithread C coding using the 1ibthread primitives Before you use your own multi threaded coding read the Guide to Multi Thread Programming Fortran 90 User s Guide 3 Mdir native Th
18. Co lll The IEEE values available are listed in the table below Table 8 2 Functions for Using IEEE Values IEEE Value Double Precision Single Precision infinity d infinity r infinity quiet NaN d quiet nan r quiet nan signaling NaN d signaling nan r signaling nan min normal d min normal r min normal min subnormal d min subnormal r min subnormal max subnormal d max subnormal r max subnormal max normal d max normal r max normal For the two NaN functions you can assign and or print out the values but comparisons using either of them always yield false To determine whether some value is a NaN use the function ir isnan r or id_isnan d see libm double 3f libm single 3f and ieee functions 3m Exception Handlers and 3eee handler A floating point user may need to know the following about IEEE exceptions What happens when an exception occurs How to use ieee handler to establish a function as a signal handler How to write a function that can be used as a signal handler How to locate the exception Where did it occur To get information about an exception Generate a signal for a floating point exception The official UNIX name for signal is floating point exception is SIGFPE To generate a SIGFPE establish a signal handler The default behavior on po SPARC hardware systems is do not generate a SIGFPE Establishing a Signal Handler Function w
19. For rounding IEEE arithmetic defaults to doing the intuitive thing and closely corresponds with old arithmetic IEEE offers choices which the expert can use to good effect while old arithmetic did it just one way What happens when we multiply two very large numbers with the same sign Large numbers of different signs Divide by zero Divide zero by zero In old arithmetic all these cases are the same The program aborts on the spot or in some very old machines the computation proceeds but with garbage IEEE provides choices The default solution is to produce the following big big Inf big big Inf num 0 0 Inf amp Where num gt 0 0 num 0 0 Inf Where num lt 0 0 0 0 0 0 NaN Not a Number Above Inf Inf and NaN are just introduced intuitively More later Also an exception of one of the following kinds is raised Invalid Examples that yield invalid are 0 0 0 0 sqrt 1 0 log 37 8 Division by zero Examples that yield division by zero are 9 9 0 0 1 0 0 0 Overflow Example with overflow MAXDOUBLE 0 0000000000001e308 Underflow Example that yields underflow MINDOUBLE MINDOUBLE Inexact Examples that yield inexact are 2 0 3 0 log 1 1 read in 0 1 no exact representation in binary for the precision involved There are various reasons to care about how all this works If you don t understand what you are using you may not lik
20. usr ccs lib usr lib The linker also searches in directories specified in LD_LIBRARY_PATH Summary of Environment Variables for Paths LD RUN PATH Value matters only when executable is created LD_LIBRARY_PATH Value matters when executable is created or run Fortran 90 User s Guide 5 lll Build Paths and Run Paths When you run the executable file the runtime linker locates the shared libraries again The linker searches in any directories specified in the LD_LIBRARY_PATH environment variable and that variable can change even after the executable file has been created Therefore it doesn t matter where the libraries were when the executable was created Finding Built in Paths Use dump to check which paths were built in when the executable was created Example Find which directories were built in to a out demoSdump Lv a out grep RPATH Libraries 67 68 Fortran 90 User s Guide Debugging N Ii This chapter is organized into the following sections Global Program Checking Xlist page 69 The dbx Debugger page 77 7 1 Global Program Checking X1ist XlistE Purpose Checking across routines helps find various kinds of bugs With Xlist 90 reports errors of alignment agreement in number and type for arguments common blocks parameters plus many other kinds of errors details follow It also mak
21. 9 explicit parallelization 201 V V 30 v 30 variable unused checking X1ist 70 used but unset checking X1ist 70 vasty deep 119 verify agreement across routines Xlist 69 version id of each compiler pass 30 vi 2 W w 31 watchpoints dbx 97 where exception occurred by line number 83 execution stopped 84 wimp 77 interface to dbx 3 96 X xemacs 2 xlibmopt use fast math routines 31 xlicinfo 31 Xlist 71 a la carte options 73 combination special 73 defaults 71 display directly to terminal 71 errors and cross reference XlistX 74 listing XlistL 74 sample usage 72 suboptions 73 details 75 summary 32 74 list global program checking 32 69 listE 74 75 listerr 75 listI 75 listln 76 listo 76 listw 76 listwar 76 listXx 76 xnolib 31 32 xnolibmopt 31 xOn 32 xpg 32 Z zero division by 101 Index 225 226 Fortran 90 User s Guide Join the SunPro SIG Today Sun Programmer Special Interest Group The benefits are SIGnificant At SunSoft in the Software Development Products business of Sun Microsystems our goal is to meet the needs of professional software developers by providing the most useful line of software development products for the Solaris platform We ve also recently formed a special interest group SunPro SIG designed to provide a worldwide forum for exchanging software development information This is
22. Complex arguments C and Fortran demo 90 c CmplxRef f90 demo cc c CmplxRefmain c demo 90 CmplxRef o CmplxRefmain o demo a out 6 0 7 0 8 0 9 0 demos M lt This does the linking Fortran 90 User s Guide Ko lll StrRefU f90 StrRefUmain c Compile Link Execute Character Arguments Passed by Reference C Calls 90 Passing strings between C and Fortran is nonstandard It is not encouraged For C calling Fortran 90 if C passes a character string argument C must pass the extra hidden argument because Fortran 90 expects requires it For the detailed requirements of passing string arguments see Character Strings and Order on page 129 Example Character arguments Fortran uses extra arguments from C SUBROUTINE StrRefU a s Character arguments use extra args passed from C CHARACTER a s a abcdefghi char 0 s abcdefghijklmnopqrstuvwxyz char 0 END SUBROUTINE StrRefU Example Character arguments C passes extra arguments void strrefu char char long long Declarefcn interface void main Pass string arguments to f90 with extra args char s10 10 s80 80 Provide memory for the strings long L10 L80 L10 10 Initialize extra args L80 80 strrefu_ s10 s80 L10 L80 Cstrings pass by reference printf s10 2 s Mn s80 s n s10 s80 Examp
23. In linking static libraries order really matters The linker processes its input files in the order that they appear on the command line that is left to right When the linker decides whether or not a library element is to be linked its decision is based only on the relocatable modules it has already processed You can use lorder and tsort to order static libraries Example Order matters If a Fortran 90 program is in two files main f90 and graf f90 and only the latter accesses the Xview library it is an error to reference that library before gra 90 or graf o Wrong demo 90 main f lFxview graf f90 o myprog Right demo f 90 main f graf f90 lFxview o myprog Sample Creation of a Static Library Base source of four routines for example on creating static library demo cat one f UBROUTINE twice a r EAL a r a 2 0 D UBROUTINE half a r FAL a r a 2 0 zZ Z iwl UBROUTINE thrice a r EAL a r a 3 0 D UBROUTINE third a r EAL a r a 3 0 z E H B Q Ej H UU Q Bi H UU 0 B H DH z iw demo Libraries 59 lll Or Create the library Note that t wice is here Note that half third andthrice are not here good 60 Main program to use one of the routines for creating static library demo cat teslib f READ x CALL twice x z WRITE z END
24. StruRefmain c Compile Link Execute 154 Structure Arguments Passed by Reference C Calls 90 Example A Fortran 90 structure argument received from C SUBROUTINE StruRef n f90 gets passed structure argument from C C calls f90 TYPE IntReal INTEGER i REAL END TYPE IntReal TYPE IntReal n oo m n n oe K ll 8 9 10 END SUBROUTINE StruRef Example A C structure argument passed to Fortran 90 struct InRl Define a structure int i float r di void struref struct InRl Use structure define function void main struct InRl ir struct InRl n amp ir n i 21 Initialize the structure n gt r 2 0 struref n Uses Fortran routine here printf n gt i d n r 3 1f Mn n i n r Example A structure argument Fortran 90 and C demo 90 c StruRef f90 demo cc c StruRefmain c demo 90 StruRef o StruRefmain o demo a out n gt i 8 n r 9 0 demos M Fortran 90 User s Guide Ko lll Pointer Arguments Passed by Reference C Calls 90 N A These two kinds of pointers are not compatible Arguments Passed by Value C Calls 90 N A In general Fortran 90 cannot pass an argument by value whether Fortran 90 calls C or C calls Fortran 90 The work around is to pass all arguments by reference Function Return Values C Calls 90
25. and you need Bbinding then you need it in the link step also Compile only do not make a out do not execute Suppress linking by the loader Make a o file for each source file Do not make an executable file You can name a single object file explicitly using the o option Generate code to run on generic SPARC architecture Use a subset of the SPARC V8 instruction set With c989 and optimization the instructions are scheduled for faster executables on a generic SPARC machine Code compiled with c989 does run on cg92 hardware Generate code to run on SPARC V8 architecture Allow the use of the full SPARC V8 instruction set General Comments on cg89 and cg92 For SPARC systems the default code generation option is cg8 9 You can mix routines compiled c989 with routines compiled cg92 that is you can have both kinds in one executable Use fpversion 1 to tell which to use so the executables run faster cg89 or cg92 It may take about a minute to start the full report Fortran 90 User s Guide Qo lll dalign dryrun d yn e Allow 90 to use double load store Generate double load store instructions wherever possible for faster execution Using this option automatically triggers the f option which causes all double precision and quadruple precision data types both real and complex to be double aligned With dalign you may not get ANSI standard Fortran 90 alignment It is
26. debugging 113 explicit parallelization 208 handlers 102 107 ieee handler 107 location in dbx by line number 83 unrequited 111 executable file built in path to dynamic libraries 28 names in nm command 60 naming it 25 strip symbol table from s 29 execution time compilation passes 30 optimization 25 explicit parallelization 201 exceptions 208 overview 190 risk 209 explicitpar parallelize explicitly 18 extended lines e 17 syntax check X1ist 70 extensions non ANSI 15 to Fortran 90 164 F f align on 8 byte boundaries 19 90 command 9 fast fast execution 19 features debugger 96 Fortran 90 standard Sun FORTRAN 77 163 feedback file for email to Sun xxi feedback to Sun help 20 FFLAGS shorten command line 33 217 218 file a out 10 directory 37 executable 10 information files xxi internal 46 object 10 permissions C FORTRAN 133 pipe 41 redirection 40 split by fsplit 3 standard error 44 standard input 44 standard output 44 system 35 file names 42 passing to programs 43 recognized by the compiler 11 165 166 FIPS 69 1 xviii fixed form source 180 form source and tabs 164 FIXED directive 179 fixed form source 19 flags synonym for help 19 floating point exceptions nonstop 19 Goldberg paper xix hardware 33 option native 23 fnonstop no stop on floating point exceptions 19 font boldface xxii conventions xx
27. handler In your own exception handler routine you can specify actions and you can turn off messages with ieee flags by clearing exception status flags Fortran 90 User s Guide Co lll 6 6 Debugging IEEE Exceptions You may want to debug programs that have worrisome messages like this NOTE the following IEEE floating point arithmetic exceptions occurred and were never cleared Inexact Division by Zero Underflow Overflow Invalid Operand Sun s implementation of IEEE arithmetic is discussed in the Numerical Computation Guide You need to do these two things Establish a signal handler using ieee handler 3m This will cause a SIGFPE to be generated when a floating point exception occurs After you invoke dbx enter the catch FPE command This causes dbx to listen for any SIGFPE and halt when it hears one See the subsection on where the exception occurred in Section 7 2 The dbx Debugger for explicit examples 8 7 Guidelines To sum up SPARC arithmetic is a state of the art implementation of IEEE arithmetic optimized for the most common cases More problems can safely be solved in single precision due to the clever design of IEEE arithmetic To get the benefits of IEEE math for most applications if your program gets one of the common exceptions then you probably want to continue with a sensible result That is you do not want to use ieee han
28. in file WhereSEGV f90 4 a j i 10 dox quit demo 82 M Fortran 90 User s Guide number where a floating point exception occurred by using the ieee handler routine with either dbx or Debugger Exception Finding the Line Number Example Find where an exception occurred WhereExcept f90 EXTERNAL myhandler Main INTEGER ieeer ieee handler myhandler REAL r 14 2 s 0 0 F i r i _handler set all myhandler You can find the source code line PRINT r s END INTEGER FUNCTION myhandler sig code context Handler INTEGER sig code context 5 CALL abort END Note the catch FP dbx command demo 90 g WhereExcept 90 demo dbx a out EJ dox catch FPE dbx run Running a out in main at line 5 in file 5 PRINT r s dox M Where Reading symbolic information for a out signal FPE floating point divide by zero Except f Debugging 83 lll N Trace of Calls Sometimes a program stops with a core dump and you need to know the sequence of calls that brought it there a stack trace Example Show the sequence of calls starting at where the execution stopped ShowTrace f90isaprogram contrived to get a core dump a few levels deep in the call sequence to show a stack trace Execution stopped line 23 gt calcb called from calc line 9 gt calc called
29. o exampl You may need to put execution permissions on fex demoS chmod x fex 49 lll O1 Creating an Alias You can create an alias to do the same command demo alias fex f90 example f90 lFxview o example Using a Script or Alias Either way to recompile example f90 you type only fex demo fex Limitations With multiple source files forgetting one compile makes the objects inconsistent with the source Recompiling all files after every editing session wastes time since not every source file needs recompiling Forgetting an option or a library produces questionable executables 5 2 Program Builds with the make Program The make program recompiles only what needs recompiling and it uses only the options and libraries you want This section shows you how to use normal basic make and it provides a simple example For a summary see make 1 The make File The way you tell nake what files depend on other files and what processes to apply to which files is to put this information into a file called the make file in the directory where you are developing the program Example A program of four source files and a make file demo 1s makefile commonblock computepts 90 pattern f90 startupcore f90 demos M 50 Fortran 90 User s Guide O1 lll Assume both pattern 90 and computepts f90 do an include of commonblock and you wish to compile e
30. p b aq The above example declares Cray pointer p and its pointee b and Cray pointer q and its pointee c Example Declare a Cray pointer to an array POINTER ix x n O m The above example declares Cray pointer ix and its pointee x and declares x to be an array of dimensions n by m 1 Features and Differences 171 172 Purpose of Cray Pointers You can use pointers to access user managed storage by dynamically associating variables to particular locations in a block of storage Cray pointers allow accessing absolute memory locations Cray pointers do not provide convenient manipulation of linked lists because for optimization purposes it is assumed that no two pointers have the same value Cray Pointers and Fortran 90 Pointers Cray pointers are declared as follows POINTER pointer name pointee name array spec Fortran 90 pointers are declared as follows POINTER object name The two kinds of pointers cannot be mixed Features of Cray Pointers Whenever the pointee is referenced 90 uses the current value of the pointer as the address of the pointee The Cray pointer type statement declares both the pointer and the pointee The Cray pointer is of type Cray pointer The value of a Cray pointer occupies one storage unit Its range of values depends on the size of memory for the machine in use The Cray pointer can appear in a COMMON list or a
31. reference or change values of array variables for any other iteration Explicitly Parallelizing a DOALL Loop To explicitly parallelize a DOALL loop do the following Use the explicitpar option on the 90 command line Insert a DOALL parallel directive immediately before the loop including specifying each variable in the loop as shared or private 206 Fortran 90 User s Guide J lll Example Explicit DOALL loop demo cat t4 90 MICS DOALL IMICS amp SHARED a b c n IMICS amp PRIVATE i DO i l Parallelized a i b i c i END DO pO k 1 m Not parallelized x k x k z k k END DO demo 90 explicitpar t4 f90 Example Explicit DOALL some calls can make dependencies demo cat t5 f90 MICS DOALL IMICS amp SHARED a b n IMICS amp PRIVATE kb k t DO 40 kb 1 n Parallelized k n 1 kb b k b k a k k t b k CALL daxpy k 1 t a 1 k 1 b 1 1 40 CONTINUE demo 90 explicitpar t5 f90 The code is taken from linpack The subroutine daxpy was analyzed by some software engineer for iteration dependencies and found to not have any It is a nontrivial analysis This example is an instance where explicit parallelization is useful over automatic parallelization iMPact Explicit Parallelization 207 CALL ina Loop It is sometimes difficult to determine if there are any inter iteration dependenc
32. show commands dryrun 17 show compile flags 1ags 19 stack the local variables stackvar 29 static binding Bstatic 15 62 strip executable file of symbol table s 29 use fast math routines xlibmopt 31 verbose v 30 compiler command 9 frequently used options 13 passes 30 recognizes files by types 11 complete path name 38 consistent across routines Xlist 69 arguments commons parameters etc 32 compile and link 11 65 continuation lines 165 219 conventions in text xxii Courier font xxii Cray character pointer 176 pointer 171 pointer and Fortran 90 pointer 172 pointer and optimization 175 create library 59 SCCS files 53 cross reference table Xlist 32 76 current working directory 37 D dalign double word align 17 data inspection dbx 96 db CIF file 17 dbx 77 allocated arrays 91 arrays 92 catch FPE 82 83 commands 96 current procedure and file 96 debug 3 90 g 20 g 79 locate exception by line number 82 83 next 81 print 80 quit 79 run 80 set breakpoint 79 structures 85 86 87 88 89 debug 113 Fortran 90 User s Guide allocated arrays 91 arguments agree in number and type 69 array slices 93 arrays 92 checking across routines for global consistency 69 column print 93 common blocks agree in size and type 69 dbx 3 debugger 3 generic function 94 IEEE exceptions 113 locating exception by line number 83 optio
33. the dn option reduces one element of variability A Simple Dynamic Shared Library You can build a shared library from the relocatable object o files using the ld command Be careful to avoid any need for reentrant code since this release does not provide a way to guarantee that code is position independent Sample Create Example Create a dynamic shared library Start with the same files used for the static library example half f90 third f90 thrice f90 twice f90 Compile demo 90 c 90 demos M Example Create a dynamic shared library Link and specify the so file and the h to get a version number demo ld o libfac so 1 dy G h libfac so 1 o demos M The G tells the linker to build a shared library Note that there is no z text because that would generate warnings The z text warns you if it finds anything other than position independent code such as relocatable text It does not warn you if it finds writable data Bind Make the executable file a out demo 90 teslib f90 libfac so 1 demos M Libraries 63 64 Run demo a out 6 12 0000 demos M Inspect the a out file for use of shared libraries The file command shows that a out is a dynamically linked executable programs that use shared libraries are completely link edited during execution demo file a out a out ELF 32 bit MSB executable SPARC Version 1
34. use what is best for this machine Direct the compiler to decide which floating point options are available on the machine the compiler is running on and generate code for the best one If you compile and link in separate steps and you compile with the native option then be sure to link with native Using the Compiler 23 24 nolib noqueue norunpath No automatic libraries Do not automatically link with any system or language library that is do not pass any 1x options on to 1d The default is to link such libraries into the executables automatically without the user specifying them on the command line The nolib option makes it easier to link one of these libraries statically The system and language libraries are required for final execution It is the users responsibility to link them in manually This provides complete control and with control comes responsibility for the user For example a program linked dynamically with 1ibF77 fails on a machine that has no 1ibF77 When you ship your program to your customer you can ship 1ibF77 or you can link it into your program statically Example Link 1ibm statically and link 1ibc dynamically demo 90 nolib any f90 1f90 Bstatic lm Bdynamic lc There is no dynamic 1ibf90 it is always linked statically Order for 1x options is important Use the order shown in the example No license queue If you use this option and no license is ava
35. 2 2 a 0 1 99 Cchanges a 0 1 Example A 2 by 2 Fortran array argument explicitly indexed from 0 to 1 PROGRAM FixedMatrix INTEGER Cc r INTEGER DIMENSION 0 1 0 1 m m 0 0 200 m 0 1 01 m 1 0 10 m 1 1 11 DO r 0 1 DO c 0 1 WRITE END DO END DO CALL FixMat m DO r 0 1 DO c 0 1 WRITE END DO END DO END PROGRAM FixedMatrix eT gp Mg get pag SY I22 r C m r c m I1 I1 I2 2 r c m r c Example A 2 by 2 array argument show m before and after the C call demo cc c FixMat c demo 90 FixMat o FixMatmain f90 demo a out m 0 0 00 m 0 1 01 m 1 0 10 m 1 1 11 m 0 0 00 m 0 1 01 m 1 0 99 lt Fortran shows that m 1 0 got changed m 1 1 11 demos M C Fortran Interface 139 StruRef c StruRefmain 90 Compile Link Execute 140 Structure Arguments Passed by Reference 90 Calls C Example A C structure argument an integer and a character string struct InCh Define a structure int nbytes char a 16 b void struref v Use the structure in definining a function struct InCh y Change the char component Change the int component bcopy oyvay v a 5 v gt nbytes 5 Example A Fortran 90 structure argument an integer and a character string
36. 2 abcdefghijklmnopqrstuvwxyz j demo M Fortran 90 User s Guide StrRefU c StrRefUmain 90 Compile Link Execute Using Extra Arguments for Strings A C function can use the extra arguments from Fortran they are after the list of other arguments and they are passed without pointers Example Character arguments a C function uses the extra arguments strrefu_ char a char z long L10 long L30 abcdefghij abcdefghijklmnopqrstuvwxyz static char ax 11 static char zx 31 printf d d Mn L10 L30 Use L10 and L30 print them strncpy a ax 11 strncpy z zx 26 Example Character arguments a Fortran call makes hidden extra arguments PROGRAM StringRefU CHARACTER a 10 Yo z 30 Yo CALL StrRefU WRITE 1 a z 1 FORMAT a 2 A END PROGRAM StringRefU a Z Wg tN A Num Example Character arguments Fortran and C C uses the extra arguments 10 30 s10 abcdefghij s30 abcdefghijklmnopqrstuvwXyz The above C function prints the extra arguments the lengths what you really do with them is up to you C Fortran Interface 137 FixVec c FixVecmain f90 Compile Link Execute FixVecmainE f90 Compile Link Execute 138 Vector Arguments Passed by Reference 90 Calls C Example A C one dimensional array argument indexed from 0 to 8 void fixvec int v 9 int su
37. Debugger you must install the appropriate Tools package read Installing SunSoft Developer Products on Solaris for details With dbx you can display and modify variables set breakpoints trace calls and invoke procedures in the program being debugged without having to recompile The Debugger program lets you make more effective use of dbx by replacing the original terminal oriented interface with a window and mouse based interface Debugging 77 78 Sample Program for Debugging The following program with bug and consisting of files al 90 a2 90 and a3 90 is used in several examples of debugging Example Main for debugging al 90 PROGRAM TryDbx INTEGER PARAMETER n 2 EAL DIMENSION n n twobytwo ALL mkidentity twobytwo n RINT determinant twobytwo END R DATA twobytwo k j k 1 n j 1 n 4 1 C P Example Function for debugging a3 90 REAL FUNCTION determinant a REAL a 2 2 determinant a 1 1 a 2 2 a 1 2 END a 2 1 Example Subroutine for debugging a2 f 90 SUBROUTINE mkidentity array m REAL DIMENSION m m array DO i 1 m DO j 1 m IF i eq j THEN array i j 1 0 ELSE array i j 0 0 END IF END DO END DO END Fortran 90 User s Guide N lll A Sample dbx Session The following example
38. END FUNCTION RetLog Example A C program uses a Fortran function that returns a LOGICAL int retlog int Declare function interface void main ine ES r 0 S retlog amp r printf sd d n r s Example Fortran and C with a LOGICAL function return value demo 90 c RetLog f90 demo cc c RetLogmain c demo 90 RetLog o RetLogmain o demo a out 01 demosMi Fortran 90 User s Guide RetChr f90 RetChrmain c The function value is passed not asa function return valu ut as these argument rval ptr pointer to string rval_len length of string The normal string argument is passed as amp ch pointer to string ch_len length of string Compile Link Execute CHARACTER Function Return Value C Calls 90 Passing strings between C and Fortran is not encouraged See Character Strings and Order on page 129 for details of compatibility Example A Fortran character string function FUNCTION RetChr C n CHARACTER RetChr c RetChr DO i 1 n RetChr i i c END DO RetChr n 1 n 1 END FUNCTION RetChr CHAR 0 Put in the null terminator for C Example A C main uses a Fortran character function void retchr_ char int char int int fen interface main Usea Fortran 90 character function C calls f90 char strbuffer 9 123456789 char rval ptr strbuffer int r
39. EXTERNAL statement to make 90 use your function rather than the intrinsic one ADJUSTL LEN TRI SELECTED INT KIND ADJUSTR IAXEPONENT SELECTED_REAL_KIND ALLOCATED INEXPONENT SET_EXPONENT ASSOCIATED NEARES SHAPE BIT_SIZE PRECISION SIZE DIGITS PRESEN SPACING EPSILON RADIX TINY EXPONENT RANGE RANSFER FRACTION REPEAT TRIM HUGE RRSPACING UBOUND KIND SCALE VERIFY LBOUND SCA The Fortran 90 standard supports the following new array intrinsic functions ALL MAXLOC RESHAPE ANY MAXVAL SPREAD COUNT MERGE SUM CSHIFT MINLOC TRANSPOSE DOT_PRODUCT MINVAL UNPACK EOSHIFT PACK ATMUL PRODUCT Features and Differences 187 E A 5 Forward Compatibility This next release of 90 is intended to be source code compatible with this release If you generate any libraries with this release of 90 they are not guaranteed to be compatible with the next release A 6 Mixing Languages On Solaris systems routines written in C can be combined with Fortran 90 programs since these languages have common calling conventions A 7 Module Files If a file containing a Fortran 90 module is compiled 90 generates a module file M file in addition to the o file By default such files are usually sought in the current working directory The Mdir option allows you to tell 9
40. IEEE Exceptions page 102 IEEE Routines page 103 Debugging IEEE Exceptions page 113 Guidelines page 113 Miscellaneous Examples page 114 This chapter introduces some floating point issues It focuses on IEEE floating point and provides some reasons for it some definitions and some examples of how to use it It lets you use IEEE floating point with some understanding It is more tutorial than the other chapters and deeper This chapter is intended for scientists and engineers who use floating point arithmetic in their work but are not necessarily numerical analysts Read the Numerical Computation Guide where you will find more complete explanations examples and details You might also want to read What Every Computer Scientist Should Know About Floating point Arithmetic by David 99 Goldberg which is in the on line READMEs directory It is a PostScript file and can be printed by lpr on any PostScript compatible printer that has Palatino font It can be viewed on line by pageview 8 2 The General Problems 100 How can IEEE arithmetic help solve real problems IEEE 754 standard floating point arithmetic offers the user greater control over computation than is possible in any other type of floating point In scientific research there are many ways for errors to creep in The model may be wrong The algorithm may be numerically unstable solving equations by inverting ATA for example The data
41. Libraries Relocatable libraries provide an easy way for commonly used subroutines to be used by several programs The programmer need only name the library when linking the program and those library modules that resolve references in the program are linked copied into the executable file This has two advantages Only the needed modules are loaded at least for static libraries The programmer need not change the link command line as subroutine calls are added and removed during program development 6 2 Static Libraries Static libraries are built from object files o files using the program ar Disadvantages of Libraries When the linker searches a library it extracts elements whose entry points are referenced in other parts of the program it is linking such as subprogram or entry names or names of COMMON blocks initialized in BLOCKDATA subprograms The nature of the elements and the nature of the search leads to some disadvantages Fortran 90 User s Guide 6 The whole thing For static libraries when the linker extracts a library element it extracts the whole thing not so for dynamic libraries A library element corresponds to the result of a compilation so routines that are compiled together are always linked together This is a difference between this operating system and some other systems and it may affect whether you chunk compilation files to many small files for your libraries Order matters
42. 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 OR NON INFRINGEMENT THIS PUBLICATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION HEREIN THESE CHANGES WILL BE INCORPORATED IN NEW EDITIONS OF THE PUBLICATION SUN MICROSYSTEMS INC MAY MAKE IMPROVEMENTS AND OR CHANGES IN THE PRODUCT S AND OR THE PROGRAM S DESCRIBED IN THIS PUBLICATION AT ANY TIME OY BO ben y Adobe PostScript Contents lun cesa E EEEE a a Ea aE PEE ITAR xvii Jl PIntfOGUelioDo sere ee ee ee 1 1 Operating Environment cas ce we ed paw eee Rae dA Rx 12 Text BGG nachna a aed 2 BR EEC EE exer ad ews 1 3 Program Development ss 222594 ALSO Vetera L4 Debugging s sid vaa EY Ser CBS ed PAS d ES MPH I T 2 Getting Started cov sexo OCPOOCOG eien UR E R RU cen Zl SUMUMOLY i RERFOCEEE XT een RUEAUT EE DP bine 22 OBI soa n reward oa ed sa dea e CR x a 2 9 RUNN osa anos RR RERO EO ata a a cw we ne C Ro UR OV DD oO Gi WwW C Q NY NY HE 24 Renaming the Executables 1 2555 s iii 3 Using the Compiler x22 pr n n OCHO RADO een enews 3 1 Compile Command s exaudi pace ce nuc OMS Compile Link S quente 14 ios eres dix cien haa d de pret Command line File Names cocer en Unrecognized Arguments o cei qu ux dhbtRPREE Y EE Y 3 2 Compile
43. Related Manuals on page xix How This Book is Organized Related Documentation xviii This book is organized as follows Chapter 1 Introduction page 1 Chapter 2 Getting Started page 5 Chapter 3 Using the Compiler page 9 Chapter 4 File System and File I O page 35 Chapter 5 Program Development page 49 Chapter 6 Libraries page 57 Chapter 7 Debugging page 69 Chapter 8 Floating Point page 99 Chapter 9 C Fortran Interface page 119 Appendix A Features and Differences page 163 Appendix B iMPact Multiple Processors page 189 Appendix C iMPact Automatic Parallelization page 195 Appendix D iMPact Explicit Parallelization page 201 The related kinds of documentation included with Fortran 90 are as follow Paper manuals hard copy On line manuals in the AnswerBook viewing system On line man pages f90 help variations On line READMEs directory of information files Fortran 90 User s Guide AnswerBook The AnswerBook system displays and searches the on line copies of the paper manuals The system and manuals are included on the CD ROM and can be installed to hard disc during installation Installing and starting AnswerBook are described in the manual Installing SunSoft Developer Products on Solaris Related Manuals The following manuals are provided on line or on paper as indicated Title Part Number Paper AnswerBook Fortran 90 User s Guide 801 5492 10 X
44. See also f90 help Variations on page xxi Include path add to the search path for INCLUDE statements Insert the path loc at the start of the list of directories in which to search for Fortran 90 INCLUDE files No space is allowed between I and loc Invalid directories are just ignored with no warning message The Iloc applies to INCLUDE files with relative not absolute path names Example 90 I usr applib growth f90 Above 90 searches for INCLUDE files in the source file directory and then in the usr applib directory Use Iloc again to insert more paths Example 90 Ipath1 Ipath2 any f90 Search Order The search for INCLUDE files is in the following order The directory containing the source file Directories named in Iloc options Library link with library 1ibx Pass 1x to the linker 1d links with object library 1ibx If shared library libx so is available 1d uses it otherwise 1d uses archive library 1ibx a If it uses a shared library the name is built in to a out No space is allowed between 1 and x character strings Example Link with the library 1ibabc demo 90 any 90 1labc Use 1x again to link with more libraries Using the Compiler 21 22 Ldir Example Link with the libraries 1iby and libz demo 90 any f90 ly lz See also Section 6 5 Library Paths on page 65 Library search this directory first
45. X Fortran 90 Handbook by Adams Brainerd et al 875 1202 10 Fortran 90 Browser 802 2190 10 X X Debugging a Program 801 7105 10 X X Numerical Computation Guide 801 7639 10 X X Installing SunSoft Developer Products on Solaris 802 1561 10 X X What Every Computer Scientist Should Know About Floating Point Arithmetic 800 7895 10 X man Pages Purpose A man page is intended to answer What does it do and How do I use it Memory Jogger A man page reminds the user of details such as arguments and syntax It assumes you knew and forgot It is not a tutorial Quick Reference A man page helps find something fast It is brief covering major highlights It is a quick reference not a complete reference xix Using man Pages To display a man page use the man command Example Display the 90 man page demo man 90 Example Display the man page for the man command demo man man The man command uses the MANPATH environment variable which can effect which set of man pages are accessed See man 1 Related man Pages The following man pages may be of interest to Fortran 90 users 90 1 Invoke the Fortran 90 compiler asa 1 Print files having Fortran carriage control dbx 1 Debug by a command line driven debugger debugger 1 Debug by a graphical user interface fpr 1 Print files having Fortran carriage control ieee flags 3M Examine set or clear floating poi
46. a floating point computation would otherwise underflow This is not accomplished in Floating Point 111 112 hardware on a SPARC processor but in software If your program happens to generate many underflows perhaps a sign of a problem with your algorithm and you run on a SPARC processor you may experience a performance loss To turn off gradual underflow compile with fnonstd or insert this CALL nonstandard arithmetic To turn on gradual underflow after you have turned it off insert this CALL standard arithmetic The standard arithmetic subroutine corresponds exactly to an earlier version named gradual underflow The nonstandard arithmetic subroutine corresponds exactly to an earlier version named abrupt underflow Messages about Floating point Exceptions For Fortran 90 the current default is to display a list of accrued floating point exceptions at the end of execution In general you will get a message if any one of the invalid division by zero or overflow exceptions occur Since most real programs raise underflow and inexact exceptions you will get a message if any two of the underflow and inexact exceptions occur in general You can turn off any or all of these messages with ieee flags by clearing exception status flags If this is done at all it is usually done at the end of your program Clearing all messages is not recommended You can gain complete control with ieee
47. a trade off of portability for speed If you compile one subprogram with dalign compile all subprograms of the program with dalign Compiler information file Generate a compiler information CIF file Commands show commands built by driver but do not execute Allow or disallow dynamic libraries for the entire executable No space is allowed between d and y or n Either y or n must be included dy Yes allow dynamically bound libraries allow shared libraries dn No do not allow dynamically bound libraries ro shared libraries If you have neither dy nor dn you get the default y These apply to the whole executable Use only once on the command line If a out uses only static libraries then dy causes a few seconds delay at runtime it makes the dynamic linker be invoked when a out is run This takes a few seconds to invoke and find that no dynamic libraries are needed dbinding is a loader linker option If you compile and link in separate steps and you need dbinding then you need it in the link step Extend the source line maximum length to 132 columns Accept lines up to 132 characters long Using the Compiler 17 18 explicitpar Multiprocessor parallelize explicitly You do the dependency analysis analyze and specify loops for inter iteration data dependencies The software parallelizes the specified loops The explicitpar option requires the Multiprocessor Fortran 90 multipr
48. ar the r option use cr only for creating demo 90 c half f demo ar r faclib a half o demos M 6 3 Dynamic Libraries A dynamic library has the following features Itis a collection of object modules such that each is already in executable file format the a out format but the collection has no main entry The object modules are not bound into the executable file by the linker during the compile link sequence such binding is deferred until runtime f you change a module of a shared library then whenever any application using it starts to execute it will get the changed version The ability to modify and improve libraries independent of the executables that use it can be a significant advantage in maintaining programs If you have a a pic option to use to generate position independent code then from the generated dynamic library a module can be used by many executing programs without duplicating it in them all In this release 90 has no pic to generate position independent code so the library is not truly shared You still save disk space for storing the executable and you can still get library changes into the executable without rebinding the executable Libraries 61 62 Performance Issues The usual trade off between space and time applies Less space In general deferring the binding of the library module uses less disk space More time It takes a little more CPU time to do the
49. being used prior to processing the INCLUDE file Restrictions The FREE FIXED directives Each must appear alone on a compiler directive line not continued Each can appear anywhere in your source code Other directives must appear within the program unit they affect Example A FREE directive DIRS FREE DO i 1 n a i b i c i END DO Features and Differences 181 lll aN Parallel Directives A parallel directive is a special comment that directs the compiler to do some parallelizing Currently there is only one parallel directive DOALL DOALL Directive The DOALL directive tells the compiler to parallelize the next loop it finds if possible Other Parallel Directives Some other parallel directives are included which are not described in detail because they are not guaranteed to be in the next release Table A 4 Parallel Directives Guaranteed Only in the Current Release Directive CASE END CASE PARALLEL END PARALLEL DO PARALLEL END DO GUARD END GUARD Form of Parallel Directive Lines Parallel directives have the following syntax MICS DOALL general parameters scheduling parameter A parallel directive line is defined as follows A parallel directive starts with the CMICS or MICS followed by A space A directive For some directives one or more
50. call then step sets a breakpoint at the first source statement of the subprogram next sets the breakpoint at the first source statement after the call but still in the calling program Fault Finding the Line Number If a program gets a segmentation fault SIGSEGV it referenced a memory address outside of the memory available to it Some Causes of SIGSEGV The most frequent causes are the following An array index being outside the declared range The name of an array index is misspelled The calling routine has a REAL argument called routine has it as INTEGER An array index is miscalculated The calling routine calls with fewer arguments than required A pointer is used before it is defined Debugging 81 You can locate the offending source line using Xlist or dbx Recompile with the X1ist option to get global program checking Use dbx to find the source code line where a segmentation fault occurred Example Program to generate a segmentation fault demo 4 cat WhereSEGV f90 INTEGER a 5 j 2000000 DO i 1 5 a j i 10 END DO PRINT a END demo 5 M Example Use dbx to locate a segmentation fault demo 5 f90 g WhereSEGV f90 demo 6 a out Segmentation fault core dumped demo 7 dbx a out Reading symbolic information for a out other messages dbx run Running a out process id 8813 signal SEGV no mapping at the fault address in main at line 4
51. demos M Split the file using split so there is one subroutine per file demo fsplit one f fsplit assumes fixed form It may not work on all f90 source demos M e Compile each with c so it will compile only and leave the o object files demo 90 c half f demo 90 c third f demo 90 c thrice f demo 90 c twice f demos M Use ar to create static library faclib a from the four object files demo ar cr faclib a half o third o thrice o twice o Alternate Specify the order using lorder and tsort demo ar cr faclib a lorder half third o thrice o twice o tsort Compile the main using the new static library demo 90 teslib f90 faclib a demos M Use nm to list the name of each object in a out built from static library demo demo nm a out grep twice 260 77832 72 FUNC GLOB 0 18 demo nm a out grep half demo nm a out grep third demo nm a out grep thrice demo M twice Fortran 90 User s Guide o gt lll Run a out demo a out 6 12 0000 demos M Sample Replacement in a Static Library If you recompile an element of a static library usually because you ve changed the source replace it in its library by running ar again A library need not be specially flagged for the linker the linker recognizes a library when it encounters one Example Recompile replace Give
52. dynamically linked not stripped demos M The 1dd command shows that a out uses some shared libraries including libfac so 1 and libc included by default by 90 It also shows exactly which files on the system will be used for these libraries demo ldd a out libfac so 1 gt libfac so 1 libF77 so 2 gt opt SUNWspro lib libF90 so 2 libc so 1 gt usr lib libc so 1 libucb so 1 gt usr ucblib libucb so 1 libresolv so 1 gt usr lib libresolv so 1 libsocket so 1 gt usr lib libsocket so 1 libnsl so 1 gt usr lib libnsl so 1 libelf so 1 gt usr lib libelf so 1 libdl so 1 gt usr lib libdl so 1 libaio so 1 gt usr lib libaio so 1 libintl so 1 gt usr lib libintl so 1 libw so 1 gt usr lib libw so 1 demos M Your path may vary Fortran 90 User s Guide or lll 6 4 Consistent Compile and Link Be consistent with compiling and linking Do not build libraries with inconsistent modules Inconsistent compilation and linkage is not supported For compiling and linking as separate steps separate commands if you compile any module with g then be sure to link with the same option Example Compile sbr 90 with g and smain 90 without it demo 90 c g sbr f90 demo 90 g sbr o smain 90 lt Pass the g to the linker The above sequence is equivalent to the following commands demo 90 c g sbr f90 demo 90 c smain f90 d
53. file records must be all the same length and all the same type A logical record in a direct access external file is a string of bytes of a length specified when the file is opened Read and write statements must not specify logical records longer than the original record size definition Shorter logical records are allowed Unformatted direct writes leave the unfilled part of the record undefined Formatted direct writes cause the unfilled record to be padded with blanks In using direct unformatted I O be careful with the number of values your program expects to read Each READ operation acts on exactly one record the number of values that the input list requires must be less than or equal to the number of values in that record Direct access READ and WRITE statements have an extra argument REC n which gives the record number to be read or written Example Direct access unformatted OPEN 2 FILE data db ACCESS DIRECT RECL 20 amp FORM UNFORMATTED ERR 90 READ 2 REC 13 ERR 30 x y This opens a file for direct access unformatted I O with a record length of 20 characters then reads the thirteenth record as is Example Open direct access formatted OPEN 2 FILE inven db ACCESS DIRECT RECL 20 amp FORM FORMATTED ERR 90 READ 2 FMT I10 F10 3 REC 13 ERR 30 a b
54. for the entire executable dbinding page 17 Build a dynamic shared library G page 20 Name a shared dynamic library hname page 20 Directory search this directory first Ldir page 22 Link with library 1ibx 1x page 21 Using the Compiler 13 lll Qo Table 3 3 Actions Options Sorted by Action Continued Action Option Details Library continued Multithread safe libraries low level threads mt page 22 Paths store into object file R list page 28 No automatic libraries nolib page 24 No run path in executable norunpath page 24 Performance Faster execution make executable run faster using a selection of options fast page 19 Generate code to run on generic SPARC architecture cg89 page 16 Generate code to run on SPARC V8 architecture cg92 page 16 Use the best floating point arithmetic for this machine native page 23 Optimize for execution time Oo n page 25 Use selected math routines optimized for performance xlibmopt page 31 Reset fast so that it does not use xlibmopt xnolibmopt page 30 Parallelization Parallelize automatically and with explicit directives parallel page 26 Parallelize explicitly explicitpar page 18 Stack local variables to allow better optimizing with parallelizing stackvar page 29 Profile by Procedure for gprof pg page 27 Procedure for prof p page 26 Information and W
55. form source as follows Fixed Put CMIC or MIC in columns 1 through 5 Directives are listed in columns 7 and beyond Columns beyond 72 are ignored An initial directive line has a blank in column 6 A continuation directive line has a nonblank in column 6 iMPact Explicit Parallelization 203 204 Free Put MIC followed by a space anywhere in the line The MICS characters are the first nonblank characters in the line actually non whitespace Directives are listed after the space Aninitial directive line has a blank tab or newline in the position immediately after the MICS A continuation directive line has a character other than a blank tab or newline in the position immediately after the MICS Thus MIC in columns 1 through 5 works for both free and fixed Example Directive with continuation lines DOALL directive and parameters MICS DOALL MICS amp SHARED a b c n MICS amp PRIVATE i DO i 1 n a i b i c i END DO Example Same directive and parameters with no continuation lines IMIC DOALL SHARED a b c n PRIVATE i DO i 1 n a i b i c i END DO Fortran 90 User s Guide D DOALL Parameters The DOALL directive allows general parameters and a scheduling parameter Table D 1 DOALL General Parameters Parameter Action IF expr SHARED v1 02 PRIVATE x1 x2
56. from main line3 gt Note reverse order main called calc calccalled calcb demo 90 g ShowTrace f90 demo a out Segmentation Fault demo dbx a out Reading symbolic information for a out core dumped dbx run process id 8939 Running a out process id 1089 signal SEGV no mapping at the fault address in calcb at line 23 in file ShowTrace f 23 v j i 10 dox where gt 1 calcb v ARRAY m 2 line 23 in ShowTrace f90 2 calc a 3 main dox M ARRAY m 2 d 0 line 9 in ShowTrace f90 line 3 in ShowTrace f90 The where command shows where in the program flow execution stopped how execution reached this point that is a stack trace of the called routines This can be helpful since you no longer get an automatic traceback as bemoaned in the ode below Ode To Traceback O blinding core File of death Alone like Abel s brother Seth The demise of process cannot face Without the aid of stackish trace To see what by you must needs be done Please see Example Twenty One Mateo Burtch 1992 1 Since trace be dead or just not there try dbx s better where Seek not example twenty one as it was cited just for fun 84 Fortran 90 User s Guide Pointer to a Scalar PtrScal f90 Example Pointer to a scalar in dbx demo 90 g PtrScal f90 demo dbx a out dox list 1 99 PROGRAM PtrScalar REAL POINTER p REAL TARGET
57. is such a wide range of improvement that it is hard to predict what speedup any one program will get Variations in Speedups To illustrate the range of possible speedups the following hypothetical scenario is presented Assume 4 Processors With parallelization the following variations occur The normal upper limit with 4 processors is about 3 times as fast Many perfectly good programs tuned for single processor computation and with the overhead of the parallelization actually run slower Many perfectly good programs tuned for single processor computation get absolutely no speedup Some programs run 10 faster A few less run 50 faster Even fewer run 100 faster Afew have so much parallelism that they run 3 or 4 times faster Vectorization Comparison If you have good speedup on vector machines with an autovectorizing compiler a first order rough approximation may be performed as follows speedup vectorization number of CPUS 1 Remember that this is only a first order rough approximation B 4 Number of Processors 192 To set the number of processors set the environment variable PARALLEL Fortran 90 User s Guide Ss lll Setting environment variables varies with the shell csh 1 or sh 1 Example Set PARALLEL to 4 sh demo PARALLEL 4 demo export PARALLEL cosh demo setenv PARALLEL 4 Guidelines for Number of Processors The fo
58. locate temporary files temp dir page 30 Time for execution display for each compilation pass time page 30 Options and What Actions They Do ansi Bbinding Options Actions Sorted by Option This section shows all 90 options with a full description including risks restrictions caveats interactions examples and other details ANSI conformance check identify many non ANSI extensions Bind as dynamic or static any library listed later in the command No space is allowed between B and dynamic or static and either dynamic or static must be included Bdynamic Prefer dynamic binding try for shared libraries Bstatic Require static binding no shared libraries If you have neither Bdynamic nor Bstatic you get the default dynamic Using the Compiler 15 16 c cg89 cg92 For Bdynamic and Bstatic there is asymmetry besides prefer require If you specify static but it finds only a dynamic version then the library is not linked and you get a warning that the library was not found If you specify dynamic but it finds only a static version then the library is linked and you get no warning You can toggle Bstatic and Bdynamic on the command line That is you can link some libraries statically and some dynamically by specifying Bstatic and Bdynamic any number of times on the command line These are loader linker options If you compile and link in separate steps
59. myprogl 2 gt amp 1 myprog2 In each shell the above command runs the program myprog1 and redirects the standard output and standard error to the program myprog2 You can connect the standard output of one program directly to the standard input of another without using an intervening temporary file The mechanism to accomplish this is called a pipe Example A shell command line using a pipe demo firstprog secondprog This causes the standard output unit 6 of firstprog to be piped to the standard input unit 5 of secondprog Piping and file redirection can be combined in the same command line Example myprog reads mydata and pipes output to wc wc writes datacnt demo myprog mydata wc datacnt The program myprog takes its standard input from the file mydata and has its standard output piped into the standard input of the wc command the standard output of wc is redirected into the file datacnt File System and File I O 41 E 4 7 Accessing Files from Fortran Programs 42 Data are transferred to or from devices or files by specifying a logical unit number in an I O statement Logical unit numbers can be nonnegative integers or the character The stands for the standard input if it appears in a READ statement or the standard output if it appears in a WRITE or PRINT statement Standard input and standard output are explained in the section on preconnected units fou
60. name character 8 model real cost real price end type product dbx M Example Structures print a pointer then quit dbx dbx print prior prior a 82 nam Schlepper model XL cost 24 0 price 104 0 dbx quit demos M Fortran 90 User s Guide N lll Allocated Arrays The exact layout and messages may vary with each release Alloc 90 Unknown size is at line 6 gt Known size is at line 9 gt buffer 1000 holds1000 gt Example Allocated arrays in dbx demo 90 g Alloc f90 demo dbx a out dbx list 1 99 J PROGRAM TestAllocate 2 INTEGER n status 3 INTEGER ALLOCATABLE buffer 4 PRINT Size 5 READ n 6 ALLOCATE buffer n STAT status 7 IF status 0 STOP cannot allocate buffer 8 buffer n n 9 PRINT buffer n 10 DEALLOCATE buffer STAT status TI END dbx stop at 6 2 stop at alloc f90 6 dbx stop at 9 3 stop at alloc f90 9 dbx run Running a out process id 10749 Size 1000 stopped in main at line 6 in file alloc f90 6 ALLOCATE buffer n STAT status dbx whatis buffer integer 4 allocatable buffer dbx next continuing stopped in main at line 7 in file alloc f90 7 IF status 0 STOP cannot allocate buffer dbx whatis buffer integer 4 buffer 1 1000 dbx cont stopped in main at line 9 in f
61. occurs just flush to zero This results in a runtime like this real 0m0 18s user Om0 01s sys 0m0 13s Note that this time is very nearly the same as promoting one variable to double The difference is that now the computed result is 0 This is bad because if this dot product is really the final result there is probably nothing wrong with this solution If however this result feeds into more elaborate computations you have thrown away some information This may be important If the algorithm is stable the input well conditioned and the implementation careful it won t matter If there is anything else shaky this may push it over Fortran 90 User s Guide O Ii C Fortran Interface This chapter is organized into the following sections Sample Interface page 120 How to Use this Chapter page 121 Compatibility Requirements page 122 Fortran Calls C page 134 C Calls Fortran page 149 Glendower I can call spirits from the vasty deep Hotspur Why so can I or so can any man But will they come when you do call for them Henry IV Part I Purpose This chapter shows how to write Fortran 90 routines that call C routines and C routines that call Fortran 90 routines A common reason to do such calls is to use existing libraries Caveat This subject requires more sophistication than most of this manual To paraphrase Hotspur any programmer can write such programs but will they work wh
62. often as they are included The following are all listed Source files INCLUDE files Cross Reference Table If the cross reference table is not suppressed then the following are all scanned while generating the cross reference table Source files INCLUDE files Default No include files Debugging 75 lll N Xlistln XlistL Xlisto name Xlistwar Xlistwar nnn XlistX Xlistwarn Suppress specific warnings 76 Page breaks Set the page length for pagination to n lines That is the letter ell for length not the digit one For example X1ist145 sets the page length to 45 lines Default 66 No Page Breaks The X1ist10 that is a zero not a letter oh option shows listings and cross reference with no page breaks easier for on screen viewing Listing and errors Show cross check errors and listing This suboption by itself does not show a cross reference Default Show listing cross reference Rename the X1ist output report file The space between o and name is required Output is then to the name 1st file To display directly to the terminal Xlisto dev tty Suppress all warning messages in the report Suppress warning nnn in the report If nnn is not specified then all warning messages will be suppressed from printing To suppress more than one but not all warnings use this option repeatedly For example X1istwar338 suppresses warning message 338 Cross refer
63. or a structure component A Cray pointee cannot be of a derived type Note Cray pointees can be of type character but their Cray pointers are different from other Cray pointers The two kinds cannot be mixed in the same expression Features and Differences 173 174 Usage of Cray Pointers Cray pointers can be assigned values as follows Set to an absolute address Example q 0 Assigned to or from integer variables plus or minus expressions Example p q 100 Cray pointers are not integers You cannot assign them to a real variable The LOC function nonstandard can be used to define a Cray pointer Example p LOC x Example Use Cray pointers as described above SUBROUTINE sub n COMMON pool 100000 ap R TEGER blk 128 word64 EAL a 1000 b n c 100000 n 1000 POINTER pblk blk ia a ib b amp ic c address word64 DATA address 64 pblk 0 ia LOC pool ib ia 1000 ic ib n Remarks about the above example word64 refers to the contents of absolute address 64 b1k is an array that occupies the first 128 words of memory a is an array of length 1000 located in blank common b follows a and is of length n c follows b a b and c are associated with pool word64 is the same as b1k 17 because Cray pointers are byte address and the integer elements of b1k are each 4 bytes long Fortran 90 User s Guide A
64. page 153 Pointer Arguments Passed by Reference C Calls f90 N A page 155 Arguments Passed by Value C Calls f90 N A page 155 Function Return Values C Calls f90 page 155 INTEGER Function Return Value C Calls f90 page 155 REAL Function Return Value C Calls f90 page 156 DOUBLE PRECISION Function Return Value C Calls f90 page 156 LOGICAL Function Return Value C Calls f90 page 158 CHARACTER Function Return Value C Calls f90 page 159 Labeled Common C Calls f90 page 160 Alternate Returns C Calls f90 page 161 9 3 Compatibility Requirements 122 Most C Fortran interfaces must get all of these aspects right Function or subroutine Underscore in names of routines Upper and lowercase in identifiers Data type compatibility Passing arguments by reference or value String arguments and order Telling the linker to use Fortran libraries Some C Fortran interfaces must also get these right Arrays Indexing and order File descriptors and stdio File permissions Fortran 90 User s Guide Ko lll Function or Subroutine The word function means different things in C and Fortran As far as C is concerned all subprograms are functions it is just that some of them return a null value As far as Fortran is concerned a function passes a return value and a subroutine does not Fortran Calls a C Function If the called C function returns a value call it from Fortran as a function If the calle
65. parameters Spaces before after or within a directive are ignored Letters of a parallel directive line can be in uppercase lowercase or mixed 182 Fortran 90 User s Guide 2 lll The form varies for fixed form and free form source as follows Fixed Put CMIC or MIC in columns 1 through 5 Directives are listed in columns 7 and beyond Columns beyond 72 are ignored An initial directive line has a blank in column 6 A continuation directive line has a nonblank in column 6 Free Put MICS followed by a space anywhere in the line The MICS characters are the first nonblank characters in the line actually non whitespace Directives are listed after the space An initial directive line has a blank tab or newline in the position immediately after the MICS Acontinuation directive line has a character other than a blank tab or newline in the position immediately after the MICS Thus MICS in columns 1 through 5 works for both free and fixed Example Directive with continuation lines DOALL directive and parameters MICS DOALL IMICS amp SHARED a MICS amp PRIVATE i DO i 1 n a i END DO Example Same directive and parameters with no continuation lines IMIC DOALL SHARED a b c n PRIVATE i DO i 1 n a i b i c i END DO Features and Differences 183 Em A 4 Compatibility with FORTRAN 77 Source Sour
66. r 1 2 3 4 p gt r 5 r 6 7 8 9 JN ue ll w N Qo PRINT r END dbx stop at 8 2 stop at PtrScal f90 8 dbx run Running a out process id 12367 2 29999995 stopped in main at line 8 in file PtrScal f90 8 PRINT r dbx whatis p real 4 p 90 pointer dbx whatis r real 4 r dbx print p p 3 2 dbx print r r 3 2 dbx it demo Debugging 85 lll N Pointer to an Array PtrArray f90 86 Example Pointer to an array in dbx demo 90 g PtrArray f90 demo dbx a out dox list 1 99 alt PROGRAM PtrArray 2 INTEGER TARGET a 5 5 3 INTEGER POINTER corners 4 DO i 1 5 5 a i i 6 7 8 9 END DO corners gt a 1 5 4 1 5 4 PRINT corners END dbx stop at 8 2 stop at PtrArray f90 8 dbx run Running a out process id 12397 stopped in main at line 8 in file PtrArray f90 8 PRINT corners dbx whatis a integer 4 a 1 5 1 5 dbx whatis corners integer 4 corners 1 2 1 2 f90 pointer dbx print corners corners Cn de OW je Fortran 90 User s Guide User Defined Types Example Structures user defined types in dbx demo 90 g DebStruc f90 demo dbx debstr DebStruc f90 dox list 1 99 dbx stop at 17 2 stop at Struct f90 17 dbx run Running a ou
67. run on processor 1 The next 2 iterations run on processor 2 e All processors run simultaneously and usually finish at about the same time But the compiler provides no synchronization for arrays and for many reasons one processor can finish before others you cannot know the finishing order in advance Processor 1 Processor 2 Processor 3 Processor 4 a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 Fortran 90 User s Guide 0 lll D 7 Signals When processor 1 does a 2 a 3 If processor 2 has done a 3 a 4 then a 2 gets 4 If processor 2 has not yet done a 3 a 4 then a 2 gets 3 Therefore the values in a 2 depend on which processor finishes first After completion of the parallelized loop the values in array a depend on which processor finishes first And which finishes second So the sum depends on events you cannot determine The major variables in the runtime environment that cause this kind of trouble are the number of processors in the system the system load interrupts and so forth However you usually cannot know them all much less control them all In general if the loop you are parallelizing does any signal handling then there is a risk of unpredictable behavior including a system hang getting hosed and other generic bad juju In particular if The I O statement raises an exception The signal handler you provid
68. sure to read Debugging a Program for the following The full range of features in the Debugger The window and mouse based interface Overview of dbx Features Useful for Fortran 90 The Debugger provides event management process control and data inspection It allows you to watch what is happening during program execution Fortran 90 User s Guide N lll Solaris 2 x Solaris 2 x Help With dbx you can do such things as the following Set watchpoints to stop or trace if a specified item changes Collect data for the performance tuning Analyzer Graphically monitor variables structures and arrays Data Inspector Set breakpoints set places to halt in the program at lines or in functions Show values once halted show or modify variables arrays structures Step through program one source line at a time or one assembly line Trace program flow show sequence of calls taken Invoke procedures in the program being debugged Step over or into function calls step up and out of a function call Run stop and continue execution at the next line or at some other line dbx safe I O in the command window Program Input Output Window Save and then replay all or part of a debugging run Stack Examine the call stack move up and down the call stack Program scripts by embedded Korn shell Follow programs as they fork 2 and exec 2 At the Debugger prompt to get All commands a list of commands grouped by act
69. the CLOSE statement Already Open If a Fortran 90 program has a file already open an OPEN statement that specifies only the file s logical unit number and the parameters to change can be used to change some of the file s parameters specifically BLANK and FORM The system determines that it must not really OPEN a new file but just change the parameter values Thus this looks like a case where the runtime system would make up a name but it does not Other In all other cases the runtime system OPENS a file with a name of the form fort n where n is the logical unit number given in the OPEN statement Passing File Names to Programs The file system does not have any notion of temporary file name binding or file equating as some other systems do File name binding is the facility that is often used to associate a Fortran logical unit number with a physical file without changing the program This mechanism evolved to communicate file names more easily to the running program because in FORTRAN 66 there was no way to open files by name File System and File I O 43 44 With this operating system the following ways communicate file names to a Fortran program Redirection and piping Redirection and piping can change the names of program input and output files without changing the program See the sections Redirection and Piping earlier in this chapter Preconnected Units When a Fortran program
70. your invitation to join our world class organization for professional programmers For a nominal annual fee of 20 your SunPro SIG membership automatically entitles you to Membership on an International SunPro SIG Email Alias Share tips on performance tuning product feedback or anything you wish available as a UUNET address and a dial up number Subscription to the SunProgrammer Quarterly Newsletter Includes advice on getting the most out of your code regular features guest columns product previews and the latest industry gossip Access to a Repository of Free Software SunSoft will collect software related to application development and make it available for downloading Free SunSoft Best of Repository CD ROM You receive one free CD ROM for joining plus we ll take the cream of the crop from the depository and distribute it to members annually Free Access to SIG Events Including national events like SIG seminars held at the SUG conference and regional SunPro SIG seminars SPECIAL OFFER Sign up today and receive a SunPro SIG Tote Bag A spiffy 15 x 12 black nylon Cordura tote with the SIG logo proof positive of your Power Programmer status So join the SunPro SIG today And plug into what s happening in SPARC and Solaris development world wide Simply complete the form below Mail to SunPro SIG 2550 Garcia Avenue MS UMPK 03 205 Mountain View CA 94043 1100 TEL 415 688 9862 or FAX 415 968 639
71. 0 to seek them in an additional location The M files cannot be stored into an archive file If you have many M files in some directory and you want to reduce the number of such files to reduce clutter you can concatenate them into one large M file 188 Fortran 90 User s Guide B 1 Requirements es Ii iMPact Multiple Processors This appendix is organized into the following sections Requirements page 189 Overview page 190 Speed Gained or Lost page 192 Number of Processors page 192 This appendix introduces ways to spread a set of programming instructions over a multiple processor system so they execute in parallel The process is called parallelizing The goal is speed It is assumed that you are familiar with parallel processing and with Sun Fortran and the SunOS or UNIX operating system Multiprocessor Fortran 90 requires the following SPARC multiple processor system Solaris 2 3 Operating Environment or later Solaris 2 3 and later supports the 1ibthread multi thread library and running many processors simultaneously Fortran 90 MP has features that exploit multiple processors using Solaris 2 3 and later The iMPact MT MP multiple processor package 189 B B 2 Overview In general this compiler can parallelize certain kinds of loops that include arrays You can let the compiler determine which loops to parallelize automatic parallelizing or you can specify each loop yours
72. 00000 7 0000000 8 0000000000000000 9 0000000000000000 demos M C Fortran Interface 135 lll Ko StrRefI c StrRefImain f90 Compile Link Execute 136 Character Arguments Passed by Reference 90 Calls C Passing strings between C and Fortran is nonstandard It is not encouraged For Fortran 90 calling C if Fortran 90 passes a character string argument it always passes an extra hidden argument The C function can ignore these extra arguments or it can use them For the detailed requirements of passing string arguments see Character Strings and Order on page 129 Ignoring Extra Arguments for Strings A C function can ignore the extra arguments since they are after the list of other arguments Example Character arguments this C function ignores the extra arguments void strrefi char a char z static char ax 11 abcdefghij static char zx 31 abcdefghijklmnopqrstuvwxyz strncpy 2a ax 10 strncpy z zx 26 Example Character arguments a Fortran call passes hidden extra arguments PROGRAM StringRefI CHARACTER a 10 Yo i z 30 a z CALL StrRefI a z WRITE 1 a z al FORMAT a A TT Lr END PROGRAM StringRefI Wap A Woo Example Character arguments Fortran and C C ignores the extra arguments demo cc c StrRefI c demo 90 StrRefI o StrRefmain f90 demo a out sl0 abcdefghij s30
73. 107 ieee values 104 106 impatient user s guide 5 INCLUDE path 21 inconsistency arguments checking X1ist 70 named common blocks checking Xlist 70 increase stack size 30 indeterminacy how it arises 210 index check of arrays 81 information files xxi input redirection 40 standard 44 inserting SCCS ID keywords 53 installation directory 65 Index interface for C and FORTRAN 119 problems checking for X1ist 70 internal files 46 intrinsic procedures extensions 178 invalid IEEE exception 101 Ipath INCLUDE files 21 italic font conventions xxii L labeled common C FORTRAN 147 160 labels unused X1ist 70 LD_LIBRARY_PATH 66 LD_RUN_PATH 66 and R not identical 28 ldir 22 libm user error making it unavailable 22 libraries C FORTRAN 131 paths in executables 28 search order 65 library 57 build G 20 create 59 load 21 loaded 58 name a shared library 20 paths in executables 28 replace module 61 static 58 license information 31 no queue 24 licensing 3 limit stack size 29 line length 165 line number of exception 83 segmentation fault SIGSEGV 81 line numbered listing X1ist 71 lines extended e 17 219 220 link options 65 sequence 10 suppress 16 linker search order 65 lint like checking across routines Xlist 69 list of options help 20 listing line numbered with diagnostics Xlist 69 Xlist 76 load library 21 ma
74. 25 lll Ko Writing C Code for Existing Fortran 90 Routines For any given Fortran 90 intrinsic data type the following table provides a close corresponding C data type Table 9 2 Fortran 90 Data Type to C Data Type Fortran 90 Intrinsic Data Type Close C Data Type Size Alignment Bytes Bytes CHARACTER x unsigned char x 1 1 CHARACTER LEN x unsigned char x n n 1 CHARACTER LEN n KIND 1 x unsigned char x n n 1 COMPLEX x struct float r i x 8 4 COMPLEX KIND 4 x struct float r i x 8 4 COMPLEX KIND 8 x struct double dr di x 16 4 DOUBLE PRECISION x double x 8 4 REAL x float x 4 4 REAL KIND 4 x float x 4 4 REAL KIND 8 x double x 8 4 INTEGER x int x 4 4 INTEGER KIND 1 x signed char x 1 4 INTEGER KIND 2 x short x 2 4 INTEGER KIND 4 x int x 4 4 LOGICAL x int x 4 4 LOGICAL KIND 1 x signed char x 1 4 LOGICAL KIND 2 x short x 2 4 LOGICAL KIND 4 x int x 4 4 m In the current release with items of type INTEGER for KIND 1 2 or 4 Each uses 4 bytes of storage Each aligns on 4 byte boundaries Each involves 32 bits if any computations are involved 126 Fortran 90 User s Guide Ko lll Passing Arguments by Reference or Value C and Fortran 90 pass arguments using the following different basic rules Fortran 90 generally passes arguments by reference C passes arguments by value Despite this seeming conflict
75. 6 Unfortunately we cannot accept credit card orders via Email since we need to have your signature on file Sign me up for SunPro SIG Sun Programmer Special Interest Group Date Name Title Company Email Address Address City State ZIP Country Phone Fax ALL INFO MUST BE FILLED OUT SunSoft A Sun Microsystems Inc Business I d like to pay for my one year membership fee of 20 by g VISA 1 MASTERCARD Card Expiration Date Signature 1 Check made payable to SunSoft
76. 6 1 r s END PROGRAM ReturnDbl Li Example Fortran and C with a DOUBLI PRECISION function return value demo cc c RetDbl c demo 90 RetDbl o RetDblmain f90 demo a out 8 0 109 0 demos M Fortran 90 User s Guide LOGICAL Function Return Value 90 Calls C Example A C function with an int function return value not a pointer RetLog c int retlog_ int r int s s r if s 0 s 1 lse s 0 return s Example A Fortran program uses a C function as if it returns a LOGICAL RetLogmain f90 PROGRAM TryRetLog LOGICAL r s RetLog r FALSE S TRUE AND RetLog r WRITE 2L4 r S END PROGRAM TryRetLog Example Fortran and C with a LOGICAL function return value Compile Link Execute demo cc c RetLog c demo 90 RetLog o RetLogmain f90 demo a out F T demo i C Fortran Interface 145 RetStr c The function value is passed not as a function return valyi ut as these argument rval ptr pointer to string rval len length of string The normal string argument is passed as amp ch_ptr pointer to string ch len length of string RetStrmain f90 Compile Link Execute 146 CHARACTER Function Return Value 90 Calls C N A Passing character strings between C and Fortran is not encouraged See Character Strings and Order on page 129 for details of compatibility Example A C chara
77. 8 6f n r S Example Fortran and C with a REAL function return value demo 90 c RetFloat f demo cc c RetFloatmain c demo 90 RetFloat o RetFloatmain o demo a out 8 000000 109 000000 demos M In earlier versions of C if C returned a function value that was a 1oat C promoted it to a double and various tricks were needed to get around that Fortran 90 User s Guide RetDb1 90 RetDblmain c Compile Link Execute DOUBLE PRECISION Function Return Value C Calls 90 Example Fortran function with a DOUBLE PRECISION function return value FUNCTION RetDbl x DOUBLE PRECISION RetDbl x RetDbl x 1 0 END E PRECISION Example A C main uses a Fortran function that returns a DOUBLI double retdbl double Declare function interface main double x y x 8 0 y 100 0 retdbl amp x printf 8 6f 8 6f n x y Example Fortran and C with a DOUBLE PR ECISION function return value demo 90 c RetDbl f demo cc c RetDblmain c demo 90 RetDbl o RetDblmain o demo a out 8 000000 109 000000 demos M C Fortran Interface 157 158 RetLog 90 RetLogmain c Compile Link Execute LOGICAL Function Return Value C Calls 90 Example A Fortran function with a LOGICAL function return value FUNCTION RetLog b LOGICAL b RetLog RetLog NOT b
78. 92 O 0 25 with g 25 o output file 25 O1 25 26 02 25 03 25 object library search directories 22 obscurities checking for X1ist 70 octal 168 ode to trace 84 off license queue 24 link system libraries 24 linking 16 trap for floating point exceptions 19 warnings IEEE accrued exceptions 106 xlibmopt 31 onetrip 25 on line documents xviii xix optimization object code 25 performance 19 options 12 and what actions they do 15 frequently used 13 list available options help 20 listed by option name 15 what they do 13 most frequently used 12 options actions sorted by option 15 show list of help 20 OPTIONS variable for command line 33 order of linker search 66 Index output file naming it 25 redirection 40 standard 44 to terminal Xlist 71 overflow IEEE 101 stack 29 P p profile by procedure 26 parallel directive 182 PARALLEL number of processors 193 parallel parallelize loops 26 parallelization automatic 195 CALL in a loop 29 explicit 18 201 general requirements 189 number of processors 193 overview 190 reduction 27 speed gained or lost 192 summary table 191 part numbers for manuals xix parts of large arrays in dbx 93 pass arguments by value 127 file names to programs 43 passes of the compiler 30 path 36 M files 23 built in during build of a out 67 INCLUDE files 21 modules files 23 path name 38 absolute 38
79. AR RE RE ORR LARA S 167 Abbreviated Size Notation for Numeric Data Types 170 Chay POHMeRS od oda s e tees 2258s ten X ew gea Tad 171 Cray Character Pomiers coe cra eee och do on t 176 INEPINSICS aee rrr EE ew eT EE ERE Wd 178 AG Directves o oottbrebllcDe 9 99 Yves oe EUER EE ES 179 General Directives our ee cannes eee eee ee Peper eesesies 179 Form of General Directive Lines 0 180 FIXED and FREE JWSeelvBs lt i vec arae ns beeen Ae oen ee 181 Parallel Directives 03039245424 ceeded P ieee ees 182 Form of Parallel Directive Lines 182 Fortran 90 User s Guide A 4 Compatibility with FORTRAN 77 04 184 Juni c sieves beh ek whe ae ne te eae eben eames 184 Execulahbles8 4E RE REDUCE poc Ce ewe Ey ses 184 LibtariBs ce e X RW REEL eee ee Ree FE e PERS 184 WS zxa esuitRPRRERERSPIESE ERE EAR PP RP RP QPCES 185 IntrinsiCS iud uec eo reb E E EYE lex AE ex 187 AS Forward Compatibility cia aau ee OR UR ERAS a 188 A 6 Mixing Languages eec e eter Rana 188 A 7 Module Files 2 os aeri loea A CCALA GR UR RA 084 R 188 B iMPact Multiple Processors 0c cece cece eens 189 B L Requirements c rkeiees oe ee eR Ree E erp eee dees 189 B 2 Overview iiam urere Os Cee ate e 190 Automatic Parallehization lt lt lt sevrsesevSoseeaaecderews 190 Explicit Patallelizing vvv eetxecx awe aqaa deer eEEDY YE Ya 190 SUMMIMNALY ico add kee ke ED OCCORRE EUER hE YRS a TS 191 S
80. ARC with hardware integer multiply and divide instructions These are accessed if you compile with the cg92 option The utility fpversion tells which floating point hardware is installed This utility runs on all Sun architectures See fpversion 1 and read the Numerical Computation Guide for details This replaces the older utility fpuversion4 Floating Point 103 104 The the following interfaces help people use all the facets of IEEE arithmetic These are mostly in the math library in the 1ibm a and libm il files and in several h files ieee flags 3m Control rounding direction Control rounding precision Query exception status Clear exception status ieee handler 3m Establish exception handler Remove exception handler ieee functions 3m List name and purpose of each IEEE function ieee values 3m A list of functions that return special values Other 1ibm functions oo _retrospectiv nonstandard arithmetic standard arithmetic Flagsand ieee flags The ieee_flags function is part of the 1ibm shipped with the operating system It allows the programmer to do the following Control rounding direction and rounding precision Check the status of the exception flags Clear exception status flags The ieee flags function can be used to query and clear exception status flags The general form of a call to ieee flags is as follows i ieee flags action mode in out Each o
81. Calls C In general if an existing C function returns a pointer to an item then Fortran 90 requires an interface block for the function Example A C function with a pointer to a float function return value static float f float retptrf float a f a ftt return amp f Example A Fortran program uses a pointer to a REAL function return value PROGRAM ReturnPtrFloat Use a C function return value that is a pointer to a real INTERFACE FUNCTION RetPtrF x REAL x REAL POINTER RetPtrF END FUNCTION RetPtrF END INTERFACE EAL a b 8 0 100 0 RetPtrF a Uses C function here RITE FE9 0 D END PROGRAM ReturnPtrFloat Soo w Example Fortran and C with a pointer to a REAL function return value demo cc c RetPtrF c demoS 90 RetPtrF o RetPtrFmain f90 demo a out 109 demos M C Fortran Interface 143 144 RetDbl c RetDblmain f90 Compile Link Execute DOUBLE PRECISION Function Return Value 90 Calls C Example A C function with a double function return value not a pointer double retdbl double s s r Stt return double r Example Fortran 90 uses a DOUBLE PRECISION function return value from C PROGRAM ReturnDbl DOUBLE PRECISION r s RetDbl r 8 0 s 100 0 RetDbl r The C function is invoked here WRITE 2F
82. Fortran 90 User s Guide amp SunSoft A Sun Microsystems Inc Business 2550 Garcia Avenue Mountain View CA 94043 U S A Part No 801 5492 10 Revision A March 1995 1995 Sun Microsystems Inc 2550 Garcia Avenue Mountain View California 94043 1100 U S A All rights reserved This product and related documentation are protected by copyright and distributed under licenses restricting its use copying distribution and decompilation No part of this product or related documentation may be reproduced in any form by any means without prior written authorization of Sun and its licensors if any Portions of this product may be derived from the UNIX and Berkeley 4 3 BSD systems licensed from UNIX System Laboratories Inc a wholly owned subsidiary of Novell Inc and the University of California respectively Third party font software in this product is protected by copyright and licensed from Sun s font suppliers RESTRICTED RIGHTS LEGEND Use duplication or disclosure by the United States Government is subject to the restrictions set forth in DFARS 252 227 7013 c 1 ii and FAR 52 227 19 The product described in this manual may be protected by one or more U S patents foreign patents or pending applications TRADEMARKS Sun the Sun logo Sun Microsystems Solaris are trademarks or registered trademarks of Sun Microsystems Inc in the U S and certain other countries UNIX is a registered trademark in the United Stat
83. IXTI ATO x bueeenee neonka Tantin EEEE Urn be cee E ee eee ewe 191 B 3 Speed Gained or Lost 5 apre i cna D AUR GR eoi 192 BA Number of Processors 2 concert e n me 192 C iMPact Automatic Parallelization 00005 195 C1 What You DG2535553 cteterpeseepeteiedeeeeeuetaue 195 C2 What the Compiler DOS cese ved dr RE EVERY 196 Parallelize the Loop vade rack ecu RO Re T de a 196 Dependency Analysis acp do eee ente Reo E ERE 196 Definitions Array Scalar and Pure Scalar 197 Contents xi C 3 Definition Automatic Parallelizing 197 General DEmnionh lt sss qae adea opo dic Rc ade OR DOR ea 197 cc p MM 197 Exceptions for Automatic Parallelizing 198 D iMPact Explicit Parallelization 0 eee eeeee 201 D1 What You DD iuh rad eqq uicti dx Ru bR PRA EE LEE 201 D 2 What the Compiler DO685 iuret oe rob 202 D 3 Parallel Directives i i eec Rh Rete 203 Form of Directive Lines ciciccerienGeeteaa rege CREER 203 DOR TE JP Arameletis sito pn hae crate bane ee VR FERE CERE 205 D 4 DOALL LOO RG oa serne eves ee ee es OR Orr PEE SERE 206 Bulle PD D 206 Explicitly Parallelizing a DOALL Loop 206 CALL ie LOOP saa ones ele de PEPE Sees EE PDC GER 208 D 5 Exceptions for Explicit Parallelizing 208 D 6 Risk with Explicit Nondeterministic Results 209 Testing is not Enough oa se ea d RA a roc C ci ADR E De Ra 209 Ho
84. Two byte logicals OGICAL 4 OGICAL KIND 4 LOGICAL 4 Four byte logicals REAL 4 REAL KIND 4 REAL 4 IEEE single precision floating point Four byte REAL 8 REAL KIND 8 REAL 8 IEEE double precision floating point Eight byte COMPLEX 8 COMPLEX KIND 4 COMPLEX 4 Single precision complex Four bytes each part COMPLEX 16 COMPLEX KIND 8 COMPLEX 8 Double precision complex Eight bytes each part The form in column one is nonstandard The kind number can vary by vendor Fortran 90 User s Guide A Cray Pointers A Cray pointer is a variable whose value is the address of another entity which is called the pointee 90 supports Cray pointers Standard Fortran 90 does not support them Syntax The Cray POINTER statement has the following format POINTER pointer_name pointee_name array spec Where pointer name pointee name and array spec are as follows pointer name Pointer to the corresponding pointee name pointer name contains the address of pointee name Must be a scalar variable name but not a structure Cannot be a constant a name of a structure an array or a function pointee name Pointee of the corresponding pointer name Must be a variable name array declarator or array name array spec If array spec is present it must be explicit shape constant or nonconstant bounds or assumed size Example Declare Cray pointers to two pointees POINTER
85. ach 90 file and link the three relocatable files plus a series of libraries into a program called pattern The make file for this example is listed below demo cat makefile pattern pattern o computepts o startupcore o 90 pattern o computepts o startupcore o Fxview o pattern pattern o pattern f90 commonblock f90 c pattern f90 computepts o computepts f90 commonblock f90 c computepts f90 startupcore o startupcore f90 f90 c startupcore f90 demos M The first line of this make file says make pattern pattern depends on pattern o computepts o and startupcore o The second line is the command for making pattern The third line is a continuation of the second because it starts with a tab There are four such paragraphs or entries in this make file The structure of these entries is Dependencies Each entry starts with a line that names the file to make and names all the files it depends on Commands Each entry has one or more subsequent lines that contain Bourne shell commands and that tell how to build the target file for this entry These subsequent lines must each be indented by a tab Using make The make command can be invoked with no arguments such as this demo make The make utility looks for a file named makefile or Makefile in the current directory and takes its instructions from there Program Development 51 lll O1 The make utility general actio
86. ags get exception overflow out IF out eq overflow PRINT overflow flag raised Example Clear the invalid exception ieeer ieee flags clear exception invalid out Example Clear all exceptions ieeer ieee flags clear exception all out Floating Point 105 106 Example Set rounding direction to zero ieeer ieee flags set direction tozero out Example Set rounding precision to double ieeer ieee flags set precision double out Turn Off All Warning Messages with ieee flags Use this only if you are certain you don t want to know about the unrequited exceptions To do this clear all accrued exceptions by putting a call to ieee flags just before your program exits Example Clear all accrued exceptions with ieee flags i ieee flags clear exception all out Calls of this form are used in the next two examples Valuesand ieee values The ieee values 3m file is a collection of functions Each function returns a special IEEE value The Fortran names for these functions are listed in libm double 3f and libm single 3f You can use special IEEE entities such as infinity or minimum normal in a user program See also the man page ieee values 3m Example A convergence test might be like this IF delta LE r min normal RETURN Fortran 90 User s Guide
87. arnings Verbose print name of each compiler pass v page 30 Version ID show version ID V page 30 Warnings suppress warnings wW page 31 Licensing License information display license server user ids xlicinfo page 30 No license queue noqueue page 24 Source Forms Fixed form source fixed page 19 Free form source free page 19 14 Fortran 90 User s Guide Qo lll Table 3 3 Actions Options Sorted by Action Continued Action Option Details Miscellaneous ANSI conformance check identify many non ANSI extensions ansi page 15 Compile only do not make a out do not execute c page 16 CIF generate a compiler information file db page 17 Command show command line built by driver but do not execute dryrun page 17 Align on 8 byte boundaries f page 19 Do not trap floating point exceptions fnonstop page 19 Options display the list of options help page 20 Include path add dir to the search path for INCLUDE statements Idir page 21 Module directory look for Fortran 90 modules in the dir directory Mdir page 23 Output rename the output file o outfil page 25 DO loops use one trip DO loops onetrip page 25 Pass option list to program Qoption pr Is page 27 Assembly source generate only assembly source code S page 30 Symbol table strip executable of symbol table prevents debugging s page 29 Temporary files set directory to
88. at line 5 of the a1 90 file Print To print a value enter the print command Example Print the variable n Note that dox handles parameters dbx print n n2 dox M Example Print the matrix twobytwo format may vary with release dbx print twobytwo twobytwo 1 1 1 0 2 1 1 0 1 2 1 0 2 2 1 0 dbx Example Print the matrix array dbx print array dbx array is not defined in the current scope dbx see help scope for details dbx M In the above example The print fails because array is not defined here only in mkidentity The error message details may vary with the release and translation Fortran 90 User s Guide 7 Next Line To advance execution to the next line enter the next command Example Advance execution to the next line dbx next stopped in main at line 6 in file al f90 6 PRINT determinant twobytwo dbx print twobytwo twobytwo 1 1 1 0 2 1 0 0 1 2 0 0 2 2 1 0 dbx quit demos M Segmentation Note that print twobytwo now displays the unit matrix The next command executes the current source line then stops at the next line It counts subprogram calls as single statements Compare next with step The step command executes the next source line or the next step into a subprogram and so forth In general if the next executable source statement is a subroutine or function
89. atically use the parallel option Example Parallelize automatically some loops get parallelized some do not demo cat t2 f90 END Do demo 90 parallel t2 f90 DO i 1 1000 Parallelized a i b i c i END DO DO k 3 1000 Not parallelized dependency x k x k 1 x k 2 Seepage 196 under Dependency Analysis 195 To determine which programs benefit from automatic parallelization study the rules the compiler uses to detect parallelizable constructs Alternatively compile the programs with automatic parallelization then time the executions C 2 What the Compiler Does 196 For automatic parallelization the compiler does two things Dependency analysis to detect loops that are parallelizable Parallelization of those loops This is similar to the analysis and transformations of a vectorizing compiler Parallelize the Loop The compiler applies appropriate dependence based restructuring transformations It then distributes the work evenly over the available processors Each processor executes a different chunk of iterations Example 4 processors 1000 iterations the following occur simultaneously Processor 1 executing iterations 1 through 250 Processor 2 executing iterations 251 through 500 Processor 3 executing iterations 501 through 750 Processor 4 executing iterations 751 through 1000 Dependency Analysis A set of operations can be executed in paralle
90. ay character pointers must not appear in EQUIVALENCE statements or any storage association statements The size can vary with the platform Cray character pointers are not optimized Code containing Cray character pointers is not parallelized A Cray character pointer in a list of an I O statement is treated as an integer Features and Differences 177 d A Intrinsics 90 supports some intrinsic procedures which are extensions beyond the standard Table A 2 Nonstandard Intrinsics Type Name Definition Function Arguments Arguments Remark Notes CLOC Get Fortran character Cray character C c NP I descriptor FCD character pointer COT Cotangent real real X x P E DDIM Positive difference double double precision X x Y y PE precision FCD Create Cray character pointer Cray i integer or I2 i J i word address NP I in Fortran character pointer Cray pointer of first descriptor FCD format j integer character j character length LEADZ Get the number of leading 0 integer Boolean integer I i NP I bits real or pointer POPCNT Get the number of set bits integer Boolean integer I i NP I real or pointer POPPAR Calculate bit population integer Boolean integer X x NP I parity real or pointer The notes in the above table are explained as follows Note Meaning P The name can be passed as an argument NP The name cannot be passed as an argument E External code for the intrinsic i
91. begins execution under this operating system there are usually three units already open They are preconnected units Their names are standard input standard output and standard error In Fortran the following are preconnected Standard input is logical unit 5 Standard output is logical unit 6 Standard error is logical unit 0 All three are connected unless file redirection or piping is done Other Units All other units are preconnected to files named fort n where n is the corresponding unit number and can be 0 1 2 with 0 5 and 6 having the usual special meanings These files need not exist and are created only if the units are actually used and if the first action to the unit is a WRITE or PRINT that is only if an OPEN statement does not override the preconnected name before any WRITE or PRINT is issued for that unit Example Preconnected Files The program OtherUnit f90 WRITE 25 I4 2 END The above program preconnects the file ort 25 and writes a single formatted record onto that file demo 90 OtherUnit f90 demo a out demo cat fort 25 2 demo Fortran 90 User s Guide HS lll 4 8 Direct I O Random access to files is also called direct access A direct access file contains a number of records that are written to or read from by referring to the record number This record number is specified when the record is written In a direct access
92. bove Then invoking the make file results in a compile command equivalent to 90 fast 04 any 90 Fortran 90 User s Guide File System and File I O 4 This chapter is organized into the following sections Summary page 35 Directories page 37 File Names page 37 Path Names page 37 Redirection page 40 Piping page 41 Accessing Files from Fortran Programs page 45 Direct I O page 45 Internal Files page 46 This chapter is a basic introduction to the file system and how it relates to the Fortran I O system If you understand these concepts then skip this chapter 4 1 Summary The basic file system consists of a hierarchical file structure established rules for file names and path names and various commands for moving around in the file system showing your current location in the file system and making deleting or moving files or directories 45 36 The system file structure of the UNIX operating system is analogous to an upside down tree The top of the file system is the root directory Directories subdirectories and files all branch down from the root Directories and subdirectories are considered nodes on the directory tree and can have subdirectories or ordinary files branching down from them The only directory that is not a subdirectory is the root directory so except for this instance you do not usually make a distinction between directories and subdirectories A se
93. ce from Sun FORTRAN 77 is not generally compatible with Fortran 90 unless it strictly follows the FORTRAN 77 standard In general i f it uses no extensions then it is compatible Executables Libraries compiled and linked in FORTRAN 77 under Solaris 2 x run in the Fortran 90 1 0 environment Libraries Libraries a and object files o compiled and linked in FORTRAN 77 under Solaris 2 x are compatible with Fortran 90 1 0 You can check the usr 4lib directory on your SunOS 5 x system for the 1ibF77 s0 2 0 and libV77 s0o 2 0 library files Example 90 main and 77 subroutine demo cat m f90 CHARACTER 74 c This is a test CALL echol c END demo cat s f UBROUTINE echol a HARACTER 74 a RINT a ETURN ND demo 77 c silent s f demo 90 m f90 s o demo a out This is a test demos M ADVAN 184 Fortran 90 User s Guide 2 lll I O The library 1ibF77 is generally compatible with 90 Example 90 main calls a routine from the 1ibF77 library demo cat tdtime f90 REAL e dtime t 2 e dtime t DO i 1 10000 k k 1 END DO e dtime t PRINT elapsed e user t 1 sys t 2 END demo 90 tdtime f90 demo a out elapsed 6 405999884E 3 user 5 943499971E 3 sys 4 625000001E 4 demos M See dt ime 3f 77 and 90 are generally I O compatible for binary I O since 90 load
94. character string argument The list of hidden arguments comes after the list of regular arguments For Fortran 90 calling C if Fortran 90 passes a character string argument the C function can ignore the extra argument or use it For C calling Fortran 90 C must pass the extra argument because Fortran 90 expects requires it Example Fortran string argument passed by reference a Fortran call CHARACTER 7 s INTEGER b CALL sam s b C Fortran Interface 129 130 Example The above Fortran call is equivalent to the following C call char s 7 long b sam s amp b 7L In the above example s is passed by pointer because s is a character string b is passed by pointer because we explicitly use an ampersand amp 7 the length is passed by value without a pointer as a literal 7 1ong Functions that are Character Strings The returned character string is passed as two extra initial arguments in the following order A pointer to the start of the string return value The length of the string return value Array Indexing and Order Array Indexing C arrays always start at zero but by default Fortran arrays start at 1 There are two common ways of approaching this e You can use the Fortran default as in the above example Then the Fortran element b 2 is equivalent to the C element b 1 e You can specify that the Fortran array b star
95. cing the computation to double precision you compute the dot product with greater accuracy and not suffer underflows REAL 8 sum DO i 1 n sum sum dble a i dble b i END DO result sum It may be advisable to have both versions and to switch to the double precision version only when required You can force a SPARC processor to behave like an older computer with respect to underflow Add the following to your Fortran 90 main program CALL nonstandard arithmetic But be aware that you are giving up the numerical safety belt that is the operating system default You can get your answers faster and you won t be any less safe than say a VAX but use at your own risk Floating Point 115 116 Use Wrong Answer You might wonder why continue if the answer is clearly wrong Consider a circuit simulation The only variable of interest for the sake of argument from a particular 50 line computation is the voltage Further assume that the only values which are possible are 5v 0 5v It is possible to carefully arrange each part of the calculation to coerce each subresult to the correct range 4 0 lt computed lt Inf gt 5 volts 4 0 lt computed lt 4 0 0 volts Inf lt computed lt 4 0 5 volts Furthermore since Inf is not an allowed value you need special logic to ensure that big numbers are not multiplied IEEE arithmetic allows the logic to be m
96. complete 38 relative 38 performance optimization 19 pg profile by procedure 27 pipes 41 221 222 pointee 171 pointer 171 pointer debug 90 porting problems checking Xlist 70 position independent code 61 pragma 179 203 preconnected units 44 prerequisites xvii preserve case 124 print P P P array parts of large in dox 93 slices in dox 93 asa 3 fpr 3 RIVATE parameter of DOALL 183 rocedure profile pg gprof 27 rocess control dbx 96 processors P number for parallelization 192 rof p 26 profile by procedure p prof 26 procedure pg gprof 27 prompt conventions xxii pure scalar variable 197 purpose of manual xvii pwd 37 Q Qoption 27 R RE R and LD RUN PATH not identical 28 R list store lib paths 28 r option for ar 61 random I O 45 ADMEs directory xxi Fortran 90 User s Guide record debug 90 recursive I O 23 redirection 40 standard error 41 reduction parallelize automatically with reduction 27 reference versus value C FORTRAN 127 referenced but not declared checking Xlist 70 relative path name 38 rename executable file 6 replace library module 61 retrospective of accrued exceptions 111 return function values to C 155 risk with explicit parallelization 209 root 36 run path in executable 24 running FORTRAN 6 S S 30 s 29 safe libraries for multi thread programmin
97. cter string function for Fortran void retstr char rval ptr int rval len char ch ptr pointer to returned string length of returned string pointer to string argument int n ptr pointer to number of copies int ch len length of string argument Return string n ptr copies of the character ch ptr int count i char cp count n ptr cp rval ptr for i20 i count i opgpe c eh ptr 5 Example A Fortran program uses a C CHARACTER function PROGRAM TryRetStr CHARACTER String 16 RetStr 9 String String 1234 RetStr 9 456 UseC function here WRITE String END PROGRAM TryRetStr Example Fortran and C with a character string function demo cc c RetStr c demo 90 RetStr o RetStrmain f90 demo a out 1234 456 demos M Fortran 90 User s Guide Ko lll Labeled Common 90 Calls C C and Fortran can share values in labeled common Example A C function uses labeled common matching the Fortran one below UseCom c extern struct comtype float p float q float r extern struct comtype ilk_ void usecom_ ilk_ p 1 0 ilk_ q 2 0 ilk_ r 3 0 Example A Fortran main program uses a labeled common UseCommain 90 PROGRAM TryUseCom REAL u V W COMMON ilk u v w u 7 0 v 8 0 w 9 0 WRITE
98. d C function does not return a value call it as a subroutine C Calls a Fortran Subprogram If the called Fortran subprogram is a function call it from C as a function that returns a comparable data type If the called Fortran subprogram is a subroutine call it from C as a function that returns a value of int comparable to Fortran INTEGER 4 or void This return value is useful if the Fortran routine does a nonstandard return C Fortran Interface 123 124 Underscore in Names of Routines The Fortran compiler appends an underscore _ to the names of subprograms for both a subprogram and a call to a subprogram This distinguishes it from C procedures or external variables with the same user assigned name Each subprogram name must have 31 or fewer characters To avoid the underscore problem in the C function definition change the name of the C function by appending an underscore to that name Case Sensitivity C and Fortran take opposite perspectives on case sensitivity Cis case sensitive uppercase or lowercase matters Fortran ignores case The Fortran default is to ignore case by converting identifiers to lowercase It converts all uppercase letters to lowercase letters except within character string constants To avoid the case sensitivity problem in the C function definition make the name of the C function all lowercase Fortran 90 User s Guide Data Type Compatibility You
99. d asks you to select one Select one of the following names 1 Generic 90 cube_root real 4 s cube root 2 Generic f90 cube root real 8 d cube root gt 1 3 stop in cube_root dbx cont continuing Enter a SP number 8 stopped in cube root at line 16 in file Generic f90 From inside s cube root 16 E cube foot x Be W 0 8 0 show current value of x dbx print x x 8 0 dbx W Debugging 95 96 Miscellaneous Tips The following tips and background concepts can help Current Procedure and File During a debug session the Debugger defines a procedure and a source file as current Requests to set breakpoints and to print or set variables are interpreted relative to the current function and file Thus stop at 5 sets one of three different breakpoints depending on whether the current file is a1 90 a2 f 90 or a3 90 Uppercase Letters In general if your program has uppercase letters in any identifiers then the Debugger recognizes them You do not need to give it any specific case sensitive insensitive commands as in some earlier versions In fact for 90 1 0 90 and dbx must both be in the case insensitive mode that is do not set dbxenv case sensitive Note Names of files or directories are always case sensitive in both Debugger and dbx This is true even if you have set the dbxenv case insensitive environment attribute Main Features of the Debugger Be
100. d to 03 Restrictions g turns off parallel Avoid parallel if you do your own thread management See mt Do not mix parallelized 77 and parallelized 90 If you use parallel and compile and link in separate steps then link with parallel The parallel option requires the Multiprocessor Fortran 90 multiprocessor enhancement package To get faster code use this option on a multiprocessor SPARC system On a single processor system the generated code usually runs slower Number of Processors To request a number of processors set the PARALLEL environment variable The default is 1 Do not request more processors than are available f Nis the number of processors on the machine then for a one user multiprocessor system try PARALLEL N 1 See Section B 4 Number of Processors Before you use parallel see Appendix B iMPact Multiple Processors Appendix C iMPact Automatic Parallelization and Appendix D iMPact Explicit Parallelization Fortran 90 User s Guide Qo lll Qoption pr op reduction Profile by procedure for gprof Produce counting code in the manner of p but invoke a runtime recording mechanism that keeps more extensive statistics and produces a gmon out file at normal termination Then you can make an execution profile by running gprof 1 pg and gprof are complementary to a and tcov Library options must be after the f and o files pg librari
101. dler to abort on the common exceptions If your system time is very large over 50 of runtime check into modifying your code or using nonstandard arithmetic Floating Point 113 8 8 Miscellaneous Examples 114 A miscellaneous collection of more or less realistic examples is provided here as a possible additional aid Kinds of Problems The problems in this chapter usually involve arithmetic operations with a result of invalid division by zero overflow underflow or inexact For instance Underflow In old arithmetic that is prior to IEEE if you multiply two very small numbers on a computer you get zero Most mainframes and minicomputers behave that way In IEEE arithmetic there is gradual underflow this expands the dynamic range of computations For example consider a machine with 1 0E 38 as the machine epsilon the smallest representable value on the machine Multiply two small numbers E 30 E 15 b a b vrer O Em In old arithmetic you get 0 0 but with IEEE arithmetic and the same word length you get 1 40130E 45 With old arithmetic if a result is near zero it becomes zero This can cause problems especially when subtracting two numbers because this is a principal way accuracy is lost You can also detect that the answer is inexact The inexact exception is common and means the calculated result cannot be represented exactly at least not in the precision be
102. e 11 13 13 32 74 74 105 107 125 126 132 170 178 179 182 XV xvi Table B 1 Parallelization Summary Table D 1 DOAL General Parameters Table D 2 DOAL Scheduling Parameters Fortran 90 User s Guide Purpose and Audience Preface This preface is organized into the following sections Purpose and Audience page xvii Before You Read This Book page xviii How This Book is Organized page xviii Related Documentation page xviii Conventions in Text page xxii This U Global program checking across routines U Making and using libraries Jsing some utilities and development tools The U U Using debuggers with Fortran 90 Mixing C and Fortran 90 guide shows how to use Sun Fortran 90 1 0 Major topics of the guide are sing the compiler command and options sing iMPact multiprocessor Fortran 90 MP sing IEEE floating point with Fortran 90 guide is intended for scientists and engineers with the following Thorough knowledge of Fortran 90 General knowledge of some operating system experience with some OS Particular knowledge of the SunOS commands cd pwd 1s cat xvii Before You Read This Book If you are not familiar with Fortran 90 you may want to consult the following Fortran 90 Handbook Fortran 90 language definition including intrinsics Fortran 90 Explained Text book introduction to Fortran 90 See
103. e mt option does not require the Multiprocessor Fortran 90 multiprocessor enhancement package but to compile and run it does require Solaris 2 2 or later The equivalent of mt is included automatically with autopar explicitpar or parallel On a single processor system the generated code can run slower with the mt option but not usually by a significant amount The Fortran 90 library 1ibf90 is multithread safe The FORTRAN 77 library that is linked in if you use mt 1ibF77 mt is also multithread safe Restrictions for mt e With mt if a function does I O do not name that function in an I O list Such I O is called recursive I O and it causes the program to hang deadlock Recursive I O is unreliable anyway but is more apt to hang with mt In general do not combine your own multi threaded coding with autopar explicitpar or parallel Either do it all yourself or let the compiler do it You may get conflicts and unexpected results if you and the compiler are both trying to manage threads with the same primitives Modules look for Fortran 90 modules in the dir directory also No space is allowed between M and dir By default such files are sought in the current working directory The Mdir option allows you to keep them in some other location in addition Background lIf a file containing a Fortran 90 module is compiled 90 generates a module file M file in addition to the o file Native floating point
104. e directive below Automatic with reduction parallel reduction Note directive below D irective DOALL MICS DOALL IMICS amp SHARED v1 v2 IMICS amp PRIVATE ul u2 other parameters High X e Notes on the Parallel Options and the Directive system the code usually runs slower Using explicitpar or parallel has high risk as soon as you insert a directive parallel includes explicitpar and does automatic parallelization The parallelization options can be in any order but must be all lower case All require a Fortran MP enhancement package and Solaris 2 2 or later To get faster code all require a multiprocessor system on a single processor e You get automatic and explicit parallelization with the parallel option The compiler automatically parallelizes all appropriate loops It also parallelizes any appropriate loops that you explicitly identify by a directive still a risk with directives of producing incorrect results A loop with an explicit directive gets no reductions Standards Multiprocessing is an evolving concept When standards for multiprocessing are established the above features may be superceded iMPact Multiple Processors 191 B B 3 Speed Gained or Lost The speed gained varies widely with the application Some programs are inherently parallel and show great speedup Many have no parallel potential and show no speedup There
105. e does I O then your system can lock up This causes problems even on single processor machines Two common ways of doing signal handling without being explicitly aware of it are the following Input Output statements WRITE PRINT and so forth that raise exceptions Requesting Exception Handling Example Output that can raise exceptions EAL x 1 0 y 0 0 RINT x y ND Fl J w Input Output statements do locking and if an exception is raised then there may be an attempt to lock an already locked item resulting in a deadlock One possibly overly cautious approach If you are parallelizing do not have I O in that loop and do not request exception handling iMPact Explicit Parallelization 211 lll I Example Using a signal handler which breaks the rules CHARACTER string 5 out 20 DOUBLE PRECISION value ERNAL exception_handler x 4 RINT 7 RINT output i _handler set all exception handler AD 5 E5 value ring 1e310 AD string E5 value amp pi ct RINT Input string string becomes value RINT Value of 1e300 1e10 is 1e300 1e10 ieee flags clear exception all out E P U umu we Vd z iw z EGER FUNCTION exception handler sig code sigcontext EGER sig code sigcontext 5 INT IEEE exception raised URN z
106. e iier ER ence ee AES TS EEEE X E 50 sing mak bi vie Bee nd eran eee ye ee eee es eho eek IEEE 51 5 3 Tracking and Controlling Changes with SCCS 52 Putting Piles under SCOS cng cduce akan b pee ee eed e 52 Checking Files Out and In cce pet ec Rr 54 b LIDTdleS sss ar e eec dca ca 3 REA ae ee s 57 6 1 Libraries in General osos eps v ERE RP ELEEK 57 Load Map esed de PR RPrPePPPE OR P EVE QUE Sier dE ERU 58 Advantages of Libraries vs esae d eme 9 FR Rad pads 58 Contents v 6 2 Static Libraries llle 58 Disadvantages of Libraries asas cerato werd ea 58 Sample Creation of a Static Library 00 0 00 cee es 59 Sample Replacement in a Static Library 61 6 3 Dynamic Libraries iuis oelore o iinttieteeereecters 61 Performance Issues ii eee rh o E hh eewecedees 62 Binding OpHODS ewe pws ka nda s eo RO ede EET tad de du 62 A Simple Dynamic Shared Library eer 63 6 4 Consistent Compile and Link 04 65 0 5 Library Vass eee k qe ek ad Ewa d dd 65 Installation Directory sins Ves veux ex EY Red 65 Building Executables 1d Search order 4 66 Running Executables 1d Search order 66 Build Paths and Run Paths obe regu severe EE CE X 67 Finding Built in Paths cccecexs prx Ee rrr EFE 4x 67 7 Deb gging ees eR REREEEEERRRRREAAEAREKYSEREXGT E VEM MUR 69 7 1 Global Program Checking X1ist eee 69 Errors in General Lek UR uade eer oup
107. e it offers the capabilities of both a line and a screen editor vi also provides several commands specifically for editing programs These are options you can set in the editor Two examples are the autoindent option which supplies white space at the beginning of a line and the showmatch option which shows matching parentheses For more information read the vi section of the manual The textedit editor and other editors are available including ed and ex For the emacs editor and other editors not from Sun read the Sun document Catalyst a Catalog of Third Party Software and Hardware Xemacs is an Emacs editor that provides interfaces to the selection service and to the ToolTalk service The EOS package Era On Sparcworks uses these two interfaces to provide simple yet useful editor integration with two SPARCworks tools the SourceBrowser and the Debugger Era is an earlier name of this editor It is available through the University of Illinois by anonymous ftp at ftp cs uiuc edu pub era Fortran 90 User s Guide lll 1 8 Program Development fsplit 1 4 Debugging dbx debugger 1 5 Licensing There are several development tools available This utility is a Fortran output filter for printing files that have Fortran carriage control characters in column one The UNIX implementation on this system does not use carriage control since UNIX systems provide no explicit printer files You use asa when
108. e line can be in uppercase lowercase or mixed The form varies for fixed form and free form source as follows Fixed Form Source Put CDIR or DIR in columns 1 through 5 Directives are listed in columns 7 and beyond Columns beyond 72 are ignored An initial directive line has a blank in column 6 A continuation directive line has a nonblank in column 6 Free Form Source Put DIRS followed by a space anywhere in the line The DIRS characters are the first nonblank characters in the line actually non whitespace Directives are listed after the space Aninitial directive line has a blank tab or newline in the position immediately after the DIRS A continuation directive line has a character other than a blank tab or newline in the position immediately after the DIRS Thus DIR in columns 1 through 5 works for both free form source and fixed form source Fortran 90 User s Guide A FIXED and FREE Directives These directives specify the source form of lines following the directive line Scope They apply to the rest of the file in which they appear or until the next FREE or FIXED directive is encountered Uses They allow you to switch source forms within a source file They allow you to switch source forms for an INCLUDE file You insert the directive at the start of the INCLUDE file After the INCLUDE file has been processed the source form reverts back to the form
109. e the results Poor arithmetic can produce poor results This cannot easily be distinguished from other causes of poor results Switching everything to double precision is no panacea Floating Point 101 8 8 4 EEE Exceptions IEEE exception handling is the default on a SPARC processor However there is a difference between detecting a floating point exception and generating a signal for a floating point exception SIGFPE Detecting a Floating point Exception In accordance with the IEEE standard two things happen when a floating point exception occurs in the course of an operation The handler returns a default result For 0 0 return NaN as the result A flag is set that an exception is raised For 0 0 set invalid operation to 1 Generating a Signal for a Floating point Exception The default on SPARC hardware systems is that they do not generate a signal for a floating point exception The assumption is that signals degrade performance and that most users don t care about most exceptions To generate a signal for a floating point exception you establish a signal handler You use a predefined handler or write your own See Exception Handlers and ieee handler later in this chapter for details Default Signal Handlers 102 By default 90 sets up some signal handlers mostly for dealing with such things as a floating point exception interrupt bus error segmentation violation or i
110. ecific to particular hardware options The utility fpversion tells which floating point hardware is installed The utility fpversion 1 takes 30 to 60 wall clock seconds before it returns since it dynamically calculates hardware clock rates of the CPU and FPU See fpversion 1 Also read the Numerical Computation Guide for details Many Options on Short Commands Some users type long command lines with many options To avoid this make a special alias or use environment variables Alias Method Example Define 90f demo alias f90f f90 fast 04 Example Use 90f demo f90f any f90 The above command is equivalent to 90 fast 04 any 90 Environment Variable Method Some users shorten command lines by using environment variables The FFLAGS or OPTIONS variables are special variables for FORTRAN If you set FFLAGS or OPTIONS they can be used in the command line If you are compiling with make files FFLAGS is used automatically if the make file uses only the implicit compilation rules Example Set FFLAGS demo setenv FFLAGS fast 0O4 Using the Compiler 33 34 Example Use FFLAGS explicitly demo 90 FFLAGS any f90 The above command is equivalent to 90 fast 04 any 90 Example Let make use FFLAGS implicitly If both The compile in a make file is implicit no explicit 90 compile line The FFLAGS variable is set as a
111. eed 70 Details obere KR RKERAIMIRASEE DRE EUN Vue dd 70 Using Global Program Checking suus 71 Suboptions for Global Checking Across Routines 73 Fortran 90 User s Guide 72 The dbx DEDURGEr x eiae ss s Rogat meaai 77 sample Program for Debugger a cene memet es 78 A Sample dbx Session ssi ila desc EY UE EF ERE ERR 79 Segmentation Fault Finding the Line Number 81 Exception Finding the Line Number 83 Trace of Calle 22 3550h000epetwe Gui REvAu EY PebbRP LONE 84 Pointer tod SCalat Lov cua pc VOIE RT ra ie 24 85 Pointer to an Altay vic rie bd e REOR RRR REEL IH dA 86 User Defined Types ja uacocascioeicin e d REN RA LA 6 87 Pointer to User Defined Type euicxexexecei ute RAE E 89 Allocated AIayScissaaak eva seco E Rew VE epp UA SAT 91 luin uL A 92 Print Array DIeeso xus eva voee P ERA E CEP TE 93 Generic Functions crt ven iva EHE RATS d EVE DE TY V 94 Miscellaneous Ipaa ev esexewe xke rra eveebeb ete ES 96 Main Features of the Debugger Jvc rro 96 Help peg NAE an Ie EMIL UE DR e x C DI ecu 97 Se Floating Point sesse 255s rede ERI RUPEE EROR QU e 99 BL DUUM Lec odi DT eee EX EU Fa Edd RSS 99 8 2 The General Problems exec ecpER ERE EE ERR 100 8 3 JEEE Soltions os 0b sweeter CHER CPP Rer E DOO 101 Contents vii 8 4 TEBE Exceptions 551a xx ae yer een gra bina ne Rec teen ae 102 Detecting a Floating point Exception serere 102 Generating a Sig
112. elf explicit parallelizing Automatic Parallelization Automatic parallelization is both fast and safe To automatically parallelize loops use the parallel option With this option the software determines which loops are appropriate to parallelize Example Automatic parallelization Do all appropriate loops demo 90 parallel any f90 Explicit Parallelizing Explicit parallelization may yield extra performance at some risk of producing incorrect results To explicitly parallelize all user specified loops do the following Determine which loops are appropriate to parallelize Insert a special directive just before each loop that you want to parallelize Use the explicitpar option on the compile command line Example Explicit parallelization Do only the DO 1 1 N loop demo cat t1 90 MICS DOALL See Appendix D iMPact Explicit Parallelization IMICS amp SHARED a b c n IMICS amp PRIVATE i DO i 1 n This loop gets parallelized a i BI e END DO DOk 1 m This loop does not get parallelized x k y X z k END DO demo 90 explicitpar t1 f90 190 Fortran 90 User s Guide Ss lll Summary The following table summarizes the parallel options and the directive Table B 1 Parallelization Summary Options Syntax Risk of Incorrect Results Explicit only explicitpar Note directive below Automatic and Explicit parallel Not
113. emo 90 g sbr o smain o 6 5 Library Paths If you compile any module under a major release of the operating system then compile all modules of that program with the same major release The linker searches for libraries in several locations and it searches in certain prescribed orders You can make some changes to the order and locations Installation Directory Some library locations depend on the installation directory These locations are described here in terms of a path called BasDir defined as follows Installation Location BasDir Standard opt SUNWspro lib Nonstandard for example my dir my dir Libraries 65 66 Building Executables 1d Search order During the build of the executable 1d searches for libraries in the following locations in order Path Comment BasDir lib Sun shared libraries here BasDir SC3 0 1 1lib Sun libraries shared or static here opt SUNWspro lib Standard location for Sun libraries usr ccs lib usr lib The linker also searches in any directories specified in LD_LIBRARY_PATH or by the Ldir option Running Executables 1d Search order During the run of the executable 1d searches for shared libraries in the following locations in order Path Comment BasDir lib Built in by driver unless norunpath opt SUNWspro lib Built in by driver unless norunpath Directories built in by R or LD RUN PATH when executable was made
114. en command line environment variable 33 subprogram in loop explicit parallelization 208 subroutine compared to function C FORTRAN 123 unused checking X1ist 70 used as a function checking Xlist 70 suffix of file names recognized by compiler 11 165 166 Sun Programmer Quarterly Newsletter 227 Sun sending feedback to xxi 20 SunOS 5 x 2 223 suppress error nnn Xlist 75 license queue 24 linking 16 trap for floating point exceptions 19 warnings Xlist 76 SVR4 2 symbol table for dbx g 20 strip executable of 29 syntax compiler 9 errors Xlist 70 90 9 System V Release 4 SVR4 2 T tab character in source 164 temp 30 templates inline 21 temporary files directory for 30 terminal display Xlist 71 76 textedit 2 third party software and hardware 2 thread stack 29 time timing compilation passes 30 traceback dbx 84 ode 84 tree 36 triangle as blank space xxii turn off warnings about IEEE accrued exceptions 106 type checking across routines Xlist 70 type declaration alternate form 170 typewriter font xxii Fortran 90 User s Guide U U do not convert to lowercase 124 underflow abrupt 112 gradual 112 IEEE 101 units preconnected 44 unrecognized options 12 unrequited exceptions 111 unused functions subroutines variables labels xXlist 70 uppercase debug 96 external names 124 usage automatic parallelization 195 compiler
115. en you do call for them Approach This chapter lists the compatibility rules and shows examples for item passable between C and Fortran Examples show how to pass an item not how it would be used in real applications 119 9 9 1 Sample Interface Example A C function to be called by a Fortran main program Samp c samp xj f int i float f both iand fare pointers 9 Oi Os Example A Fortran main program to call a C function Sampmain f90 PROGRAM Sample INTEGER i REAL r CALL Samp i r bothiand rare passed by reference WRITE I2 F4 1 i x END PROGRAM Sample Example A Fortran program calls a C function Compile Link Execute demo ec 9 9 9 demos M c Samp c demo 90 Samp o Sampmain f90 lt This does the linking demo a out 120 Fortran 90 User s Guide Ko lll 9 2 How to Use this Chapter 1 Examine the previous section Sample Interface 2 Examine the next section Compatibility Requirements 3 Find what to do in the section Fortran Calls C or C Calls Fortran The following two tables help find the appropriate subsection For a Fortran 90 main and a C function Fortran Calls C page 134 Arguments Passed by Reference f90 Calls C page 134 Simple Arguments Passed by Reference f90 Calls C page 134 Co
116. ence table and errors Show cross checking errors and cross reference This suboption by itself does not show a listing The cross reference table shows information about each identifier Is it an argument Does it appear in a COMMON or EQUIVALENCE declaration Is it set or used Example Use Xlistwarnnn to suppress two specific warnings demo 90 Xlistwar338 Xlistwar348 XlistE Repeat f90 demo cat Repeat lst FILE demo Repeat f90 Fortran 90 User s Guide N lll 7 2 The dbx Debugger This section is organized as follows Sample Program for Debugging example page 78 A Sample dbx Session example page 79 Segmentation Fault Finding the Line Number example page 81 Exception Finding the Line Number example page 83 Trace of Calls example page 84 Pointer to a Scalar example page 85 Pointer to an Array example page 86 User Defined Types example page 87 Pointer to User Defined Type example page 89 Allocated Arrays example page 91 Print Arrays example page 92 Print Array Slices example page 93 Generic Functions example page 94 Miscellaneous Tips page 96 Main Features of the Debugger page 96 Help example page 97 This section introduces some dbx features likely to be used with Fortran Use it as a quick start for debugging Fortran Be sure to try the help feature Note Before you use the
117. er to a character string C always passes arrays and character strings using pointers In fact C universally promotes character strings and arrays to pointers So in C you cannot pass arrays or character strings by value Passing Arguments by Value N A If a C function passes an argument by value using no pointers there is no compatible way of passing to Fortran 90 That is Fortran 90 cannot interface with such a function Example Define a C function dummy argument is an int no pointer simvall int i The above function cannot be called from Fortran 90 Fortran 90 User s Guide Ko lll Character Strings and Order Passing strings between C and Fortran is nonstandard It is not encouraged The following compatibility rules are provided for those who need to do it despite the complexities Rules for Passing Any Character Strings If you make a string in Fortran and pass it to C you must provide an explicit null terminator because Fortran does not automatically do that and C expects requires it All C character strings pass using pointers Arguments that are Character Strings For a character argument Fortran 90 passes needs an extra argument that Contains the length of the character string Is equivalent to a C 1ong int s passed by value The order of arguments is as follows A list of the regular arguments A list of hidden arguments one for each
118. errors found in a Fortran 90 program Portability problems codes that do not conform to ANSI Fortran 90 if the appropriate option is used Fortran 90 User s Guide N lll Using Global Program Checking To cross check the named source files use X1ist on the command line Example Compile three files for global program checking demo 90 Xlist anyl f90 any2 f 90 any3 f90 In the above example 90 does the following Saves the output in the file any1 1st Compiles and links the program if there are no errors Example Compile all Fortran 90 files for global program checking demo 90 Xlist 90 Terminal Output To display directly to the terminal rename the output file to dev tty Example Display to terminal demo 90 Xlisto dev tty anyl f90 See Xlisto name on page 76 The Default Output Features The simple X1ist option as shown in the example above provides a combination of features available for output That is with no other X1ist options on the f90 command line the plain simple Xlist option provides the following The output file has the same name as the first file with a 1st extension The output content includes A line numbered source listing Default Error messages embedded in listing for inconsistencies across routines Cross reference table of the identifiers Default Pagination at 66 lines per page 79 columns per
119. es a listing and a cross reference table combinations and variations of these are available using suboptions An example follows Example Errors only Use X1isti E to show errors only Form of output varies demo 90 XlistE Repeat f90 demo cat Repeat lst FILE Repeat f90 demos MM 69 70 Errors in General Details Global program checking can do the following Enforce type checking rules of Fortran 90 more stringently than usual especially between separately compiled routines Enforce some portability restrictions needed to move programs between different machines and or operating systems Detect legal constructions that are nevertheless wasteful or error prone Reveal other bugs and obscurities More particularly global cross checking reports problems such as Interface problems Checking number and type of dummy and actual arguments Checking type of function values Checking possible conflicts of incorrect usage of data types in common blocks of different subprograms Usage problems Function used as a subroutine or subroutine used as a function Declared but unused functions subroutines variables and labels Referenced but not declared functions subroutines variables and labels Usage of unset variables Unreachable statements Implicit type variables Inconsistency of the named common block lengths names and layouts Syntax problems syntax
120. es and other countries exclusively licensed through X Open Company Ltd OPEN LOOK is a registered trademark of Novell Inc PostScript and Display PostScript are trademarks of Adobe Systems Inc CRAY is a registered trademark of Cray Research Inc All other product names mentioned herein are the trademarks of their respective owners All SPARC trademarks including the SCD Compliant Logo are trademarks or registered trademarks of SPARC International Inc SPARCstation SPARCserver SPARCengine SPARCstorage SPARCware SPARCcenter SPARCclassic SPARCcluster SPARCdesign SPARC811 SPARCprinter UltraSPARC microSPARC SPARCworks and SPARCompiler are licensed exclusively to Sun Microsystems Inc Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems Inc The OPEN LOOK and Sun Graphical User Interfaces were developed by Sun Microsystems Inc for its users and licensees Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry Sun holds a non exclusive license from Xerox to the Xerox Graphical User Interface which license also covers Sun s licensees who implement OPEN LOOK GUIs and otherwise comply with Sun s written license agreements X Window System is a product of the Massachusetts Institute of Technology THIS PRODUCT IS DERIVED FROM CRAY CF90 A PRODUCT OF CRAY RESEARCH INC THIS PUBLICATION IS
121. es are static If you compile and link in separate steps and you compile with pg then be sure to link with pg Compare this profiling method with the one described in the manual Performance Tuning an Application For Solaris 2 x when the operating system is installed gprof is included if you do a Developer Install rather than an End User Install it is also included if you install the package SUNWbtool Option pass option list to specified program Pass the option list op to the program pr There must be a blank between Qoption and pr and op The Q can be uppercase or lowercase The list is a comma delimited list of options no blanks within the list Each option must be appropriate to that program and can begin with a minus sign The assembler used by the compiler is named fbe Example Pass the help option for help to the linker 1d demo 90 Qoption ld Dhelp src f90 Example Pass the load map to the linker 1d demo 90 Qoption ld m src f90 Multiprocessor reduction loops analyze loops for reduction Analyze loops for reduction during automatic parallelization There is potential for roundoff error with the reduction The reduction option requires the Multiprocessor Fortran 90 multiprocessor enhancement package To get faster code this option requires a multiprocessor system On a single processor system the generated code usually runs slower Using the Compiler 27 28 R Is
122. et fast so that it does not use the library of selected math routines optimized for performance Use this after the fast option f90 fast xnolibmopt Using the Compiler al 22 xO n Xpg xtime Xlist Synonym for o n Synonym for pg Synonym for time Global program checking check across routines arguments commons This helps find a variety of bugs by checking across routines for consistency in arguments common blocks parameters and so forth In general X1ist also makes a line numbered listing of the source and a cross reference table of the identifiers The errors found do not necessarily prevent the program from being compiled and linked Table 3 4 Summary of Xlist Suboptions Option Action Xlist no suboption Errors listing and cross reference table XlistE Errors Xlisterr Suppress all error messages in the verification report Xlisterr nnn Suppress error nnn in the verification report XlistI Include files XlistL Listing and errors Xlistln Page length is n lines Xlisto name Rename the X1ist output report file Xlistwar Suppress all warning messages in the report Xlistwar nnn Suppress warning nnn in the report XlistX Cross reference table and errors For more information see Details of Xlist Suboptions on page 75 Fortran 90 User s Guide Qo lll 3 3 Miscellaneous Tips Floating Point Hardware Type Some compiler options are sp
123. eturns C and Fortran Compile Link Execute demo 90 c AltRet f90 Obsolescent The alternate RETURN construct is obsolete at line 6 Obsolescent The alternate RETURN construct is obsolete at line 7 demo acc c AltRetmain c demo 90 AltRet o AltRetmain o demo a out 92 demo In this example the C main receives a 2 as the return value of the subroutine because the RETURN 2 was executed C Fortran Interface 161 162 Fortran 90 User s Guide A 1 Standards aN Ii Features and Differences This appendix is organized into the following sections Standards page 163 Extensions page 164 Directives page 179 Compatibility with FORTRAN 77 page 184 Forward Compatibility page 188 Mixing Languages page 188 Module Files page 188 This appendix shows some of the major features differences between Standard Fortran 90 and Sun Fortran 90 FORTRAN 77 and Fortran 90 This Fortran is an enhanced ANSI Standard Fortran 90 development system It conforms to the ANSI X3 198 1992 Fortran standard and the corresponding International Standards Organization ISO IEC 1539 1991 E Fortran 90 standard It provides an IEEE standard 754 1985 floating point package 163 A 2 Extensions On SPARC systems it provides support for optimization exploiting features of SPARC V8 including the SuperSsPARC implementation These features are defined
124. f the four arguments is a string Input action mode and in Output out and i ieee flags is an integer valued function Useful information is returned in i Refer to the man page for ieee flags 3m for complete details Fortran 90 User s Guide Co lll Possible parameter values are shown below action get set clear clearall mode direction precision exception in out nearest tozero negative positive extended double single inexact division underflow overflow invalid all common The meanings of the possible values for in and out depend on the action and mode they are used with These are summarized in the following table Table 8 1 ieee_flags Argument Meanings Value of in and out Refers to nearest tozero negative positive Rounding direction extended double single Rounding precision inexact division underflow overflow Exceptions invalid all All 5 exceptions common Common exceptions invalid division overflow Example To determine what is the highest priority exception that has a flag raised pass the input argument in as the null string ieeer ieee flags get exception out PRINT out flag raised Example To determine if the overflow exception flag is raised set the input argument in to overflow On return if out equals overflow then the overflow exception flag is raised otherwise it is not raised ieeer ieee fl
125. following Load the library during runtime Do the link editing operations Execute the library position independent code Programs Vary Because of these various performance issues some programs are slower if they use nonshared libraries and some if they use shared libraries You might bind each way to tell whether one method is significantly better for your program Binding Options You can specify the binding option when you compile that is dynamic or static libraries These options are actually linker options but they are recognized by the compiler and passed on to the linker d y n Allow or disallow dynamic libraries for the entire executable dy Yes allow dynamically bound libraries allow shared libraries dn No do not allow dynamically bound libraries no shared libraries These apply to the whole executable Use only once on the command line The default is y B dynamic static Bind as dynamic or static libraries listed later This applies to any library listed later in the command The default is dynamic Bdynamic Prefer dynamic binding try for shared libraries Bstatic Require static binding no shared libraries Fortran 90 User s Guide 6 If you provide a library for your customers then providing both a dynamic and a static version allows the customers the flexibility of binding whichever way is best for their application For example if the customer is doing some benchmarks
126. g A bitwise logical expression has a Boolean result each of its bits is the result of one or more logical operations on the corresponding bits of the operands For binary arithmetic operators and for relational operators f one operand is Boolean the operation is performed with no conversion If both operands are Boolean the operation is performed as if they were integers No user specified function can generate a Boolean result although some nonstandard intrinsics can Boolean and logical types differ as follows Variables arrays and functions can be of logical type but they cannot be Boolean type There is a LOGICAL statement but no BOOLEAN statement A logical variable or constant represents only one value A Boolean constant can represent as many as 32 values A logical expression yields one value A Boolean expression can yield as many as 32 values Logical entities are invalid in arithmetic relational or bitwise logical expressions Boolean entities are valid in all three Features and Differences 167 168 Alternate Forms of Boolean Constants 90 allows a Boolean constant octal hexadecimal or Hollerith in the following alternate forms no binary Variables cannot be declared Boolean Standard Fortran 90 does not allow these forms Octal ddddddB where d is any octal digit You can use the letter B or b There can be 1 to 11 octal digits 0 through 7 11 octal digits represe
127. g 22 sample interface C FORTRAN 120 SCCS 52 checking in files 54 checking out files 54 creating files 53 inserting keywords 53 making directory 52 putting files under SCCS 52 search object library directories 22 segmentation fault 29 82 some causes 81 set directory for temporary files 30 INCLUDE path 21 number of processors for parallelization 192 Shakespeare 119 shared library name a shared library 20 SHARED parameter of DOALL 183 shell script 49 shorten command lines alias 33 environment variable 33 show commands 17 SIG Sun Programmers Special Interest Group xxi 227 SIGFPE debugging 113 definition 102 107 detect in dbx 113 generate 107 when generated 109 113 signal handler 109 with explicit parallelization 211 SIGSEGV some causes 81 size of data types 125 126 slices of arrays in dbx 93 Solaris 2 source lines e 17 source form directives 166 options 165 suffixes 166 speed gained or lost from parallelization 192 spirits 119 Index stack overflow 29 variables 29 stack trace 84 stackvar 29 standard arithmetic 112 conformance to standards xviii error 41 error accrued exceptions 111 Fortran 90 163 input 40 44 output 40 44 statement unreachable checking X1ist 70 static binding 17 62 library 58 strip executable of symbol table s 29 structure debug 87 88 89 stupid UNIX tricks shorten command line alias 33 short
128. g when it is run This means that if myprog is a Fortran 90 program and reads from unit 5 it reads from the mydata file Output Iruncate The shell command line demo myprog myoutput The above command causes the file myoutput which is created if it does not exist or rewound and truncated if it does to be connected to the standard output of the program myprog when it is run So if the Fortran 90 program myprog writes to unit 6 it writes to the file myoutput Output Append The shell command line demo myprog myoutput The above command causes the file myoutput which must exist to be connected for appending So if the Fortran 90 program myprog writes to unit 6 it writes to the file myoutput but after wherever the file ended before Fortran 90 User s Guide E 46 Piping Both standard input and standard output may be redirected to and from different files on the same command line Standard error may also be redirected so it does not appear on your workstation display In general this is not a good idea since you usually want to get error messages from the program immediately rather than sending them to a file The shell syntax to redirect standard error varies depending on whether you are using sh or csh Example csh Redirecting standard error and standard output demo myprogl amp myprog2 Example sh Redirecting standard error and standard output demo
129. idual components can be only 512 characters long However to prevent the shell from misinterpreting certain special punctuation characters restrict your use of punctuation in file names to the dot underscore _ comma plus and minus The slash character has a specific meaning in a file name and is only used to separate components of the path name as described in the following section Also avoid using blanks in file names Directories are just files with special properties and follow the same naming rules as files The only exception is the root directory named slash To describe a file anywhere in the file system you can list the sequence of names for the directory subdirectory and so forth and file separated by slash characters down to the file you want to describe If you show all the directories starting at the root that s called an absolute path name If you show only the directories below the current directory that s called a relative path name File System and File I O af 38 Relative Path Names From anywhere in the directory structure you can describe a relative path name of a file Relative path names start with the directory you are in the current directory instead of the root For example if you are in the directory usr you and you use the relative path name mail record that is equivalent to using the absolute path name usr you mail record This is illustrated in the diag
130. ies A subprogram invoked from within the loop requires advanced dependency analysis Since such a case works only under explicit parallelization it is you who must do the advanced dependency analysis not the compiler The following rule sometimes helps with subprogram calls in a loop Within a subprogram if all local variables are automatic rather than static then the subprogram does not have iteration dependencies Note that the above rule is sufficient but it is by no means necessary For instance the daxpy routine in the previous example does not satisfy this rule and it does not have iteration dependencies although that is not obvious You can make all local variables of a subprogram automatic as follows List them in an automatic statement However then you cannot initialize them in a data statement D 5 Exceptions for Explicit Parallelizing 208 The following are the primary exceptions that prevent the compiler from explicitly parallelizing a DO loop The compiler issues error messages that the loops are not parallelized except for a DO loop nested inside another DO loop which is so common that messages would be distracting The DO loop is nested inside another DO loop that is parallelized This exception holds for indirect nesting too If you explicitly parallelize a loop and that loop includes a call to a subroutine then even if you parallelize loops in that subroutine still at runtime those loops are n
131. ification report page 75 XlistI Include files page 75 XlistL Listing and errors page 76 Xlistln Page length is in n lines page 76 Xlisto name Rename the X1ist output report file page 76 Xlistwar Suppress all warning messages in the report page 76 Xlistwar nnn Suppress warning nnn in the report page 76 XlistX Cross reference table and errors page 76 74 Fortran 90 User s Guide N lll Xlisterr Xlisterr nnn XlistE XlistI Details of X1ist Suboptions Suppress all error messages in the verification report Suppress error nnn in the verification report This is useful if you want a cross reference or a listing without the error messages It is also useful if you do not consider certain practices to be real errors To suppress more than one error use this option repeatedly Example Xlisterr338 suppresses error message 338 If nnn is not specified then suppress all error messages Global cross check errors Show cross routine errors This suboption by itself does not show a listing or a cross reference Include files List and cross check the include files If XlistI is the only X1list option suboption used then you get the standard X1ist output of a line numbered listing error messages and a cross reference table but include files are shown or scanned as appropriate Listing If the listing is not suppressed then the include files are listed in place Files are listed as
132. ight depending on your attitude or needs Nonsquare arrays are worse Compile Link Execut e Before After Matrix Arguments Passed by Reference C Calls 90 Example A Fortran 2 by 2 array argument explicitly indexed from 0 to 1 SUBROUTINE MatRef a total f90 gets passed a two dimensional array from C C calls f90 INTEGER c r total a 0 1 0 1 a 0 1 99 Changes a 0 1 total 0 DO r 0 1 Sums all ofa DO c 0 1 total total a r c END DO END DO END SUBROUTINE MatRef Example A 2 by 2 C array argument indexed from 0 to 1 void matref int void main AC two dimensional array argument passed to f90 1 2 1 int Declare fen interface int GC f sum 7 int m 2 2 00 01 10 11 for c 0 c 2 ctt for r 0 r 2 rtt printf m d d 02d Mn c r m c r matref 1m amp sum Arrays pass by reference for c ce2 ttt for r 0 r 2 rt printf m d d 02d Mn c r m c r Example A 2 by 2 array argument show m before and after Fortran call MON OM ON OS oS C shows that m 1 0 got changed d BH BHuddiBs moUuoonmnr nmPooco om pomnbcnonmo ll o o C Fortran Interface 153 lll Ko StruRef f90 See also Complex Arguments Passed by Reference C Calls f90 on page 150
133. ii Courier xxii italic xxii FORTRAN calls C 134 is called by C 149 read me file bugs new changed features xxi Fortran print fpr 3 Fortran 90 User s Guide FPE catch in dox 83 fpr FORTRAN print 3 fpversion show floating point version 33 free form source 180 form source and tabs 164 FREE directive 179 181 free free form source 19 fsplit FORTRAN file split 3 function called within a loop parallelization 208 compared to subroutine C FORTRAN 123 data type of checking xXlist 70 names 124 return values from C 141 return values to C 155 unused checking X1ist 70 used as a subroutine checking Xlist 70 G g debug 20 G generate a dynamic library 20 generic functions debug 94 getcwd 37 Glendower 119 global program checking 69 Goldberg floating point white paper xix gprof pg profile by procedure 27 gradual underflow 112 graphically monitor variables dbx 97 GSA validated xviii guidelines for number of processors 193 H h name 20 handlers exception 102 107 hardware floating point fpversion 33 help 20 help list of options 20 Henry IV 119 hexadecimal 168 hierarchical file system 35 Hollerith 169 Hotspur 119 I I O 40 identifiers and lowercase 124 IEEE 101 111 113 754 xviii exceptions 102 signal handler 109 standard 754 1985 163 warning messages off 106 ieee flags 104 105 ieee functions 104 ieee handler 104
134. ilable the compiler returns without queueing your request and without doing your compile A nonzero status is returned for testing in make files No run path in executable If an executable file uses shared libraries then the compiler normally builds in a path that tells the runtime linker where to find those shared libraries The path depends on the directory where you installed the compiler The norunpath option prevents that path from being built in to the executable This option is helpful if you have installed in some nonstandard location and you ship an executable to your customers but you do not want to make the customers deal with that nonstandard location Compare with Rlist Fortran 90 User s Guide Qo lll o nm onetrip Output file rename the output file Name the final output file nm instead of a out There must be a blank between 0 and nm DO loops use one trip DO loops Compile DO loops so that they are performed at least once if reached DO loops in Fortran 90 ordinarily are not performed at all if the upper limit is less than the lower limit unlike some implementations of FORTRAN 66 DO loops Optimize the object code for speed of execution The n can be 1 2 3 or 4 No space is allowed between 0 and n If o n is not specified the compiler still performs a default level of optimization that is it executes a single iteration of local common subexpression elimination and live dead anal
135. ile alloc f90 9 PRINT buffer n dbx print n n 1000 dbx print buffer n buffer n 1000 dbx M Debugging Ei 92 Print Arrays Arraysdbx f90 Example dbx recognizes arrays It can print arrays demo dbx a out dbx list 1 25 1 DIMENSION iarr 4 4 2 DO i 1 4 3 DO j 1 4 4 iarr i j i 10 5 END DO 6 END DO Y END dbx stop at 7 1 stop at Arraysdbx f90 7 dbx run Running a out stopped in main at line 7 in file Arraysdbx f90 7 END dbx print IARR iarr 1 1 11 2 1 21 3 19 31 4 1 41 1 2 12 2 2 22 35 2 32 4 2 42 1 3 13 2 3 23 3 3 33 4 3 43 1 4 14 2 4 24 3 4 34 4 4 44 dbx print IARR 2 3 iarr 2 3 23 lt order of user specified subscripts ok dbx quit demo M Fortran 90 User s Guide zi Print Array Slices This section shows one way of printing portions of large arrays Example dbx prints array slices if you specify which rows and columns ShoSli f90 demo 90 g ShoSli f90 demo dbx a out dbx list 1 12 L INTEGER 4 a 3 4 col row 2 DO row 1 3 3 DO col 1 4 4 a row col row 10 col 5 END DO 6 END DO 7 DO row 1 3 8 write 413 A row col col 1 4 9 END DO 10 END dbx stop at 7 1 stop at ShoSli f90 7 dbx run Running a out stopped in main at line 7 in file ShoS
136. in the SPARC Architecture Manual Version 8 Sun Fortran 90 provides the following extensions Tabs in the Source 90 allows the tab character in fixed form source and in free form source Standard Fortran 90 does not allow tabs The tab character is not converted to a blank so the visual placement of tabbed statements depends on the utility you use to edit or display text Fixed Form Source For a tab in column one If the next character is a nonzero digit then the current line is a continuation line otherwise the current line is an initial line Atab cannot precede a statement label Atab after column one is treated by 90 the same as a blank character except in literal strings Free Form Source 90 treats a tab and a blank character as equivalent except in literal strings 1 SuperSPARC is a trademark of Texas Instruments Inc Fortran 90 User s Guide A Continuation Line Limits 90 allows 99 continuation lines 1 initial and 98 continuation lines Standard Fortran 90 allows 19 for fixed form and 39 for free form Fixed Form Source of 96 Characters In fixed form source lines can be 96 characters long Columns 73 through 96 are ignored Standard Fortran 90 allows 72 character lines Directives 90 allows directive lines starting with CDIRS IDIRS CMICS or MICS They look like comments but are not For full details on directives see Directives on page 179 Standard Fortran 90 ha
137. ing Linker option arguments Names of 90 compatible object programs maybe from a previous run Libraries of 90 compatible routines If an unrecognized argument Has a then it is an option and generates a warning Has no then it generates no warnings but if the linker does not recognize them the linker issues error messages 3 2 Compiler Options This compiler has the power of many optional features so this tends to produce a very long list of features To help you use this long list the options are organized from different perspectives so you can look up an action to see which option does it or you can look up an option to see what it does List Perspective How to Get It Actions and What Invokes Them Actions Options Sorted by Action Frequent Actions Options Frequently Used See page 13 Summary One line descriptions See page 13 See also compile action in the Index Options and What They Do Options Actions Sorted by Option Summary One line descriptions 90 help Full Descriptions Examples risks trade offs restrictions interactions All risks trade offs restrictions interactions and examples See page 15 Some risks trade offs restrictions interactions examples man 90 See also the option name in the Index 12 Fortran 90 User s Guide Qo lll Actions Options Frequently Used A few options are needed by almost every programmer Table 3 2 Optio
138. ing a selection of options Select the combination of compilation options that optimize for speed of execution without excessive compilation time This should provide close to the maximum performance for most realistic applications If you combine fast with other options the last specification applies If you do not specify the level as in fast O you get fast 03 If you compile and link in separate steps and you compile with fast then be sure to link with fast Fixed form source Interpret all Fortran 90 source files by fixed form rules Overrides file suffix See also FIXED and FREE Directives on page 181 Synonym for help Do not trap floating point exceptions Without nonstop there is a trap on the invalid overflow and divide by zero floating point exceptions Free form source Interpret all Fortran 90 source files by free form rules Overrides file suffix See also FIXED and FREE Directives on page 181 Using the Compiler 19 20 g hnm help Debug produce additional symbol table information for the debugger Produce a symbol table of information for the debuggers You get much more debugging power if you compile with g before using the debuggers e g overrides O e gis turned off by explicitpar parallel or reduction Library build a dynamic library Tell the linker to build a dynamic library Without G the linker builds an executable file With G it build
139. ing used but it is as good as can be delivered Underflow tells us as we can tell in this case that we got an answer smaller than the machine naturally represents This is accomplished by stealing some bits from the mantissa and shifting them over to the exponent The result is less precise in some sense but more so in another The deep implications are beyond this discussion The interested reader may wish to consult Computer January 1980 Volume 13 Number 1 particularly I Coonen s article Underflow and the Denormalized Numbers Fortran 90 User s Guide 8 Roundoff Most scientific programs have sections of code that are sensitive to roundoff often in an equation solution or matrix factorization So be concerned about numerical accuracy if your computer doesn t do a good job your results will be tainted and there is often no way to know that this has happened Simple Underflow Some applications actually do a lot of work very near zero This is common in algorithms which are computing residuals or differential corrections For maximum numerically safe performance perform the key computations in extended precision If the application is a single precision application this is easy as we can perform key computations in double precision Example A simple dot product computation sum 0 DO i 1 n sum sum a i b i END DO If a i and b i are small many underflows will occur By for
140. input to x READ x I3 I4 nl n2 Reads the internal file x WRITE nl n2 d d D emo 90 internl emo a out Enter two numbers 12 99 12 99 demos MM Example Array for internal file sequential formatted read demo cat intern3 f90 CHARACTER 16 Line 4 DATA Line 81 81 82 82 7 83 83 7 84 84 READ Line 214 i j k 1 m n Reads internal file Line PRINT i Jy Ky l m n END demo 90 intern3 demo a out 81 81 82 82 83 83 demos M File System and File I O 47 48 Fortran 90 User s Guide Program Development 5 This chapter is organized into the following sections Simple Program Builds page 49 Program Builds with the make Program page 50 Tracking and Controlling Changes with SCCS page 52 5 1 Simple Program Builds For a program that depends on a few source files and some system libraries you can easily compile all of the source files every time you change the program Even in this simple case the f90 command can involve much typing and with options or libraries a lot to remember A script or alias can help Writing a Script A shell script can save typing For example to compile a small program that is in the file example 90 and that uses the Xview support library you can save a one line shell script onto a file here called fex that looks like this 90 example f90 lFxview
141. ion type help Details of one command a command explanation type help cmdname Changes a list of the new and changed features type help changes FAQ answers to frequently asked questions type help FAQ Example Command Summary output varies with release dbx help Command Summary Execution and Tracing cancel catch clear cont delete fix fixed handler ignore intercept next pop replay rerun restore run save status step stop trace unintercept when whocatches Displaying and Naming Data assign call demangle dis display down dump examine exists frame hide inspect print undisplay unhide up whatis where whereami whereis which lt many commands omitted gt Debugging 97 98 Example help cmdnam details for the where command dbx where where where where where where info help where Print a procedure traceback num Print the num top frames in the traceback f num Start traceback from frame num h Include hidden frames q Quick traceback only function names v Verbose traceback include function args and line Any of the above forms may be followed by a thread or LWP ID to obtain the traceback for the specified entity dbx Fortran 90 User s Guide 8 1 Summary Floating Point 8 This chapter is organized into the following sections Summary page 99 IEEE Solutions page 101 The General Problems page 100
142. ip location sip fault address actions you take END fault uap Pattern hand4x sig code context hand4x is your name for your integer functionForm Signal handler function Example Detect an exception using a handler and abort SunOS 5 x or 4 x 5 x and 4 x DetExcHan f90 SunOS 5 x or 4 x SIGFPE is generated whenever a floating point exception occurs gt Then the SIGFPE is detected and control is passed to the myhandler function PROGRAM DetExcH EXTERNAL myhandler REAL r 14 2 s 0 0 handler set i i t r s END INTEGER FUNCTION myhandler sig OK in SunOS 5 x 4 x as all we do is abort INTEGER sig code INTEGER DIMENSION 5 CALL abort END demo demo code context f90 DetExcHan f90 a out abort called Abort core dumped demos M division context myhandler Handler 5 x or 4 x Floating Point 109 Example Locate an exception get address using a handler 5 x PROGRAM LocExcH5x Locate Exception by Handler SunOS 5 x LocExcHan5x f90 EXTERNAL hand5x INTEGER hand5x SunOS 5 x REAL r 14 2 s 0 0 i i _handler set division hand5x An addressis mosily for those wh
143. ironment variables used by the driver Version ID show version ID Print the name and version ID of each pass as the compiler executes Fortran 90 User s Guide Qo lll w n xlibmopt xlicinfo xnolib xnolibmopt Warnings suppress warnings The n can be any one of 0 1 2 3 or 4 w0 suppresses the least warnings w4 suppresses the most warnings e w with no n is the same as wO0 Use selected math routines optimized for performance This usually generates faster code It may produce slightly different results if so they usually differ in the last bit The order on the command line for this library option is not significant License information display license server user ids Return license information about the licensing system In particular return the name of the license server and the user ID for each of the users who have licenses checked out Generally with this option no compilation is done and a license is not checked out and generally this option is used with no other options However if a conflicting option is used then the last one on the command line wins and there is a warning Example Report license information do not compile order counts demo 90 c xlicinfo any f90 Example Do not report license information do compile order counts demo 90 xlicinfo c any f90 Synonym for nolib Reset fast so that it does not use xlibmopt Res
144. is is not desirable Solution 1 Change All of the Program If you change the code to be double precision by rewriting the code with double precision variables you get vast improvement real 0m0 20s user 0m0 08s sys Om0 11s Now of course it may not be desirable to promote an entire program to double precision though this is what is traditionally done to make up for the fact that old style arithmetic is less accurate Floating Point 117 118 Solution 2 Change One Double Precision Variable If you declare sum to be DOUBLE PRECISION and change only the summation line of code as follows sum sum a i dble b i then you get real 0m0 18s user 0m0 06s sys Om0 11s By promoting one variable to double you eliminate the software underflow problem Note that in a real application put the variable sum in double precision and coerce it to single precision only on output This is not a performance issue but a numeric one Of course it may not be easy to tell which variables in a huge program need to be promoted The effort is worthwhile not only because of the performance which as you will learn can be achieved in other ways but because the numerics are enhanced as well Solution 3 Nonstandard Arithmetic There is a quick and dirty solution which is CALL nonstandard arithmetic This tells the hardware to act like an old style computer and when underflow
145. ith ieee_handler To establish a signal handler pass the following to ieee handler Name of the function Exception to watch for Action to take Floating Point 107 108 Once a handler is established a signal is generated whenever the particular floating point exception occurs The form of invoking ieee_handler is as follows i ieee_handler action exception handler action character get or set or clear exception character invalid or division or overflow or underflow or inexact handler function name The name of the function you wrote return value integer 0 OK Writing a Signal Handler Function Actions taken by the function are up to you but the form of the function is The function must be an integer function The function must have three arguments typed as follows Pattern hand5x sig sip uap hand5x is your name for your integer function sig is an integer e sip is a record which has the structure siginfo see sample below uap is not used here Fortran 90 User s Guide Co lll Form Signal handler function 5 x SunOS 5 x Form INTEGER FU IN CTION hand5x EGER sig location YPE f _typ INTEGER address END TYPE fault_typ YPE siginfo I I L sig sip NTEGER si_signo NTEGER SI_CODE NTEGER si_errno TYPE fault typ END TYPE siginfo TYPE siginfo s
146. l only if the computational result does not depend on the order of execution The compiler does a dependency analysis to detect loops with no order dependence If it errs it does so on the side of caution Also it may not parallelize a loop that could be parallelized because the gain in performance does not justify the overhead Example Automatic parallelizing skips this loop it has data dependencies DO k 3 1000 x k x k 1 x k 2 END DO You cannot calculate x k until two previous elements are ready Fortran 90 User s Guide C lll Definitions Array Scalar and Pure Scalar e An array variable is one that is declared with dimensioning in a DIMENSION statement or a type statement examples below e A scalar variable is a variable that is not an array variable Apure scalar variable is a scalar variable that is not aliased not referenced in an equivalence statement and not in a pointer statement Examples Array scalar both m and a are array variables s is pure scalar DIMENSION a 10 REAL m 100 10 s u X Z REAL ARGET x REAL POINTER px EQUIVALENCE u z s 0 0 The variables u x z and px are scalar variables but not pure scalar C 3 Definition Automatic Parallelizing General Definition Details Automatic parallelization parallelizes DO loops that have no inter iteration data dependencies This compi
147. laintypewriter font shows prompts and coding In dialogs boldface typewriter font shows text the user types in demo echo hello hello demos M Italics indicate general arguments or parameters that you replace with the appropriate input Italics also indicate emphasis For Solaris 2 x the default shell is sh and the default prompt is the dollar sign Most systems have distinct host names and you can read some of our examples more easily if we use a symbol longer than a dollar sign Examples generally use demo as the system prompt where the csh shell is shown we use demo as the system prompt A small clear triangle A shows a blank space where that is significant AA36 001 We generally tag nonstandard features with a small black diamond 9 Wherever we indicate that a feature is nonstandard that means a program using it does not conform to the ANSI X3 198 1992 standard as described in American National Standard for Programming Language Fortran Extended ANSI X3 198 1992 1992 American National Standards Institute Inc informally abbreviated as the Fortran 90 Standard We usually show Fortran 90 examples in free form not fixed form or tab We usually abbreviate Sun Fortran 90 as 90 We usually show Fortran 90 keywords and intrinsics in uppercase and all else in lowercase or mixed case Fortran 90 User s Guide Introduction 1 This chapter is organized in
148. le Character arguments C and Fortran demo 90 c StrRef f90 demo cc c StrRefmain c demo 90 StrRef o StrRefmain o demo a out sl0 abcdefghi s80 abcdefghijklmnopaqrstuvwxyz demo E C Fortran Interface 151 lll Ko VecRef f90 VecRecmain c Compile Link Execute 152 Vector Arguments Passed by Reference C Calls 90 Example A Fortran one dimensional array arg implicitly indexed from 1 to 9 SUBROUTINE VecRef v total f90 gets passed a one dimensional array argument from C C calls f90 INTEGER i total v 9 total 0 DOi 1 9 total total v i END DO END SUBROUTINE VecRef Example A C one dimensional array argument indexed from 0 to 8 void vecref int int Declare fcn interface void main A one dimensional array argument passed to f90 int i sum int v 9 1 2 3 4 5 6 7 8 9 vecref v amp sum Arrays pass by reference printf d Mn sum Example A one dimensional array argument Fortran and C demo 90 c VecRef f90 demo cc c VecRefmain cO0 demo 90 VecRef o VecRefmain f90 demo a out 45 demos M Fortran 90 User s Guide MatRef 90 In a two dimensional array the rows and columns are switched comparing C and Fortran MatRefmain c Such square arrays are either incompatible for C and Fortran or awkward to do r
149. le Using parallel a call inside a loop DO 40 kb 1 n Not parallelized k n 1 kb b k b k a k k t b k call daxpy k 1 t a 1 k 1 b 1 1 40 CONTINUE Fortran 90 User s Guide Example Using parallel a constant step size loop INTEGER PARAMETER del 2 DO k 3 1000 del Parallelized x k x k z k k END DO Example Using parallel a variable step size loop INTEGER del 2 DO k 3 1000 del Not parallelized x k x k z k k END DO Example Using parallel nested loops DO 900 i 1 1000 Parallelized outer loop do 200 j 1 1000 Not parallelized inner loop 200 CONTINUE 900 CONTINUE Example Using parallel a jump out of loop DO i 1 1000 Not parallelized IF a i gt min threshold GO TO 20 END DO 20 CONTINUE iMPact Automatic Parallelization 199 200 Example Using parallel a loop that conditionally changes a scalar variable referenced after a loop DO i 1 IF END DO t k s 1000 whatever S Not parallelized v i Fortran 90 User s Guide See Appendix B iMPact Multiple Processors for required background D 1 What You Do iMPact Explicit Parallelization The appendix is organized into the following sections
150. ler finds and parallelizes any loop that meets the following criteria but note exceptions below The construct is a DO loop uses the DO statement but not DO WHILE The values of array variables for each iteration of the loop do not depend on the values of array variables for any other iteration of the loop Calculations within the loop do not conditionally change any pure scalar variable that is referenced after the loop terminates Calculations within the loop do not change a scalar variable across iterations This is called loop carried dependency iMPact Automatic Parallelization 197 198 There are slight differences from vendor to vendor since no two vendors have compilers with precisely the same criteria Example Using the parallel option DO i 1 a i END DO n Parallelized demo 90 parallel t 90 Exceptions for Automatic Parallelizing For automatic parallelization the compiler does not parallelize a loop if any of the following occur The DO loop is nested inside another DO loop that is parallelized Flow control allows jumping out of the DO loop There is a user level subprogram invoked inside the loop There is an I O statement in the loop Calculations within the loop change an aliased scalar variable Examples The following examples illustrate the definition of what gets done with automatic parallelization plus the exceptions Examp
151. li f90 7 DO row 1 3 dbx E Example Print row 3 dbx print a 3 3 1 4 a 3 3 1 4 3 1 31 3 2 32 3 3 33 3 4 34 dbx i Example Print column 4 dbx print a 1 3 4 4 a 3 3 1 4 1 4 14 2 4 24 3 4 34 dbx E Debugging 93 94 Generic Functions Example Generic function cube root dbx Generic f90 I 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 21 38 39 40 list 1 99 MODULE QE INTERFACE cube root EA FUNCTION s cube root x RI 1 tt S cube root REAL INT ENT IN x D FUNCTIO s cube root nj pd UNCTIO d cube root x D D ND OUBLE PRECISION d cube root OUBLE PRECISION INTENT IN x FUNCTIO d cube root UO p END I NTERFACE END MOD FUNCTIO REA ULE cr Ss cube root x 1 tt S cube root REA S C END FUN FUNCTIO DOU DOU 1 INTENT IN x ube root x 1 0 3 0 CTION s cube root d cube root x BLE PRECISION d cube root BLE PRECISION INTENT IN x d cube root x 1 0d0 3 0d0 FUNCTIO Cc EAL x d cube root Cx CISION y Cy RITE vy m Enter a SP number D R DOUBLE PRE W R EAD cx c
152. line Defaults No call graph Default No expansion of include files Default Debugging 71 Repeat 90 Form of output varies Compile with xlist gt List the x1ist output file gt 72 Example Using Xlist a program with inconsistencies between routines demo cat Repeat f90 PROGRAM repeat pnl REAL CALL subrl CALL nwfrk PRINT END LOC pnl pnl pni PROGRAM repeat rpl SUBROUTINE subrl x IF x GT 1 0 CALL subrl x END IF E D 5 9 END SUBROUTINE AL nwfrk fork INTEGER prnok fork PRINT prnok ix D ix fork ti INTEGER FUNCTION prnok x prnok INT x LOC x D tj SUBROUTINE unreach sub CALL sleep 1 END f90 Xlist Repeat f90 cat Repeat lst demo demo Fortran 90 User s Guide N lll Suboptions for Global Checking Across Routines The standard global cross checking option is X1ist with no suboption This shows the listing errors and cross reference table For variations from this standard report add one or more suboptions to the command line Suboption Syntax Add suboptions according to the foll Append the suboption to Xlist Put no space between the X1ist owing rules and the suboption Put only one suboption per X1ist Combination Special and A La Carte Subo
153. link in separate steps demo 90 demo 90 c filel f90 file2 90 file3 f90 make o files filel o file2 o file3 o make a out file Of course every file named in the first step as a 90 file must also be named in the second step as a o file Consistent Compile and Link Be consistent with compiling and linking If you compile and link in separate steps and you compile any subprogram with dalign or fast then be sure to link with the same options Command line File Names If a file name in the command line has any of the following suffixes the compiler recognizes it otherwise it is passed to the linker Table 3 1 File Name Suffixes Fortran 90 Recognizes Suffix Language Form Action 90 Fortran 90 Free Compile Fortran 90 source files put object files in current directory default name of object file is that of the source but with o suffix f Fortran 90 or Fixed Same as 90 but different source form standard FORTRAN 77 for Same as f Fixed Same as f ftn Same as f Fixed Same as f s Assembler Assemble source files with the assembler o Object Files Pass object files through to the linker Fixed form source and free form source are explained in Section 3 3 Source Form of the Fortran 90 Handbook Using the Compiler 11 lll Qo Unrecognized Arguments Any arguments 90 does not recognize are taken to be one of the follow
154. llegal instruction Although you would not generally want to turn off this default behavior it is possible to do so by setting the global C variable 77 no handlers to 1 Example Get no default signal handlers set 77 no handlers to 1 1 Create the following C program demo cat NoHandlers c int 90 no handlers 1 demo Fortran 90 User s Guide Co lll 8 5 IEEE Routines 2 Compile it and save the o file demo cc c o NoHand NoHandlers c demo 3 Link the corresponding o file into your executable file demo 90 NoHand o Any f90 demo Otherwise by default it is 0 The effect is felt just before execution is transferred to the user s program so it does not make sense to set unset it in the user s program Note This variable is in the name space of the user s program so do not use 90_no_handlers as the name of a variable anywhere else other than in the above C program Many vendors support the IEEE standard The SPARC processors conform to the IEEE standard in a combination of hardware and software support for different aspects The older Sun 4 uses the Weitek 1164 5 and the Sun 4 110 has that as an option The newer Sun 4 and the SPARCsystem series both use floating point units with hardware square root This is accessed if you compile with the c989 option The newest SPARCsystem series uses new floating point units including SuperSP
155. llowing are general guidelines not hard and fast rules It usually helps to be flexible and experimental with number of processors For these guidelines let N be the number of processors on the machine Do not set PARALLI EL to more than N usually degrades performance Try PARALLEL set to the number of processors wanted and expected to get In general allow at least one processor for activities other than the program you are parallelizing for overhead other users and so forth For a one user system try PARALLEL N 1 and try PARALLEL N Fora multiple user system if the machine is overloaded with users it may help to try PARALLEL set to much less than N For example with a 10 user machine it may help to try PARALLEL at 4 or 6 or 8 If you ask for 10 and cannot get 10 then you may end up time sharing some CPU s with other users iMPact Multiple Processors 193 194 Fortran 90 User s Guide C 1 What You Do See Appendix B iMPact Multiple Processors for required background iMPact Automatic Parallelization C This appendix is organized into the following sections What You Do page 195 What the Compiler Does page 196 Definition Automatic Parallelizing page 197 This appendix shows an easy way to parallelize programs for multiple processors This is called automatic parallelizing This is a how to guide To tell the compiler to parallelize autom
156. m int i sum 0 for i 0 i lt 8 i sum sum v i Example A Fortran vector argument implicitly indexed from 1 to 9 PROGRAM FixedVector INTEGER DIMENSION 9 a INTEGER i sum CALL FixVec a sum WRITE a 9I2 p y END PROGRAM FixedVector 1 2 3 4 5 6 7 8 9 sums 3 a i i 1 9 sum Example A vector argument Fortran and C implicitly indexed from 1 to 9 demo cc c FixVec c demo 90 FixVec o FixVecmain f90 demo a out a 1234567 8 9 demos M sum 45 Example A vector argument Fortran and C explicitly indexed from 0 to 8 PROGRAM FixedVectorE a is explicitly indexed 0 to 8 INTEGER DIMENSION 0 8 a 1 2 3 4 5 6 7 8 9 INTEGER i sum CALL FixVec a sum WRITE a 912 sum I3 a i i 0 8 sum END PROGRAM FixedVectorE Example A vector argument Fortran and C explicitly indexed from 0 to 8 demo cc c FixVec c demo 90 FixVec o FixVecmain 90 demo a out a 123456789 demos M sum 45 Fortran 90 User s Guide Ko lll FixMat c FixMatmain f90 Compile Link Execut e Before After Matrix Arguments Passed by Reference 90 Calls C In a two dimensional array the rows and columns are switched Example A 2 by 2 C array argument indexed from 0 to 1 fixmat int a
157. m uses a C function that returns an int RetIntmain f90 PROGRAM ReturnInt INTEGER r s RetInt r 8 s 100 RetInt r TheC function is invoked here WRITE 214 r s END PROGRAM ReturnInt Example Fortran and C with an INTEGER function return value Compile Link Execute demo cc c RetInt c demo 90 RetInt o RetIntmain f90 demo a out 8 109 demo C Fortran Interface 141 RetFloat c RetFloatmain f90 Compile Link Execute 142 REAL Function Return Value 90 Calls C Example A C function yields a float function return value not a pointer float retfloat float pf float f f pf ft return e b cr Example A Fortran program uses a C function that returns a float RAM ReturnFloat RetFloat 8 0 100 0 RetFloat RITE 2F6 1 PROGRAM ReturnFloat PROG REAL r S r TheC function is invoked here r S W fr B END Example Fortran and C with a REAL function return value demo cc c RetFloat c demo 90 RetFloat o RetFloatmain f demo a out 8 0 109 0 demos M In earlier versions of C if C returned a function value that was a float C promoted it to a double and various tricks were needed to get around that Fortran 90 User s Guide Ko lll RetPtrF c RetPtrFmain f90 Compile Link Execute Pointer to a REAL Function Return Value 90
158. may be ill conditioned The computer may be doing something astonishing or at least unexpected It is nearly impossible to separate these error sources Using library packages which have been approved by the numerical analysis community reduces the chance of there being a code error Using good algorithms is another must Using good computer arithmetic is the next obvious step The IEEE standard represents the work of many of the best arithmetic specialists in the world today It was influenced by the mistakes of the past It is by construction better than the arithmetic employed in the 5 360 family the VAX family the CDC CRAY and UNIVAC families to name but a few This is not because these vendors are not clever but because the IEEE pundits came later and were able to evaluate the choices of the past and their consequences Does IEEE arithmetic solve all problems No But in general the IEEE Standard makes it easier to write better numerical computation programs 1 CDC isa registered trademark of Control Data Corporation 2 UNIVAC is a registered trademark of UNISYS Corporation Fortran 90 User s Guide Co lll 8 3 IEEE Solutions IEEE arithmetic is a relatively new way of dealing with arithmetic operations where the result yields such problems as invalid division by zero overflow underflow or inexact The big differences are in rounding handling numbers near zero and handling numbers near the machine maximum
159. may want to write Fortran 90 routines to interface with existing C routines or C routines to interface with existing Fortran 90 routines Writing Fortran 90 Code for Existing C Routines For any given C intrinsic data type the following table provides a close corresponding Fortran 90 data type Table 9 1 C Data Type to Fortran 90 Data Type C Intrinsic Type Close Fortran 90 Type Size Alignment Bytes Bytes char x CHARACTER x 1 1 signed char x INTEGER KIND 1 x 1 4 signed char x n CHARACTER LEN n n 1 unsigned char x n CHARACTER LEN n n 1 float x REAL x 4 4 double x DOUBLE PRECISION x 8 4 long double x N A 16 4 int x INTEGER x 4 4 signed x INTEGER x 4 4 signed int x INTEGER x 4 4 long x INTEGER x 4 4 long int x INTEGER x 4 4 signed long x INTEGER x 4 4 signed long int x INTEGER x 4 4 unsigned int x INTEGER x 4 4 unsigned long x INTEGER x 4 4 unsigned long int x INTEGER x 4 4 short x INTEGER KIND 2 x 2 4 short int x INTEGER KIND 2 x 2 4 signed short int x INTEGER KIND 2 x 2 4 unsigned short x INTEGER KIND 2 x 2 4 unsigned short int x INTEGER KIND 2 x 2 4 long long x N A unsigned long long x N A C double aligns on 8 byte boundaries unless in a common block then on 4 C Fortran Interface 1
160. mmand ld Undefined symbol lt missing routine Fc mult demo M C Fortran Interface 131 lll Ko File Descriptors and st dio Fortran I O channels are in terms of unit numbers The I O system does not deal with unit numbers but with file descriptors The Fortran runtime system translates from one to the other so most Fortran programs don t have to know about file descriptors Many C programs use a set of subroutines called standard I O or st dio Many functions of Fortran I O use standard I O which in turn uses operating system I O calls Some of the characteristics of these I O systems are listed below Table 9 3 Characteristics of Three I O Systems Fortran Units Standard I O File Pointers File Descriptors Files Open Opened for read Opened for reading or Opened for reading or ing and writing Opened for writing or Opened for writing or Opened for both or Opened for both Opened for appending See OPEN 3S Attributes Formatted or Always unformatted but Always unformatted unformatted can be read or written with format interpreting routines Access Direct or Direct access if the physical Direct access if the sequential file representation is direct physical file representa access but can always be tion is direct access but read sequentially can always be read sequentially Structure Record Character stream Character stream Form Arbitrary Pointers to structures inthe Integers fr
161. mplex Arguments Passed by Reference f90 Calls C page 135 Character Arguments Passed by Reference f90 Calls C page 136 Vector Arguments Passed by Reference f90 Calls C page 138 Matrix Arguments Passed by Reference f90 Calls C page 139 Structure Arguments Passed by Reference f90 Calls C page 140 Pointer Arguments Passed by Reference f90 Calls C J N A page 140 Arguments Passed by Value f90 Calls C page 141 Function Return Values f90 Calls C page 141 INTEGER Function Return Value f90 Calls C page 141 REAL Function Return Value f90 Calls C page 142 Pointer to a REAL Function Return Value f90 Calls C page 143 DOUBLE PRECISION Function Return Value f90 Calls C page 144 LOGICAL Function Return Value f90 Calls C page 145 CHARACTER Function Return Value f90 Calls C N A page 146 Labeled Common f90 Calls C page 147 Alternate Returns f90 Calls C N A page 148 C Fortran Interface 121 For a C main and a Fortran 90 subprogram C Calls Fortran page 149 Arguments Passed by Reference C Calls f90 page 149 Simple Arguments Passed by Reference C Calls f90 page 149 Complex Arguments Passed by Reference C Calls f90 page 150 Character Arguments Passed by Reference C Calls f90 page 151 Vector Arguments Passed by Reference C Calls f90 page 152 Matrix Arguments Passed by Reference C Calls f90 page 152 Structure Arguments Passed by Reference C Calls f90
162. n g 20 parameters agree globally 69 pointer 90 to a scalar 85 to an array 86 to user defined type 89 record 90 row print 93 slices of arrays 93 stack trace 84 structure 85 86 87 88 89 trace of calls 84 uppercase lowercase 96 user defined type 87 debugger main features 96 declared but unused checking Xlist 70 deep vasty 119 dependency analysis 196 with explicit parallelization 210 diamond indicates nonstandard xxii differences Fortran 90 standard Sun FORTRAN 77 163 direct I O 45 directive 165 179 182 203 DOALL 182 explicit parallelization 180 182 203 line defined 180 directory 37 current working 37 object library search 22 temporary files 30 display to terminal Xlist 71 division by zero IEEE 101 dn 17 62 DO loops executed once onetrip 25 DOALL directive 182 doall loop 206 double word align dalign 17 dryrun 17 dy 17 62 dynamic binding 17 62 library 61 build G 20 name a dynamic library 20 path in executables 28 E e extended source lines 17 ed 2 emacs 2 email alias Sun Programmers SIG 227 send feedback comments to Sun xxi environment variable shorten command line 33 EOS package 2 era 2 errata and addenda for manuals read me file xxi error standard error 41 44 standard error accrued exceptions 111 errors only XlistE 75 Index establish a signal handler 109 event management dbx 96 ex 2 exceptions
163. n they are nondeterministic you can get incorrect results Testing is not Enough An entire test suite can produce correct results over and over again and then produce incorrect results What happens is that the number of processors or the system load or some other parameter changed So you must test with different numbers of processors different system loads and so forth But this means you cannot be exhaustive in your test cases iMPact Explicit Parallelization 209 210 The problem is not roundoff but interference between iterations An example of this is one iteration referencing an element of an array that is calculated in another iteration but the reference happens before the calculation One approach is systematic analysis of every explicitly parallelized loop To be sure of correct results you must be certain there are no dependencies Example Loop with dependency parallelize explicitly nondeterministic result REAL a 1001 s 0 0 DO i 1 1001 Initialize array a a i i END DO MICS DOALL IMICS amp SHARED a MICS amp PRIVATE i DO i 1 1000 This loop has dependencies a i a itl END DO DO i 1 1000 Get the sum of all a i s s a i END DO PRINT s Print the sum END demo 90 explicitpar t1 90 How Indeterminacy Arises In a simpler example 4 processors 8 iterations same kind of initialization The first 2 iterations
164. n c demo 90 UseCom o UseCommain o demo a out ilk p 2 7 0 ilk q 8 0 ilk r 9 0 demos M Note Any of the options that change size or alignment or any equivalences that change alignment might invalidate such sharing 160 Fortran 90 User s Guide Ko lll Alternate Returns C Calls 90 Some C programs may need to use a Fortran routine with nonstandard returns No new Fortran 90 routine needs alternate returns they are obsolete Example One regular argument and two alternate returns AltRet f90 SUBROUTINE AltRet i Obsolete INTEGER i k Obsoletefeatures are candidates i29 for removal from the next version k 20 of the standard Fortran 90 has better ways of doing the same ETURN 1 Obsolete ETURN 2 Obsolete IF k eq 10 IF k eq 20 RI RI thing i RETURN END SUBROUTINE AltRet Example Alternate returns C invokes the subroutine as a function AltRetmain c int altret_ int Declare function interface main To C a Fortran routine with nonstandard returns does return int k m an int INTEGER 4 The return wc r value specifies which alternate return was used If the routine has no entry points with alternate return arguments the returned value is undefined m altret_ amp k Use the Fortran subroutine printf sd d n k m Example Alternate r
165. nal for a Floating point Exception 102 Default Signal Handlers i3 eve cbbt keen rg bes 102 8 5 JEEE ROULIDeS 2222 2 RRRREDEE XR Ret ione Eter 103 Flags and ieee_flags ii cee s ees ededededeeeestawte es 104 Values and ieee values cece cece eee eee eee 106 Exception Handlers and ieee handler 107 Retrospectives dp e rn agee cena ee EE REE RR REOR OR EERE LAS 111 Nonstandard Arithmetic cae ues deer ER CER ER RR 111 Messages about Floating point Exceptions 112 8 6 Debugging IEEE Exceptions scere 113 8 7 Guidelines ees ex kese reeds ERE NSUE eRe ee eg RES 113 8 8 Miscellaneous Examples x 2 sis coors ver Cx a 114 Kinds Of Problems o9 co eer hese ee ee ree behets 114 Simple UnderfloW 3x eds dran coin eae RR OR Ronin 115 Use Wrong Answer 25 daas s eR OC ROCK sheng aba aaa 116 Excessive Underflow ov iii 22 ites edeee up Ed 116 9 C Fortran Intetface xssusdsua ya kie gcc o cab Ge wens 119 9 1 Sample MeEI aee aoa pepe P mpppRDHP eere PRPRPEPCEI 120 9 2 How to Use this Chapter 2 cwevexoez tene o rer EYES 121 viii Fortran 90 User s Guide 9 3 Compatibility Requirements dan wn wwe emm 122 Function or Subroutine sah et a cere Gerda dn qi Rp reote 123 Underscore in Names of Routines 005 124 Case Sensitivity cese ey EE RI deen ex ECCE Kop eee 124 Data Type Compatibility os coswewsves e PuberR E REECO LES 125 Passing Arguments by Reference or Value
166. nd delget is a composite of the two simpler SCCS commands delta and get The delta command does the first three items in the list above and the get command does the fourth and fifth Program Development 55 56 Fortran 90 User s Guide Libraries 6 This chapter is organized into the following sections Libraries in General page 57 Static Libraries page 58 Dynamic Libraries page 61 Consistent Compile and Link page 65 Library Paths page 65 See 1d 1 for more details 6 1 Libraries in General A library can be a collection of subprograms Each member of this collection is called a library element or module A relocatable library is one whose elements are relocatable o files These object modules are inserted into the executable file by the linker during the compile link sequence Some examples of static libraries on the system are Fortran 90 library 1ib 90 a Math library libm a C library libc a 57 lll Or 58 Some examples of shared dynamic libraries on the system are FORTRAN 77 library libF77 so C library libc so Load Map To display a load map pass the load map option to the linker by Qoption This displays which libraries are linked and which routines are obtained from which libraries during the creation of the executable module This is a very simple load map Example m for load map demo 90 Qoption ld m any f90 Advantages of
167. nd later in this chapter Accessing Named Files Before a program can access a file with a READ WRITE or PRINT statement the file must be created and a connection established for communication between the program and the file The file can already exist or be created at the time the program executes The Fortran 90 OPEN statement establishes a connection between the program and file to be accessed For a description of OPEN read the Fortran 90 Handbook File names can be simple expressions as listed below Quoted character constants File myfile out Character variables File Filnam Character expressions File LEN TRIM Prefix LEN TRIM Name A program can read file names from a file or terminal keyboard READ 4 401 Filnam Fortran 90 User s Guide HS lll Accessing Unnamed Files When a program opens a Fortran 90 file without a name the runtime system supplies a file name There are several ways it can do this Opened as Scratch If you specify STATUS SCRATCH in the OPEN statement then the system opens a file with a name of the form tmp FAAAxnnnnn where nnnnn is replaced by the current process ID AAA is a string of three characters and x is a letter the AAA and x make the file name unique This file is deleted upon termination of the program or execution of a CLOSE statement unless STATUS KEEP is specified in
168. ns Frequently Used Action Option Details Debug produce additional symbol table information for the debugger g page 20 Performance make executable run faster using a selection of options fast page 19 Performance make executable run faster using the optimizer O n page 25 Bind as dynamic or static any library listed later in the command Bdynamic Bstatic Bbinding page 15 Library Allow or disallow dynamic libraries for the entire executable dy dn dbinding page 17 Compile only suppress linking make a o file for each source file c page 16 Name the final output file nm instead of a out o nm page 25 Display a list of compiler options help page 20 Check Details for trade offs risks restrictions interactions and examples Actions and What Options Invoke Them Actions Options Sorted by Action This section groups related actions together Check Details for risks trade offs restrictions interactions and examples Table 3 3 Actions Options Sorted by Action Action Option Details Debug Compile for use with the debugger g page 20 Global checking across routines arguments commons parameters Xlist page 32 Version ID show version ID along with name of each compiler pass V page 30 Library Bind as dynamic or static any library listed later in the command Bbinding page 15 Allow or disallow dynamic libraries
169. ns are From the make file it gets all the target files it must make and what files they depend on It also gets the commands used to make the target files It gets the date and time changed for each file If any target file is not up to date with the files it depends on then that target is rebuilt using the commands from the make file for that target 5 8 Tracking and Controlling Changes with SCCS SCCS is Source Code Control System It provides a way to Keep track of the evolution of a source file change history Prevent different programmers from changing the same source file at the same time Keep track of the version number by providing version stamps The basic three operations of SCCS are putting files under SCCS control checking out a file for editing and checking in a file This section shows you how to use SCCS to do these things and provides a simple example using the previous program It describes normal basic SCCS and introduces only three SCCS commands create edit and delget Putting Files under SCCS Putting files under SCCS control involves making the SCCS directory inserting SCCS ID keywords into the files optional and creating the SCCS files Making the SCCS Directory To begin you must create the SCCS subdirectory in the directory in which your program is being developed demo mkdir SCCS demos M The SCCS must be uppercase Fortran 90 User s Guide O1 lll
170. nt a full 32 bit word with the leftmost digit allowed to be 0 1 2 or 3 Each octal digit specifies three bit values The last rightmost digit specifies the content of the rightmost three bit positions bits 29 30 and 31 If less than 11 digits are present the value is right justified it represents the rightmost bits of a word bits n through 31 The other bits are 0 Blanks are ignored Within an I O format specification the letter B indicates binary digits elsewhere it indicates octal digits Hexadecimal D d ddd or X ddd where d is any hexadecimal digit There can be 1 to 8 hexadecimal digits 0 through 9 A F Any of the letters can be uppercase or lowercase X x A F a f The digits must be enclosed in either apostrophes or quotes Blanks are ignored The hexadecimal digits may be preceded by a or sign 8 hexadecimal digits represent a full 32 bit word and the binary equivalents correspond to the contents of each bit position in the 32 bit word If less than 8 digits are present the value is right justified it represents the rightmost bits of a word bits n through 31 The other bits are 0 Fortran 90 User s Guide 2 lll Hollerith nu es moa T fist T Tae s mR LTR R Above is a string of characters and n is the character count A Hollerith constant is type Boolean If any character constant is in a bitwise logical expression the expression is evaluated as H
171. nt exception bits ieee handler 3M Handle exceptions matherr 3M Handle errors XX Fortran 90 User s Guide 90 help Variations The following variations are meant to suggest other possibilities 90 help more The list does not scroll off the screen 90 help grep par Show only parallel options f90 help grep lib Show only library options f90 help lp Print a copy on paper f90 help MyWay Put list onto a file regroup reorder delete f90 help tail Show how to send feedback to Sun README s The READMEs directory has information files bug descriptions information discovered after the manuals were printed feedback form and so forth Standard Installation Nonstandard Installation to my dir Location opt SUNWspro READMEs my dir SUNWspro READMEs Contents File Names feedback Sun programmers email template file Send feedback comments to Sun fortran_90 Fortran 90 bugs new features behavior changes documentation errata SIG Sun Programmers Special Interest Group membership entitles you to other documentation and software A membership form is included at the very end of this book See Join the SunPro SIG Today on page 215 xxt Conventions in Text xxii We use the following conventions in this manual to display information We show code listing examples in boxes WRITE Hello world P
172. o E 2 8 use such low level debuggers as END adb INTEGER FUNCTION hand5x sig sip uap Handler SunOS5 x For how get the line numbersee TNIEGER esa tOn TSL Section 8 6 Debugging IEEE TEE IR Exceptions for details INTEGER address END TYPE fault typ YPE siginfo INTEGER si signo INTEGER si code INTEGER si errno TYPE fault typ fault END TYPE siginfo TYPE siginfo sip Caveat I O in a handler is risky POSS SOS BIpebaultyaddiess Calling abort reduces the risk WRITE Exception at Z28 location Risky ina handler CALL abort Just to reduce risk END Example Locate an exception get address using a handler 11FA8 5 x demo 90 LocExcHan5x 90 Compile Load Run demo a out SunOS 5 x Exception at Th ladd ith abort called e actua a ress varies wit Abort core dumped installation and architecture l Note Following IEEE demos M ieee_handler 3M Sun s implementation of IEEE the Numerical Computation Guide floating point traps enabled see Division by Zero arithmetic is discussed in 110 Fortran 90 User s Guide Co lll 4 x Compile Load Run SunOS 4 x The actual address varies with installation and architecture Example Locate an exception get address using a handler demos 90 LocExcHan4x 90 demo a out Exception at pc 9172 abort called Abort core dumped Retro
173. ocessor enhancement package To get faster code this option requires a multiprocessor system On a single processor system the generated code usually runs slower Before you parallelize explicitly see Appendix B iMPact Multiple Processors Appendix C iMPact Automatic Parallelization and Appendix D iMPact Explicit Parallelization Summary To parallelize explicitly do the following Analyze the loops to find those that are safe to parallelize Insert MIC DOALL to parallelize a loop Use the explicitpar option Example Insert a parallel pragma immediately before the loop MICS DOALL DO i 1 n a i b i c i END DO Example Compile to explicitly parallelize demo 90 explicitpar any f90 Restrictions g turns off explicitpar Avoid explicitpar if you do your own thread management See mt Do not mix parallelized 77 and parallelized 90 If you use explicitpar and compile and link in separate steps then link with explicitpar Fortran 90 User s Guide Qo lll fast fixed flags fnonstop free Align on 8 byte boundaries Align all COMMON blocks and all double precision and quadruple precision local data on 8 byte boundaries This applies to both real and complex data If you compile with f for any subprogram of a program then compile all subprograms of that program with f Faster execution make executable run faster us
174. ollerith A Hollerith constant can have 1 to 4 characters Examples Octal and hexadecimal constants Boolean Constant Internal Octal for 32 bit word OB 00000000000 77740B 00000077740 X ABE 00000005276 x 340 34777 TI6300 XU 2 3 00000000443 X FFFFFFFFFFFFFFFF 37777777777 Examples Octal and hexadecimal in assignment statements i 13575 j X 28FF k X 5A Alternate Contexts of Boolean Constants 90 allows BOZ constants in the places other than DATA statements B bbb O 000 Z Zzzz B bbb O 000 Z zzz If these are assigned to a real variable no type conversion occurs Standard Fortran 90 allows these only in DATA statements Features and Differences 169 170 Abbreviated Size Notation for Numeric Data Types 90 allows the following nonstandard type declaration forms in declaration statements function statements and IMPLICIT statements Table A 1 Size Notation for Numeric Data Types Nonstandard Declarator Short Form Meaning INTEGER 1 INTEGER KIND 1 INTEGER 1 Onme byte signed integers INTEGER 2 INTEGER KIND 2 INTEGER 2 Two byte signed integers INTEGER 4 INTEGER KIND 4 INTEGER 4 Four byte signed integers jOGICAL 1 OGICAL KIND 1 LOGICAL 1 One bytelogicals OGICAL 2 OGICAL KIND 2 LOGICAL 2
175. om 0 63 nonnegative user s address space integers 132 Fortran 90 User s Guide Ko lll File Permissions C programmers traditionally open input files for reading and output files for writing sometimes for both In Fortran it s not possible for the system to foresee what use you will make of the file since there s no parameter to the OPEN statement that gives that information Fortran tries to open a file with the maximum permissions possible first for both reading and writing then for each separately This occurs transparently and is of concern only if you try to perform a READ WRITE or ENDFILE but you don t have permission Magnetic tape operations are an exception to this general freedom since you can have write permissions on a file but not have a write ring on the tape C Fortran Interface 138 9 9 4 Fortran Calls C Arguments SimRef c SimRefmain f90 Compile Link Execute 134 Passed by Reference 90 Calls C Simple Arguments Passed by Reference 90 Calls C The simple arguments are of Fortran 90 data types INTEGER REAL DOUBLI PRECISION or LOGICAL without pointers dimensions or structures Li Example Simple arguments C function C arguments as pointers void simref b4 i4 r4 d8 Simple types passed by reference from 90 f90 calls C int b4 int i4 float eds us double Ge s b4 1 KAA S g r4
176. ot run in parallel A flow control statement allows jumping out of the DO loop The index variable of the loop is subject to side effects such as being equivalenced There is an I O statement in the loop For the following exception the compiler issues no error message Fortran 90 User s Guide D If you explicitly parallelize a loop and that loop includes a call to a subroutine then even if you parallelize loops in that subroutine still at runtime those loops are not run in parallel Example A parallelized loop with a call to a routine that also has a parallelized loop S SUBROUTINE calc b y MICS DOALL sus MICS amp SHARED X MICS DOALL MICS amp PRIVATE i IMICS amp SHARED DO 100 i 1 200 IMICS amp PRIVATE m DO 1 m 1 1000 a CALL calc a x HE CONTINUE 100 CONTINUE RETURN END T At runtime loops within this subroutine do not run in parallel D 6 Risk with Explicit Nondeterministic Results A set of operations can be safely executed in parallel only if the computational result does not depend on the order of execution For explicit parallelizing you rather than the compiler specify which constructs to parallelize and then the compiler parallelizes the specified constructs You do your own dependency analysis If you force parallelization where dependencies are real then the results depend on the order of executio
177. p 58 loaded library 58 local variables 29 locating exception by line number 83 segmentation fault by line number 82 long command lines 33 loop parallelizing a CALL in a loop 29 lowercase do not convert to 124 M M files M files 23 m linker option for load map 58 main stack 29 make 50 making SCCS directory 52 man pages xix manuals xix many options short commands 33 map load 58 mateo 84 math library user error making it unavailable 22 Fortran 90 User s Guide Mdir modules directory 23 membership in SunPro SIG Sun Programmers Special Interest Group 227 MIL STD 1753 xviii miscellaneous tips alias many options short commands 33 environment variable many options short commands 33 floating point version 33 mixing form of source lines 166 monitor variables graphically dbx 97 MP FORTRAN 189 mt multi thread safe libraries 22 multiprocessing standards 191 multiprocessor FORTRAN 189 N name compiler pass show each 30 executable file 25 names in executable nm command 60 native floating point 23 NBS validated xviii nesting parallelized loops 198 208 network licensing 3 NIST validated xviii nm names in executable 60 no license queue 24 nolib 24 non ANSI extensions 15 nondeterministic results explicit parallelization 209 nonstandard arithmetic 111 indicated by diamond xxii noqueue 24 norunpath 24 number of processors for parallelization 1
178. page 11 The 1x is the option to link with library libx a The 1x is after the list of file names Always safer Not always required The files and the results of compilations are linked in the order given to make an executable program named by default a out or with a name specified by the o option Purpose The purpose of 90 is to translate source to an executable file Other major uses Translate source code files to relocatable binary o files Link o files into an executable load module a out file Show the commands built by the compiler but do not execute Prepare for debugging Compile Link Sequence With the above commands if you successfully compile the files growth 90 and fft 90 the object files growth o and fft o are generated then an executable file is generated with the default name a out The files growth o and fft o are not removed If there is more than one object file o file then the object files are not removed This allows easier relinking if there is a linking error If the compile fails you get an error message for each error the a out file is not generated and the remaining o files are not generated Fortran 90 User s Guide Qo lll Compile and Link in Separate Steps You can compile and link in separate steps This is usually done if one of several source files was changed that way you need not recompile all the other source files Example Compile and
179. ptions Combine suboptions according to the following rules The combination special X1ist li The a la carte options are X1listi sting errors and cross reference table E XlistL and XlistxX Once you start ordering a la carte All other options are detail options not a la carte not combination special the three parts of the combination special are cancelled and you get only what you specify Example Each of these two commands does the same thing demo 90 XlistL any f90 demo 90 XlistL Xlist any f90 Debugging 73 lll N Combination special or a la carte suboptions with no other suboptions Table 7 1 Xlist Combination Special or A La Carte Suboptions Type Amount of Output Option Comment Details Errors listing cross reference table Xlist No suboptions page 71 Errors XlistE By itself does not show listing or cross reference table page 75 Errors and listing XlistL By itself does not show cross reference table page 76 Errors and cross reference table XlistX By itself does not show listing page 76 Summary of X1ist Suboptions Table 7 2 Xlist Suboptions Summary Option Action Details Xlist nosuboption Errors listing and cross reference table page 73 XlistE Errors page 75 Xlisterr Suppress all error messages in the verification report page 75 Xlisterr nnn Suppress error nnn in the ver
180. quence of branching directory names and a file name in the file system tree describes a path Files are at the ends of paths and cannot have anything branching from them When moving around in the file system down means away from the root and up means toward the root The figure below shows a diagram of a file system tree structure root directory file subdirectory subdirectory file subdirectory file file Figure 4 1 File System Hierarchy Fortran 90 User s Guide HS lll 4 2 Directories 4 3 File Names 4 4 Path Names All files branch from directories except the root directory Directories are just files with special properties While you are logged on you are said to be in a directory When you first log on you are usually in your home directory At any time wherever you are the directory you are in is called your current working directory It is often useful to list your current working directory The pwd command prints the current working directory name and the get cwd routine gets returns the current working directory name You can change your current working directory simply by moving to another directory The cd shell command and the chdir routine change the current working directory to a different directory All files have names and you can use almost any character in a file name The name can be up to 1024 characters long but indiv
181. r Options i3 vio rack wea de A C eV E RR Rua Actions Options Frequently Used eee e Actions and What Options Invoke Them Options and What Actions They Do 3 3 Miscellaneous TIpSa du saves Es Ee ceux YR EA Add Floating Point Hardware Type eee eee eeee Many Options on Short Commands 05 4 File System and File VO aaseexu e RYE RR RERREROR REA Al SUMIMALY soba vec ER COOPER VIEW ERE EHE LAB u c PPP ER Z3 Pile N MeS uoo ke uui wa o EUR eee RR eee ees eres 4A Pathi INGIIBS S pennti ta hi ode EEUU ST ERE SES Relative Path Names zai orkuercuex Ub pi vna dud d pr ded Absolute Path Names cue Leber ex ex ERR PR PC PEECC EFE Fortran 90 User s Guide 4 7 Accessing Files from Fortran Programs 42 Accessing Named Files uuu cucucacca ba eset n RU a oe xs 42 Accessing Unnamed Piles 5 ees coeibecxece rs Pe ee i 43 Passing File Names to Programs 000 00 eee 43 48 Det U C os zia2 E RrrrtPREOpe Dn E e CEPR PP PPEREES 45 219 Internal PUeS qoa oes wed ODER RE EE SES 46 5 Program Developnient e s 4E Ea Ee re C Paas ptexrmis 49 5 1 Simple Program Builds 522i es 49 WEE d koe aa ACRI ROCA ODER AA A 49 Cr atinge ano dau ees acto ln ane EORR EAE ARRA AUR 4 50 Using a Script or Alias ai es deus eo E cR IRE NAA 50 Linutatiotnig a bep eee bote S rr e pop ee Bap Fe He dcr d 50 5 2 Program Builds with the make Program 50 Themake Pil
182. r Pointers For a pointee that has been declared with an assumed length character type the Cray pointer declaration statement declares the pointer to be a Cray character pointer 1 Before the Cray pointer declaration statement declare the pointee as a character type with an assumed length 2 Declare a Cray pointer to that pointee 3 Assign a value to the Cray character pointer You can use functions CLOC or FCD both nonstandard intrinsics Example Declare Ccp to be a Cray character pointer and use CLOC to make it point to character string s CHARACTER a POINTER Ccp a CHARACTER 80 s abcdefgskooterwxyz Ccp CLOC s Fortran 90 User s Guide 2 lll Operations on Cray Character Pointers You can do the following operations with Cray character pointers Ccpl i Ccpl i i CepI Ccpl Ccp2 Ccp1 relational operator Ccp2 where Ccp1 and Ccp2 are Cray character pointers and i is an integer Restrictions on Cray Character Pointers and Pointees All restrictions to Cray pointers also apply to Cray character pointers In addition the following apply A Cray character pointee cannot be an array In a relational operation a Cray character pointer can be mixed with only another Cray character pointer not with a Cray pointer not with an integer A relational operation applies only to the character address and the bit offset the length field is not involved Cr
183. ram below usr you mail record Figure 4 2 Relative Path Name Absolute Path Names A list of directories and a file name separated by slash characters from the root to the file you want to describe is called an absolute path name It is also called the complete file specification or the complete path name A complete file specification has the general form directory directory directory file There can be any number of directory names between the root and the file at the end of the path as long as the total number of characters in a given path name is less than or equal to 1024 Fortran 90 User s Guide HS lll An absolute path name is illustrated in the diagram below usr you mail record usr you mail record Figure 4 3 Absolute Path Name File System and File I O 39 E 40 4 5 Redirection Redirection is a way of changing the files that a program uses without passing a file name to the program Both input to and output from a program can be redirected The symbol for redirecting standard input is the sign and for standard output is the gt sign File redirection is a function performed by the command interpreter or shell when a program is invoked by it Input The shell command line demo myprog mydata The above command causes the file mydata which must already exist to be connected to the standard input of the program mypro
184. ransformations of a vectorizing compiler The compiler applies appropriate dependence based restructuring transformations It then distributes the work evenly over the available processors Each processor executes a different chunk of iterations Example 4 processors 1000 iterations the following occur simultaneously Processor 1 executing iterations 1 through 250 Processor 2 executing iterations 251 through 500 Processor 3 executing iterations 501 through 750 Processor 4 executing iterations 751 through 1000 202 Fortran 90 User s Guide v lll D 3 Parallel Directives Explicitly parallelizing loops requires using both of the following A parallel directive One or more command line options A parallel directive is a special comment that directs the compiler to do some parallelizing Directives are also called pragmas DOALL Currently there is one parallel directive DOALL The compiler parallelizes the next loop it finds if possible Form of Directive Lines Parallel directives have the following syntax MIC DOALL general parameters scheduling parameter A directive line is defined as follows It starts with the 5 characters CMIC or MICS followed by A space A directive For some directives one or more parameters Spaces before after or within a directive are ignored Letters of a directive line can be in uppercase lowercase or mixed The form varies for fixed and free
185. readed program has a thread stack The default stack size is about 8 MBytes for the main stack and 256 KBytes for each thread stack The 1imit command no parameters shows the current main stack size If you get a segmentation fault using stackvar you might try doubling the main stack size at least once Using the Compiler 29 lll Qo The main stack size gt temp dir time V 30 Example Stack size show the current main stack size demo limit cputime unlimited filesize unlimited datasize 523256 kbytes stacksize 8192 kbytes coredumpsize unlimited descriptors 64 memorysize unlimited demo M Example Set the main stack size to 64 MBytes demo limit stacksize 65536 Example Set each thread stack size to 8 MBytes demo setenv STACKSIZE 8192 See csh 1 for details on the limit command Assembly source generate only assembly source code Compile the named programs and leave the assembly language output on corresponding files suffixed with s no o file is created Temporary files set directory to locate temporary files Set directory for temporary files used by 90 to be dir No space is allowed within this option string Without this option they go into tmp Time for execution display for each compilation pass Verbose print name of each compiler pass Print the name of each pass as the compiler executes plus display in detail the options and env
186. s a dummy argument The Cray pointee has no address until the value of the Cray pointer is defined If an array is named as a pointee it is called a pointee array Its array declarator can appear in A separate type statement A separate DIMENSION statement The pointer statement itself Fortran 90 User s Guide A If the array declarator is in a subprogram the dimensioning can refer to Variables in a common block or Variables that are dummy arguments The size of each dimension is evaluated on entrance to the subprogram not when the pointee is referenced Restrictions on Cray Pointers If pointee name is of character type it must be a variable typed CHARACTER If pointee name is an array declarator it must be explicit shape constant or nonconstant bounds or assumed size An array of Cray pointers is not allowed A Cray pointer cannot be Pointed to by another Cray pointer or by a Fortran 90 pointer A component of a structure Declared to be any other data type A Cray pointer cannot appear in A PARAMETER statement or in a type declaration statement that includes the PARAMETER attribute A DATA statement Restrictions on Cray Pointees A Cray pointee cannot appear in a SAVE DATA EQUIVALENCE COMMON or PARAMETER statement A Cray pointee cannot be a dummy argument A Cray pointee cannot be a function value A Cray pointee cannot be a structure
187. s a dynamic library Library make nm be the name of the generated shared dynamic library When generating a shared dynamic library the compile time linker records the specified name in the library file as the internal name of the library If there is no hnm option then no internal name is recorded in the library file and the path of the library is stored instead Advantage 1f the library has an internal name then whenever the executable is run the linker needs only a library with the exact same internal name it can be in any path the linker is searching If the library has no internal name then whenever the executable is run the linker must find the library in the exact same path used when the executable was created That is the internal name method is more flexible Remarks A space between h and nm is optional In general this name must be the same as what follows the o The hnm option is meaningless without G Internal names facilitate versions of a dynamic library This is a linker option See the Linker and Libraries Manual Options display the list of options Display an equivalent of this list of options This also shows how to send feedback comments to Sun Fortran 90 User s Guide Qo lll Iloc Variations for help f90 help more Do not scroll the list off screen 90 help grep par Show only parallel options 90 help tail Show how to send feedback to Sun
188. s called at run time I 90 generates inline code for the intrinsic procedure 178 Fortran 90 User s Guide A A 3 Directives A compiler directive directs the compiler to do some special action Directives are also called pragmas A compiler directive is inserted into the source program as one or more lines of text Each line looks like a comment but has additional characters that identify it as more than a comment for this compiler For most other compilers it is treated as a comment so there is some code portability General Directives I Currently there are only two general directives FREE and FIXED These directives tell the compiler to assume free form source or fixed form source Other General Directives Some other parallel directives are included which are not described in detail because they are not guaranteed to be in the next release Table A 3 General Directives Guaranteed Only in the Current Release Directive TASK NOTASK SUPPRESS varl var2 TASKCOMMON cb1 cb2 Features and Differences 179 180 Form of General Directive Lines General directives have the following syntax IDIRS di d2 A general directive line is defined as follows A directive line starts with the 5 characters CDIR or DIRS followed by A space A directive Spaces before after or within a directive are ignored Letters of a directiv
189. s for you if you know Fortran 90 thoroughly and need to start writing programs in this Fortran 90 immediately Skip to Chapter 3 Using the Compiler to learn more about it first 2 1 Summary Before you use this release of To use this Fortran 90 involves three steps tte Mnstalling Sun son Write and save a Fortran 90 program use 90 or f as file name suffix Developer Products on Solaris Compile and link this file using the 90 command Execute by typing the name of the executable file lll No 2 2 Compiling 2 3 Running Example This program displays a message on the screen demo cat hack f90 PROGRAM Opinion PRINT Real programmers hack Fortran 90 END PROGRAM Opinion demos M Compile and link using the 90 command as follows demo 90 hack demos M In the example above 90 compiles hack 90 and puts the executable code in the a out file Run the program by typing a out on the command line demo a out Real programmers hack Fortran 90 demos M 2 4 Renaming the Executables It is awkward to have the result of every compilation on a file called a out since if such a file exists it is overwritten You can avoid this in two ways After each compilation use mv to change the name of a out demo mv a out maven demo M On the command line use o to rename the output executable file demo 90 o maven hack demos M
190. s no directives Source Form Assumed The source form assumed by 90 depends on options directives and suffixes Command line options Option Action fixed Interpret all source files as Fortran 90 fixed form free Interpret all source files as Fortran 90 free form If the free or fixed option is used that overrides the file name suffix Features and Differences 165 lll aN File name suffixes Suffix Source Form 90 Fortran 90 free form source files J Fortran 90 fixed form source files or ANSI standard FORTRAN 77 source files for Same as f ftn Same as f other None file name is passed to the linker Directives Directive Action DIRS FIXED Interpret the rest of the source file as Fortran 90 fixed form DIRS FREE Interpret the rest of the source file as Fortran 90 free form If either a FREE or FIXED directive is used that overrides the option and file name suffix Mixing Forms Some mixing of source forms is allowed n the same 90 command some source files can be fixed form some free In the same file free form can be mixed with fixed form by using directives 166 Fortran 90 User s Guide A Boolean Type 90 supports constants and expressions of Boolean type There are no Boolean variables or arrays and there is no Boolean type statement Miscellaneous Rules Governing Boolean Type Maskin
191. s raw it inserts only the paths you name and no others LD RUN PATH then the paths of LD_RUN_PATH are put in a out plus paths for Fortran 90 libraries So LD RUN PATH is augmented it inserts the ones you name plus various others Both LD RUN PATH and R then only the paths of R are putin a out and those of LD RUN PATH are ignored Strip the executable file of its symbol table makes debugging impossible Stack the local variables to allow better optimizing with parallelizing Use the stack to allocate all local variables and arrays in a routine unless otherwise specified This makes them automatic rather than static Purpose More freedom to optimizer for parallelizing a CALL in a loop Parallel CALL This option gives more freedom to the optimizer for such tasks as parallelizing a loop that includes a CALL Definition Variables and arrays are local unless they are Arguments in a SUBROUTINE or FUNCTION statement already on stack Global items in a COMMON or SAVE or STATIC statement Initialized items in a type statement or a DATA statement such as REAL X 8 0 or DATA X 8 0 Segmentation Fault and stackvar You can get a segmentation fault using stackvar with large arrays Putting large arrays onto the stack can overflow the stack so you may need to increase the stack size There are two stacks The whole program has a main stack Each thread of a multi th
192. s the 77 I O compatibility library Such compatibility includes the following two situations In the same program you can write some records in 90 then read them in IJ An 90 program can write a file Then an 77 program can read it The numbers read back in may or may not equal the numbers written out Unformatted The numbers read back in do equal the numbers written out Floating point formatted The numbers read back in can be different from the numbers written out This is caused by slightly different base conversion routines or by different conventions for uppercase lowercase spaces plus or minus signs and so forth Examples 1 0e12 1 0E12 1 0E 12 Features and Differences 185 186 ist directed The numbers read back in can be different from the numbers written out This can be caused by various layout conventions with commas spaces Zeros repeat factors and so forth Example 0 0 as compared to 0 Example 7 as compared to 7 Example 3 4 5 as compared to 3 4 5 Example 3 0 as compared to 0 0 0 The above results are from integer v 3 0 0 0 print v Example 0 333333343 as compared to 0 333333 The above results are from PRINT 1 0 3 0 Fortran 90 User s Guide A Intrinsics The Fortran 90 standard supports the following new intrinsic functions that FORTRAN 77 does not have If you use one of these names in your program you must add an
193. s use the sample program above Compile To use dbx or Debugger compile and link with the g flag You can do this in one step or two as shown in the examples below Example Compile and link in one step with g demo 90 o silly g a1 f 90 a2 f90 a3 f90 Example Compile and link in separate steps demo 90 c g a1 f90 a2 90 a3 f90 demo 90 o silly al o a2 0 a3 o Start dbx To start dbx type dbx and the name of your executable file Example Start dbx on the executable named silly demo dbx silly Reading symbolic information dbx M Quit dox To quit dbx enter the quit command Example Quit dbx dbx quit Skip this for now so you can do the next steps demo M Breakpoint To set a breakpoint at the dbx prompt type stop in subnam where subnam names a subroutine or function and subnam can be upper case or lower case Example A way to stop at the first executable statement in a main program dbx stop in main 2 stop in main dox M Debugging 79 80 Run Program To run a program from within dbx enter the run command Example Run a program from within dbx dbx run Running silly process id 8786 stopped in main at line 5 in file al f90 5 CALL mkidentity twobytwo n dox M When the breakpoint is reached dbx displays a message showing where it stopped in this case
194. some compatibility can be achieved at least for the Fortran 90 pass by reference The compatibility is possible because a C program can specify that the value being passed is actually an address For C this is traditionally described as passing pointers Passing Arguments by Reference Pass by reference in Fortran 90 can be made compatible with pass pointers in C In C passing pointers is specified in either of the following ways one for defining new functions and another for invoking existing functions Defining New Functions In a function where data types of arguments are declared if you precede a dummy argument by an asterisk C passes a pointer to the item Example Define a C function a dummy argument is a pointer to an int void simrefl int d disa pointer to an int C Fortran Interface 127 128 Invoking Existing Functions To make C pass the address of the argument in the statement that invokes the function do the following If the item is not a character string or array then precede the actual argument by an ampersand amp Example An actual argument is a pointer to an int int a simref2 amp a amp aisapointer toan int If the item is a character string or array then do not precede the actual argument by an ampersand amp Example An actual argument is a pointer to a character string char s 9 i simref3 s sisa point
195. spective Note Following IEEE floating point traps enabled see ieee handler 3M Division by Zero Sun s implementation of IEEE arithmetic is discussed in the Numerical Computation Guide demos M The ieee retrospective function queries the floating point status registers to find out which exceptions have accrued If any exception has a raised accrued exception flag a message is printed to standard error to inform the programmer which exceptions were raised but not cleared For Fortran 90 this function is called automatically just before execution terminates The message typically looks like this may vary slightly with each release NOTE The following IEEE floating point arithmetic exceptions occurred and were never cleared Inexact Division by Zero Underflow Overflow Invalid Operand Sun s implementation of IEEE arithmetic is discussed in the Numerical Computation Guide Nonstandard Arithmetic Another useful math library function is nonstandard arithmetic The IEEE standard for arithmetic specifies a way of handling underflowed results gradually by dynamically adjusting the radix point of the significand Recall that in IEEE floating point format the radix point occurs before the significand and there is an implicit leading bit of 1 Gradual underflow allows the implicit leading bit to be cleared to 0 and to shift the radix point into the significand when the result of
196. stripmining an inner loop unrolling is used to automatically improve scheduling iMPact Explicit Parallelization 205 lll I Restrictions on DOALL Parameters No one variable can be declared both shared and private The loop control variable of the DOALL loop must be declared private These variables cannot be array elements or components of derived types A directive can have many general parameters A directive can have at most one scheduling parameter D 4 DOALL Loops To use explicit parallelization safely you must understand the rules for explicit parallelizing Explicit parallelization of a DOALL loop requires more analysis and sophistication than automatic parallelization There is far more risk of indeterminate results This is not only roundoff but inter iteration interference Definition For explicit parallelization the DOALL loop is defined as follows The construct is a DO loop uses the DO statement but not DO WHILE The values of array variables for each iteration of the loop do not depend on the values of array variables for any other iteration of the loop Calculations within the loop do not change any scalar variable that is referenced after the loop terminates Such scalar variables are not guaranteed to have a defined value after the loop terminates since the compiler does not ensure a proper storeback for them For each iteration any subprogram invoked inside the loop does not
197. t process id 12326 dbx whatis prodl product prodi dbx whatis t product type product integer 4 id character 16 name character 8 model real 4 cost real 4 price end type product dbx alt PROGRAM Struct Debug a Structure 2 TYPE product 3 INTEGER id 4 CHARACTER 16 name 5 CHARACTER 8 model 6 REAL cost 7 REAL price 8 END TYPE product 9 10 TYPE product prodl L1 L2 prodl id 82 L3 prodl name Schlepper 14 prodlsmodel XL L5 prodi cost 24 0 L6 prodl price 104 0 L7 WRITE prodl name L8 END stopped in main at line 17 in file Struct f90 17 WRITE prodl name Debugging 87 88 Example Structures user defined types in dbx dbx print prod1 prodl id 82 nam Schlepper model XL cost 24 0 price 104 0 dbx it dbx Fortran 90 User s Guide mmm Pointer to User Defined Type Example Structures user defined types and pointers in dbx demo 90 o debstr g DebStruc f90 demo dbx debstr dbx stop in main 2 stop in main DebStruc f90 dox list 1 99 1 PROGRAM DebStruPtr Debug structures amp pointers 2 TYPE product Declare a user defined type INTEGER id 4 CHARACTER 16 name 5 CHARACTER 8 model 6 REAL cost E REAL price Declare variables prod1 and 8 END TYPE product prod2 to be of tha
198. t type and 9 targets 10 YPE product TARGET prodl prod2 Declare variables curr and prior 1 TEED rOJUCE G POINTER Parar PETOT as pointers to the type 2 3 curr gt prod2 Make curr point to prod1 4 prior gt prodi Make prior point to prod1 5 prior id 82 6 prior name Schlepper Initialize prior 7 prior model XL 18 prior cost 24 0 19 prior price 104 0 20 curr prior 21 WRITE curr name prior name Set curr to prior 22 END PROGRAM DebStruPtr Print name from curr and prior dbx Example Structures set a breakpoint and run under dbx dbx stop at 21 The exact layout and messages 1 stop at DebStruc f90 21 may vary with each release dbx run Running debstr process id 10972 Stopped in main at line 21 in file DebStruc f90 21 WRITE curr name prior name dox M Debugging 89 lll N Ask about the variable Ask about the type t dbx displays the contents of a pointer which is an address This address can be different with every run 90 Example Structures print an item of user defined type dbx print prodi prodl id 82 name Schlepper model XL cost 24 0 price 104 0 dbx M Above dbx displays all fields of the user defined type including field names Example Structures inquire about an item of user defined type dbx whatis prodl product prodl dbx whatis t product type product integer 4 id character 16
199. to the following sections Operating Environment page 2 Text Editing page 2 Program Development page 3 Debugging page 3 Licensing page 3 Sun Fortran 90 comes with a programming environment including certain operating system calls and support libraries It integrates with powerful development tools including SunSoft tools such as the Debugger make MakeTool and TeamWare Some examples assume you installed the Source Compatibility Package iMPact and Workshop The compiler is available in various packages and configurations Alone or as part of a package such as the Fortran 90 Workshop With or without the iMPact MT MP multiple processor package lll 1 1 Operating Environment 1 2 Text Editing vi textedit emacs xemacs Sun Fortran 90 runs in the Solaris 2 x operating environments The Solaris 2 x operating environment includes among other components the SunOS 5 x operating system SunOS 5 x is based on the System V Release 4 SVR4 UNIX operating system and the ONC family of published networking protocols and distributed services including ToolTalk Abbreviations Solaris 2 x is an abbreviation for Solaris 2 3 and later SunOS 5 x is an abbreviation for SunOS 5 3 and later There are several text editors available The major text editor for source programs is vi vee eye the visual display editor It has considerable power becaus
200. ts at 0 as follows INTEGER b 0 2 This way the Fortran element b 1 is equivalent to the C element b 1 Fortran 90 User s Guide Ko lll Array Order Fortran arrays are stored in column major order C arrays in row major order For one dimensional arrays this is no problem For two dimensional and higher arrays switch subscripts in all references and declarations Tip Many users tell us that it gets confusing say to triangularize in C and then pass the parts to Fortran More generally it may be confusing to do some of the matrix manipulation in C and some in Fortran So if passing parts of arrays between C and Fortran does not work or if it is confusing try passing the whole array to the other language and do all the matrix manipulation there avoid doing part in C and part in Fortran Libraries and Linking with the 90 Command To get the proper Fortran libraries linked use the 90 command to pass the o files on to the linker This usually shows up as a problem only if a C main calls Fortran Dynamic linking is encouraged and made easy Example 1 Use f90 to link demo 90 c RetCmplx f90 demo cc c RetCmplxmain c demo 90 RetCmplx o RetCmplxmain o This does the linking demo a out 4 0 4 5 8 0 9 0 demos M Example 2 Use cc to link This fails The libraries are not linked demo 90 c RetCmplx f90 demo cc RetCmplx o RetCmplxmain c lt wrong link co
201. ube x root x UUET0 4 FLO Mp UZ Gp Up JEDE Enter a DP number READ cy cube_ x y cx cube_ WRITE E END y root y root x Single Double UQETQ 2 U y FLO MEA MO py Sy My QUEE X Yr X Yr cy cy Fortran 90 User s Guide N lll Example dbx with a generic function cube root dbx stop at 26 2 stop at Generic f90 26 dbx run Running Generic process id 14633 stopped in main at line 26 in file Generic 90 26 WRITE Enter a SP number If asked Whatis cube root dbx whatis cube root dbx tells you there are two More than one identifier cube root and asks you to select one Select one of the following names 1 Generic f90 cube root s cube root real 4 s cube root 2 Generic f90 cube root s cube root real 8 d cube root gt 1 real 4 function cube_root x dummy argument real 4 x dbx print cube_root 8 0 More than one identifier cube_root Select one of the following names If asked for cube root 8 dbx tells you there are two and asks you to select one 1 Generic f90 cube root real 4 s cube root 2 Generic f90 cube root real 8 d cube root gt 1 cube root 8 2 0 If told to stop in cube root dbx stop in cube_root dbx tells you there are two More than one identifier cube_root an
202. uch simpler as the computation can be written in the obvious fashion and only the final result need be coerced to the correct value since Inf can occur and can be easily tested Furthermore the special case of 0 0 can be detected and dealt with as you wish The result is easier to read and faster executing since you don t do unneeded comparisons Excessive Underflow If two very small numbers are multiplied the result underflows The hardware being designed for the typical case does not produce a result instead software is employed to compute the correct IEEE complying result As one might guess this is much slower In the majority of applications this is invisible When it is not the symptom is that the system time component of your runtime which can be determined by running your application with the time command is much too large Fortran 90 User s Guide Co lll Example Excessive underflow PROGRAM dotprod INTEGER maxn PARAMETER maxn 10000 REAL a maxn b maxn eps 1 0e 37 sum DO i 1 maxn a i 1 0e 30 b i 1 0e 15 END DO sum 0 DO i 1 maxn sum sum a i b i END DO END After compiling and running dotprod the results of the t ime command are real 0m4 50s user Om0 11s sys 0m4 35s So the real computation required about 0 1 seconds but the software fix required four seconds In a real application this can be hours Clearly th
203. val len sizeof strbuffer char ch extra initial arg 1 extra initial arg 2 for normal arg 1 int n 4 for normal arg 1 int ch len sizeof ch extra finalarg printf Ss n strbuffer retchr rval ptr rval len amp ch amp n ch len printf Ss n strbuffer j Example C and Fortran with a character string function demo 90 c RetChr f90 demo cc c RetChrmain c demo 90 RetChr o RetChrmain o demo a out 123456789 Fk Ax x ng demos M C Fortran Interface 159 lll Ko Labeled Common C Calls 90 C and Fortran can share values in labeled common Example A Fortran subroutine uses a labeled common UseCom 90 SUBROUTINE UseCom REAL u V W COMMON ilk u v w u 7 0 v 8 0 w 9 0 END SUBROUTINE UseCom Example A C main uses a labeled common matching the Fortran one above UseCommain c extern struct comtype Declarea structure float p float q float r ba extern struct comtype ilk_ Define an item using the structure void usecom Declare function interface void main ilk p 1 0 ilk_ q 2 0 ilk_ r 3 0 usecom printf ilk_ p 4 1f ilk q 4 1f ilk_ r 4 1f n ilk p ilk q ilk r Example Fortran and C share a labeled common Compile Link Execute demo 90 c UseCom f90 demo cc c UseCommai
204. ventions xxii Boolean constant alternate forms 168 type constants 167 bounds of arrays checking 81 box clear xxii BS 6832 xviii Bstatic 15 62 C C 155 calls FORTRAN 149 function return value 141 is called by FORTRAN 134 C FORTRAN function compared to subroutine 123 key aspects of calls 122 labeled common 147 160 c compile only 16 call C from FORTRAN 134 FORTRAN from C 149 CALL in a loop parallelize 29 Fortran 90 User s Guide case preserving 124 catalog 2 Catalyst 2 catch FPE 83 113 CDIRS in directives 180 cg89 16 cg92 16 CIF file db 17 clear box xxii CMICS in directives 183 code generator option cgyr 16 command ar create static library 60 asa 3 compiler 9 90 9 comments as directives 179 to Sun xxi 20 compatibility C 188 FORTRAN 77 184 forward 188 with 77 I O 185 with 77 libraries 185 with 77 object files 184 compile check across routines Xlist 71 fails message 10 link for a dynamic shared library 20 link sequence 10 link consistent 65 make assembler source files only 30 only c 16 passes times for 30 compile action align on 8 byte boundaries 19 ANSI show non ANSI extensions ansi 15 assembly language output files keep S 30 check across routines Xlist 32 compile action continued compile only c 16 debug g 20 DO loops for one trip min onetrip 25 do not trap on floating point exceptions
205. w Indeterminacy Arises i cere ete em 210 DF Signals ise ciecibidbe Eta tis cong eden vanes de ed 211 dex ctct2ecttan er Tl et beed oohes eee ee Re eee CREE RES 213 Join the SunPro SIG Today iis bib even Cen Re eie 227 xii Fortran 90 User s Guide Figures Figure 4 1 Figure 4 2 Figure 4 3 File System Hierarchy Relative Path Name Absolute Path Name lesse xiii xiv Fortran 90 User s Guide Tables Table 3 1 Table 3 2 Table 3 3 Table 3 4 Table 7 1 Table 7 2 Table 8 1 Table 8 2 Table 9 1 Table 9 2 Table 9 3 Table A 1 Table A 2 Table A 3 Table A 4 File Name Suffixes Fortran 90 Recognizes Options Frequently Used 00 e eee eee Actions Options Sorted by Action 0 00000 eee Summary of Xlist Suboptions 66 60 c eee eee Xlist Combination Special or A La Carte Suboptions Xlist Suboptions Summary 6 60 e cee eee ieee flags Argument Meanings 06 Functions for Using IEEE Values 00000 0005 C Data Type to Fortran 90 Data Type ssssssssess Fortran 90 Data Type to C Data Type 0 Characteristics of Three I O Systems isses Size Notation for Numeric Data Types suss Nonstandard Intrinsics llseeeleeeeeeeeeeeee General Directives Guaranteed Only in the Current Release Parallel Directives Guaranteed Only in the Current Releas
206. you want to transform files formatted with Fortran carriage control conventions into files formatted according to UNIX line printer conventions See asa 1 and fpr 1 This utility splits one Fortran file of several routines into several files so that there is one routine per file There are two debugging tools An interactive symbolic debugger that understands Sun Fortran 90 programs available with the SPARCworks set A window icon mouse and pointer interface to dbx in SPARCworks set This compiler uses network licensing Before you use Sun Fortran 90 purchase and install a SunSoft Fortran 90 license When you invoke the compiler if a license is available the compiler simply starts If no license is available your request for a license is put on a queue and your compile continues when a license becomes available See also noqueue and xlicinfo Licensing information is in the manual Installing SunSoft Developer Products on Solaris including among other items Installing a license Starting a license daemon Restarting a license daemon after a license server crash Introduction 3 Fortran 90 User s Guide No Ii Getting Started This chapter is organized into the following sections Summary page 5 Compiling page 6 Running page 6 Renaming the Executables page 6 This chapter gives a bare minimum on how to compile and run Fortran 90 programs under Solaris This chapter i
207. ysis g suppresses On If you do not specify an n 90 uses whatever n is most likely to yield the fastest performance for most reasonable applications For the current release this is 3 Do only conservative scalar optimization This level usually results in moderate code size and compile time If an optimization can create a false exception then that optimization is not performed At this level 90 can analyze whether a variable is used before it is defined Do moderate optimization Do aggressive scalar optimization Some of these optimizations can create false exceptions This level can result in larger code size and compile time At this level 90 can analyze whether a variable is used before it is defined Using the Compiler 25 26 P parallel For this release 04 is equivalent to 03 Profile by procedure for prof Prepare object files for profiling see prof 1 If you compile and link in separate steps and if you compile with the p option then be sure to link with the p option p with prof is provided mostly for compatibility with older systems pg with gprof does more Multiprocessor Parallelize automatically and parallelize explicitly indicated loops Parallelize loops both automatically by the compiler and as explicitly specified by the programmer With explicit parallelization of loops there is a risk of producing incorrect results If optimization is not at 03 then it is raise
Download Pdf Manuals
Related Search
Related Contents
Outils d`aide pour la mise en œuvre de PPRE de passage CM2-6ème Gebrauchsanweisung Guía del usuario - produktinfo.conrad.com Trust Wireless Laser Mouse MI-7570K Philips DVP3362K/51 User's Manual CITRAFLEET, poudre pour solution buvable en sachet-dose ATEN Technology AS-402PII User's Manual GEIGER-Funk Blind Controller GFJ006 GFJ007 GFJ009 Installation AL-KO HT 550 Service Manual - Masterxoloda.ru Copyright © All rights reserved.
Failed to retrieve file