Programming in Occam-pi: A Tutorial By: Zain-ul-Abdin

Slides:



Advertisements
Similar presentations
COMMUNICATING SEQUENTIAL PROCESSES C. A. R. Hoare The Queen’s University Belfast, North Ireland.
Advertisements

Claim Communicating Sequential Processes (CSP) A mathematical theory for specifying and verifying complex patterns of behaviour arising from interactions.
Parallel Processing & Parallel Algorithm May 8, 2003 B4 Yuuki Horita.
Parallel Computing in Matlab
VSMC MIMO: A Spectral Efficient Scheme for Cooperative Relay in Cognitive Radio Networks 1.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
(C) P. H. Welch1 Chapter 4 Fundamentals of occam.
Structured Thread Models Kahn Process Networks, CSP, Go 1Dennis Kafura – CS5204 – Operating Systems.
Go Language * Go - Routines * Channels. New Concepts Do not communicate by sharing memory; instead, share memory by communicating. creating shared memory.
Clockless Logic System-Level Specification and Synthesis Ack: Tiberiu Chelcea.
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
Chapter 7 Protocol Software On A Conventional Processor.
INTRODUCTION COMPUTATIONAL MODELS. 2 What is Computer Science Sciences deal with building and studying models of real world objects /systems. What is.
CS 584. A Parallel Programming Model We need abstractions to make it simple. The programming model needs to fit our parallel machine model. Abstractions.
Using a CSP based Programming Model for Reconfigurable Processor Arrays By: Zain-ul-Abdin
Concurrency CS 510: Programming Languages David Walker.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
Why Behavioral Wait statement Signal Timing Examples of Behavioral Descriptions –ROM.
Learning Objectives Understanding the difference between processes and threads. Understanding process migration and load distribution. Understanding Process.
3.5 Interprocess Communication
Chapter 11: Distributed Processing Parallel programming Principles of parallel programming languages Concurrent execution –Programming constructs –Guarded.
CS533 - Concepts of Operating Systems
1 Ivan Lanese Computer Science Department University of Bologna Italy Concurrent and located synchronizations in π-calculus.
1 Concurrency: Deadlock and Starvation Chapter 6.
02/02/2004CSCI 315 Operating Systems Design1 Interprocesses Communication Notice: The slides for this lecture have been largely based on those accompanying.
Asynchronous Message Passing EE 524/CS 561 Wanliang Ma 03/08/2000.
1 Organization of Programming Languages-Cheng (Fall 2004) Concurrency u A PROCESS or THREAD:is a potentially-active execution context. Classic von Neumann.
 Parallel Computer Architecture Taylor Hearn, Fabrice Bokanya, Beenish Zafar, Mathew Simon, Tong Chen.
