SuperPascal

Last updated
SuperPascal
Paradigm concurrent, imperative, structured
Family Wirth Pascal
Designed by Per Brinch Hansen
First appeared1993;31 years ago (1993)
Stable release
1 / 1993;31 years ago (1993)
Typing discipline Strong
Website brinch-hansen.net
Influenced by
Communicating sequential processes, Pascal, Concurrent Pascal, Joyce, occam

SuperPascal is an imperative, concurrent computing programming language developed by Per Brinch Hansen. [1] It was designed as a publication language: a thinking tool to enable the clear and concise expression of concepts in parallel programming. This is in contrast with implementation languages which are often complicated with machine details and historical conventions. It was created to address the need at the time for a parallel publication language. Arguably, few languages today are expressive and concise enough to be used as thinking tools.

Contents

History and development

SuperPascal is based on Niklaus Wirth's sequential language Pascal, extending it with features for safe and efficient concurrency. Pascal itself was used heavily as a publication language in the 1970s. It was used to teach structured programming practices and featured in text books, for example, on compilers [2] and programming languages. [3] Hansen had earlier developed the language Concurrent Pascal, [4] one of the earliest concurrent languages for the design of operating systems and real-time control systems.

The requirements of SuperPascal were based on the experience gained by Hansen over three years in developing a set of model parallel programs, which implemented methods for common problems in computer science. [5] This experimentation allowed him to make the following conclusions about the future of scientific parallel computing:

These then led to the following requirements for a parallel publication language:

Features

The key ideas in the design of SuperPascal was to provide a secure programming, with abstract concepts for parallelism. [6] [7]

Security

SuperPascal is secure in that it should enable its compiler and runtime system to detect as many cases as possible in which the language concepts break down and produce meaningless results. [8] SuperPascal imposes restrictions on the use of variables that enable a single-pass compiler to check that parallel processes are disjoint, even if the processes use procedures with global variables, eliminating time-dependent errors. Several features in Pascal were ambiguous or insecure and were omitted from SuperPascal, such as labels and goto statements, pointers and forward declarations. [6]

Parallelism

The parallel features of SuperPascal are a subset of occam 2, with the added generality of dynamic process arrays and recursive parallel processes. [7]

A parallel statement denotes that the fixed number of statements it contains must be executed in parallel. For example:

parallel     source() |     sink() end 

A forall statement denotes the parallel execution of a statement by a dynamic number of processes, for example:

forall i := 0 to 10 do     something() 

Channels and communication

Parallel processes communicate by sending typed messages through channels created dynamically. Channels are not variables in themselves, but are identified by a unique value known as the channel reference, which are held by channel variables. A channel is declared, for example, by the declaration

typechannel=*(boolean,integer);varc:channel;

which defines a new (mixed) type named channel and a variable of this type named c. A mixed type channel is restricted to transmitting only the specified types, in this case boolean and integer values. The channel c is initialised by the open statement:

open(c) 

Message communication is then achieved with the send(channel, value) and receive(channel, variable) statements. The expression or variable providing the value for send, and the variable in receive, must both be of the same type as the first channel argument. The following example shows the use of these functions in a process that receives a value from the left channel and outputs it on the right one.

varleft,right:channel;a:number;receive(left,a);send(right,a)

The functions send and receive can both take multiple input and output arguments respectively:

send(channel, e1, e2,..., en); receive(channel, v1, v2,..., vn) 

The following runtime communication errors can occur:

  • Channel contention occurs when two parallel processes both attempt to send or receive on the same channel simultaneously.
  • A message type error occurs when two parallel processes attempt to communicate through the same channel and the output expression and input variable are of different types.
  • Deadlock occurs when a send or receive operation waits indefinitely for completion.

Parallel recursion

Recursive procedures can be combined with parallel and forall statements to create parallel recursive processes. The following example shows how a pipeline of processes can be recursively defined using a parallel statement.

procedurepipeline(min,max:integer;left,right:channel);varmiddle:channel;beginifmin<maxthenbeginopen(middle);parallelnode(min,left,middle)|pipeline(min+1,max,middle,right)endendelsenode(min,left,right)end;

Another example is the recursive definition of a process tree:

proceduretree(depth:integer,bottom:channel);varleft,right:channel;beginifdepth>0thenbeginopen(left,right);paralleltree(depth-1,left)|tree(depth-1,right)|root(bottom,left,right)endendelseleaf(bottom)

Interference control

The most difficult aspect of concurrent programming is unpredictable or non-reproducible behaviour caused by time-dependent errors. Time-dependent errors are caused by interference between parallel processes, due to variable updates or channel conflicts. If processes sharing a variable, update it at unpredictable times, the resulting behaviour of the program is time-dependent. Similarly, if two processes simultaneously try to send or receive on a shared channel, the resulting effect is time-dependent.

