Re: Need a FORTRAN compiler for Win7 (or XP)

On 8/18/11 1:40 PM, glen herrmannsfeldt wrote:
Richard Maine<nospam@xxxxxxxxxxxxx> wrote:
JB<foo@xxxxxxxxxxx> wrote:

IIRC at some point there was discussion about passing scalar
intent(in) arguments by value for procedures with an explicit
interface; I don't think this has been done so far.

I won't say it is impossible, but that would have complications that
might not be obvious to some at first glance. Mostly the complication
has to do with having the implementation of a procedure depend on
whether it has an explicit interface. That's a complication because
having an explicit interface is a concept defined only in the scope
where a procedure is referenced - not where the procedure is defined.
There are some properties of a procedure that mean it will require an
explicit interface in order to be referenced, but intent(in) isn't one
of those.

You could do it in cases where the explicit interface was already
required. If a routine has an assumed shape array, then use
pass by value for other intent(in) arguments. That does seem
strange, though.

Thus, a procedure with an intent(in) dummy might be referenced with an
explicit interface in some places, but without an explicit interface in
others. Having two versions of the procedure might work in some cases,
but would be tricky if there were saved local variables. So-called
link-time optimization has been mentioned here recently. I suppose that
might be used to procrastinate the decision until "link time", which
could allow the compiler to know things about all the referencing

You could have two entry points to the same procedure, though a
previous post indicates that many object formats don't allow
for multiple entry points.

-- glen

Back in the late 80s (or so) the Convex compiler would make clones of routines. Mostly, they looked for routines that were called (hopefully) many times and had an integer argument (or 2 or 3) that was a constant. The clone was compiled "as if" the argument(s) were replaced by parameters with the same value. Frequently the optimizer could do a very good job when it knew the value of the integers. The same could be done for reals, logicals, etc., but the payoff seems likely to be smaller.

There's no reason why you couldn't do a similar thing for INTENT(IN) arguments, compile a clone and call it when it makes clear sense. But, IMO, calling by value is a very very very small optimization for integer arguments, especially intent(in). Any half-way decent optimizer will pull the values up into a register during the entry set-up and keep it there as long as it is needed. The net saving on the called side will be an instruction issue or two. And, those cycles will likely have occurred on the calling side.

Dick Hendrickson

Relevant Pages

  • Re: Passing pointers to derived types to subroutines
    ... Intel Fortran Compiler v9.1): ... You have failed to provide an explicit interface for the subroutine ... Having a pointer dummy argument is one of the many ...
  • Re: Fortran/C interoperability
    ... I want to make a library built with Fortran to be callable from Fortran ... requirement for an explicit interface. ... Consider that the explicit interface provides a way for the compiler to ... end module mymod ...
  • Re: optional routine arguments
    ... Your original code is not legal Fortran, because it lacks the explicit interface for a routine with optional arguments. ... The problem is that the compiler has no way to know that it needs to pass something special to indicate that you omitted k. ... Current Intel Fortran with interface checking on gives, ... Developer Products Division ...
  • Re: help for program
    ... I suppose your compiler must accept them as an extension, ... Error: clf.f90: Explicit interface required for CREAALBEROF from\ ... I call this unlucky because it can mislead you into ... as I didn't try to fix it and then check further. ...
  • Re: glibc detected *** ./run.out: munmap_chunk(): invalid pointer:
    ... the code is working fine with ifort but fails on other compiler. ... if I am trying to use dynamic allocation, ... I'm almost certain that your problem is that the subroutine doesn't have ... an explicit interface in the place where it is called from. ...