Difference between pages "Sync" and "String"

From Mesham
(Difference between pages)
Jump to navigationJump to search
(Syntax)
 
 
Line 1: Line 1:
 
== Syntax ==
 
== Syntax ==
  
sync name;
+
String
  
 
== Semantics ==
 
== Semantics ==
  
Will synchronise processes where they are needed. For instance, if using the asynchronous communication type, the programmer can synchronise with a variable name and the keyword will ensure all communications of that variable are up to date. One sided communication (variable sharing MPMD style in a par loop) is also linked into this keyword and it will ensure all communication is completed. Without a variable will synchronise all outstanding variables that need synchronising. If a process has no variables that need syncing then it will ignore this keyword and continue.
+
A string of characters. All strings are immutable, concatenation of strings will in fact create a new string.
  
[[Category:Parallel]]
+
=== Default typing ===
 +
 
 +
{{ElementDefaultTypes}}
 +
 
 +
== Example ==
 +
 
 +
function void main() {
 +
    var i:String;
 +
    var p:="Hello World!";
 +
};
 +
 
 +
In this example variable ''i'' is explicitly declared to be of type ''String''. Variable ''p'' is found, via type inference, also to be of type ''String''.
 +
 
 +
''Since: Version 0.41b''
 +
 
 +
== Communication ==
 +
 
 +
{{ElementTypeCommunication}}
 +
 
 +
[[Category:Element Types]]
 +
[[Category:Type Library]]

Revision as of 14:28, 15 April 2013

Syntax

String

Semantics

A string of characters. All strings are immutable, concatenation of strings will in fact create a new string.

Default typing

In the absence of further type information, the following types are added to the chain:

Example

function void main() {
   var i:String;
   var p:="Hello World!";
};

In this example variable i is explicitly declared to be of type String. Variable p is found, via type inference, also to be of type String.

Since: Version 0.41b

Communication

When a variable is assigned to another, depending on where each variable is allocated to, there may be communication required to achieve this assignment. Table \ref{tab:eltypecomm} details the communication rules in the assignment \emph{assignmed variable := assigning variable}. If the communication is issued from MPMD programming style then this will be one sided. The default communication listed here is guaranteed to be safe, which may result in a small performance hit.


Assigned Variable Assigning Variable Semantics
multiple[] multiple[] local assignment
single[on[i]] multiple[] individual processes write values to process i
multiple[] single[on[i]] individual processes read values from process i
single[on[i]] single[on[i]] local assignment where i==i
single[on[i]] single[on[j]] communication from j to i where i!=j

Communication Example

var a:Int;
var b:Int :: allocated[single[on[2]]];
var p;
par p from 0 to 3 {
   if (p==2) b:=p;
   a:=b;
   sync;
};


This code will result in each process reading the value of b from process 2 and then writing this into a. As already noted, in absence of allocation information the default of allocating to all processes is used. In this example the variable a can be assumed to additionally have the type allocated[multiple]. Note that communication groups are the same as multiple in this context and share the same semantics. All variables marked multiple are private to their containing process.