Difference between revisions of "Gather"

From Mesham
Jump to navigationJump to search
(Created page with '== Syntax == gather[elements,root] == Semantics == Gather a number of elements (equal to ''elements'') from each process and send these to the root process. == Example == …')
 
m (4 revisions imported)
 
(3 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
== Example ==
 
== Example ==
  
  var x:array[Int,12] :: allocated[single[on[2]]];
+
  function void main() {
var r:array[Int,3] :: allocated[multiple[]];
+
    var x:array[Int,12] :: allocated[single[on[2]]];
var p;
+
    var r:array[Int,3] :: allocated[multiple[]];
par p from 0 to 3
+
    var p;
{
+
    par p from 0 to 3 {
    (x::gather[3,2]):=r;
+
      (x::gather[3,2]):=r;
 +
    };
 
  };
 
  };
  
 
In this example, the variable ''x'' is allocated on the root process (2) only. Whereas ''r'' is allocated on all processes. In the assignment all three elements of ''r'' are gathered from each process and sent to the root process (2) and then placed into variable ''x'' in the order defined by the source's PID.  
 
In this example, the variable ''x'' is allocated on the root process (2) only. Whereas ''r'' is allocated on all processes. In the assignment all three elements of ''r'' are gathered from each process and sent to the root process (2) and then placed into variable ''x'' in the order defined by the source's PID.  
 +
 +
''Since: Version 0.41b''
  
 
[[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

gather[elements,root]

Semantics

Gather a number of elements (equal to elements) from each process and send these to the root process.

Example

function void main() {
   var x:array[Int,12] :: allocated[single[on[2]]];
   var r:array[Int,3] :: allocated[multiple[]];
   var p;
   par p from 0 to 3 {
      (x::gather[3,2]):=r;
   };
};

In this example, the variable x is allocated on the root process (2) only. Whereas r is allocated on all processes. In the assignment all three elements of r are gathered from each process and sent to the root process (2) and then placed into variable x in the order defined by the source's PID.

Since: Version 0.41b