The ‘local’ Statement¶
This README describes the local statement in the Chapel language. Its definition and implementation is an area of ongoing work and it should be used with caution.
Overview¶
The local construct in Chapel performs runtime checks for any communication within the construct. If communication occurs, an error is reported. The checks are performed in the code within the lexical scope of the construct, as well as in all function calls performed by that code, directly or indirectly, explicitly or implicitly. The checks can be disabled with the --no-local-checks flag, which is implied by the --no-checks and --fast flags.
Communication occurs in the following cases:
- remote memory (i.e. data not located on the current locale) is referenced (read from or assigned to), or
- an on statement attempts to execute on a remote locale.
The local construct is useful to establish that certain code is communication free. This may be desired, for example, when tuning the performance of a program, as communication usually slows down execution.
The local construct does not necessarily indicate the cause of communication when present. See the Module: CommDiagnostics for ways to diagnose communication.
Syntax¶
The local construct is a statement. It consists of the local keyword followed by a statement:
local-statement:
"local" statement
Examples¶
Here is an example of a local statement:
local
x = A(5);
The inner statement is often a block, commonly referred to as a “local block”:
local {
initializeMyData();
compute();
}
In the above examples, the Chapel implementation checks whether x, as well as all memory referenced during the calls of A.this(5) (an implicit call for A(5)), initializeMyData(), and compute(), are located on the current locale. Otherwise an error is reported. Analogously, if on statement(s) are executed during these calls that attempt to execute on a different locale, an error is reported.