Software Issues Derived from Dr. Fawcett’s Slides Phil Pratt-Szeliga Fall 2009.
.NET Mobile Application Development Remote Procedure Call.
Chapter 4.1 Interprocess Communication And Coordination By Shruti Poundarik.
Client Server Model and Software Design TCP/IP allows a programmer to establish communication between two application and to pass data back and forth.
How do you simplify? Simple Complicated.
Copyright © 2003 ProsoftTraining. All rights reserved. Sun Certified Java Programmer Exam Preparation Guide.
Concurrency: Deadlock and Starvation Chapter 6. Goal and approach Deadlock and starvation Underlying principles Solutions? –Prevention –Detection –Avoidance.
1 Concurrency: Deadlock and Starvation Chapter 6.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Parallel & Concurrent Programming: Occam Vitaliy Lvin University of Massachusetts.
A Bridge to Your First Computer Science Course Prof. H.E. Dunsmore Concurrent Programming Threads Synchronization.
General What is an OS? What do you get when you buy an OS? What does the OS do? What are the parts of an OS? What is the kernel? What is a device.
1 Robot Networking Greg McChesney Texas Tech University Apr 21, 2009 CS5331: Autonomous Mobile Robots.
DEVS Namespace for Interoperable DEVS/SOA
CSE 260 – Parallel Processing UCSD Fall 2006 A Performance Characterization of UPC Presented by – Anup Tapadia Fallon Chen.
HCL and ALU תרגול 10. Overview of Logic Design Fundamental Hardware Requirements – Communication: How to get values from one place to another – Computation.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
1 Advanced Behavioral Model Part 1: Processes and Threads Part 2: Time and Space Chapter22~23 Speaker: 陳 奕 全 Real-time and Embedded System Lab 10 Oct.
4. Computer Maths and Logic 4.2 Boolean Logic Logic Circuits.
Internet Security CSCE 813 Communicating Sequential Processes.
Parallel execution Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Model 3: Message-Passing Text We saw –Diagrams –Shared-variables text Now –Message-passing text (like CSP)
A Concurrent Matrix Transpose Algorithm, The Implementation Presentedby Pourya Jafari.
Lecture 4 Introduction to Promela. Promela and Spin Promela - process meta language G. Holzmann, Bell Labs (Lucent) C-like language + concurrency dyamic.
Secure Composition of Untrusted Code: Wrappers and Causality Types Kyle Taylor.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
MSE Presentation 3 By Lakshmikanth Ganti Under the Guidance of Dr. Virgil Wallentine – Major Professor Dr. Paul Smith – Committee Member Dr. Mitch Neilsen.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Computer Science and Engineering Parallel and Distributed Processing CSE 8380 April 28, 2005 Session 29.
JCSP Tutorial & Homework Hints
03 – Remote invoaction Request-reply RPC RMI Coulouris 5
G.Anuradha Reference: William Stallings
Parallel Programming By J. H. Wang May 2, 2017.
About the Presentations
Some occam- Basics Co631 (Concurrency)
CSCI1600: Embedded and Real Time Software
Object Oriented Programming
Concurrency: Mutual Exclusion and Process Synchronization
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
Teach Parallelism Using Video Games
Presentation transcript:

