Peter, Michael, On Wed, 2015-07-22 at 13:19 +0200, Peter Kjellström wrote: > On Mon, 20 Jul 2015 20:24:19 +0200 > Michael Dietrich <[email protected]> wrote: > > > Hi Chapel team, > > > > I just remembered an old homework about parallelizing a program in > > OpenMP and decided to re-implement it in Chapel. > > It is a simple iterative algorithm for calculating the number Pi > > [1]. In serial it needed around 18.7 seconds on my machine. > > You seem to be using a very slow converging 1/i^2 pi approx (just > establishing that we're not talking about approx pi in any sane or > efficient way...).
I recognize this solution, I have been using it for >8 years as part of my Python, Groovy, Java, Scala, etc. workshops. There are many (some even interesting) aspects to this implementation other than looking for scaling over processor count. Issues depend on the audience and the goal. Some of the issues are: scaling, convergence, comparison of language features in implementation, checking efficiency of internal iteration higher-order functions, accuracy of floating point numbers, error handling, testing,… Anyone is welcome to peruse the repository on GitHub: https://github.com/russel/Pi_Quadrature Any constructive comments, or even pull requests, are most welcome. Currently I am focusing on Scala, Clojure and Go due to early September commitments. For mid-September's PyConUK 2015 I shall be doing Chapel along with D and C++ working with Python. > In that context the simplest expression I know of is to simply sum > 1/i^2 which will give you pi^2/6. This can be very cleanly expressed > in > chapel using the reduce statement as: > > var pi = sqrt(6.0 * (+ reduce [ i in 1..N by -1 ] 1.0/(i*i) )); Chapel's reduce is extremely good, far better than D's equivalent, and almost as fast as C++/TBB, though the C++/TBB solution, whilst fast, is incomprehensible. The only downside of Chapel reduce is it is always parallel, never sequential. > This works and gives a speedup on my laptop vs serial (i == 10^9 > takes > ~4s on two cores). On my ancient twin Xeon, I get very good indicators of near linear scaling of this embarrassingly parallel problem – it is just addition after all :-) > The above is pointless both mathematically and programming wise > though... (except for the lesson that built in par. primitives in > high > level languages should be exploited if available). "Toy Problems" and solutions like this one clearly have no useful place in real comuptations, but they are wonderful in a teaching/learning context, mostly because of the size of the code relative to the various issues that arise. > /Peter > > > Obviously my first thought was about simply parallelizing the > > for-loop. In every iteration the final result is updated so its' > > variable and the update are atomic now [2]. However this solution > > seemed not to be useful since it didn't even terminate after some > > minutes. Maybe all these uses of the atomic operations need too > > much > > time > > So I changed the program in a way that the atomic operation needed > > to be used only once in the whole program [3] - and it worked: On a > > PC with four cores it needed only 3.6 seconds of time. However I > > think this implementation looks quite long-winded to me. Can you > > suggest a shorter solution in Chapel or is this considered > > appropriate in certain cases like this? > > > > bye > > Michael > > > > [1] > > https://www-user.tu-chemnitz.de/~michd/chpl_pi/eng/pi_serial.chpl > > [2] > > https://www-user.tu-chemnitz.de/~michd/chpl_pi/eng/pi_local1.chpl > > [3] > > https://www-user.tu-chemnitz.de/~michd/chpl_pi/eng/pi_local2.chpl I might do some new versions based on these ones to extend the various possibilities. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:[email protected] 41 Buckmaster Road m: +44 7770 465 077 xmpp: [email protected] London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
signature.asc
Description: This is a digitally signed message part
------------------------------------------------------------------------------ Don't Limit Your Business. Reach for the Cloud. GigeNET's Cloud Solutions provide you with the tools and support that you need to offload your IT needs and focus on growing your business. Configured For All Businesses. Start Your Cloud Today. https://www.gigenetcloud.com/
_______________________________________________ Chapel-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/chapel-users
