Encyclopedia > Occam programming language

  Article Content

Occam programming language

Occam is a parallel programming language developed by Inmos[?] for their line of Transputers. Implementations for other platforms exist as well.

Occam builds on Communicating Sequential Processes (CSP) and shares many of the same features. It is, in a way, a practical implementation of CSP. Occam is a procedural language, similar to Pascal etc.

One feature (also found in Python) necessary to understand the examples below is that indentation and formatting is critical: expressions are terminated by the end of the line, lists of expressions need to be on the same level of indentation.

The most interesting language constructs are described in the following.

Communication between processes work through named channels. One process outputs data to a channel via ! while another one inputs data with ?. Input and output will block until the other end is ready to accept or offer data. Examples (c is a variable):

  keyboard ? c

  screen ! c

SEQ introduces a list of expressions that are evaluated sequentially. This is not implicit as it is in most other programming languages. Example:

  SEQ
    x := x + 1
    y := x * x

PAR begins a list of expressions that may be evaluated concurrently. Example:

  PAR
    x := x + 1
    y := y * 2

ALT specifies a list of guarded commands. The guards are combination of a boolean condition and an input expression (both optional). Each guard for which the condition is true and the input channel is ready is successful. One of the successful alternatives is selected for execution. Example:

  ALT
    count1 < 100 & c1 ? data
      SEQ
        count1 := count1 + 1
        merged ! data
    count2 < 100 & c2 ? data
      SEQ
        count2 := count2 + 1
        merged ! data
    status ? request
      SEQ
        out ! count1
        out ! count2

This will read data from channels c1 or c2 (whichever is ready) and pass it into a merged channel. If countN reaches 100, reads from the corresponding channel will be disabled. A request on the status channel is answered by outputting the counts to out.

Documentation and implementations are available from the Internet Parallel Computing Archive: Occam (http://wotug.ukc.ac.uk/parallel/occam/)



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Battle Creek, Michigan

... size is 2.43 and the average family size is 3.04. In the city the population is spread out with 27.2% under the age of 18, 8.7% from 18 to 24, 29.5% from 25 to 44, ...

 
 
 
This page was created in 58.6 ms