IT105 Midterm Lecture Part1
IT105 Midterm Lecture Part1
In Computer Science, a Parallel Programming Model is a model for writing parallel programs which can be compiled and
executed //en.wikipedia.org//
Parallel programming model is a set of software technologies to express parallel algorithms and match applications with
underlying parallel systems.
Classifications of parallel programming models can be divided broadly into two areas: process interaction and problem
decomposition.
A. Process interaction relates to the mechanisms by which parallel processes are able to communicate with each
other. The most common forms of interaction are shared memory and message passing, but it can also be
implicit.
1. Shared memory is an efficient means of passing data between programs. Depending on context, programs
may run on a single processor or on multiple separate processors.
In this model, parallel tasks share a global address space which they read and write to
asynchronously.
This requires protection mechanisms such as locks, semaphores and monitors to control concurrent
access.
An advantage of this model from the programmer's point of view is that the notion of data
"ownership" is lacking, so there is no need to specify explicitly the communication of data between
tasks. Program development can often be simplified.
An important disadvantage in terms of performance is that it becomes more difficult to understand
and manage data locality:
o Keeping data local to the processor that works on it conserves memory accesses, cache
refreshes and bus traffic that occurs when multiple processors use the same data.
o Unfortunately, controlling data locality is hard to understand and may be beyond the
control of the average user.
2. Message passing is a concept from computer science that is used extensively in the design and
implementation of modern software applications; it is key to some models of concurrency and object-
oriented programming.
In a message passing model, parallel tasks exchange data through passing messages to one another.
These communications can be asynchronous or synchronous.
This model demonstrates the following characteristics:
o A set of tasks that use their own local memory
during computation. Multiple tasks can reside on the
same physical machine and/or across an arbitrary
number of machines.
o Tasks exchange data through communications by
sending and receiving messages.
o Data transfer usually requires cooperative
operations to be performed by each process. For
example, a send operation must have a matching
receive operation.
3. Implicit Model - In an implicit model, no process interaction is visible to the programmer, instead the
compiler and/or runtime is responsible for performing it. This is most common with domain-specific
languages where the concurrency within a problem can be more prescribed.
Advantages
o A programmer that writes implicitly parallel code does not need to worry about task
division or process communication, focusing instead in the problem that his or her program
is intended to solve.
o Implicit parallelism generally facilitates the design of parallel programs and therefore results
in a substantial improvement of programmer productivity.
o Many of the constructs necessary to support this also add simplicity or clarity even in the
absence of actual parallelism. The example above, of List comprehension in the sin()
function, is a useful feature in of itself.
o By using implicit parallelism, languages effectively have to provide such useful constructs to
users simply to support required functionality (a language without a decent for() loop, for
example, is one few programmers will use).
Disadvantages
o Languages with implicit parallelism reduce the control that the programmer has over the
parallel execution of the program, resulting sometimes in less-than-optimal parallel
efficiency.
o A larger issue is that every program has some parallel and some serial logic. Binary I/O, for
example, requires support for such serial operations as Write() and Seek(). If implicit
parallelism is desired, this creates a new requirement for constructs and keywords to
support code that cannot be threaded or distributed.
2. Data-Parallel Model focuses on performing operations on a data set which is usually regularly
structured in an array. A set of tasks will operate on this data, but independently on separate partitions.
In a shared memory system, the data will be accessible to all, but in a distributed-memory system it will
divided between memories and worked on locally.
Hybrid Model
A simple parallel programming model. The figure shows both the instantaneous state of a computation and a detailed
picture of a single task. A computation consists of a set of tasks (represented by circles) connected by channels (arrows).
A task encapsulates a program and local memory and defines a set of ports that define its interface to its environment. A
channel is a message queue into which a sender can place messages and from which a receiver can remove messages,
``blocking'' if messages are not available.
We consider next the question of which abstractions are appropriate and useful in a parallel programming model. Clearly,
mechanisms are needed that allow explicit discussion about concurrency and locality and that facilitate development of
scalable and modular programs. Also needed are abstractions that are simple to work with and that match the
architectural model, the multicomputer. While numerous possible abstractions could be considered for this purpose, two
fit these requirements particularly well: the task and channel. These are illustrated below and can be summarized as
follows:
The four basic task actions. In addition to reading and writing local memory, a task can send a message, receive a
message, create new tasks (suspending until they terminate), and terminate.
1. A parallel computation consists of one or more tasks. Tasks execute concurrently. The number of tasks can vary
during program execution.
2. A task encapsulates a sequential program and local memory. (In effect, it is a virtual von Neumann machine.) In
addition, a set of inports and outports define its interface to its environment.
3. A task can perform four basic actions in addition to reading and writing its local memory : send messages on its
outports, receive messages on its inports, create new tasks, and terminate.
4. A send operation is asynchronous: it completes immediately. A receive operation is synchronous: it causes
execution of the task to block until a message is available.
5. Outport/inport pairs can be connected by message queues called channels. Channels can be created and
deleted, and references to channels (ports) can be included in messages, so connectivity can vary dynamically.
Consider the following real-world problem. A bridge is to be assembled from girders being constructed at a foundry.
These two activities are organized by providing trucks to transport girders from the foundry to the bridge site. This
situation is illustrated below (a) with the foundry and bridge represented as tasks and the stream of trucks as a channel.
Notice that this approach allows assembly of the bridge and construction of girders to proceed in parallel without any
explicit coordination: the foundry crew puts girders on trucks as they are produced, and the assembly crew adds girders
to the bridge as and when they arrive.
Two solutions to the bridge construction problem. Both represent the foundry and the bridge assembly site as separate
tasks, foundry and bridge. The first uses a single channel on which girders generated by foundry are transported as fast as
they are generated. If foundry generates girders faster than they are consumed by bridge, then girders accumulate at the
construction site. The second solution uses a second channel to pass flow control messages from bridge to foundry so as
to avoid overflow.
A disadvantage of this scheme is that the foundry may produce girders much faster than the assembly crew can use them.
To prevent the bridge site from overflowing with girders, the assembly crew instead can explicitly request more girders
when stocks run low.