From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: Ada and OpenMP
Date: Fri, 08 Mar 2013 11:18:48 +0100
Date: 2013-03-08T11:18:46+01:00 [thread overview]
Message-ID: <5139bb06$0$6634$9b4e6d93@newsspool2.arcor-online.net> (raw)
In-Reply-To: <932708405384391902.448869rm-host.bauhaus-maps.arcor.de@news.arcor.de>
On 08.03.13 00:43, Georg Bauhaus wrote:
> "Peter C. Chapin" <PChapin@vtc.vsc.edu> 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;
next prev parent reply other threads:[~2013-03-08 10:18 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-07 18:04 Ada and OpenMP Rego, P.
2013-03-07 20:04 ` Ludovic Brenta
2013-03-07 22:22 ` Peter C. Chapin
2013-03-07 23:42 ` Randy Brukardt
2013-03-08 0:39 ` Peter C. Chapin
2013-03-08 3:31 ` Randy Brukardt
2013-03-08 7:17 ` Simon Wright
2013-03-08 23:40 ` Randy Brukardt
2013-03-08 12:07 ` Peter C. Chapin
2013-03-08 14:40 ` Rego, P.
2013-03-08 1:15 ` Shark8
2013-03-08 3:42 ` Randy Brukardt
2013-03-08 14:53 ` Rego, P.
2013-03-08 15:47 ` Georg Bauhaus
2013-03-08 23:40 ` Randy Brukardt
2013-03-08 16:52 ` Shark8
2013-03-08 23:36 ` Randy Brukardt
2013-03-09 4:13 ` Brad Moore
2013-03-10 4:24 ` Randy Brukardt
2013-03-08 7:37 ` Simon Wright
2013-03-10 18:00 ` Waldek Hebisch
2013-03-07 23:43 ` Georg Bauhaus
2013-03-08 10:18 ` Georg Bauhaus [this message]
2013-03-08 14:24 ` Rego, P.
2013-03-07 22:52 ` Simon Wright
2013-03-08 21:37 ` Brad Moore
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox