User`s guide

Cray XMT Programming Environment Users Guide
Future statements contain the name of a future variable and parameters, a body, and
a return statement. The future variable's value is set by the return statement. The
future variable is optional; if no future variable is specified, the return statement of
the future body supplies no value. For example:
int x, y, z
future int i$;
future i$(x, y, z)
{
/* Some body statements */
return x*y*z;
}
In the previous example, when the computation completes, the return value returns
in the future variable i$. Subsequent accesses to i$ are delayed until the future
completes.
The use of future variables is limited to scalar data types such as char, int, float,
double, pointers, and array elements. The body of a future statement may contain
any legal statement including function calls and other future statements.
For a recursive operation, you can eliminate some of the overhead of blocking a
thread by using the keyword touch in your program. This leaves the semantics
unchanged, but if the future body has not begun, the calling thread executes it
directly.
int search_tree(Tree *root, unsigned target) {
int sum = 0;
if (root) {
future int left$;
future left$(root, target) {
return search_tree(root->llink, target);
}
sum = root->data == target;
sum += search_tree(root->rlink, target);
sum += touch(&left$);
}
return sum;
}
In the previous example, the touch operation checks if any thread has started to
execute the future body associated with left$. If so, it waits for the future body to
complete. If not, the thread calling touch executes the future body itself.
3.5.1 Improving Performance of Future Statements
When your application is compiled, future statements cause the compiler to create
continuations. Continuations are structures that contain pointers to routines that
contain the code from the body of the future statement and a list of arguments to
pass to that code.
32 S247920