Han Dong <saviola7...@gmail.com> wrote on 06/20/2010 11:27:54 PM:

> Hi,
> 
> I have this merge sort function in x10:
> 
> public def mergeSort(tmp:GrowableRail[Pair[String, Int]],
>                         low: Int, high: Int)
>    {
>       val lo:Int = low;
>       val hi:Int = high;
> 
>       val N:Int = hi - lo; //elements to sort
> 
>       if(N <= 1)
>       {
>          return 0;
>       }
> 
>       val mid:Int = lo + (N/2);  //middle index
> 
>       //recursively sort left and right halves
>       mergeSort(tmp, lo, mid);
>       mergeSort(tmp, mid, hi);
> 
>       var aux: GrowableRail[Pair[String, Int]] =
>          new GrowableRail[Pair[String,Int]](N)
> 
>       var i:Int = lo;
>       var j:Int = mid;
> 
>       //merge 2 sorted subarrays
>       for(var k:Int = 0; k < N; k++)
>       {
>          if(i == mid)
>          {
>             aux.set(tmp(j++), k);
>          }
>          else if(j == hi)
>          {
>             aux.set(tmp(i++), k);
>          }
>          else if(tmp(j).first < tmp(i).first)
>          {
>             aux.set(tmp(j++), k);
>          }
>          else
>          {
>             aux.set(tmp(i++), k);
>          }
>       }
> 
>       //copy back into original array
>       for(var k:Int = 0; k < N; k++)
>       {
>          tmp.set(aux.apply(k), (lo+k));
>       }
>   }
> 
> I have an almost exact copy of it in Java. The Java version works fine 
so I
> thought I could just rewrite it in x10, but it doesn't seem to be 
working at
> all. Is there something about recursion in x10 that is different than 
Java?

Not enough information.  What exactly doesn't work?  Are you getting
compilation errors?  Runtime errors?  Incorrect results?  What version
of X10 are you using?  What environment? What options do you give to
the compiler?
        Igor
-- 
Igor Peshansky  (note the spelling change!)
IBM T.J. Watson Research Center
X10: Parallel Productivity and Performance (http://x10-lang.org/)
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)
"I hear and I forget.  I see and I remember.  I do and I understand" -- 
Confucius


------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to