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: a07f3367d7,5164ccc41905b2d0 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.68.132.73 with SMTP id os9mr9135003pbb.4.1363061211571; Mon, 11 Mar 2013 21:06:51 -0700 (PDT) Path: jm3ni45289pbb.0!nntp.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!news-in-01.newsfeed.easynews.com!easynews.com!easynews!novia!border4.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!backlog2.nntp.ams.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!weretis.net!feeder1.news.weretis.net!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 08 Mar 2013 11:18:48 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/20130216 Thunderbird/17.0.3 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada and OpenMP References: <87k3pjht79.fsf@ludovic-brenta.org> <932708405384391902.448869rm-host.bauhaus-maps.arcor.de@news.arcor.de> In-Reply-To: <932708405384391902.448869rm-host.bauhaus-maps.arcor.de@news.arcor.de> Message-ID: <5139bb06$0$6634$9b4e6d93@newsspool2.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 08 Mar 2013 11:18:46 CET NNTP-Posting-Host: 1fa9d5e5.newsspool2.arcor-online.net X-Trace: DXC=ejVXloTj_RoVFJUo34j6ieZ2m^ X-Complaints-To: usenet-abuse@arcor.de X-Original-Bytes: 3442 X-Received-Bytes: 3698 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: 2013-03-08T11:18:46+01:00 List-Id: On 08.03.13 00:43, Georg Bauhaus wrote: > "Peter C. Chapin" wrote: >> OpenMP is a different animal than Ada tasks. It provides fine grained >> parallelism where, for example, it is possible to have the compiler >> automatically parallelize a loop. In C: >> >> #pragma omp parallel for >> for( i = 0; i < MAX; ++i ) { >> array[i]++; >> } > > Fortunately, OpenMP is no longer needed to achieve automatic > parallelism in either C or Ada at the low level. GCC's vectorizer > produces code that runs in parallel for a number of loop patterns. > These are documented, and they work in GNAT GPL or more > recent FSF GNATs. Later 4.7s IIRC. For example, adding -ftree-vectorize to the set of options (-O2 ...) increases the speed of the program below by factors up to 3, depending to some extent on the value of MAX. (Option -O3 is even easier in this case, and yields improvements when MAX = 8.) The assembly listing includes instructions like MOVDQA and PADDD used with SSE registers. GNAT will report successful optimizations when -fopt-info-optimized is among the switches (or -ftree-vectorizer-verbose=2 for older GNATs). package Fast is MAX : constant := 50; subtype Number is Integer; type Index is new Natural range 0 .. MAX; type Vect is array (Index) of Number; procedure Inc_Array (V : in out Vect); end Fast; package body Fast is procedure Inc_Array (V : in out Vect) is begin for K in Index loop V (K) := V (K) + 1; end loop; end Inc_Array; end Fast; with Ada.Real_Time; use Ada.Real_Time; with Ada.Text_IO; with Fast; use Fast; procedure Test_Fast is Start, Finish : Time; Data : Vect; Result : Integer := 0; pragma Volatile (Result); begin Start := Clock; for Run in 1 .. 500_000_000/MAX loop Inc_Array (Data); if Data (Index(MAX/2 + Run mod MAX/2)) rem 2 = 1 then Result := 1; end if; end loop; Finish := Clock; Ada.Text_IO.Put_Line (Duration'Image (To_Duration (Finish - Start))); end Test_Fast;