|
Prev: Good book on FORTRAN OT
Next: branch prediction?
From: Herman D. Knoble on 10 Apr 2008 11:11 On Thu, 10 Apr 2008 14:50:02 GMT, Charles Coldwell <coldwell(a)gmail.com> wrote: -|robert.corbett(a)sun.com writes: -| -|> According to my understanding of Section 14.1.2.4.1 of the Fortran 95 -|> standard and Section 12.4.4.1 of the Fortran 2003 standard, the -|> program -|> -|> PROGRAM MAIN -|> INTERFACE COS -|> REAL FUNCTION MYCOS(X) -|> END FUNCTION -|> END INTERFACE -|> CALL SUBR -|> CONTAINS -|> SUBROUTINE SUBR -|> INTRINSIC COS -|> PRINT *, COS(0.0) -|> END SUBROUTINE -|> END -|> -|> REAL FUNCTION MYCOS(X) -|> MYCOS = 2.0 -|> END -|> -|> should print -|> -|> 1.0 -|> -|> or something else like it. The third item in the lists in the cited -|> sections of -|> the cited standards says that the call of the generic function COS in -|> the -|> PRINT statement should call the intrinsic specific function COS, not -|> the -|> external procedure MYCOS. I am sorry to have to admit that Sun -|> Fortran -|> gets it wrong. I would like to know if other compilers get it right. -| -|$ ifort --version -|ifort (IFORT) 10.1 20070913 -|Copyright (C) 1985-2007 Intel Corporation. All rights reserved. -| -|gives 2.0 (wrong?) Try using ifort options: -O0 -fltconsistency Skip Knoble -| -|$ gfortran --version -|GNU Fortran (GCC) 4.1.2 20070925 (Red Hat 4.1.2-27) -|Copyright (C) 2007 Free Software Foundation, Inc. -| -|gives 1.0 (right?) -| -|$ pgf90 -V -| -|pgf90 6.0-5 32-bit target on x86 Linux -|Copyright 1989-2000, The Portland Group, Inc. All Rights Reserved. -|Copyright 2000-2005, STMicroelectronics, Inc. All Rights Reserved. -| -|won't compile it: -| -|$ pgf95 -o test /tmp/test.f90 -|PGF90-S-0126-Name cos is not an intrinsic function (/tmp/test.f90: 9) -| -|Chip
From: Bil Kleb on 10 Apr 2008 11:38 robert.corbett(a)sun.com wrote: > According to my understanding of Section 14.1.2.4.1 of the Fortran 95 > standard and Section 12.4.4.1 of the Fortran 2003 standard, the > program [..] > > I would like to know if other compilers get it right. Your team should have a compiler gauntlet? (We find ours extremely valuable for finding compiler bugs and for detecting questionable code.) gcc version 4.0.3 (g95 0.90!) Mar 7 2008 $ g95 corbett.f90 && ./a.out 1. gcc version 4.1.1 20070105 (Red Hat 4.1.1-52) % gfortran corbett.f90 && ./a.out 1.000000 ifort (IFORT) 10.1 20071116 % ifort corbett.f90 && ./a.out 2.000000 f95: Sun Fortran 95 8.3 Linux_i386 Patch 127145-01 2007/07/31 % f95 corbett.f90 && ./a.out 2.0 gcc version 4.0.1 (g95!) Jan 12 2006 % g95 corbett.f90 && ./a.out 1. Lahey/Fujitsu Fortran 95 Express Release L6.20d % lf95 corbett.f90 && ./a.out Encountered 0 errors, 0 warnings in file corbett.f90. 1.00000000 Compaq Fortran Compiler V1.2.0-1882-48BBF a2n9% fort corbett.f90 && ./a.out 2.000000 pgf90 6.1-2 32-bit target on x86 Linux % pgf95 corbett.f90 && ./a.out PGF90-S-0126-Name cos is not an intrinsic function (corbett.f90: 9) PathScale EKOPath(TM) Compiler Suite: Version 2.5 % pathf90 corbett.f90 && ./a.out 2. NAGWare Fortran 95 compiler Release 5.0(347) % f95 corbett.f90 && ./a.out Warning: corbett.f90, line 16: Unused dummy argument X detected at END@<end-of-statement> [f95 continuing despite warning messages] 1.0000000 Lahey/Fujitsu Linux64 Fortran Express Release L8.00a % lf95 corbett.f90 && ./a.out Encountered 0 errors, 0 warnings in file corbett.f90. 1.00000000 pgf95 7.1-5 64-bit target on x86-64 Linux -tp k8-64e % pgf95 corbett.f90 && ./a.out PGF90-S-0126-Name cos is not an intrinsic function (corbett.f90: 9) NAGWare Fortran 95 compiler Release 5.1(347,355,357-364,365) % f95 corbett.f90 && ./a.out Warning: corbett.f90, line 16: Unused dummy argument X detected at END@<end-of-statement> [f95 continuing despite warning messages] 1.0000000 Absoft 64-bit Fortran 95 10.1.2 % af95 corbett.f90 && ./a.out 2.00000 Intel(R) Fortran Compiler for 32-bit applications, Version 9.1 Build 20070109Z (9.1.041) % ifort corbett.f90 && ./a.out 2.000000 Regards, -- Bil Kleb http://fun3d.larc.nasa.gov
From: Herman D. Knoble on 10 Apr 2008 12:08 On Thu, 10 Apr 2008 11:11:06 -0400, Herman D. Knoble <SkipKnobleLESS(a)SPAMpsu.DOT.edu> wrote: -|-|$ ifort --version -|-|ifort (IFORT) 10.1 20070913 -|-|Copyright (C) 1985-2007 Intel Corporation. All rights reserved. -|-| -|-|gives 2.0 (wrong?) -|Try using ifort options: -O0 -fltconsistency -| -|Skip Knoble Sorry. The options I previously suggested have no effect on the results. Skip
From: Steve Lionel on 10 Apr 2008 16:42 On Thu, 10 Apr 2008 01:21:52 -0700 (PDT), robert.corbett(a)sun.com wrote: >According to my understanding of Section 14.1.2.4.1 of the Fortran 95 >standard and Section 12.4.4.1 of the Fortran 2003 standard, the >program > >or something else like it. The third item in the lists in the cited >sections of >the cited standards says that the call of the generic function COS in >the >PRINT statement should call the intrinsic specific function COS, not >the >external procedure MYCOS. Bob, My reading is somewhat different from yours. The actual wording of the section you cite is this: 19 (3) If (1) and (2) do not apply, if the scoping unit contains either an INTRINSIC attribute 20 specification for that name or a USE statement that makes that name accessible from a 21 module in which the corresponding name is specified to have the INTRINSIC attribute, and 22 if the reference is consistent with the interface of that intrinsic procedure, the reference is 23 to that intrinsic procedure. Note the initial clause "If (1) and (2) do not apply". (1) is: 8 (1) If the reference is consistent with a nonelemental reference to one of the specific interfaces of 9 a generic interface that has that name and either is in the scoping unit in which the reference 10 appears or is made accessible by a USE statement in the scoping unit, the reference is to 11 the specific procedure in the interface block that provides that interface. The rules in 16.2.3 12 ensure that there can be at most one such specific procedure. In your program, the reference COS(0.0) *is* consistent with a nonelemental reference to one of the specific interfaces of the visible generic COS, therefore (3) does not apply and it would be correct to call MYCOS. I also found this: 2 C547 (R503) (R1216) If the name of a generic intrinsic procedure is explicitly declared to have the 3 INTRINSIC attribute, and it is also the generic name in one or more generic interfaces (12.3.2.1) 4 accessible in the same scoping unit, the procedures in the interfaces and the specific intrinsic 5 procedures shall all be functions or all be subroutines, and the characteristics of the specific 6 intrinsic procedures and the procedures in the interfaces shall differ as specified in 16.2.3. My head was spinning when I read this, but I interpret it as saying that your program is non-standard because it explicitly declares COS as INTRINSIC in a scope where a generic interface containing a procedure that has the same signature as the intrinsic COS. If this reading is correct, the proper behavior would be to issue a standards violation diagnostic for the INTRINSIC COS, but otherwise calling MYCOS (and printing 2.0) is right. I am not as steeped in the standard as some so I welcome counterarguments. -- Steve Lionel Developer Products Division Intel Corporation Nashua, NH For email address, replace "invalid" with "com" User communities for Intel Software Development Products http://softwareforums.intel.com/ Intel Fortran Support http://support.intel.com/support/performancetools/fortran My Fortran blog http://www.intel.com/software/drfortran
From: John Harper on 10 Apr 2008 18:23
In article <29usv3l33ltn44h1tnfvb7nlttuh1168ci(a)4ax.com>, Steve Lionel <Steve.Lionel(a)intel.invalid> wrote: > >I also found this: [complicated standard-speak followed by] >6 intrinsic procedures and the procedures in the interfaces shall differ as >specified in 16.2.3. > >My head was spinning when I read this, but I interpret it as saying that your >program is non-standard because it explicitly declares COS as INTRINSIC in a >scope where a generic interface containing a procedure that has the same >signature as the intrinsic COS. > >If this reading is correct, the proper behavior would be to issue a standards >violation diagnostic for the INTRINSIC COS, but otherwise calling MYCOS (and >printing 2.0) is right. F2003 16.2.3 refers one to C.11.2, which reduces the head-spinning rate and would seem to support Steve's interpretation, but of course it's a nonnormative note. -- John Harper, School of Mathematics, Statistics and Computer Science, Victoria University, PO Box 600, Wellington 6140, New Zealand e-mail john.harper(a)vuw.ac.nz phone (+64)(4)463 6780 fax (+64)(4)463 5045 |