Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: X10 2.2
-
Fix Version/s: X10 2.2.1
-
Component/s: Class Library: Array Library
-
Labels:None
-
Testcase included:yes
-
Patch Submitted:Yes
-
Number of attachments :
Description
Iterating over a DistArray to read and update elements is slow, largely because of the cost of virtual function calls to Region.indexOf() to calculate the index of the element within the local storage at each place.
Where the local portion of a DistArray has a rectangular region, it can safely be treated as an Array, thereby avoiding the virtual function call. Furthermore it is then possible to cast to a constrained type to treat the array as {rect} and/or {zeroBased}, further reducing the indexing cost.
The attached patch to x10-trunk adds a new API DistArray.getLocalPortion(). This returns the local portion at this place as an Array; if the local portion is not rectangular it throws an exception. I have deliberately not constrained the return type to be {rect} in case non-rectangular local Arrays are implemented in the future.
The included benchmark demonstrates the speedup from iterating a 1K-size 1D rectangular DistArray (on my Intel Core2 Q9550 @2.83GHz: 366µs) to iterating using getLocalPortion() (199µs) to using getLocalPortion() as Rail[T] (43µs).
Is there a reason we cannot make DistArray restriction (i.e., a|here) behave the same, instead of adding a new API?