The following code:

class D {
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 (p 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: " + (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
  }
}
}

produces the following output:

Array index: (1) distributed place :(Place 0)
Array element: 1
Array index: (2) distributed place :(Place 1)
Array element: 4
Array index: (3) distributed place :(Place 2)
Array element: 9
Array index: (4) distributed place :(Place 3)
Array element: 16

There are two changes from the code below.

First, the iterator for the for loop is changed to "for (p in D)...". 
Note that the type of p is not specified explicitly. This permits the 
compiler to infer the type of p as Point(D.rank) -- this is necessary so 
that the subsequent array access data_squares(p) can work -- 
data_squares must be accessed with a point of the right rank (D.rank).

Alternatively you could also write "for (p: Point(D.rank) in D)...".

(We are working on some changes to type checking in X10 so that this 
first change would not be needed.)

Now the second change is that X10 requires that the remote locations be 
accessed within an "at"statement or expression so that by just looking 
at the code you can see where there may be a possible inter-place 
communication. Hence the access data_squares(p) should be wrapped in an 
at statement which specifies the place where that data item is located, 
hence "(at (D(p)) data_squares(p))".

Hope this helps,

Best,
Vijay

Haris H wrote:
> 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
>   }
> }
> ------------------------------------------------------------------------------
> 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
>
>
>
>   



------------------------------------------------------------------------------
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

Reply via email to