TUTORIAL 1 Parallel Processing
Q.1.Write a program for creating a child process using fork()
command.
PROGRAM:-
#include<stdio.h>
int
main()
{
int id;
id=fork();
printf("ID:%d\n",id);
}
OUTPUT:-
[08ce55@linux ~]$ ./a.out
ID:0
ID:6057
Q.2.Explain concept of parallel programming.
A parallel
programming model is a concept that enables the expression of parallel
programs which can be compiled and executed. The value of a programming model
is usually judged on its generality: how well a range of different problems can
be expressed and how well they execute on a range of different architectures.
The implementation of a programming model can take several forms such as
libraries invoked from traditional sequential languages, language extensions,
or complete new execution models.
Consensus on a
particular programming model is important as it enables software expressed
within it to be transportable between different architectures. The von Neumann
model has facilitated this with sequential architectures as it
provides an efficient bridge
between hardware and software, meaning that high-level languages can be
efficiently compiled to it and it can be efficiently implemented in hardware.
Main classifications and paradigms
Classifications of parallel programming models can be
divided broadly into two areas: process interaction and problem decomposition.
Process interaction
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.
Shared memory
Main article: Shared
memory
In a shared memory 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. Shared memory can be emulated on distributed-memory systems
but non-uniform memory access (NUMA) times can come in to play.
Message passing
Main article: Message
passing
In a message passing model, parallel tasks exchange data
through passing messages to one another. These communications can be
asynchronous or synchronous. The Communicating Sequential Processes (CSP)
formalisation of message-passing employed communication channels to 'connect'
processes, and led to a number of important languages such as Joyce, occam and
Erlang.
Implicit
Main article: Implicit parallelism
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.
Problem decomposition
Any parallel program is composed of simultaneously executing
processes, problem decomposition relates to the way in which these processes
are formulated. This classification may also be referred to as algorithmic skeletons or parallel programming paradigms.
Task parallelism
Main article: Task
parallelism
A task-parallel model focuses on processes, or threads of
execution. These processes will often be behaviourally distinct, which
emphasises the need for communication. Task parallelism is a natural way to
express message-passing communication. It is usually classified as MIMD/MPMD or
MISD.
Data parallelism
Main article: Data
parallelism
A 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. Data parallelism
is usually classified as SIMD/SPMD.