Parallel Programming Concepts. Theory of Concurrency - Multicomputer. Peter Tröger

Similar documents
Parallel Programming Concepts. Theory of Concurrency - Multicomputer. Peter Tröger

Parallel Programming Concepts. Shared Nothing Parallelism - Theory. Dr. Peter Tröger M.Sc. Frank Feinbube

Section 13: CSP to OCCAM. Evolution of Software Languages

Shared-Memory Concurrency

Com S 541. Programming Languages I

Inter-process communication (IPC)

EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization

Reminder from last time

Process Management And Synchronization

Message Passing Part I

Performance Throughput Utilization of system resources

CS3502 OPERATING SYSTEMS

Introduction to Linear-Time Temporal Logic. CSE 814 Introduction to LTL

Concurrency: what, why, how

Top500 Supercomputer list

Shared-Memory Concurrency Programmierung Paralleler und Verteilter Systeme (PPV)

Ch 9: Control flow. Sequencers. Jumps. Jumps

Concurrent Models of Computation

Verification Finite-state process modeling and reachability analysis

MODEL BASED TEST DESIGN AT UNITY

Embedded Systems 7. Models of computation for embedded systems

CONCURRENT/DISTRIBUTED PROGRAMMING ILLUSTRATED USING THE DINING PHILOSOPHERS PROBLEM *

Verification of Java programs using networks of finite automata with discrete data.

Welcome to. Instructor Marc Pomplun CS 470/670. Introduction to Artificial Intelligence 1/26/2016. Spring Selectivity in Complex Scenes

Functional Programming. Big Picture. Design of Programming Languages

Hardware Description Languages & System Description Languages Properties

Concurrent Programming (RIO) Lesson 9. Ch 8 [BenA 06] Messages Channels Rendezvous RPC and RMI. X=f(..); send X to B. OS kernel.

Chapter 13 Topics. Introduction. Introduction

Fundamental Algorithms for System Modeling, Analysis, and Optimization

Concurrency Control in Distributed Environment

Parallel Computing. Slides credit: M. Quinn book (chapter 3 slides), A Grama book (chapter 3 slides)

UNIT 3

Petri Nets ~------~ R-ES-O---N-A-N-C-E-I--se-p-te-m--be-r Applications.

CPEG 852 Advanced Topics in Computing Systems The Dataflow Model of Computation

First-Class Synchronization Barriers. Franklyn Turbak Wellesley College

Process Modelling. Fault Tolerant Systems Research Group. Budapest University of Technology and Economics

Concurrency: what, why, how

CSE Traditional Operating Systems deal with typical system software designed to be:

Parallel Programming Concepts. Introduction. Peter Tröger

Chapter 13. Concurrency ISBN

Specifications and Modeling

Processor speed. Concurrency Structure and Interpretation of Computer Programs. Multiple processors. Processor speed. Mike Phillips <mpp>

Chapter Machine instruction level 2. High-level language statement level 3. Unit level 4. Program level

Hardware Description Languages & System Description Languages Properties

Interprocess Communication By: Kaushik Vaghani

Parallel programming models. Main weapons

Dining Philosophers with π-calculus

COMP 150-CCP Concurrent Programming. Lecture 12: Deadlock. Dr. Richard S. Hall

Programming Languages

Interactions A link message

Verifying Concurrent ML programs

Software Architecture

THE QUEEN S UNIVERSITY OF BELFAST

Contribution:javaMultithreading Multithreading Prof. Dr. Ralf Lämmel Universität Koblenz-Landau Software Languages Team

Lecture 3: Intro to Concurrent Processing using Semaphores

G Programming Languages - Fall 2012

Lecture Topics. Announcements. Today: Concurrency (Stallings, chapter , 5.7) Next: Exam #1. Self-Study Exercise #5. Project #3 (due 9/28)

Deterministic Concurrency

Chapter 9. Labelled Transition Systems. System Composition. specifications. implementations.

Dealing with Issues for Interprocess Communication

Deadlocks. Deadlock in Resource Sharing Environment. CIT 595 Spring Recap Example. Representing Deadlock

FSMs & message passing: SDL

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

Paradigms of computer programming

The learning objectives of this chapter are the followings. At the end of this chapter, you shall

fakultät für informatik informatik 12 technische universität dortmund Specifications Peter Marwedel TU Dortmund, Informatik /11/15

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Processes and Threads

CS 242. Fundamentals. Reading: See last slide

Deadlock. Concepts: Models: Practice: Aim: deadlock avoidance - to design systems where deadlock cannot occur. Chapter 6. Deadlock

The Problem with Threads

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA

Distributed Systems Programming (F21DS1) Formal Verification

CPS 506 Comparative Programming Languages. Programming Language Paradigms

