To add to Josh's comments. If you have an object o at a place p, and you
need to go to a place q, and then come back and modify o (and not a copy
of o), you have to use a GlobalRef. (You can also use a PlaceLocalHandle.)
Thus:
val a = makeArray();
val globalA = GlobalRef(a);
val home = here;
at (here.next()) {
val x = ...
at (home) { // go back to the original place
globalA()(0) = x; // assign x to a(0).
}
}
at(here.next())
> at(here)
> {
> for(p in src_array)
> {
> src_array(p) = 10000;
> }
>
> }
>
> for(p in src_array)
> Console.OUT.println(src_array(p));
On 12/17/2010 1:14 AM, Josh Milthorpe wrote:
> Hi Kirak,
>
> I'm assuming that src_array was created at (here).
>
> In the first example, the src_array that is modified is actually a copy
> of a copy - it is copied to here.next() in the first line and then again
> (to the same place). Note that at(here) is _not_ a noop - it copies all
> variables in the closure environment! This is to make the behaviour of
> the at statement consistent regardless of the target place.
>
> The second example doesn't actually work for me, etiher (against SVN
> HEAD) - if I print the contents of src_array, they have not been
> updated. Again, the src_array that is updated is a copy, so the updates
> don't affect the original src_array.
>
> Have a look at the RemoteArray class and the Array.copy(...) and
> Array.asyncCopy(...) methods. These support a variety of patterns of
> local and remote updates - hopefully one of them matches your requirement.
>
> Cheers,
>
> Josh
>
> On 17/12/10 16:16, Kirak Hong wrote:
>> Hi,
>>
>> I have another question regarding X10 array. I tried to modify a local array
>> from remote place using following code. I noticed that there's some
>> computation running, but the content of array was never changed.
>>
>> at(here.next())
>> at(here)
>> {
>> for(p in src_array)
>> {
>> src_array(p) = 10000;
>> }
>>
>> }
>>
>> for(p in src_array)
>> Console.OUT.println(src_array(p));
>>
>> However, the following code seems to be working, although it is highly
>> inefficient.
>>
>> at(here.next())
>> for(p in src_array)
>> {
>> var x : int = 0;
>> at(here)
>> {
>> x = 10000;
>> }
>> src_array(p) = x;
>> }
>>
>> I looked at the X10 programming manual and it says it will implicitly copy
>> an object to another place if that object is used within 'at' clause.
>> However, I don't understand why above behavior happens. Can anybody tell me
>> the reason?
>>
>> Thanks,
>> Kirak
------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
X10-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/x10-users