"TAJCHMAN Marc" <marc.tajch...@cea.fr> wrote on 09/20/2009 06:30:15 AM:

> Hi everyone,
> 
> Thanks for helping me on previous messages (especially Igor).
> 
> Below are 2 versions of a test (defining and accessing a distributed 
> array on several places).
> This is a variation of an example code from X10 distribution 
> (EncapsulatedArray2D).
> 
> The first version is (apparently) working well but the second one 
> launches several x10.lang.BadPlaceException.
> 
> The differences are :
> 
> - first version : the distributed array is created and accessed only 
> from the static main function
> - second version : the array is now a member of the class containing 
> the main function. It's created inside the class constructor and 
> accessed from other class method.
> 
> Thanks a lot for any suggestion.
> 
> Marc

Hi, Marc,

Don't forget that in version 2, t is of a class type, and
thus lives in a particular place (where it was created,
in this case place 0).  When you access "A" in the input()
and output() methods, it's really a shorthand for "this.A",
so you are reading a field of an object.  Attempting to do
this in any place other than where the object lives will
give you a BPE -- that's expected behavior.

There are a couple of possible solutions.  One is to
capture the field value separately from the object, namely:

    def init() {
        val A = this.A;
        finish ateach (val (i): Point in A.dist) 
            A([i]).init(i);
    }

    def output() {
        val A = this.A;
        for (val p in A.dist.places())
            at(p) { 
                val r : Region = A.dist.get(here);
                for ((i): Point in r) {
                    println("subdomain "+i+" place = "+ here);
                    A([i]).output();
                    println("");
                }
            }
    }

Another is to make test8 a value class, which would
enable replication of the object across places.

Hope this helps,
        Igor

> // =====================================================
> // working code
> public class test8 {
> 
>     static def println(s:String) = Console.OUT.println(s);
>     static def print(s:String) = Console.OUT.print(s);
> 
>     static value bloc{
>         val m_array: Array[double];
>         def this(val a_array: Array[double]): bloc = {
>             m_array=a_array;
>         }
>         def init(val i:int) : Void = {
>             for (val (j): Point(1) in m_array) 
>                 m_array([j])= 10*j + i;
>         }
>         def output() : Void = {
>             for (val (j): Point(1) in m_array) {
>                 println(" "+j+" : " + m_array([j]));
>             }
>         }
>     }
> 
> 
>     public static def main(a: Rail[String]) : void {
> 
>         val R : Region = [1..5];
>         val r : Region = [1..3];
> 
>         val D = Dist.makeCyclic(R, 0); 
>         val A = Array.make[bloc]
>             (D, (p:Point) => 
>              new bloc(Array.make[double](r->here,(Point)=>0.0D)));
> 
>         finish ateach (val (i): Point in D) 
>             A([i]).init(i);
> 
>         for (val p in A.dist.places())
>             at(p) { 
>                 val r : Region = A.dist.get(here);
>                 for ((i): Point in r) {
>                     println("subdomain "+i+" place = "+ here);
>                     A([i]).output();
>                 println("");
>                 }
>             }
>     }
> }
> 
> // ========================================================
> // non working version
> 
> public class test8c {
> 
>     val A : Array[bloc];
> 
>     static def println(s:String) = Console.OUT.println(s);
>     static def print(s:String) = Console.OUT.print(s);
> 
>     static value bloc{
>         val m_array: Array[double];
>         def this(val a_array: Array[double]): bloc = {
>             m_array=a_array;
>         }
>         def init(val i:int) : Void = {
>             for (val (j): Point(1) in m_array) 
>                 m_array([j])= 10*j + i;
>         }
>         def output() : Void = {
>             for (val (j): Point(1) in m_array) {
>                 println(" "+j+" : " + m_array([j]));
>             }
>         }
>     }
> 
>     def init() {
>         finish ateach (val (i): Point in A.dist) 
>             A([i]).init(i);
>     }
> 
>     def output() {
>         for (val p in A.dist.places())
>             at(p) { 
>                 val r : Region = A.dist.get(here);
>                 for ((i): Point in r) {
>                     println("subdomain "+i+" place = "+ here);
>                     A([i]).output();
>                     println("");
>                 }
>             }
>     }
> 
>     def this() {
> 
>         val R : Region = [1..5];
>         val r : Region = [1..3];
> 
>         val D = Dist.makeCyclic(R, 0); 
>         A = Array.make[bloc]
>             (D, (p:Point) => 
>              new bloc(Array.make[double](r->here,(Point)=>0.0D)));
>     }
> 
>     public static def main(a: Rail[String]) : void {
>         val t : test8c = new test8c();
>         t.init();
>         t.output();
>     }
> }
-- 
Igor Peshansky  (note the spelling change!)
IBM T.J. Watson Research Center
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)
X10: Parallel Productivity and Performance (http://x10.sf.net/)


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to