Deleted Variable Declarations

How do declarations with a remote variable work? I tried to increase the declaration of a regular variable with the on clause, as described in section 26.2.1 Chapel Language Specification , but that doesn’t mean it seems to work. For example, this line of code:

on Locales[1] var x: [0..10] real;

unable to compile with error syntax error: near 'var'.

+4
source share
1 answer

In short, the syntax is specified, but it is not currently implemented. Unfortunately, the language specification does not currently indicate that this is a future feature.

, . , , , GitHub Chapel, .

:

  • on .
  • on

.

-, . , :

on Locales[1] var A: [0..10] real; // declare array stored on Locales[1]
A = 1; // on Locale 0, set every element of A to 1
writeln(A); // on Locale 0, print out the array

// print out the locale storing each element
for x in A {
  write(x.locale.id, " ");
}
writeln();

on :

on Locales[1] {
  var A: [0..10] real;
  on Locales[0] {
    A = 1;
    writeln(A);
    for x in A {
      write(x.locale.id, " ");
    }
    writeln();
  }
}
// result, when run on 2 locales:
// from printing array elements:
// 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
// from printing element locales:
// 1 1 1 1 1 1 1 1 1 1 1

, , Locale 0. , Locale , on (, var fromLocale = here;) on.

on, , , . . , - Owned/Shared, , delete.

, , delete.

class MyArrayWrapper {
  var A: [0..10] real;
}
var myObject: MyArrayWrapper; // starts out as nil
on Locales[1] {
  // set myObject to a new instance
  // since we do that on Locales[1], it is allocated there
  // and the contained array is stored there too.
  myObject = new MyArrayWrapper();
}
myObject.A = 1;
writeln(myObject.A);
for x in myObject.A {
  write(x.locale.id, " ");
}
writeln();
delete myObject;
// result, when run on 2 locales:
// from printing array elements:
// 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
// from printing element locales:
// 1 1 1 1 1 1 1 1 1 1 1

, , ? , 11 Locales the Chapel .

use BlockDist;

const MyDom = {0..10}; // this domain represents the index set 0..10
// declare a Block-distributed index set 0..10
// by default, this is distributed over all available Locales
const MyBlockDistributedDomain = MyDom dmapped Block(boundingBox=MyDom);
// declare an Block-distributed array
var BlockDistributedA: [MyBlockDistributedDomain] real;
BlockDistributedA = 1;
writeln(BlockDistributedA);
for x in BlockDistributedA {
  write(x.locale.id, " ");
}
writeln();
// result, when run on 2 locales:
// from printing array elements:
// 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
// from printing element locales:
// 0 0 0 0 0 0 1 1 1 1 1

, . , :

use BlockDist;

const MyDom = {0..10};
// This time, specify the target locales for the Block distribution to use.
// Here we pass in an anonymous array storing just Locales[1], so that
// the resulting array only stores elements on Locales[1].
const MyDistributedDomain = MyDom dmapped Block(boundingBox=MyDom,
                                                targetLocales=[Locales[1]]);
var DistributedA: [MyDistributedDomain] real;
DistributedA = 1;
writeln(DistributedA);
for x in DistributedA {
  write(x.locale.id, " ");
}
writeln();
// result, when run on 2 locales:
// from printing array elements:
// 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
// from printing element locales:
// 1 1 1 1 1 1 1 1 1 1 1
+5

Source: https://habr.com/ru/post/1688496/


All Articles