Parallel Programming Concepts. Parallel Algorithms. Peter Tröger

Overview. Background: Efforts Prior to EduPar 11. EduPar 11 Outcome (I): Required Core Modules. EduPar 11 Outcome (II): Advanced/Elective Modules

Concurrency. Lecture 14: Concurrency & exceptions. Why concurrent subprograms? Processes and threads. Design Issues for Concurrency.

Unified Modeling Language

Executive Summary. It is important for a Java Programmer to understand the power and limitations of concurrent programming in Java using threads.

Deadlock and Monitors. CS439: Principles of Computer Systems September 24, 2018

Lecture 2: Modeling Introduction

Parallel Programming Concepts. Summary. Dr. Peter Tröger M.Sc. Frank Feinbube

Synchronization. Silvina Hanono Wachman Computer Science & Artificial Intelligence Lab M.I.T.

A Theory of Parallel Computation The π-calculus

Chapter 7 Control I Expressions and Statements

Concurrent ML. John Reppy January 21, University of Chicago

Cover Page. The handle holds various files of this Leiden University dissertation

Shared-Memory Programming Models

The S-Expression Design Language (SEDL) James C. Corbett. September 1, Introduction. 2 Origins of SEDL 2. 3 The Language SEDL 2.

Course Modelling of Concurrent Systems Summer Semester 2016 University of Duisburg-Essen

Software Specification 2IX20

Control Abstraction. Hwansoo Han

Synchronization problems with semaphores

Organization of Programming Languages CS3200/5200N. Lecture 11

Specifications and Modeling

The Dining Philosophers Problem CMSC 330: Organization of Programming Languages

Course Modelling of Concurrent Systems Summer Semester 2016 University of Duisburg-Essen

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

Concurrency: Deadlock 1. Magee/Kramer 2 nd Edition

Advances in Programming Languages

Transcription:

Parallel Programming Concepts Theory of Concurrency - Multicomputer Peter Tröger

Von Neumann Model Process Processor Pipelining Super-scalar VLIW Branch prediction... Process Processor Processor Processor Memory Processor executes a sequence of instructions, which specify Arithmetic operation Memory to be read / written Address of next instruction Software layering tackles complexity of instruction stream Parallelism adds coordination problem between multiple instruction streams being executed ParProg Theory 2 PT 2010

Terminology Concurrency Supported to have two or more actions in progress at the same time Classical operating system responsibility (resource sharing for better utilization of CPU, memory, network,...) Demands scheduling and synchronization Parallelism Supported to have two or more actions executing simultaneously Demands parallel hardware, concurrency support, (and communication) Programming model relates to chosen hardware / communication approach Examples: Windows 3.1, threads, signal handlers, shared memory ParProg Theory 3 PT 2010

History 1963: Co-Routines concept by Melvin Conway Foundation for message-based concurrency concepts Late 1970 s Parallel computing moved from shared memory towards multicomputers Dijkstra / Hoare / Hansen worked on different according abstractions 1975, Concept of recursive non-deterministic processes by Dijkstra Generator concept, foundation for Hoare s work on Communicating Sequential Processes (CSP) 1978, Distributed Processes: A Concurrent Programming Concept, B. Hansen Synchronized procedure called by one process and executed by another Foundation for RPC variations in Ada and other languages ParProg Theory 4 PT 2010

Co-Routines Conway, Melvin E. (1963). "Design of a Separable Transition-Diagram Compiler". Communications of the ACM (New York, NY, USA: ACM) 6 (7): 396 408. doi:10.1145/366663.366704. Routines can suspend (yield) and resume in their execution Co-routines that always yield new results are also called generators Good for concurrent, not for parallel programming Foundation for theoretical and practical message passing concepts var q := new queue coroutine produce loop while q is not full create some new items add the items to q yield to consume coroutine consume loop while q is not empty remove some items from q use the items yield to produce Broad language support today ParProg Theory 5 PT 2010

Co-Routines Explicit language primitive to indicate transfer of control flow - resume primitive Example: Chess game - classical approach demands master procedure detach primitive: Return to control point that initially activated the co-routine Co-routines allow caller / callee model to be expressed in code coroutine PLAYER1; initialize local variables detach while TRUE do make a move if game won then print message detach else resume(player2) coroutine PLAYER2; initialize local variables detach while TRUE do make a move if game won then print message detach else resume(player1) ParProg Theory 6 PT 2010

Communicating Sequential Processes Developed by Tony Hoare at University of Oxford from 1977 Formal process algebra to describe concurrent systems Book: T. Hoare, Communicating Sequential Processes, 1985 Basic idea Computer systems act and interact with the environment continuously Decomposition in subsystems (processes) which operate concurrently Interact with other processes - subsystems or the environment Modular approach Based on mathematical theory, described with algebraic laws Direct mapping to Occam programming language 7

