Difference between pages "Prefix sums" and "Writestring"

From Mesham
(Difference between pages)
Jump to navigationJump to search
m (8 revisions imported)
 
m
 
Line 1: Line 1:
<metadesc>Mesham is a type oriented programming language allowing the writing of high performance parallel codes which are efficient yet simple to write and maintain</metadesc>
 
 
== Overview ==
 
== 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.  
+
This writestring(f,a) function will write the value of ''a'' to the file denoted by handle ''f''.
  
== Source Code ==
+
* '''Pass:''' The [[File]] handle to write to and the [[String]] to write
 +
* '''Returns:''' Nothing
 +
 
 +
== Example ==
  
#include <maths>
 
 
  #include <io>
 
  #include <io>
#include <string>
+
  var f:=open("hello.txt","w");
+
writestring(f,"hello - test");
  var processes:=10;
+
  close(f);
 
function void main(var argc:Int,var argv:array[String]) {
 
    var a:Int :: allocated[multiple[]];
 
    var p;
 
    par p from 0 to processes - 1 {
 
      var mine:Int; // Force to be an integer as randomnumber function defaults to double
 
      mine:= randomnumber(0,toint(argv[1]));
 
      var i;
 
      for i from 0 to processes - 1 {
 
          var myvalue:=mine;
 
          if (i < p) myvalue:=0;
 
          (a :: reduce[i, "sum"]):=myvalue;
 
      };
 
      print(itostring(p)+" "+itostring(mine)+" = "+itostring(a)+"\n");
 
    };
 
  };
 
 
 
''This code requires at least Mesham version 1.0''
 
 
 
== Notes ==
 
 
 
The user can provide, via command line options, the range of the random number to find. The (relative) complexity of the prefix sums is taken away by using the reduce primitive communication type.
 
 
 
== Download ==
 
  
Download the entire prefix sums source code [http://www.mesham.com/downloads/prefix.mesh here] you can also download a legacy version for Mesham 0.5 [http://www.mesham.com/downloads/prefix-0.5.mesh here]
+
''Since: Version 0.41b''
  
[[Category:Example Codes]]
+
[[Category:Function Library]]
 +
[[Category:IO Functions]]

Revision as of 18:42, 13 January 2013

Overview

This writestring(f,a) function will write the value of a to the file denoted by handle f.

  • Pass: The File handle to write to and the String to write
  • Returns: Nothing

Example

#include <io>
var f:=open("hello.txt","w");
writestring(f,"hello - test");
close(f); 

Since: Version 0.41b