Hi Peter --

> Attempting to fix this I went looking for an example forall with proper
> syncronization. The first one I found was:
> 
>  http://chapel.cray.com/tutorials.html ->
>  http://faculty.knox.edu/dbunde/teaching/chapel/ ->
>  2.1. Forall and Coforall ->
> 
>  var sum : int = 0;
>  forall i in 1..1000000 {
>   sum += i;
>  }
>  writeln(sum);
> 
> Which by the looks of it contains the same mistake I did...

If you read the text just below this example, it points out that there is a 
race condition with a forward reference for how to fix it (though the fix is 
not quite as elegant as the one you used below -- I'll check with them to see 
whether that was intentional.

> Reading the Forall part of the otherwise great "Productive Programming in
> Chapel: a Next-Generation Language for General, Locality-Aware Parallelism,
> University of Bergen Tutorial, April 10th, 2013." (also from
> http://chapel.cray.com/tutorials.html) didn't yield any clues or references to
> atomic or sync variables.

atomic and sync variables are considered part of the task parallel subset of 
the language (though they can also be used in any other parallel or serial part 
of the language), so are discussed in that subset of the tutorial slides.

> I proceeded to read the language spec that came with my 1.8.0 chapel and found
> information on sync variables and modified my forall to:
> 
>  config const N = 10;
>  var sum$ : sync real = 0.0;
>  forall i in 1..N by -1 do sum$ += 1.0/(i*i);
>  writeln(sqrt(sum$*6));

This is a reasonable approach and has been the traditional way to do this in 
Chapel; atomic types are a newer addition to the language and are the more 
optimal way to express this, at least for compilers for which we've implemented 
them using the compiler's/hardware's atomic primitives (primarily gcc at 
present, I believe -- someone else may be able to correct me).  You should be 
able to write this as:

var sum: atomic real = 0.0;
forall i in 1..N by -1 do sum.add(1.0/(i*i));

Still musing over the 1- vs. 2-core performance results, the mechanism used to 
achieve them, and whether I'm surprised...

-Brad

------------------------------------------------------------------------------
Sponsored by Intel(R) XDK 
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to