李伟 <liweifrie...@gmail.com> wrote on 06/09/2010 02:51:00 AM:

> Hi:
> 
> I've written a x-10 problem as follows:
> 
> public class Fun2
> {
>  public static def main(argv:Rail[String]!) =
>  {
>      val a : DistArray[Int]
>              =
> DistArray.make[Int](Dist.makeBlock(1..35),((i):Point)=>i*i);
>      x10.io.Console.OUT.println(str(a));
>  }
> 
>  static def str[T](a:DistArray[T]):String  {
>      var s : String = "";
>      var first : Boolean = true;
>      for(point in a)
>      {
>       if (first) first = false;
>       else s += ",";
>       s += a(point).toString();
>      }
>      return s;
>  }
> }
> 
> It can be compiled. And when running, the program crashed. The output 
info
> is as follows:
> 
> x10.lang.BadPlaceException: point (10) not defined at (Place 0)
>  at x10.array.DistArray$2.apply(DistArray.java:613)
>  at x10.array.DistArray$2.apply(DistArray.java:1)
>  at x10.array.BaseRegion.check(BaseRegion.java:120)
>  at x10.array.DistArray.checkPlace(DistArray.java:1407)
>  at x10.array.DistArray.apply(DistArray.java:998)
>  at Fun2.str(Fun2.java:149)
>  at Fun2.main(Fun2.java:106)
>  at Fun2$Main$2.apply(Fun2.java:51)
>  at x10.lang.Runtime$5.apply(Runtime.java:4454)
>  at x10.lang.Activity.run(Activity.java:217)
>  at x10.lang.Runtime$Worker$3.apply(Runtime.java:3455)
>  at x10.runtime.impl.java.Runtime.runAt(Runtime.java:105)
>  at x10.lang.Runtime$Worker.loop(Runtime.java:3422)
>  at x10.lang.Runtime$Worker.apply(Runtime.java:3308)
>  at x10.lang.Runtime$Pool.apply(Runtime.java:3842)
>  at x10.lang.Runtime.start(Runtime.java:4461)
>  at Fun2$Main.main(Fun2.java:34)
>  at x10.runtime.impl.java.Runtime.run(Runtime.java:50)
>  at java.lang.Thread.run(Unknown Source)
> 
> When changing the sentence:
> s += a(point).toString();
> into the new form:
> s += at(a.dist(point)){a(point).toString()};
> it runs well.
> 
> In my opinion, toString is global. And therefore I don't need to use the
> "at" clause. Are there any problems here?
> 
> Best regards,
> Wei Li

Hi, Wei,

Indeed, toString() is global, but array access is not.  You are
getting the BadPlaceException from accessing a(point) in the wrong
place.

FYI,

s += (at(a.dist(point)) a(point)).toString();

should work (note that toString() is invoked in the place running
the loop -- only the array access has been executed remotely).

Hope this clarifies things,
        Igor
P.S. It would be great if you stated your affiliation in your messages
when posting from a generic address (e.g., GMail).
-- 
Igor Peshansky  (note the spelling change!)
IBM T.J. Watson Research Center
X10: Parallel Productivity and Performance (http://x10-lang.org/)
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)
"I hear and I forget.  I see and I remember.  I do and I understand" -- 
Confucius

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to