All, I did make some changes to the tutorial in response to this thread. I put a warning as a comment in the code demonstrating the forall loop and also put in the correct version with sync variables (in addition to the version that was already there that used a sync variable to create a lock). I'll add the atomic version in the next revision; there are other things that I want to fix/improve as well.
- David On Fri, Dec 6, 2013 at 4:50 AM, Peter Kjellström <[email protected]> wrote: > On Thursday 05 December 2013 17:17:54 Brad Chamberlain wrote: >> 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/ -> > ... >> > 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. > > Doh, now I feel really silly.. > > On the other hand, maybe making the sole forall example an incorrect "do not > do this"-example, without a warning before or in the code, wasn't such a great > idea. > >> > Reading the Forall part of the otherwise great "Productive Programming in >> > Chapel[...] >> > 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 see, I've not yet interested myself in the task parallel parts. Maybe a > reference/link from the data parallel part would be a good idea? > > ... >> > var sum$ : sync real = 0.0; >> > forall i in 1..N by -1 do sum$ += 1.0/(i*i); >> >> 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 > ... >> 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)); > > Almost, direct assignment is not allowed but this works: > > var sum : atomic real; > sum.write(0.0); // not needed? atomic vars seem to be 0-initialized... > forall i in 1..N do sum.add(1.0/(i*i)); > writeln(sqrt(6*sum.read())); > > AFAICT there's no documentation of the atomic typ methods in the language spec > (but I did find the one page in the task parallel section you pointed at > earlier). > >> Still musing over the 1- vs. 2-core performance results, the mechanism used >> to achieve them, and whether I'm surprised... > > For completeness, the above atomic example ran in 38s optimized (vs the 130s > for sync). > > /Peter > > ------------------------------------------------------------------------------ > 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 > ------------------------------------------------------------------------------ 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
