"TAJCHMAN Marc" <marc.tajch...@cea.fr> wrote on 09/21/2009 06:35:01 PM:

> Hi,
> 
> I have a array distributed on 2 places and I want to copy a line of 
> array coefficients to another line
> (i.e.  a(0, j) <- a(1, j) for j=0 to 9). Both lines are on different 
places.
> 
> What is the preffered way to do that ?
> 
> Below there is a small example (each value is transfered separately). 
> It works, but I find my solution neither elegant neither efficient.
> 
> Suggestions are welcome.
> 
> Thanks in advance.
> Marc

Marc,

The preferred idiom in the 1.7 version of the language is to capture
the values in a ValRail and use them inside an "at" (or an "async at").
For example, your transfert() function could look like this:

   def transfert() {
       val v = at (Place.places(1))
                   Rail.makeVal[double]((a.dist | here).size(),
                                        (j:Int)=>a(1,j));
       for ((i,j) in a.dist | here)
           a(i,j) = v(j);
   }

This will cause only one round of communication (one message to
place 1, and one reply with the value).  Note that the syntax for
array accesses and distribution restriction is somewhat simplified
from what you have below.

The 2.0 version of the language has a System.copyTo() function,
which accomplishes the above a bit more efficiently.
        Igor
P.S. X10 also has a no-arg println(), which does the same as
println("").

> //=========================================================
> // example
> 
> import x10.io.Console;
> import x10.util.Timer;
> 
> public value test10
> {
>    public static def println(s:String) = Console.OUT.println(s);
>    public static def print(s:String) = Console.OUT.print(s);
>    public static def now():double = Timer.nanoTime() * 1e-9;
> 
>    val a:Array[double];
> 
>    def this() {
>         R : Region = Region.makeRectangular([0,0], [1,9]);
>         D : Dist  = Dist.makeCyclic(R, 0); 
>         a = Array.make[double](D, ((i,j):Point) => 10*i+j as Double) ;
>    }
> 
>    def output(val s : String) {
>        println("\n" + s);
>        for (p in a.dist.places())
>          at (p) {
>             println("place : " + here); 
>             for ((i,j): Point in a.dist.get(p))
>                 print(" " + a([i,j]));
>             println("");
>          }
>    }
> 
>    def transfert() {
>        for ((i,j): Point in a.dist.get(Place.places(0)))
>            a([i,j]) = at (Place.places(1)) a([1-i,j]);
>    }
> 
>    static public def main(args : Rail[String]) {
> 
>         t:test10 = new test10();
> 
>         t.output("before copy");
>         t.transfert();
>         t.output("after copy");
>    }
> 
> }

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