Kshitij Mehta wrote:
> Hello
> I am running an x10 1.7 application using the java backend. I am using a 
> block distribution on an array and I get a badplaceexception when i use 
> ateach on the array. I understand this is caused when i try to access an 
> array value that resides on another place. Can someone show a small example 
> on how to fix it? Please note that I cannot make the array a val object, it 
> has to be a 'var'.  
>   
The basic idea is to ensure that each array element is read or written 
at the place at which it resides. So the typical idiom is

ateach(p in a.dist) {
   // read a(p) or write a(p)
}

or you can use the idiom expressed in the following piece of code:

        val R = 1..1000;
        val D = Dist.makeBlock(R, 0);
        val A = Array.make[Int](D, ((p): Point)=>p);
        val places = A.dist.places();
        finish for (p in places)  async at(p) {
           
            val myR:Region(1) = (A|p).region as Region(1);
            var sum:Int=0;
            for (q in myR)
                sum +=  A(q);
            Console.OUT.println("sum at " + p + " is " + sum);
      }
   


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
X10-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to