ifp()

Sometimes you wish to perform an operation on only a subset of the elements of a vector or matrix. In the following example, we wish to compute the absolute value of a vector A:

ifp (A < 0) B = -A; else B = A; The ifp() statement works much like an if() statement in C, except that it works in parallel, and the condition is a vector or matrix condition. In the example above, the expression A < 0 is a vector condition. In parallel, every element of A is compared with 0, resulting in a boolean value (true or false). (Thus, the result of such a comparison is a booleanVector). The subset of elements (virtual processors) where the expression was true executes the then clause. The subset of elements (virtual processors) where the expression was false executes the else clause, if any. In this example, every element of B will be assigned some value, either -A or A, as appropriate. Note that both clauses are always executed; it's just that a different set of virtual processors are active in each clause.

Here's another example:

ifp (A != 0) B /= A; else B = 0;

ifp() may be nested. Each ifp reduces the size of the set of virtual processors that are active. Thus, in

ifp (A == B) C = 0; // A == B here else ifp (A < B) // A != B here C = -1; // A < B here else C = 1; // A > B here The second ifp() is part of the else clause of the first ifp, so it is only executed by those virtual processors who are active there, i.e., those who found their elements A != B.