Programming in Occam-pi: A Tutorial By: Zain-ul-Abdin

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 2 Outline Occam-pi basics –Networks and communication –Types, channels, processes... –Primitive Processes –Structured Processes –Examples: Integration, Matrix Multiplication Mobility –Mobile Semantics –Mobile Assignment –Mobile Communication –FORKing Processes –Example: Dynamic Process Creation

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 3 CSP CSP deals with processes, networks of processes and various forms of synchronisation / communication between processes. A network of processes is also a process - so CSP naturally accommodates layered network structures (networks of networks).

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 4 Occam-pi Introduction Named after Occam Razor ”If you have two equally likely solutions to a problem, choose the simplest” Combines the concepts of CSP with pi-calculus Parallel processing language that simplifies the description of systems Allows composing simple components to build complex systems Semantics [A+B] = Semantics [A] + Semantics [B] Built in semantics for concurrency –Processes –Channels (Unbuffered message passing)

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 5 Processes A process is a component that encapsulates some data structures and algorithms for manipulating that data. Both its data and algorithms are private. The outside world can neither see that data nor execute those algorithms! [It is not an object.] The algorithms are executed by the process in its own thread (or threads) of control. So, how does one process interact with another? myProcess

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 6 Processes The simplest form of interaction is synchronised message-passing along channels. The simplest forms of channel are zero-buffered and point-to-point (i.e. wires). myProcess

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 7 Synchronized Communication Output value down the channel out This operation does not complete until the process at the other end of the channel inputs the information Until that happens, the outputting process waits out ! value

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 8 Synchronized Communication- cont’d Input the next piece of information from channel in into the variable x This operation does not complete until the process at the other end of the channel outputs the information Until that happens, the inputting process waits in ? x

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 9 Synchronized Communication- cont’d A may write on c at any time, but has to wait for a read. B may read from c at any time, but has to wait for a write. c A A B B c ! x x c ? y y

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 10 Types Primitive types –INT, BYTE, BOOL –INT16, INT32, INT64 –REAL32, REAL64 Arrays types (indexed from 0) –[100]INT –[32][32][8]BYTE –[50]REAL64

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 11 Operators +, -, *, /, \ PLUS, MINUS, TIMES +, -, *, /, \ =, > =, <> /\(and), \/(or), > >(rshift), <<(lshift) ~ (not) INTxx, INTxx → INTxx BYTE, BYTE → BYTE REALxx, REALxx → REALxx INTxx, INTxx → BOOL BYTE, BYTE → BOOL REALxx, REALxx → BOOL *, * → BOOL INTxx, INTxx → INTxx BYTE, BYTE → BYTE INTxx → INTxx BYTE → BYTE Precision must be matched Types must match

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 12 Expressions No auto-coercion happens between types: if x is a REAL32 and i is an INT, then x + i is illegal... Where necessary, explicit casting between types must be programmed: e.g. x + (REAL32 i)... No precedence is defined between operators, we must use brackets: e.g. a + (b*c)... The operators +, -, * and / trigger run-time errors if their results overflow.

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 13 Declarations All declarations end in a colon A declaration cannot be used before it is made... Declarations are aligned at the same level of indentation... Variable declarations Channel declarations INT a, b: [max]INT c: [max]BYTE d: CHAN BYTE p: [max<<2]CHAN INT q:

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 14 An Occam-pi Process Syntactically, an occam-pi process consists of: –an optional sequence of declarations (e.g. values, variables, channels) –a single executable process All the declarations – and the executable – are aligned at the same level of indentation. The executable process is either primitive or structured.

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 15 Process Abstractions PROC foo (VAL []BYTE s, VAL BOOL mode, INT result, CHAN INT in?, out!, CHAN BYTE pause?)... : foo(s, mode, result) pauseout in

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 16 Primitive Processes Assignment a := c[2] + b Input (synchronising) in ? a Output (synchronising) out ! a + (2*b) Null (do nothing) SKIP Timer (increments every millisec.) TIMER tim

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 17 Structured Processes- SEQ and PAR SEQ in ? sum in ? x sum := sum + x out ! Sum PAR in0 ? a in1 ? b out ! a + b c := a + (2*b) Processes can run in any order, No data race hazards

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 18 Structured Processes- IF and WHILE IF x > 0 screen ! 'p‘ x < 0 screen ! 'n' TRUE screen ! 'z' WHILE TRUE INT x: SEQ in ? x out ! 2*x

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 19 Structured Processes- PROC instance PROC octople (CHAN INT in?, out!) CHAN INT a, b: PAR double (in?, a!) double (a?, b!) double (b?, out!) :

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 20 Example - Integrate PROC integrate (CHAN INT in?, out!) INT total: SEQ total := 0 WHILE TRUE INT x: SEQ in ? x total := total + x out ! total : Sequential implementation

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 21 Example - Integrate PROC integrate (CHAN INT in?, out!) CHAN INT a, b, c: PAR delta (a?, out!, b!) prefix (0, b?, c!) plus (in?, c?, a!) : Parallel implementation

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 22 Example – Matrix Multiplication

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 23 Tool Set KROC- Kent Retargetable Occam Compiler

