Difference between revisions of "Reduce"

From Mesham
Jump to navigationJump to search
(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 …')
 
m (6 revisions imported)
 
(5 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
== Semantics ==
 
== 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.
+
All processes in the group will combine their values together at the root process and then the operation will be performed on them.
  
 
== Example ==
 
== Example ==
  
  var t:Int::allocated[multiple[]];
+
  function void main() {
var x:Int::allocated[multiple[]];
+
    var t:Int::allocated[multiple[]];
var p;
+
    var x:Int::allocated[multiple[]];
par p from 0 to 3
+
    var p;
{
+
    par p from 0 to 3 {
    x:(x::reduce[1,"max"];
+
      x:(x::reduce[1,"max"];
    x:=p;
+
      x:=p;
    t:=x;
+
      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''.  
 
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''.  
  
 +
''Since: Version 0.41b''
 +
 +
== Supported operations ==
 +
 +
{{ Template:ReductionOperations }}
  
 
[[Category:Type Library]]
 
[[Category:Type Library]]
[[Category:Composite Types]]
+
[[Category:Compound Types]]
 
[[Category:Primitive Communication Types]]
 
[[Category:Primitive Communication Types]]

Latest revision as of 15:44, 15 April 2019

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.

Example

function void main() {
   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.

Since: Version 0.41b

Supported operations

Operator Description
max Identify the maximum value
min Identify the minimum value
sum Sum all the values together
prod Generate product of all values