Message from discussion
argument passing/copying
Path: supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!144.212.100.101!newsfeed.mathworks.com!nycmny1-snh1.gtei.net!news.gtei.net!news-xfer.mccc.edu!news.IAEhv.nl!not-for-mail
From: Jos Bergervoet <berge...@iaehv.iae.nl>
Newsgroups: comp.lang.fortran
Subject: Re: argument passing/copying
Date: 8 Apr 2001 20:38:11 GMT
Organization: Internet Access Eindhoven, the Netherlands
Lines: 46
Message-ID: <9aqi7j$k6$1@news.IAEhv.nl>
References: <3ACD97BF.D337E363@lvv.iet.mavt.ethz.ch> <9ak5uf$5pt$1@iletudy.ifremer.fr> <3ACDDDC6.C4CB7902@lvv.iet.mavt.ethz.ch> <J4mz6.12893$RF1.896633@bgtnsc06-news.ops.worldnet.att.net> <9apm42$kps$1@gemini.ncsc.org> <b91A6.13358$IJ1.1136719@bgtnsc05-news.ops.worldnet.att.net>
NNTP-Posting-Host: iaehv.iae.nl
User-Agent: tin/1.5.4-20000523 ("1959") (UNIX) (FreeBSD/3.4-STABLE (i386))
James Giles <jamesgi...@worldnet.att.net> wrote:
> ... Anyway, what you said still doesn't contradict the observation
> that making copies is *sometimes* a more efficient way.
>
> If you require procedures to accept and work with discontiguous
> slices in all cases, your code will usually be slower than making
> a copy and passing it as a contiguous piece.
It may be useful to point out that there are actually two problems
that both can lead to significant slowing down of the code:
A) The compiler makes a copy when calling a routine, in a case
where we know it is not necessary.
B) The compiler assumes that an argument can be discontiguous,
and treats it accordingly in the routine.
If the argument really is discontiguous, then either A or B will
be necessary, and the only thing we could wish for is that the
compiler chooses the least of two evils. This seems pretty
difficult to do (and compilers don't do it, as far as I know).
If the argument is contiguous, especially if this is true for each
call to the routine, then one can still argue that A may be useful
in rare cases, but we would at least want the compiler to avoid the
overhead of B. Again, many compilers fail to do this.
In practice, this means that when passing a contiguous arry, for
instance, to a time-critical routine, one should:
(1) Write the routine with an f77-style argument.
(2) Call the routine with a single array argument, even though
you want it to work with the entire array, e.g.:
call sub( A(1,1,1) )
if A is a rank-3 array.
This seems a bit out of style, in f90, but if you forget (1), then
current compilers give you penalty B, and if you forget (2) they
often give you penalty A.
> ...
> more direct way for programmers to control these issues. Ken
> Kennedy proposed such a mechanism in 1982 ...
Did this address (and solve) both the issues described above?
-- Jos