Difference between pages "File:Mandle.gif" and "Prefix sums"

From Mesham
(Difference between pages)
Jump to navigationJump to search
m (1 revision imported)
 
(Created page with '== Overview == Prefix sums is a very simple, basic parallel algorithm commonly used as the building block of many applications. Also known as a scan, each process will sumate th…')
 
Line 1: Line 1:
Mandelbrot example written in Mesham
+
== Overview ==
 +
 
 +
Prefix sums is a very simple, basic parallel algorithm commonly used as the building block of many applications. Also known as a scan, each process will sumate their value with every preceding processes' value. For instance, p=0 returns its value, p=1 returns p=1 + p=0 values, p=2 returns p=2 + p=1 + p=0 values. The MPI reduce command often implements the communication via the logarithmic structure shown below.
 +
 
 +
== Source Code ==
 +
 
 +
function void main[var arga,var argb]
 +
{
 +
  var m:=10;
 +
  var a:Int :: allocated[multiple[]];
 +
  var p;
 +
  par p from 0 to m - 1
 +
  {
 +
    var mine:Int;
 +
    mine:= randomnumber[0,toInt[argb#1]];
 +
    var i;
 +
    for i from 0 to m - 1
 +
    {
 +
      var myvalue:=mine;
 +
      if (i < p) myvalue:=0;
 +
      (a :: reduce[i, "sum"]):=myvalue;
 +
    };
 +
    print[p," = ",a,"\n"];
 +
  };
 +
};
 +
 
 +
== Notes ==
 +
 
 +
The function main has been included here so that the user can provide, via command line options, the range of the random number to find. The complexity of the prefix sums is taken away by using the reduce primitive communication type.
 +
 
 +
== Download ==

Revision as of 23:02, 10 January 2010

Overview

Prefix sums is a very simple, basic parallel algorithm commonly used as the building block of many applications. Also known as a scan, each process will sumate their value with every preceding processes' value. For instance, p=0 returns its value, p=1 returns p=1 + p=0 values, p=2 returns p=2 + p=1 + p=0 values. The MPI reduce command often implements the communication via the logarithmic structure shown below.

Source Code

function void main[var arga,var argb]
{
 var m:=10;
 var a:Int :: allocated[multiple[]];
 var p;
 par p from 0 to m - 1
 {
   var mine:Int;
   mine:= randomnumber[0,toInt[argb#1]];
   var i;
   for i from 0 to m - 1
   {
     var myvalue:=mine;
     if (i < p) myvalue:=0;
     (a :: reduce[i, "sum"]):=myvalue;
   };
   print[p," = ",a,"\n"];
 };
};

Notes

The function main has been included here so that the user can provide, via command line options, the range of the random number to find. The complexity of the prefix sums is taken away by using the reduce primitive communication type.

Download

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current16:07, 15 April 2019Thumbnail for version as of 16:07, 15 April 2019500 × 500 (31 KB)Polas (talk | contribs)
  • You cannot overwrite this file.

The following page links to this file: