comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Loops and parallel execution
Date: Tue, 25 Jan 2011 17:37:03 +0100
Date: 2011-01-25T17:37:07+01:00	[thread overview]
Message-ID: <b3snrlfvvwlj$.19t5s0w6izb44$.dlg@40tude.net> (raw)
In-Reply-To: 4d3eeef7$0$6879$9b4e6d93@newsspool2.arcor-online.net

On Tue, 25 Jan 2011 16:40:38 +0100, Georg Bauhaus wrote:

> A quick idea.  Assume that some subprogram Op from package P
> is reentrant (and does not depend on global state). Then,
> 
> with P;
> ...
>    for K in all First .. Last loop
>        P.Op (K);
>    end loop;
> 
> should have the effect of the following being permitted:
> 
> (a) to pick K from  First .. Last  in any order
> 
> (b) to execute P (J) in parallel with P (K) for J, K from
> First .. Last
> 
> The same would be allowed for sufficiently simple expressions:
> 
>    for K in all First .. Last loop
>        L(K) := Standard."*" (K, 3);
>    end loop;
> 
> Can this be borrowed from HPF (IIUC)?
> Is pragma Pure (P) sufficient to signal reentrance?

No, it is not sufficient because it is wrong. P cannot be pure because all
instances of P.Op must be synchronized at the end of the "loop." You need
some frame, context relatively to which P might become pure. "Embedded
task", thread, fiber, call it as you want. If you have that at the language
level, then it becomes no matter whether the thing executed on such a
context is pure or not. This is similar to proper Ada tasks, you can access
shared data from a task as you wish. If you do this inconsistently that is
your problem (erroneous execution).

The point is, if you are going to somehow derive concurrency stuff from a
sequentially written program using pragmas and a "mind reading" compiler, I
doubt that could go anywhere. If you want to add light-weight embedded in
code tasking constructs a-la Occam, that might go, but I don't think that
they could be much useful. You need to map them onto OS services in order
to gain something, because normally there is no direct access to the cores.
That is not light-weight. Have you some certain OS in mind?

This thing you wanted in present Ada:

   task type Worker (Do_Me : not null access procedure (K : Integer)) is
      entry Op (K : Integer);
   end Worker;
   task body Worker is
      I : Integer;
   begin
      accept Op (K : Integer) do
         I := K;
      end Op;
      Do_Me (I);
   end Worker;

   procedure Print (K : Integer) is
   begin
      Put_Line (Integer'Image (K));
   end Print;
...
   declare
      Threads : array (1..20) of Worker (Print'Access);
   begin
      for K in Threads'Range loop
         Threads (K).Op (K);
      end loop;
   end;

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2011-01-25 16:37 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-25 15:40 Loops and parallel execution Georg Bauhaus
2011-01-25 16:37 ` Dmitry A. Kazakov [this message]
2011-01-25 17:36   ` Georg Bauhaus
2011-01-25 17:38     ` Georg Bauhaus
2011-01-25 21:32     ` Dmitry A. Kazakov
2011-01-25 22:07       ` Georg Bauhaus
2011-01-26  1:31         ` Yannick Duchêne (Hibou57)
2011-01-26  9:04         ` Dmitry A. Kazakov
2011-01-26  1:06       ` Yannick Duchêne (Hibou57)
2011-01-26 10:08         ` Dmitry A. Kazakov
2011-01-31 13:01         ` Paul Colin Gloster
2011-02-06 20:06           ` Yannick Duchêne (Hibou57)
2011-02-07 11:43             ` Nicholas Paul Collin Gloster
2011-01-26  8:46 ` Egil Høvik
2011-01-26 10:47   ` Georg Bauhaus
2011-02-14 23:27     ` Tuck
2011-02-15 21:10       ` Georg Bauhaus
2011-01-26 11:29 ` Peter C. Chapin
2011-01-26 21:57 ` Randy Brukardt
2011-01-27 23:01   ` tmoran
2011-01-29  0:23     ` Randy Brukardt
2011-02-06 20:10       ` Yannick Duchêne (Hibou57)
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox