Port old X10 Example to version 2.5

129 views Asked by At

I have an old X10 example in class which I'm trying to compile.

import x10.array.Array;
import x10.io.Console;
...
public static def main(args: Array[String](1)) {
    val regionTest = 1..12;
    val testArray = new Array[Int](1..12, (Point)=>0);
    for ([i] in testArray) {
        testArray(i) = i;   
        Console.OUT.println("testArray("+i+") = " + testArray(i));
    }
}

Unfortunately it seems to be outdated. I could figure out by myself that you have to write public static def main(args:Rail[String]) now. The definition of val regionTest = 1..12 seems to be ok. The syntax for the array must be wrong, all following lines maybe too. I tried to fix this with this guide, but did not succeed.

My setup is working, the initial class in a new X10 Eclipse IDE project runs.

Could somebody help me port this to version 2.5.x?

1

There are 1 answers

0
Josh Milthorpe On

There were a number of non-backward-compatible changes in X10 version 2.4, which require code changes - see the guide to "porting to X10 2.4".

Your example would be updated as follows:

import x10.regionarray.Array;
import x10.regionarray.Region;
import x10.io.Console;
....
public static def main(args:Rail[String]) {
    val regionTest = Region.makeRectangular(1..12);
    val testArray = new Array[Int](regionTest, (Point)=>0n);
    for ([i] in testArray) {
        testArray(i) = i as Int;
        Console.OUT.println("testArray("+i+") = " + testArray(i));
    }
}

This demonstrates a number of important changes:

  • (Lines 1--2) The general-purpose array classes have moved from the x10.array package to x10.regionarray. These classes are no longer imported by default.
  • (Lines 6--7) There is no implicit type conversion from LongRange (1..12) to Region. A Region object must be explicitly constructed and passed to the x10.regionarray.Array constructor.
  • (Line 7) The default integral type is now Long instead of Int. An Int literal must be suffixed with the character 'n' as in '(Point)=>0n'.
  • (Lines 8--9) The index type for array classes has changed from Int to Long (to support very large data structures). Therefore the exploded Point iterator for ([i] in testArray) now yields i:Long instead of i:Int - which means the cast i as Int is now required when assigning to an Int array element on line 9.