CSP: Processes Behavior of real-world objects can be described through their interaction with other objects, leaving out internal implementation details Interface of a process is described as set of atomic events Event examples for an ATM: card insertion of a credit card in an ATM card slot money extraction of money from the ATM dispenser Alphabet - set of relevant (!) events for the description of an object Event may never happen in the interaction Interaction is restricted to this set of events αatm = {card, money} A CSP process is the behavior of an object, described with its alphabet 8

CSP: Processes Event is an atomic action without duration Time is expressed with start/stop events, can overlap Timing of events is not relevant for logical correctness, but ordering Makes reasoning independent of execution speed and performance No concept of simultaneous events May be represented as single event, if synchronization is modeled STOPA Process with alphabet A which never engages in any of the events of A Expresses a non-working part of the system 9

CSP: Process Description through Prefix Notation (x -> P) x then P x: event, P: process Behavioral description of an object which first engages in x and than behaves as described with P Prefix expression itself is a process (== behavior), chainable approach α(x -> P) = αp - Processes must have the same alphabet Example 1: (card -> STOPαATM) ATM which takes a credit card before breaking Quiz: ATM which serves one customer and breaks while serving the second customer - αatmq={card, money} 10

CSP: Recursion Prefix notation may lead to long chains of repetitive behavior for the complete lifetime of the object (until STOP) Solution: Self-referential recursive definition for the object Example: An everlasting clock object αclock = {tick} CLOCK = (tick -> CLOCK) Enables description of an object with one single stream of behavior through prefixing and recursion 11

CSP Process Description - Choice Object behavior may be influenced by the environment Support for multiple behavior streams triggered by the environment Externally-triggered choice between two ore more events, leads to different subsequent behavior (== processes), forms a process by itself (x -> P y -> Q) Example: Vending machine offers choice of slots for 1 coin or 2 coin VM = ( in1eur -> (cookie -> VM) in2eur -> (cake -> VM) crowncap -> STOP) is an operator on prefix expression, not on the processes itself 12

Process Description: Pictures VM = in1eur crowncap in2eur ( in1eur -> (cookie -> VM) in2eur -> (cake -> VM) cookie cake crowncap -> STOP) Single processes as circles, events as arrows Pictures may lead to problems - difficult to express equality, hard with large or infinite number of behaviors 13

Concurrency in CSP Process = Description of possible behavior Set of occurring events depends on the environment, which may also be described as a process Allows to investigate a complete system, were the description is again a process Formal modelling of interacting processes Formulate events that trigger simultaneous participation of multiple processes Parallel combination: Process which describes a system composed of the processes P and Q: P Q α(p Q) = αp U αq Interleaving: Parallel activity with different events 14

Graphical Representation a P b b Q d c c b a P ( P Q ) Q d c 15

Communication in CSP Special class of event: communication Modeled as uni-directional channel, only between two processes Channel name is a member of the alphabets of both processes Described by the events c.v which are part of the processes alphabet c: name of a channel on which communication takes place v: value of the message being passed Set of all messages which P can communicate on channel c: α c(p) = {v c.v ε αp} channel(c.v) = c, message(c.v) = v Input choice: ( c?x -> P(x) d?y -> Q(y) ) 16

Communication (contd.) Process which first outputs v on the channel c and then behaves like P: (c!v -> P) = (c.v -> P) Process which is initially prepared to input any value x from the channel c and then behave like P(x): (c?x -> P(x)) = (y: {y channel(y) = c} -> P(message(y))) input channel P output channel 17

Communication (contd.) Channel approach assumes rendezvous behavior Sender and receiver block on the channel operation until the message was transmitted Meanwhile common concept in messaging-based concurrency approaches When two concurrent processes communicate with each other only over a single channel, they cannot deadlock (see book) Network of non-stopping processes which is free of cycles cannot deadlock Acyclic graph can be decomposed into subgraphs connected only by a single arrow Pipes: Processes with only one input and one output channel Join of two pipes P and Q : P>>Q 18

The Dining Philosophers (E.W.Dijkstra) Five philosophers work in a college, each philosopher has a room for thinking Common dining room, furnished with a circular table, surrounded by five labeled chairs In the center stood a large bowl of spaghetti, which was constantly replenished When a philosopher gets hungry: Sits on his chair Picks up his own fork on the left and plunges it in the spaghetti, then picks up the right fork When finished he put down both forks and gets up May wait for the availability of the second fork 19

