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...). 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) )); This works and gives a speedup on my laptop vs serial (i == 10^9 takes ~4s on two cores). 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). /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 > > > ------------------------------------------------------------------------------ > 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 ------------------------------------------------------------------------------ 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
