Re: No call for Ada (was Re: Announcing new scripting/prototyping language)

From: Robert I. Eachus (rieachus_at_comcast.net)
Date: 02/11/04


Date: Wed, 11 Feb 2004 17:58:32 -0500

MSG wrote:

> Can you write (*) a matrix multiplication routine in Ada, compile it
> with GNAT and measure the number CPU cycles per FLOP, compare to a
> similar routine in C?
> The shootout seems to put GNAT closer to Perl and Java than to C/C++.

As a matter of fact I am writing a fairly complex linear algebra package
in Ada that is designed for high-performance in supercomputer type
applications. I probably could write it in C and stay out of the
asylum, but it would be a close call. Why? It does things like A := A*B;
in place, with only a row sized temporary, and using Strassen's
algorithm with almost no copying. For efficiency the code works not
with an array type, but with a view that may share data with another
view. That way I can, for example, divide an existing matrix into four
smaller matrices in O(1) time and space. Eventually I will also have
code present to support both transposed views of matrices, in fact I
just finished the fast transpose code. That way I can transpose the
right argument, and avoid doing it more than once.

But if I did write the same code in C, I would not expect performance to
be better. (There are a few cases where the parameter passing overhead
in C would be higher, so performance would be technically worse, but
only by a few instructions.)

> (*) Only if you think the one on the shootout page is inadequate.

Which shootout page, this one? http://dada.perl.it/shootout/matrix.html

If so the only questions I would have is why are there no default
initial values for the matrices to insure consistancy. (It would be
possible for any implementation to fail unless overflow checking is
turned off, and in Ada that can cause code to run slower.) Incidently
on this page, on this test gcc takes ten milliseconds, GNAT takes 20 ms.
  Hardly in the same class as perl, 34.31 seconds, or even java, 73
milliseconds.

Also I just submitted a new version of the strcat routine to fix a
minor problem that resulted in the test being reported as failed. (The
length was printed with leading spaces, and the test harness didn't
expect that.) While I was at it I rewrote basically the whole thing:

with Ada.Command_Line; use Ada.Command_Line;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Fixed; use Ada.Strings;
with Ada.Text_Io; use Ada.Text_Io;
procedure Strcat is
    N: Integer;
    Hello : String := "hello" & Ascii.Lf;
begin
    if Argument_Count < 1
    then N := 10_000;
    else N := Integer'Value(Argument(1));
    end if;
    declare
      Buffer : Unbounded_String := N*Hello;
    begin
    Put_Line(Ada.Strings.Fixed.Trim
              (Integer'Image(Length(Buffer)),Left));
    end;
end Strcat;

This results in about a 100x speed up. Is this the right way to write
it and the code they had wrong? In one sense, that probably is true.
But if I use Bounded_String, the version on the website is slightly
faster, and both versions fall midway between the fast and slow
Unbounded versions. (A version that just uses String is actually faster
than the Unbounded String version. However, I think that version is a
bit of a cheat. ;-)

-- 
                                           Robert I. Eachus
"The war on terror is a different kind of war, waged capture by capture, 
cell by cell, and victory by victory. Our security is assured by our 
perseverance and by our sure belief in the success of liberty." -- 
George W. Bush


Relevant Pages