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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!newsfeed.hanau.net!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: GNAT compiler switches and optimization Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1161341264.471057.252750@h48g2000cwc.googlegroups.com> Date: Fri, 20 Oct 2006 14:35:01 +0200 Message-ID: <1maiu8u6yrfjm$.1itxhhsvd2vc2.dlg@40tude.net> NNTP-Posting-Date: 20 Oct 2006 14:35:01 CEST NNTP-Posting-Host: a3f21c94.newsspool1.arcor-online.net X-Trace: DXC=Yol63YNbW9C0YVY]kmLTlDic==]BZ:afN4Fo<]lROoRA^YC2XCjHcbICFFJ[iAPm?NDNcfSJ;bb[EFCTGGVUmh?DN\HXHJ4e80N_2[moHaOd_G X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:7075 Date: 2006-10-20T14:35:01+02:00 List-Id: On 20 Oct 2006 03:47:44 -0700, 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. > > I'm using GNAT (GPL 2006) and GFortran (4.2.0) and the following > compile options: > > gnat make -O3 -gnatp tst_array > gfortran -O3 tst_array.f95 > > Running them on 800x800 matrices (on my 2GHz laptop) > > for Ada: "tst_array 800" runs in 18 seconds > for Fortran "tst_array 800" runs in 6 seconds > > (if I use the fortran "matmul" intrinsic the fortran time drops to > 2.5 seconds) > > Note, I tried reordering the loops, removing the random calls, etc. > none of which made huge changes. There is something killing > performance > and/or a switch or two that I'm missing, but I can't seem to find it. > Any thoughts? > > Here is the code: [...] Pointers + index checks I'd say. Try this: with Ada.Numerics.Float_Random; use 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_2 is package F_IO is new Ada.Text_IO.Float_IO(Float); package D_IO is new Ada.Text_Io.Fixed_Io(Duration); type Real_Matrix is array(Integer range <>,Integer range <>) of Float; N : Positive; G : Ada.Numerics.Float_Random.Generator; Start, Finish : Ada.Calendar.Time; Sum : Float := 0.0; begin N := Positive'Value (Argument (1)); declare subtype Matrix is Real_Matrix (1..N, 1..N); A, B, C : Matrix; begin for I in A'range(1) loop for J in A'range(2) loop A(I,J) := Ada.Numerics.Float_Random.Random(G); B(I,J) := Ada.Numerics.Float_Random.Random(G); end loop; end loop; Start := Ada.Calendar.Clock; for I in A'range(1) loop for J in A'range(2) loop Sum := 0.0; for R in A'range(2) loop Sum := Sum + A(I,R)*B(R,J); end loop; C(I,J) := Sum; 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; end; Put ("Time: "); D_IO.Put(Finish-Start); New_Line;New_Line; end tst_array_2; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de