chapel-lang/chapel — pull request #1006 by daviditen (2014-12-12 20:34:58+00:00)
Title:  Add support for standalone parallel iterators

When a forall loop is parsed, it is translated into a call to the leader and
follower iterators, approximately:

for block in iter(leader) {
for i in iter(follower, block) {
body;
}
}

For standalone iterators, we don't want this nested loop. To accomplish
this, I added a condition with a chpl__tryToken. Now unzippered forall
loops are built as:

if chpl__tryToken {
for i in iter(standalone) {
body;
}
} else {
for block in iter(leader) {
for i in iter(follower, block) {
body;
}
}
}

This way, if a standalone parallel iterator exists and can be used, it will
be chosen and the leader-follower case will be folded out during resolution.
If the standalone iterator does not exist, the standalone side will be
removed and the leader-follower branch will be used. For the most part
standalone parallel iteration is treated the same as the leader case
throughout the rest of the compiler. One main exception is that forall
intents are not yet implemented on the standalone side.

A simple standalone iterator is defined in the test
standaloneParallelIter.chpl. It uses a coforall to generate parallelism
and define blocks and iterates over the blocks yielding individual elements.
It also defines a leader and follower iterator to verify the standalone
iterator is chosen over them and that zippered iteration still calls the
leader/followers. Finally it uses a for loop that results in a serial
iterator getting called.

Tested on the full suite for standard linux64 and linux64+gasnet