Reduce

From Mesham
Revision as of 19:27, 10 January 2010 by Polas (talk | contribs) (Created page with '== Syntax == reduce[root,operation] == Semantics == All processes in the group will combine their values together at the root process and then the operation will be performed …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Syntax

reduce[root,operation]

Semantics

All processes in the group will combine their values together at the root process and then the operation will be performed on them. Numerous operations are supported, such as sum, min, max, multiply.

Example

var t:Int::allocated[multiple[]];
var x:Int::allocated[multiple[]];
var p;
par p from 0 to 3
{
   x:(x::reduce[1,"max"];
   x:=p;
   t:=x;
};

In this example, x is to be reduced, with the root as process 1 and the operation will be to find the maximum number. In the first assignment x:=p all processes will combine their values of p and the maximum will be placed into process 1's x. In the second assignment t:=x processes will combine their values of x and the maximum will be placed into process 1's t.