Mobility in occam-pi

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 25 Copy Semantics Classical occam: data is copied from the workspace of A into the workspace of B. Subsequent work by A on its x variable and B on its y variable causes no mutual interference. c A A B B c ! x x c ? y y SAFE but SLOW

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 26 Copy Assignment As assignment changes the state of its environment, which we can represent by a set of ordered pairs mapping variables into data values. In occam, because of its zero-tolerance of aliasing, assignment semantics is what we expect: [In all other languages with assignment, the semantics are much more complex - since the variable x0 may be aliased to other variables … and the values associated with those aliases will also have changed to v.] {,, … } x0 := x1 {,, … }

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 27 Reference Semantics Java/JCSP: references to data (objects) are copied from the workspace of A into B. Subsequent work by A on its x variable and B on its y variable causes mutual interference (race hazard). c A A B B c ! x x c ? y y UNSAFE but FAST

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 28 Reference Semantics c A A B B xy c ! xc ? y HEAP before

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 29 Reference Semantics c A A B B xy c ! xc ? y HEAP after

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 30 Movement Semantics Consider copy and move operations on files … copy duplicates the file, placing the copy in the target directory under a (possibly) new name. move moves the file to the target directory, possibly renaming it: –the original file can no longer be found at the source address; –it has moved.

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 31 Mobile Assignment Mobile semantics differs in one crucial respect: The value of the variable at the source of the assignment has become undefined - its value has moved to the target variable. It must be noted: mobile semantics is strictly weaker than copy semantics. {,, … } x0 := x1 {,, … }

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 32 Mobile Communication The semantics for assignment and communication are directly related. In occam, communication is just a distributed form of assignment - a value computed in the sending process is assigned to a variable in the receiving one (after the two processes have synchronised). For example, if x0 and x1 were of type FOO, we have the semantic equivalence: x0 := x1 CHAN OF FOO c: PAR c ! x1 c ? x0 equals

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 33 Mobile data Syntax Occam-pi has a new keyword – a MOBILE qualifier for data types/variables The MOBILE qualifier doesn’t change the semantics of types as types. For example, MOBILE types are compatible with ordinary types in expressions. But it imposes the mobile semantics on assignment and communication between MOBILE variables. The MOBILE qualifier need not be burnt into the type declaration - it can be associated just with particular variables. MOBILE INT x0, x1:

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 34 Mobile data – cont’d Mobiles are safe references Assignment and communication with reference semantics Only one process may hold a given mobile

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 35 Mobile Channel Type In occam programs, channels are fixed in place at compile time What if we want to reconnect the process network at runtime? A channel type is a bundle of one or more related channels: for example, the set of channels connecting a client and a server Note this has to be a CHAN TYPE, else you can’t put channels in it Channel direction specifiers are mandatory

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 36 Mobile Channel Bundles Defined as ‘client’ and ‘server’ ends of a “mobile channel-type”, e.g.: Directions specified in the type are server-relative –Channel ends inside channel type ends can be used like regular channels CHAN TYPE INT.IO MOBILE RECORD CHAN INT in?: CHAN INT out!: : INT.IO! cli: SEQ cli[in] ! 42 cli[out] ? r INT.IO? svr: SEQ svr[in] ? x svr[out] ! x+1

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 37 Communicating Mobile Channels The main use of mobile channel bundles is to support the run-time reconfiguration of process networks P and Q are now directly connected Process networks may be arbitrarily reconfigured using mobile channels –dynamic process creation makes this much more interesting c ? a d ? b Generator P Q c d a b

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 38 Dynamic Process Creation N-replicated PAR, where the replicator count is a constant The creating process has to wait for them all to terminate before creating process has to wait for them all to terminate before it can do anything else. VAL N IS 10: SEQ PAR i = 1 FOR N...

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 39 Dynamic Process Creation Asynchronous process invocation using FORK Essentially a procedure instance that runs in parallel with the invoking process Parameter passing is strictly uni-directional and uses a communication semantics occam-pi introduces two new keywords – FORKING and FORK Inside a FORKING block, you can use FORK at any time to spawn a new process When the FORKING block exits, it’ll wait for all the spawned processes to finish

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 40 Dynamic Process Creation PROC A ()... local state SEQ FORKING SEQ FORK P(n, svr, cli)... : VAL data is copied into a FORKed process MOBILE data and channel-ends are moved into a FORKed process

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 41 Client-Server Application CS response request P

"Programming in Occam-pi: A Tutorial", Zain-ul-Abdin 42 Client-Server Application Fault-tolerance by Replication CS response request P BS