Par Loop

Next: , Previous: Parallel Composition, Index: Index

The par loop is the parallel equivalent of the for loop.

par [variable] from [var/value] to [var/value]
{
body code here
};

Here the body will be executed parallely on n processes, where n is the to value - from value. Remember the sequential composition after the block. Also, very importantly, The bounds of a par loop MUST be known statically (during compilation). The par loop allows the programmer to write code in MPMD style.

Examples

var p;
par p from 0 to 3
{
printf["I am process ",p," in the par loop\n"];
};


Here the body is run on 4 process, their ID within the block being found in variable p. Each of them displays a message indicating which process they are. The par variable, in this case p can be quite useful, as it allows the programmer to perform conditionals and select within the block certain processes - for instance if (p > 1) {....}; will execute the body of the conditional if the processes's p is creater than 1.

Last Modified: August 2008