Hi Saurabh --
[BTW, questions like these would be great StackOverflow questions if you're
open to posting them there...]
> I wanted to know if copying of sliced arrays is done in parallel? i.e.,
> Is array1[a..b]=array2[c..d] parallelized?
Yes, it will be. In general, array assignments like this are equivalent to:
forall (a,b) in zip(A, B) do
a = b;
(where A and B can be array expressions like your slices, in addition to simply
arrays).
> If so will array1[a..b] = array1[c..d] cause a race condition if the
> ranges a..b and c..d overlap?
Yes it will, due to the equivalence of the assignment to the forall loop above
and the Chapel's assumption that the user is responsible for ensuring data
parallel operations are race-free.
> If it is a race condition, how can I avoid it? Or force it to be serial (i
> know its not wise but would still like to know)?
You could change the assignment to a serial zippered loop, like:
for (x, y) in zip(array1[a..b], array[c..d]) do
x = y;
or like:
for (i,j) in zip(a..b, c..d) do
array1[i] = array2[j];
you could also use the serial statement:
serial array1[a..b] = array2[c..d];
If you'd like the assignment to be parallel when they're non-overlapping, I'd
suggest checking for that case and parallelizing if they don't. This could be
done either using a conditional or by using the boolean condition on the serial
statement. For example:
// intersect the two ranges; if the size of the resulting range is
// positive, they must overlap
const overlap = (a..b[c..d]).size > 0;
serial (overlap) array1[a..b] = array2[c..d];
[Disclaimer: I haven't tested my code above. Hopefully I haven't made any
transcription errors or other mistakes, but let me know if something seems
wrong].
-Brad
________________________________
From: Saurabh Sood <[email protected]>
Sent: Wednesday, April 5, 2017 8:27:54 PM
To: [email protected]
Subject: [Chapel-developers] Is Copying Array Slices Done in Parallel?
Hi,
I am working on implementing the galloping phase of TimSort in PR #5840, and am
stuck on a bug.
I wanted to know if copying of sliced arrays is done in parallel? i.e.,
Is array1[a..b]=array2[c..d] parallelized?
If so will array1[a..b] = array1[c..d] cause a race condition if the ranges
a..b and c..d overlap?
If it is a race condition, how can I avoid it? Or force it to be serial (i know
its not wise but would still like to know)?
Thank you.
Regards,
Saurabh Sood
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers