You would have been 'already there' through iteration if you had used an "ateach" loop:
public static def main(args:Rail[String]!){ val R = 1..4; // The inferred type here is Region(1){rect} val D = Dist.makeCyclic(R); // The inferred type here is Dist{region==R) val data_squares = Array.make[Int](D, ((i):Point(1)) => i*i); ateach (val p in D) { // The inferred type here is Point(1) Console.OUT.println( "Array index: " + p + " distributed place :" + D(p)); // Note that, due to the ateach loop, D(p)==here, // so now you're 'already there' Console.OUT.println( "Array element: " + data_squares(p)); } } Hope this helps. Igor Haris H <hha...@gmail.com> wrote on 03/29/2010 09:01:27 PM: > Thank you very much guys, > I had this idea that "at" is not needed since I am 'already there' through > iteration. > > I may come back for more stuff later but this definitely clears much of my > confusion. > > Thank you again. > > Haris > > > > > > On Sun, Mar 28, 2010 at 9:00 PM, Igor Peshansky <ig...@us.ibm.com> wrote: > > > This is a typical X10 beginner mistake: you specify types that > > are too imprecise. You cannot index into an Array with a Point > > unless it can be statically proven that the rank of that Point > > is exactly equal to the rank of the Array's region. > > > > The best rule of thumb is to let X10 infer the types for you. > > Barring that, you should look carefully at the methods you call > > to ensure that the rank is propagated correctly. Incidentally, > > to get efficient iteration, you'd want to propagate other > > pr0operties of the Array's region (e.g., the fact that it's > > rectangular). > > > > Another problem is that array elements have to be accessed in > > the place where they live (as specified by the distribution). > > This is not something that can be checked statically, but you > > will get a runtime exception if this rule is violated. > > > > So, you should rewrite your code as follows: > > > > public static def main(args:Rail[String]!){ > > val R = 1..4; // The inferred type here is Region(1){rect} > > val D = Dist.makeCyclic(R); // The inferred type here is > > Dist{region==R) > > > > val data_squares = Array.make[Int](D, ((i):Point(1)) => i*i); > > > > for (val p in D) { // The inferred type here is Point(1) > > Console.OUT.println( "Array index: " + p + " distributed place :" + > > D(p)); > > > > // this is the problem part, but this is how I understood arrays > > > > Console.OUT.println( "Array element: " + at (D(p)) data_squares(p)); > > > > // how can I access e.g. data_squares(3) and its value and place. > > // using 2.0 java back end on eclipse > > } > > } > > > > Vijay already covered most of these points, but one that I wanted > > to bring up is that, unless you know exactly what the type is, > > better let the type system infer the most precise type. In > > particular, if you'd left the type of D as just Dist, the iteration > > would have been woefully inefficient (which would have hurt your > > peformance for larger arrays). > > > > As Vijay said, we are working on relaxing that requirement. > > Igor > > > > Haris H <hha...@gmail.com> wrote on 03/28/2010 03:57:47 PM: > > > > > Hi guys, > > > can somebody clear this up for me please. > > > I can not get my head around this element manipulation in distributed > > arrays > > > in 2.0. > > > > > > Here is the overly simplified code but represents my problem, > > > so please tell me what am I doing wrong and what it should be. > > > > > > I am having trouble understanding accessing elements of the array and > > their > > > distributed location. > > > > > > Thank you. > > > > > > public static def main(args:Rail[String]!){ > > > > > > R: Region = 1..4; > > > D: Dist = Dist.makeCyclic(R); > > > > > > val data_squares = Array.make[Int](D, ((i):Point) => i*i); > > > > > > for (val p: Point in D) { > > > Console.OUT.println( "Array index: " + p + " distributed place :" > > + > > > D(p)); > > > > > > // this is the problem part, but this is how I understood arrays > > > > > > Console.OUT.println( "Array element: " + data_squares(p)); > > > > > > // how can I access e.g. data_squares(3) and its value and place. > > > // using 2.0 java back end on eclipse > > > } > > > } -- 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 ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ X10-users mailing list X10-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/x10-users