Difference between revisions of "Par"

From Mesham
Jump to navigationJump to search
(Created page with '== Syntax == par p from a to b<br> {<br> par body<br> };<br> == Semantics == The parallel equivalent of the for loop, each iteration will execute concurrently on different pro…')
 
Line 8: Line 8:
 
== Semantics ==
 
== Semantics ==
  
The parallel equivalent of the for loop, each iteration will execute concurrently on different processes. This allows the programmer to write code MPMD style, with the limitation that bounds ''a'' and ''b'' must be known during compilation. All (variable sharing) communication in a par loop is performed using one sided communication, whereas variable sharing SPMD style is performed using synchronous communication for performance reasons.
+
The parallel equivalent of the for loop, each iteration will execute concurrently on different processes. This allows the programmer to write code MPMD style, with the limitation that bounds ''a'' and ''b'' must be known during compilation. Variables declared to be multiply allocated within parallel scope, such as a par block, will automatically be allocated just to the subgroup of processes within that scope.
  
 
== Example ==
 
== Example ==
  
 +
#include <io>
 
  var p;
 
  var p;
  par p from 0 to 10
+
  par p from 0 to 9 {
{
+
     print("Hello world\n");
     print["Hello from process ",p,"\n"];
 
 
  };
 
  };
  
The code fragment will spawn 11 processes (0 to 10 inclusive) and each will display a message.
+
The code fragment will involve 10 processes (0 to 9 inclusive) and each will display a ''Hello world'' message.
  
 
[[Category:Parallel]]
 
[[Category:Parallel]]

Revision as of 13:22, 12 January 2013

Syntax

par p from a to b
{
par body
};

Semantics

The parallel equivalent of the for loop, each iteration will execute concurrently on different processes. This allows the programmer to write code MPMD style, with the limitation that bounds a and b must be known during compilation. Variables declared to be multiply allocated within parallel scope, such as a par block, will automatically be allocated just to the subgroup of processes within that scope.

Example

#include <io>
var p;
par p from 0 to 9 {
   print("Hello world\n");
};

The code fragment will involve 10 processes (0 to 9 inclusive) and each will display a Hello world message.