What is the correct way to call this sorting funtion in x10?

122 views Asked by At

I am trying to sort an array in x10 using qsort().

First I was writing sequential code, so there were no issues. Now, I am trying to parallelize my code. Now I need to run this sort function from different places.

public def qsort_cmp_idx(var a:Long,var b:Long):Int
{
 if(item_order(a)<item_order(b)) return x10.lang.Int.operator_as(-1);
  else if (item_order(a)>item_order(b))
   return x10.lang.Int.operator_as(1);
  else return x10.lang.Int.operator_as(0);
}

x10.util.RailUtils.qsort(jump,jt,jump_siz-1,(i:Long,j:Long)=>qsort_cmp_idx(i,j));

item_order is a Rail[Long] at Place 0, and jump is a Rail[Long] at some other Place x.

What is the best way to achieve this?

1

There are 1 answers

0
Dave Grove On BEST ANSWER

In your code snippet, the qsort_cmp_idx function that will be running at Place x needs access to data (the item_order Rail) at Place 0. In X10, an activity can only access data in the Place where it is currently running. So you need to either (a) copy in item_order to Place x before invoking qsort or (b) use the at construct within qsort_cmp_idx to temporarily shift to Place 0 to access item_order. Very likely option (a) is the best approach, because shifting from Place x to Place 0 on every comparison operation in qsort is going to be very slow.