Let me mention that the Chapel team is working on "reduce intents",
which will allow specifying reduction succinctly like this:
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);
'pi' inside the loop is an implicit task-private variable. Each task's
task-private variable is accumulated atomically into the outer 'pi' upon
the task completion.
The current status is that reduce intents work only for some
user-defined iterators. So the above code will work only when
0..intervals is replaced by a suitable parallel iterator.
Vass
On 07/20/15 11:24, Michael Dietrich 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.
> 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
>
------------------------------------------------------------------------------
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users