Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Critical
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: X10 2.3.2
-
Component/s: X10 Compiler: Front-end
-
Labels:None
-
Number of attachments :
Description
Here is the revision of 'at', and the new related construct 'athome'.
See the spec for more details.
at(p)S copies all values in 'val' variables in S to place p, giving them the same
names that they have in S. 'var' variables from outside are not accessible in
S. (In particular, 'at' does not permit either delayed initialization, or
assignment to vars.)
'at' may take a list of bindings. If this list is provided, only values in
the list will be copied to S, and they will be referred to by the names given
in the list. Specific examples:
at(p; x1 = x)S ---- copies the value of x, giving it the name x1. It will
be a 'val' variable.
at(p; val x1 = x)S ---- same as at(p; x1=x)S
at(p; x) S ---- copies the value of x, reusing the name x for the copy.
at(p; x,y,z) S ---- If S's free variables are the vals x,y,z, then this is
the same as at(p)S.
at(p; var y : Int = x) S ---- copies the value of x to an Int-valued var y.
y's home is p, and it is a var and can be updated.
at(p; f = this.f) S ---- see how easy it is to copy a field of 'this'
without copying all of 'this'
at(p; f = this.m()) S ---- Note that this.m() isn't kept locally; it is
evaluated and transmitted.
at(p; ) S ---- evaluate S at p, copying nothing.
at(p; x, y1=y, val z1=z) S ---- you can copy many things.
The at-expression at(...)E is just like at(...)S, but it evaluates to a copy
of the result of E.
athome(x) S evaluates S at the place where variable x was defined. x may be a
local var, in which case x may be read or written. Or, x may be a val, in which
case it may be initialized (if it isn't) or read (once it is initialized).
athome(x,y,z) S — evaluates S at the place where x,y, and z are declared.
It is a static error if X10 can't tell that all three of these are the same
place. All three variables can be accessed and modified/initialized inside
of S.
athome(v,a,r,s ; stuffToCopy) S — athome has precisely the same copying
behavior as 'at'.
athome S is equivalent to athome(x1,...,xn) S, where x1-xn are the variables
appearing on lhs of '=' in S but not in the scope of any interior 'at' or 'athome'.
------------------------------------------------------------------------------
EXAMPLES:
Here's the basic there-and-back-again idiom.
val sum: Int, product: Int;
at(mathProcessor; x, y) {
val s = x + y;
val p = x * y;
athome(sum, product) {
sum = s;
product = p;
}
}
println("Sum = " + sum + "; product = " + product);
Here's a distributed summation.
public class Summer { public static def sum(f:(Int)=>Int, low : Int, high:Int) : Int { var sum : Int = 0; finish for(p in Place.places()) { async{ at(p; f, var i : Int = low + p.id(), high) { var localSum : Int = 0; while(i <= high) { localSum += f(i); i += Place.MAX_PLACES; } athome(sum; localSum) { atomic{ sum += localSum; } }//athome }//at }//async }//finish for } }
------------------------------------------------------------------------------
Conversion
Converting existing code to the new atorigin syntax:
- if you accessed a "var" in an "at", or
- if you used remote initialization for a "val"
then you will get an error suggesting you should use "atorigin" (or initialize the "val")
Issue Links
- is depended upon by
-
XTENLANG-2563
Distinguish between lvals and rvals in captured closure environment
-
-
XTENLANG-2439
X10 2.2 language design decisions (umbrella)
-
-
XTENLANG-2971
Umbrella language/front-end JIRA for X10 2.3.1
-
- is related to
-
XTENLANG-2660
Remove ability for code in an at statement/expr to assign a local variable declared outside the at statement/expr
-
Parsing support committed in r21200.