From: Jean-Pierre Rosen <rosen@EMAIL.ENST.FR>
Subject: Re: Ada-95 for numerics?
Date: 1996/04/02
Date: 1996-04-02T00:00:00+00:00 [thread overview]
Message-ID: <199604021629.SAA00724@email.enst.fr> (raw)
At 08:28 02/04/1996 GMT, you wrote:
>[...] So I started coding some of _my_ problems in Ada-95 and check
>for the speed. Yet, I am still a beginner in Ada-95, so maybe the coding style
>is somewhat unlucky...
Something you have to remember is that Ada has nice facilities for dealing
with arrays globally. For example, a typical benchmark trap is to translate:
DO 10 I=1,N
DO 10 J=1,N
10 A(I,J) = B(I,J)
into:
for I in 1..N loop
for J in 1..N loop
A(I,J) := B(I,J)
end loop;
end loop;
The correct translation is of course (assuming N is the size of the array):
A := B;
It is important, because since the compiler KNOWS that global assignment is
available, it will not spend a huge time trying to unwind loops, the way the
FORTRAN compiler does. And your FORTRAN might look faster...
In the same vein, you wrote :
> function Unit (n : Integer) return Matrix is
> C : Matrix (1..N, 1..N);
> begin
> for i in C'range(1) loop
> for j in C'first(2)..i loop
> C(i,j) := 0.0;
> C(j,i) := 0.0;
> end loop;
> C(i,i) := 1.0;
> end loop;
> return (C);
> end Unit;
This should be:
function Unit (n : Integer) return Matrix is
C : Matrix (1..N, 1..N) := (Others => (Others => 0.0));
begin
for i in C'range(1) loop
C(i,i) := 1.0;
end loop;
return (C);
end Unit;
If the compiler is not very clever, generated code will be the same as with
what you wrote. But it is much easier for the compiler to recognize that a
simple "move byte string" instruction is enough to do the trick.
Can't be worse, likely to be better....
+------------------------------------o-------------------------------------+
| P-mail: | E-mail: rosen@enst.fr |
| ADALOG - 27 avenue de Verdun | Tel: +33 1 46 45 51 12 |
| 92170 Vanves - FRANCE | Fax: +33 1 46 45 52 49 |
+------------------------------------o-------------------------------------+
next reply other threads:[~1996-04-02 0:00 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-04-02 0:00 Jean-Pierre Rosen [this message]
1996-04-03 0:00 ` Ada-95 for numerics? Robert I. Eachus
-- strict thread matches above, loose matches on Subject: below --
1996-04-05 0:00 Dr J Parker
1996-04-02 0:00 Joerg Rodemann
1996-04-02 0:00 ` Robert Dewar
1996-04-01 0:00 Joerg Rodemann
1996-04-01 0:00 ` Ted Dennison
1996-04-01 0:00 ` Robert Dewar
1996-04-01 0:00 ` Robert Dewar
1996-04-02 0:00 ` michael
1996-04-02 0:00 ` Dale Stanbrough
1996-04-03 0:00 ` Robert I. Eachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox