Difference between revisions of "Evendist"

From Mesham
Jump to navigationJump to search
m
m (5 revisions imported)
 
(2 intermediate revisions by the same user not shown)
Line 11: Line 11:
 
== Example ==
 
== Example ==
  
  var a:array[Int,16,16] :: allocated[row[] :: horizontal[4] :: single[evendist[]]];
+
  function void main() {
var b:array[Int,16,16] :: allocated[row[] :: vertical[4] :: single[evendist[]]];
+
    var a:array[Int,16,16] :: allocated[row[] :: horizontal[4] :: single[evendist[]]];
var e:array[Int,16,16] :: allocated[row[] :: single[on[1]]];
+
    var b:array[Int,16,16] :: allocated[row[] :: vertical[4] :: single[evendist[]]];
var p;
+
    var e:array[Int,16,16] :: allocated[row[] :: single[on[1]]];
par p from 0 to 3
+
    var p;
{
+
    par p from 0 to 3 {
    var q:=b[p][2][3];
+
      var q:=b[p][2][3];
    var r:=a[p][2][3];
+
      var r:=a[p][2][3];
    var s:=b :: horizontal[][p][2][3];
+
      var s:=b :: horizontal[][p][2][3];
 +
    };
 +
    a:=e;
 
  };
 
  };
a:=e;
 
 
  
 
In this example (which involves 4 processors) there are three [[array|arrays]] declared, ''a'', ''b'' and ''e''. Array ''a'' is [[horizontal|horizontally]] partitioned into 4 blocks, evenly distributed amongst the processors, whilst ''\emph b'' is [[vertical|vertically]] partitioned into 4 blocks and also evenly distributed amongst the processors. Array ''e'' is located on processor 1 only. All arrays are allocated [[row]] major. In the [[par]] loop, variables ''q'', ''r'' and ''s'' are declared and assigned to be values at specific points in a processor's block. Because ''b'' is partitioned [[vertical|vertically]] and ''a'' [[horizontal|horizontally]], variable ''q'' is the value at ''b's'' block memory location 11, whilst ''r'' is the value at ''a's'' block memory location 35. On line 9, variable ''s'' is the value at ''b's'' block memory location 50 because, just for this expression, the programmer has used the [[horizontal]] type to take a horizontal view of the distributed array. It should be noted that in line 9, it is just the view of data that is changed, the underlying data allocation is not modified.
 
In this example (which involves 4 processors) there are three [[array|arrays]] declared, ''a'', ''b'' and ''e''. Array ''a'' is [[horizontal|horizontally]] partitioned into 4 blocks, evenly distributed amongst the processors, whilst ''\emph b'' is [[vertical|vertically]] partitioned into 4 blocks and also evenly distributed amongst the processors. Array ''e'' is located on processor 1 only. All arrays are allocated [[row]] major. In the [[par]] loop, variables ''q'', ''r'' and ''s'' are declared and assigned to be values at specific points in a processor's block. Because ''b'' is partitioned [[vertical|vertically]] and ''a'' [[horizontal|horizontally]], variable ''q'' is the value at ''b's'' block memory location 11, whilst ''r'' is the value at ''a's'' block memory location 35. On line 9, variable ''s'' is the value at ''b's'' block memory location 50 because, just for this expression, the programmer has used the [[horizontal]] type to take a horizontal view of the distributed array. It should be noted that in line 9, it is just the view of data that is changed, the underlying data allocation is not modified.
 
In line 11 the assignment ''a:=e'' results in a scatter as per the definition of its declared type.
 
In line 11 the assignment ''a:=e'' results in a scatter as per the definition of its declared type.
  
 +
''Since: Version 0.41b''
  
 
[[Category:Type Library]]
 
[[Category:Type Library]]
 
[[Category:Compound Types]]
 
[[Category:Compound Types]]
 
[[Category:Distribution Types]]
 
[[Category:Distribution Types]]

Latest revision as of 15:44, 15 April 2019

Syntax

evendist[]

Semantics

Will distribute data blocks evenly amongst the processes. If there are too few processes then the blocks will wrap around, if there are too few blocks then not all processes will receive a block. The figure below illustrates even distribution of 10 blocks of data over 4 processes.

Even distribution of 10 blocks of data over 4 processors using type oriented programming

Example

function void main() {
   var a:array[Int,16,16] :: allocated[row[] :: horizontal[4] :: single[evendist[]]];
   var b:array[Int,16,16] :: allocated[row[] :: vertical[4] :: single[evendist[]]];
   var e:array[Int,16,16] :: allocated[row[] :: single[on[1]]];
   var p;
   par p from 0 to 3 {
      var q:=b[p][2][3];
      var r:=a[p][2][3];
      var s:=b :: horizontal[][p][2][3];
   };
   a:=e;
};

In this example (which involves 4 processors) there are three arrays declared, a, b and e. Array a is horizontally partitioned into 4 blocks, evenly distributed amongst the processors, whilst \emph b is vertically partitioned into 4 blocks and also evenly distributed amongst the processors. Array e is located on processor 1 only. All arrays are allocated row major. In the par loop, variables q, r and s are declared and assigned to be values at specific points in a processor's block. Because b is partitioned vertically and a horizontally, variable q is the value at b's block memory location 11, whilst r is the value at a's block memory location 35. On line 9, variable s is the value at b's block memory location 50 because, just for this expression, the programmer has used the horizontal type to take a horizontal view of the distributed array. It should be noted that in line 9, it is just the view of data that is changed, the underlying data allocation is not modified. In line 11 the assignment a:=e results in a scatter as per the definition of its declared type.

Since: Version 0.41b