This example covers some features that are not supported by Regent. In particular, any use of mutable state must be carefully controlled, because it may be a hazard for parallel and distributed execution. Regent has features specifically to allow mutable state (that are safe within the language); these will be considered in a later tutorial.
Regent has no mutable global variables.
Lua variables (introduced with
local outside of a task) are global, but from Regent’s perspective they are fixed at compile time. Remember that Lua cannot call Regent directly, so the execution of the Lua portion of a program completes before
regentlib.start is called. Any references to Lua variables in Regent are replaced, as if the user had written directly the value of the variable in the Regent task itself.
So for example, the following program is ok and prints the value
On the other hand, it makes no sense to attempt to modify a Lua variable inside Regent. In the code below,
x is replaced by
2, resulting in the nonsensical assignment
2 = 3. This fails with a compile error.
Regent allows calls to C functions, and permits the use of C pointers. However, these features must be used carefully. Consider, for example, that a subtask may execute on a processor in a different address space (on a different node in a distributed machine) than its parent—so a pointer passed from parent to child might not be valid, and could result in a crash. In most cases it is not safe to pass C pointers to Regent tasks, and Regent will issue a warning if this is attempted.
For further reading on restrictions to the use of pointers, see the discussion in the Legion tutorial.
Continue to the next tutorial to see how aggregate data is stored in Regent.