From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7767a311e01e1cd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!wns14feed!worldnet.att.net!attbi_s21.POSTED!53ab2750!not-for-mail From: "Jeffrey R. Carter" Organization: jrcarter at acm dot org User-Agent: Thunderbird 1.5.0.7 (Windows/20060909) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: GNAT compiler switches and optimization References: <1161341264.471057.252750@h48g2000cwc.googlegroups.com> In-Reply-To: <1161341264.471057.252750@h48g2000cwc.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <9Qb_g.111857$aJ.65708@attbi_s21> NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s21 1161382277 12.201.97.213 (Fri, 20 Oct 2006 22:11:17 GMT) NNTP-Posting-Date: Fri, 20 Oct 2006 22:11:17 GMT Date: Fri, 20 Oct 2006 22:11:17 GMT Xref: g2news2.google.com comp.lang.ada:7100 Date: 2006-10-20T22:11:17+00:00 List-Id: tkrauss wrote: > I'm a bit stuck trying to figure out how to coax more performance > out of some Ada code. I suspect there is something simple (like > compiler switches) but I'm missing it. As an example I'm using > a simple matrix multiply and comparing it to similar code in > Fortran. Unfortunately the Ada code takes 3-4 times as long. 1st, make sure you're timing the same thing. How does Ada matrix multiplication compare to FORTRAN? You don't know, because you're also timing the random number generators and I/O. Ada.Text_IO, especially, is quite heavy-weight compared to other languages. Here's my version of your program: with Ada.Numerics.Float_Random; with Ada.Command_Line; use Ada.Command_Line; with Ada.Text_IO; use Ada.Text_IO; with Ada.Calendar; use Ada.Calendar; procedure Tst_Array is package F_IO is new Ada.Text_IO.Float_IO (Float); package D_IO is new Ada.Text_Io.Fixed_Io (Duration); N : constant Positive := Integer'Value (Argument (1) ); type Real_Matrix is array (1 .. N, 1 .. N) of Float; pragma Convention (FORTRAN, Real_Matrix); G : Ada.Numerics.Float_Random.Generator; A,B : Real_Matrix := (others => (others => Ada.Numerics.Float_Random.Random (G) ) ); C : Real_Matrix := (others => (others => 0.0) ); Start, Finish : Ada.Calendar.Time; begin Start := Ada.Calendar.Clock; for I in A'range (1) loop for J in A'range (2) loop for R in A'range (2) loop C (I, J) := C (I, J) + A (I, R) * B (R, J); end loop; end loop; end loop; Finish := Ada.Calendar.Clock; F_IO.Put (C (1, 1) ); F_IO.Put (C (1, 2) ); New_Line; F_IO.Put (C (2, 1) ); F_IO.Put (C (2, 2) ); New_Line; Put ("Time: "); D_IO.Put (Finish - Start); New_Line; end Tst_Array; I compiled as gnatmake -O3 -gnatnp -fomit-frame-pointer tst_array With MinGW GNAT 3.4.2, Windows XP, and a 3.2 GHz Pentium 4 HT processor, I get C:\Documents and Settings\All Users\Documents\Code>tst_array 800 2.05839E+02 2.01230E+02 2.00866E+02 1.94039E+02 Time: 5.821082831 I don't have a FORTRAN compiler for comparison. FORTRAN will probably do better, but I wouldn't expect the difference to be as great as your values. -- Jeff Carter "I was hobbling along, minding my own business, all of a sudden, up he comes, cures me! One minute I'm a leper with a trade, next minute my livelihood's gone! Not so much as a 'by your leave!' You're cured, mate. Bloody do-gooder!" Monty Python's Life of Brian 76