SuperPascal enforces certain restrictions on the use of variables and communication to minimise or eliminate time-dependent errors. With variables, a simple rule is required: parallel processes can only update disjoint sets of variables. [1] For example, in a parallel statement a target variable cannot be updated by more than a single process, but an expression variable (which can't be updated) may be used by multiple processes. In some circumstances, when a variable such as an array is the target of multiple parallel processes, and the programmer knows its element-wise usage is disjoint, then the disjointness restriction may be overridden with a preceding [sic] statement.

Structure and syntax

SuperPascal is a block structured language, with the same basic syntax as Pascal. A program consists of a header, global variable definitions, function or procedure definitions and a main procedure. Functions and procedures consists of blocks, where a block is a set of statements. Statements are separated by semicolons, as opposed to languages like C or Java, where they are terminated by semicolons.

The following is an example of a complete SuperPascal program, which constructs a pipeline communication structure with 100 nodes. A master node sends an integer token to the first node, this is then passed along the pipeline and incremented at each step, and finally received by the master node and printed out.

programpipeline;constlen=100;typechannel=*(integer);varleft,right:channel;value:integer;procedurenode(i:integer;left,right:channel);varvalue:integer;beginreceive(left,value);send(right,value+1)end;procedurecreate(left,right:channel);typerow=array[0..len]ofchannel;varc:row;i:integer;beginc[0]:=left;c[len]:=right;fori:=1tolen-1doopen(c[i]);foralli:=1tolendonode(i,c[i-1],c[i])end;beginopen(left,right);parallelsend(left,0)|create(left,right)|receive(right,value)end;writeln('The resulting value is ',value)end.

Implementation

The SuperPascal software can be accessed freely from the Brinch Hansen Archive. [9] It consists of a compiler and interpreter, which are both written in normal, sequential Pascal (ISO Level 1 standard Pascal). This is supported by the GNU Pascal compiler and newer versions of the Free Pascal compiler (2.7.1+) with the -Miso switch, with the following respective small modifications to the code.

For GPC, the file interpret.p uses the non-standard clock function (line 1786), which is used to obtain the system time. Instead, the Extended Pascal getTimeStamp function can be used (which is supported by the GNU Pascal compiler), by declaring a variable of type TimeStamp, setting that with the current time using getTimeStamp and assigning the Second field of the TimeStamp to the variable t.

Free Pascal also needs a solution to the above "clock" problem (On windows, just declare gettickcount as external with "clock" as name). Further, the reset/rewrites that are marked as non-standard in the source code must be changed to assign/reset (or rewrite) pairs. (GPC probably only errors on this if you enable strict flags), and the C preprocessor commands #include 'xx' must be changed to {$include 'xx'}.

{ Time code for readtime in Freepascal on unix systems }FunctionFpTime(vartloc:integer):integer;externalname'FPC_SYSC_TIME';procedurereadtime(vart:integer);begin{ A nonstandard function reads    the processor time in ms }t:=fptime(t);end;

Related Research Articles

Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named after French mathematician, philosopher and physicist Blaise Pascal.

SAIL, the Stanford Artificial Intelligence Language, was developed by Dan Swinehart and Bob Sproull of the Stanford AI Lab. It was originally a large ALGOL 60-like language for the PDP-10 and DECSYSTEM-20. The language combined the earlier PDP-6/-10 language GOGOL compiler, essentially an integer-only version of ALGOL, with the associative store from the LEAP language. The first release was in November 1969 and it saw continued development into the 1980s, including a commercial derivative, MAINSAIL.

PL/0 is a programming language, intended as an educational programming language, that is similar to but much simpler than Pascal, a general-purpose programming language. It serves as an example of how to construct a compiler. It was originally introduced in the book, Algorithms + Data Structures = Programs, by Niklaus Wirth in 1976. It features quite limited language constructs: there are no real numbers, very few basic arithmetic operations and no control-flow constructs other than "if" and "while" blocks. While these limitations make writing real applications in this language impractical, it helps the compiler remain compact and simple.

<span class="mw-page-title-main">ALGOL 68</span> Programming language

ALGOL 68 is an imperative programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously defined syntax and semantics.

<span class="mw-page-title-main">Per Brinch Hansen</span> Danish-American computer scientist

Per Brinch Hansen was a Danish-American computer scientist known for his work in operating systems, concurrent programming and parallel and distributed computing.

The computer programming languages C and Pascal have similar times of origin, influences, and purposes. Both were used to design their own compilers early in their lifetimes. The original Pascal definition appeared in 1969 and a first compiler in 1970. The first version of C appeared in 1972.

In computer programming, a one-pass compiler is a compiler that passes through the parts of each compilation unit only once, immediately translating each part into its final machine code. This is in contrast to a multi-pass compiler which converts the program into one or more intermediate representations in steps between source code and machine code, and which reprocesses the entire compilation unit in each sequential pass.

IP Pascal is an implementation of the Pascal programming language using the IP portability platform, a multiple machine, operating system and language implementation system. It implements the language "Pascaline", and has passed the Pascal Validation Suite.

In computer science, future, promise, delay, and deferred refer to constructs used for synchronizing program execution in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is not yet complete.

Concurrent computing is a form of computing in which several computations are executed concurrently—during overlapping time periods—instead of sequentially—with one completing before the next starts.

<span class="mw-page-title-main">Recursion (computer science)</span> Use of functions that call themselves

In computer science, recursion is a method of solving a computational problem where the solution depends on solutions to smaller instances of the same problem. Recursion solves such recursive problems by using functions that call themselves from within their own code. The approach can be applied to many types of problems, and recursion is one of the central ideas of computer science.

The power of recursion evidently lies in the possibility of defining an infinite set of objects by a finite statement. In the same manner, an infinite number of computations can be described by a finite recursive program, even if this program contains no explicit repetitions.

S-algol is a computer programming language derivative of ALGOL 60 developed at the University of St Andrews in 1979 by Ron Morrison and Tony Davie. The language is a modification of ALGOL to contain orthogonal data types that Morrison created for his PhD thesis. Morrison would go on to become professor at the university and head of the department of computer science. The S-algol language was used for teaching at the university at an undergraduate level until 1999. It was also the language taught for several years in the 1980s at a local school in St. Andrews, Madras College. The computer science text Recursive Descent Compiling describes a recursive descent compiler for S-algol, implemented in S-algol.

PLANC is a high-level programming language.

In computing, the producer-consumer problem is a family of problems described by Edsger W. Dijkstra since 1965.

Concurrent Pascal is a programming language designed by Per Brinch Hansen for writing concurrent computing programs such as operating systems and real-time computing monitoring systems on shared memory computers.

Joyce is a secure programming language for concurrent computing designed by Per Brinch Hansen in the 1980s. It is based on the sequential language Pascal and the principles of communicating sequential processes (CSP). It was created to address the shortcomings of CSP to be applied as a programming language, and to provide a tool, mainly for teaching, for distributed computing system implementation.

Pic Micro Pascala.k.a. PMP is a free Pascal cross compiler for PIC microcontrollers. It is intended to work with the Microchip Technology MPLAB suite installed; it has its own IDE (Scintilla-based) and it is a highly optimized compiler.

Ateji PX is an object-oriented programming language extension for Java. It is intended to facilliate parallel computing on multi-core processors, GPU, Grid and Cloud.

<span class="mw-page-title-main">ParaSail (programming language)</span>

Parallel Specification and Implementation Language (ParaSail) is an object-oriented parallel programming language. Its design and ongoing implementation is described in a blog and on its official website.

Smart Pascal is a dialect of the Object Pascal programming language that is derived from Delphi Web Script, but is adapted for Smart Mobile Studio, a commercial development suite that generates JavaScript rather than machine code.

References

  1. 1 2 Hansen, Per Brinch (1993), SuperPascal: a publication language for parallel scientific computing
  2. Welsh, Jim (1980). Structured System Programming . Upper Saddle River, NJ, USA: Prentice-Hall. ISBN   0-13-854562-6.
  3. Tennent, R. D. (1981). Principles of Programming Languages . Upper Saddle River, NJ, USA: Prentice-Hall. ISBN   0-13-709873-1.
  4. Hansen, Brinch (1977). The Architecture of Concurrent Programs. Prentice-Hall. ISBN   978-0130446282.
  5. Hansen, Brinch (May 1993), "Model programs for computational science: A programming methodology for multicomputers", Concurrency: Practice and Experience, pp. 407–423
  6. 1 2 Hansen, Brinch (1994). "The programming language SuperPascal". Software: Practice and Experience. 24, 5: 399–406.
  7. 1 2 Hansen, Brinch (1977). The invention of concurrent programming. New York: Springer-Verlag. ISBN   0-387-95401-5.
  8. Hoare, C. A. R. (1974). "Hints on programming language design". Computer System Reliability: 505–534.
  9. Hayden, C.C. (2008-06-11). "Per Brinch Hansen Archive" . Retrieved 2020-03-03.