comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Ada lacks lighterweight-than-task parallelism
Date: Fri, 29 Jun 2018 17:47:42 -0500
Date: 2018-06-29T17:47:42-05:00	[thread overview]
Message-ID: <ph6cue$v90$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: ph6b2l$1cta$1@gioia.aioe.org

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:ph6b2l$1cta$1@gioia.aioe.org...
> On 2018-06-30 00:01, Randy Brukardt wrote:
...
>> "Parallel" is mainly a hint to
>> the compiler that parallelism can be used (there's almost no case today
>> where a compiler could automatically use parallel code, as there would be 
>> a
>> substantial risk of that code being slower than sequential code would 
>> be).
>
> Why does it need such hints?

One reason is that a loop is defined to iterate operations in a specific 
order. For instance, in
for I in 1..5 loop -- I takes on the values of 1, 2, 3, 4, and 5, in that 
order. The ability of a compiler to parallelize in such a case then requires 
determining all of the following:
(1) That there are enough iterations in order to make parallelizing 
worthwhile;
(2) That there is enough code in each iteration in order to make 
parallelizing worthwhile;
(3) That there is no interaction between iterations;
(4) That there is no use of global variables.

With "parallel", the compiler knows that the programmer has requested 
unordered, parallel iteration, so it only needs make safety checks and 
create the appropriate implementation.

Otherwise, it can't make the optimization without knowing all of the above 
(having simple loops run very slowly because they were parallelized 
unnecessarily is not going to be accepted by many). Indeed, you pretty much 
can only do it when the number of iterations is static and the body of the 
iteration doesn't contain any external calls -- and the number of iterations 
is relatively large.

It's clearly possible that sometime in the future, we'll have new hardware 
and operating systems that would make the overhead small enough that such 
optimizations could be done automatically in enough cases to make it worth 
it. But that's fine; the situation then would be similar to that for 
"inline" -- not 100% necessary but still a useful hint to the compiler.

                                        Randy.


  reply	other threads:[~2018-06-29 22:47 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-19 22:14 Ada lacks lighterweight-than-task parallelism Dan'l Miller
2018-06-19 22:23 ` Dan'l Miller
2018-06-20  0:03 ` Dan'l Miller
2018-06-20  0:41 ` Lucretia
2018-06-20  1:36   ` Dan'l Miller
2018-06-20 13:39     ` Luke A. Guest
2018-06-20  1:12 ` Shark8
2018-06-20  1:41   ` Dan'l Miller
2018-06-20  7:13     ` Dmitry A. Kazakov
2018-06-20 12:03       ` Dan'l Miller
2018-06-20 12:29         ` Dmitry A. Kazakov
2018-06-20 13:14           ` Mehdi Saada
2018-06-20 13:38             ` Dmitry A. Kazakov
2018-06-20 14:01               ` Mehdi Saada
2018-06-20 14:32                 ` Dmitry A. Kazakov
2018-06-29 22:01                   ` Randy Brukardt
2018-06-29 22:15                     ` Dmitry A. Kazakov
2018-06-29 22:47                       ` Randy Brukardt [this message]
2018-06-30  8:41                         ` Dmitry A. Kazakov
2018-06-30 15:43                           ` Brad Moore
2018-07-01  9:46                             ` Dmitry A. Kazakov
2018-07-02 13:13                               ` Marius Amado-Alves
2018-07-02 15:05                                 ` Dmitry A. Kazakov
2018-07-02 16:01                                   ` Marius Amado-Alves
2018-07-02 16:48                                     ` Dmitry A. Kazakov
2018-06-20 15:58                 ` Niklas Holsti
2018-06-29 21:58                 ` Randy Brukardt
2018-06-21  0:19               ` Shark8
2018-06-21  9:09                 ` Dmitry A. Kazakov
2018-06-21 14:42                   ` Shark8
2018-06-21 15:55                     ` Dan'l Miller
2018-06-27 11:49                       ` Marius Amado-Alves
2018-06-21 16:06                     ` Dmitry A. Kazakov
2018-06-22 17:06                       ` Shark8
2018-06-22 18:53                         ` Dmitry A. Kazakov
2018-06-21  0:17         ` Shark8
2018-06-20 12:28 ` Brian Drummond
2018-06-21  1:51   ` Dan'l Miller
2018-06-21 10:22     ` Brian Drummond
replies disabled

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