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!news2.google.com!news3.google.com!news.glorb.com!wns14feed!worldnet.att.net!attbi_s22.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> <9Qb_g.111857$aJ.65708@attbi_s21> <434o04-7g7.ln1@newserver.thecreems.com> <4539ce34$1_2@news.bluewin.ch> <453A532F.2070709@obry.net> <9kfq04-sgm.ln1@newserver.thecreems.com> <453b649e_4@news.bluewin.ch> In-Reply-To: <453b649e_4@news.bluewin.ch> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4uQ_g.1032209$084.294126@attbi_s22> NNTP-Posting-Host: 12.201.97.213 X-Complaints-To: abuse@mchsi.com X-Trace: attbi_s22 1161548800 12.201.97.213 (Sun, 22 Oct 2006 20:26:40 GMT) NNTP-Posting-Date: Sun, 22 Oct 2006 20:26:40 GMT Date: Sun, 22 Oct 2006 20:26:41 GMT Xref: g2news2.google.com comp.lang.ada:7142 Date: 2006-10-22T20:26:41+00:00 List-Id: Gautier wrote: > > The Sum variable was *removed* by someone at some point of the > discussion in order to challenge a bit more the Ada compiler's optimizer. > If you replace a good algorithm by a bad one, don't be surprised that > the program is slow. At some point of bad coding the best code optimizer > won't be able to help you. I did that in my 1st version. I wanted to see if the optimizer would result in equivalent code. No such luck. > Eventually the optimizer will transform this: > for R in A'range (2) loop > C (I, J) := C (I, J) + A (I, R) * B (R, J); > end loop; > into something like: > Sum:= C (I, J); -- hopefully a Sum is mapped to a register > for R in A'range (2) loop > Sum := Sum + A (I, R) * B (R, J); > end loop; > C (I, J):= Sum; > but in that case it probably won't be able to guess that the C(I,J) was > zeroed before and replace the first line by: > Sum:= 0.0; Thanks for the discussion. The initialization of C is static, so a good optimizer could. They're hard to find, though. > sparing the reading of C(I,J) (must cost much time...). > If you are luckier, the optimizer will do > Sum:= 0.0; > for R in A'range (2) loop > Sum := Sum + A (I, R) * B (R, J); > end loop; > C (I, J):= C (I, J) + Sum; > But still, it won't spare the time lost to fill the C matrix with zeros. I didn't include that in the timing. > If you want to do a benchmark with Fortran, it's really not a good idea > to begin with "pessimizing" the Ada code. I'm more interested in seeing what makes a difference in the Ada. In this case, the high-level features that let you write less code. -- Jeff Carter "I unclog my nose towards you." Monty Python & the Holy Grail 11