Thread Links | Date Links | ||||
---|---|---|---|---|---|
Thread Prev | Thread Next | Thread Index | Date Prev | Date Next | Date Index |
I think I understood your point about explicitly versus effectively, and we mostly agree. I just don't agree with Dan that order of evaluation is just "effectively not specified" in Fortran, or with you that the order is always "explicitly unspecified". I believe the truth is between.
I apologize to you and anyone else who felt misled. It was not deliberate. Let me say it a different way that I hope is clearer.
The Fortran standard does NOT leave the order of evaluation of an _expression_ implicitly or effectively unspecified just by not specifying it. It also does NOT explicitly specify that the order of evaluation is always unspecified. It is deliberately more selective.
The standard explicitly specifies when the order of evaluation IS specified (by the programmer using parentheses in an _expression_). As you say, "the significance of parentheses is specified", and it is that they control the order of evaluation. (See below for wording in one version of the standard. Others are equivalent.)
The standard explicitly specifies when the order is UNspecified (by the programmer omitting parentheses), and it explicitly specifies that the order is always UNspecified in some contexts like calls to impure functions.
Forall statements are interesting: The iterations "may be done in any order" but within each iteration "each statement ... is executed in sequence", and impure functions are disallowed in them. So their ordering is partly explicitly unspecified but partly explicitly specified, in addition to the normal rules.
All that gives the programmer the ability to control the order when it is believed to be important, and gives the compiler the ability to improve the performance when the user allows.
Controlling the order is not trivial. It requires being careful to add parentheses in many places. If performance matters more than repeatability, it also involves thinking about where to add them and where not too, and can be a maintenance headache. (Did the author omit a pair deliberately? Or is it a bug?)
The rules allow different compilers, or different versions of the same compiler, or the same compiler used with different options to make different choices that produce different results. But they explicitly require a program using parentheses everywhere and avoiding specified undefined usage to have its operations done in close enough to the same order to produce repeatable results on different systems using equivalent floating point hardware and libraries. (Libraries differ enough that perfect portability is generally impossible.)
Also the standard implicitly does not explicitly specify the effect of using multiple threads because those are not in the language (excluding High Performance Fortran and CoArray Fortran, and OpenMP and other extensions that dictate or imply the use of threads), but the explicitly specified specification and explicitly specified unspecification still apply (although that doesn't mean they're totally followed).
- Ian McIntosh IBM Canada Lab Compiler Back End Support and Development
From the September 2002 committee draft, because it's handiest.
![]() From: | ![]() "N.M. Maclaren" <nmm1@xxxxxxxxx> |
![]() To: | ![]() Ian McIntosh/Toronto/IBM@IBMCA |
![]() Date: | ![]() 08/04/2011 06:35 PM |
![]() Subject: | ![]() Re: Let's not BE NP-hard, shall we...? |