Mathematical Model Philosophers: PHIL 0 PHIL 4 αphil i = { i.sits down, i.gets up, i.picks up fork.i, i.picks up fork.(i 1), i.puts down fork.i, i.puts down fork.(i 1) } : Addition modulo 5 == i 1 is the right-hand neighbor of PHILi Alphabets of the philosophers are mutually disjoint, no interaction between them αfork i = { i.picks up fork.i, (iθ1).picks up fork.i, i.puts down fork.i, (iθ1).puts down fork.i } 20

21

Behavior of the Philosophers PHIL i = ( i.sits down -> i.picks up fork.i -> i.picks up fork.(i 1) -> i.puts down fork.i -> i.puts down fork.(i 1) -> i.gets up -> PHIL i ) FORK i = ( i.picks up fork.i -> i.puts down fork.i -> FORK i (iθ1).picks up fork.i -> (iθ1).puts down fork.i -> FORK i ) PHILOS=(PHIL 0 PHIL 1 PHIL 2 PHIL 3 PHIL 4 ) FORKS=(FORK 0 FORK 1 FORK 2 FORK 3 FORK 4 ) COLLEGE=(PHILOS FORKS) We leave out the proof here ;-)... 22

What s the Deal? Any possible system can be modeled through event chains Enables mathematical proofs for deadlock freedom, based on the basic assumptions of the formalism (e.g. channel assumption) Some tools available (look at the CSP archive) CSP was the formal base for the Occam language Language constructs follow the formalism, to keep proven properties Mathematical reasoning about behavior of written code Still active research topics, channel concept adopted at several places CSP channel implementation for Java, MPI design Other formalism, e.g. Task / Channel model ParProg Theory 23 PT 2010

Occam Example PROC producer (CHAN INT out!) INT x: SEQ x := 0 WHILE TRUE SEQ out! x x := x + 1 : PROC consumer (CHAN INT in?) WHILE TRUE INT v: SEQ in? v.. do something with `v' : PROC network () CHAN INT c: PAR producer (c!) consumer (c?) : ParProg Theory 24 PT 2010

Task-Channel Model [Foster] Computational model for multi-computer case Parallel computation consists of one or more tasks Tasks execute concurrently Number of tasks can vary during execution Task encapsulates sequential program with local memory A task has in-ports and outports as interface to the environment Basic actions: read / write local memory, send message on outport, receive message on inport, create new task, terminate Process Process Process Process Process Node Network ParProg Theory 25 PT 2010

Task-Channel Model [Foster] Outport / in-port pairs are connect by message queues called channels Channels can be created and deleted Channels can be referenced as ports, which can be part of a message Send operation is asynchronous Receive operation is synchronous Messages in a channel stay in order Tasks are mapped to physical processors Multiple tasks can be mapped to one processor Data locality is explicit part of the model Channels can model control and data dependencies ParProg Theory 26 PT 2010

Task-Channel Model [Foster] Effects from channel-only interaction model Performance optimization does not influence semantics Example: Shared-memory channels for multiple tasks on one machine Task mapping does not influence semantics Align number of tasks to problem, not to execution environment Improves scalability of implementation Modular design with well-defined interfaces Determinism made easy Verify that each channel has a single sender and receiver ParProg Theory 27 PT 2010

Task-Channel Model [Foster] Model results in some algorithmic style Task graph algorithms, data-parallel algorithms, master-slave algorithms Theoretical performance assessment Execution time: Period of time where at least one task is active Number of communications / messages per task Rules of thumb Communication operations should be balanced between tasks Each task should only communicate with a small group of neighbors Task should perform computations concurrently (task parallelism) Task should perform communication concurrently ParProg Theory 28 PT 2010

Actor Model Carl Hewitt, Peter Bishop and Richard Steiger. A Universal Modular Actor Formalism for Artificial Intelligence IJCAI 1973. Another mathematical model for concurrent computation No global system state concept (relationship to physics) Actor as computation primitive, which can make local decisions, concurrently creates more actors, or concurrently sends / receives messages Asynchronous one-way messaging with changing topology (CSP communication graph is fixed), no order guarantees CSP relies on hierarchy of combined parallel processes, while actors rely only on message passing paradigm only Recipient is identified by mailing address, can be part of a message Everything is an actor ParProg Theory 29 PT 2010

Actor Model Influenced the development of the Pi-Calculus Serves as theoretical base to reason about concurrency, and as underlying theory for some programming languages (Erlang, Scala) Influences by Lisp, Simula, and Smalltalk Behavior as mathematical function - describes activity on message processing ParProg Theory 30 PT 2010

Other Formalisms Lambda calculus by Alonzo Church (1930s) Concept of procedural abstraction, originally via variable substitution Functions as first-class citizen Inspiration for concurrency through functional programming languages Petri Nets by Carl Adam Petri (since 1960s) Mathematical model for concurrent systems Directed bipartite graph with places and transitions Huge vibrant research community Process algebra, trace theory,... ParProg Theory 31 PT 2010