Good question!

The outcome is the same (I think). The difference is in performance.

* Parallel-safe accumulation happens once per thread with reduce intents 
vs. once per loop iteration in your case.

   In the reduce-intent case, "pi += inter;" in the body of the loop 
accumulates onto a task-private variable. This does not require parallel 
safety and so can be done fast, get vectorized, etc.

* With reduce intents, the parallel-safe accumulation is done using an 
atomic add. When using a sync variable, even a single += operation is 
quite expensive, e.g. it involves grabbing and releasing a lock.

Vassily

On 07/22/15 11:56, Russel Winder wrote:
> On Wed, 2015-07-22 at 10:16 -0700, Vassily Litvinov wrote:
>> […]
>>
>>     var pi: real;
>>     forall j in 0..intervals with (+ reduce pi) {
>>       const x = (j-0.5)*delta;
>>       const inter = 4.0/(1.0+x**2);
>>       pi += inter;
>>     }
>>     writeln("Pi: ", pi*delta);
>>
> […]
>
> Will this be different from:
>
>    var sum: sync real = 0.0;
>    forall i in 1..n do { sum += 1.0 / (1.0 + ((i - 0.5) * delta) ** 2);
> }
>    const pi = 4.0 * delta * sum;
>
> ?
>

------------------------------------------------------------------------------
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to