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

// =====================================================
// 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();
    }
}





------------------------------------------------------------------------------
Come build with us! The BlackBerry® 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-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
X10-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to