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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx23.iad.POSTED!not-for-mail From: Brad Moore User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: =?windows-1252?Q?GNAT=A0and_Tasklets?= References: <8277a521-7317-4839-b0b6-97f8155be1a4@googlegroups.com> <9e1d2b9f-1b97-4679-8eec-5ba75f3c357c@googlegroups.com> <478c81f9-5233-4ae1-a3eb-e67c4dbd0da1@googlegroups.com> <1r2ziulc78imb$.ad6zx5upic6s$.dlg@40tude.net> <4s9b9ah19vch9lshchrbi3vndv0ktan5i4@4ax.com> In-Reply-To: <4s9b9ah19vch9lshchrbi3vndv0ktan5i4@4ax.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 68.145.219.148 X-Complaints-To: internet.abuse@sjrb.ca X-Trace: 1419098310 68.145.219.148 (Sat, 20 Dec 2014 17:58:30 UTC) NNTP-Posting-Date: Sat, 20 Dec 2014 17:58:30 UTC Date: Sat, 20 Dec 2014 10:58:32 -0700 X-Received-Bytes: 4243 X-Received-Body-CRC: 3519622550 Xref: news.eternal-september.org comp.lang.ada:24180 Date: 2014-12-20T10:58:32-07:00 List-Id: On 14-12-20 09:49 AM, Dennis Lee Bieber wrote: > On Fri, 19 Dec 2014 11:35:05 -0700, Brad Moore > declaimed the following: > >> >> I haven't listed all the semantics but for the questions you ask, >> each arm of the parallel block is a separate thread of execution (which >> we have been calling a tasklet). >> >> Each tasklet starts off with its own local declaration of Total, >> initialized to 0, which is the Identity value for the reduction. >> >> So, for the top Total, you end up with {Top_}Total := 1 + A + B; > > There is no way I would ever interpret /that/ result... I'd actually > expect an optimizing compiler to see that the result of incrementing Total > is thrown away by the next statement in the block. You are absolutely right. I had missed that Total wasn't being added back in on the second statement. I don't know if Dmitry had intended that in his original question, or had missed that as well. In any case, hopefully the question has been answered. The useless increment of total in that case has no effect on the result, and you end up with Total = A + B + C + D Sorry if this was confusing people. Each branch of the parallel block is a separate thread of execution. Within each branch the sequence of statements is executed sequentially. > >> for the bottom Total, you end up with {Bottom_}Total := C + D; >> >> Then during the reduction phase, those two results get reduced using the >> reduction operation, which in this case is "+". >> >> So the end result is Total = 1 + A + B + C + D; >> > > So your reduction phase becomes the equivalent of a summing > operation... > > par_sum( 1, > A + B, > C + D ) {of course, to do this right requires deferred > evaluation of the parameters} As mentioned above, the reduction only involves summing the results from each branch, and 1 is not part of the first result. so par_sum(A + B, C + D) > > What if you want the result to be a product? > That's why reductions are tricky. It depends on the operation, For integer addition and subtraction, the reducing operation is "+", and the identity value is 0. For products and divisions, the reducing operation is "*", and the identity value is 1. The identity value is a value that when applied as a parameter using the reducting operation, yields the same result. For elementary types such as integer and float, the compiler should be able to choose a default reducer and identity, but for user defined types, the compiler is not likely going to be able to determine a suitable reducer function, or identity value, so the programmer needs to have a way to specify this. As I mentioned already, for parallel blocks it is questionable whether you even need to have automatic reduction support. The complexity of the feature may not be worth adding, though it does seem to be needed for parallel loops. Brad