HPC Unit 2 Parallel Programming
HPC Unit 2 Parallel Programming
“PARALLEL PROGRAMMING”
By
Prof. Anand N. Gharu
(Assistant Professor)
PVGCOE Computer Dept.
2. Decomposition Techniques
• Decomposition Techniques
– Recursive Decomposition
– Recursive Decomposition
– Exploratory Decomposition
– Hybrid Decomposition
n-1 Task n
Computation of each element of output vector y is independent of other elements. Based on this, a
dense matrix-vector product can be decomposed into n tasks. The figure highlights the portion of the
matrix and vector accessed by Task 1.
Observations: While tasks share data (namely, the vector b), they do not
have any control dependencies – i.e., no task needs to wait for the (partial)
completion of any other. All tasks are of the same size in terms of number
of operations. Is this the maximum number of tasks we could decompose
this problem into?
Example: Database
Query Processing
Consider the execution of the query:
MODEL = ‘‘CIVIC’’ AND YEAR = 2001 AND
(COLOR = ‘‘GREEN’’ OR COLOR = ‘‘WHITE)
ID# Color
3476 White
ID# Model Year 7623 Green
6734 Civic 2001 Civic AND 2001 White OR Green 9834 Green
4395 Civic 2001 6734 White
5342 Green
8354 Green
Decomposing the given query into a number of tasks. Edges in this graph
denote that the output of one task is needed to accomplish the next.
Example: Database Query Processing
Note that the same problem can be decomposed into subtasks in other ways as
well.
ID# Year
ID# Model ID# Color
7623 2001
4523 Civic 6734 2001 7623 Green
6734 Civic ID# Color 9834 Green
5342 2001
4395 Civic 3845 2001 3476 White 5342 Green
7352 Civic 4395 2001 6734 White 8354 Green
ID# Color
3476 White
White OR 7623 Green
Green 9834 Green
6734 White
5342 Green
8354 Green
Task 2
Task 3
Task 4
• Since the number of tasks that can be executed in parallel may change
over program execution, the maximum degree of concurrency is the
maximum number of such tasks at any point during execution. What is the
maximum degree of concurrency of the database query examples?
• The longest such path determines the shortest time in which the
program can be executed in parallel.
10 10 10 10 10 10 10 10
6 Task 5
9 Task 6 6 Task 5
11 Task 6
8 Task 7 7 Task 7
(a) (b)
What are the critical path lengths for the two task dependency graphs? If each
task takes 10 time units, what is the shortest parallel execution time for each
decomposition? How many processors are needed in each case to achieve this
minimum parallel execution time? What is the maximum degree of concurrency?
Task Dependency Graphs
Task Dependency Graphs
Task Dependency Graphs
Task Interaction Graphs
• Subtasks generally exchange data with others in a
decomposition. For example, even in the trivial decomposition
of the dense matrix-vector product, if the vector is not
replicated across all tasks, they will have to communicate
elements of the vector.
5
4
4 6
7
8
9
Task 11 8 10 11
(a) (b)
Processes and Mapping
• In general, the number of tasks in a decomposition exceeds the
number of processing elements available.
Note: These criteria often conflict with each other. For example, a
decomposition into one task (or no decomposition at all) minimizes
interaction but does not result in a speedup at all! Can you think of other
such conflicting cases?
Processes and Mapping: Example
Task 4 Task 3 Task 2 Task 1 Task 4 Task 3 Task 2 Task 1
10 10 10 10 10 10 10 10
P3 P2 P1 P0 P3 P2 P1 P0
P0 6 Task 5
P2 9 Task 6 P0 6 Task 5
P0 11 Task 6
P0 8 Task 7 P0 7 Task 7
(a) (b)
(a) (b)
Processes and Mapping: Example
(a) (b)
Decomposition Techniques
So how does one decompose a task into various subtasks?
While there is no single techniques that works for all problems,
we present a set of commonly used techniques that apply to broad
classes of problems. These include:
• recursive decomposition
• data decomposition
• exploratory decomposition
• speculative decomposition
Recursive Decomposition
• Generally suited to problems that are solved using the divide-
and-conquer strategy.
1 3 4 2 5 12 11 10 6 8 7 9
1 2 3 4 5 6 8 7 9 12 11 10
1 2 3 4 5 6 7 8 9 10 12 11
5 6 7 8 10 11 12
11 12
In this example, once the list has been partitioned around the pivot, each sublist can be
processed concurrently (i.e., each sublist represents an independent subtask). This can be
repeated recursively.
Data Decomposition
• Identify the data on which computations are performed.
. Σ . Σ . Σ
A 1 ,1 A 1 ,2 B 1 ,1 B 1 ,2 C 1 ,1 C 1 ,2
. →
A 2 , 1 A 2 ,2 B 2 , 1 B 2 ,2 C 2 , 1 C 2 ,2
1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4
5 6 8 5 6 7 8 5 6 7 8 5 6 7 8
9 10 7 11 9 10 11 9 10 11 9 10 11 12
13 14 15 12 13 14 15 12 13 14 15 12 13 14 15
1 2 3 4
5 6 7 8
9 1 1
0 15 121
13 14
1 2 3 4 1 23 4
task 4
5 6 7 8 5 67
9 10 9 10 11 8
11 15 12
13 14 13 14 15 12
1 2 3
4
5
9 6 7
8
of the current state and to view them as independent tasks.
13 14 15
10 11
12
1 2 3 4
5 6 7 8
9 1 1
0 15 121
13 14
1 2 3 4
5 6 7 8
1 2 3 4 9 10
5 6 7 8 1112
13 14 15
9 10 11
1 2 3 4
13 14 15 12
5 7 8
task 3
9 6 10
1112
13 14 15
1 2 3 4
1 2 3 4 5 6 7 8
9 14 10
5 6 7 8 1 11
3 15 12
9 10 11 1 2 3 4
5 6 8
13 14 15 12
9 1 7
0 151112
13 14
1 2 3 4
5 6 8
1 2 3 4 9 1 7 1
0 15 121
13 14
5 6 8
9 10 7 11
task 2
1 2 4
13 14 15 12
5 6 3 8
9 1 7 11
0 15 12
13 14
1 2 3 4
5 6 7 8
9 1 1
0 15 121
13 14
1 2 3
4
5
9 6 7
8
13 14 12
10 15
1 2 3 1 211 3 4
4
5 5 6 7 8
9 6 7
task 1
9 10 15
8 11
13 14 1 1
10 15 2 3 14 12
11 1 2 3 4
5 6 7 8
9 1 1
0 15 121
13 14
Speculative Decomposition
• In some applications, dependencies between tasks are not known
a-priori.
• Consider your day today as a discrete event system – you get up, get ready,
drive to work, work, eat lunch, work some more, drive back, eat dinner, and
sleep.
A D
System
Inputs
E G I
System
Output
B
F H
System Components
Characteristics of
Tasks & Interaction
Characteristics of Tasks
Once a problem has been decomposed into independent tasks, the
characteristics of these tasks critically impact choice and
performance of parallel algorithms. Relevant task characteristics
include:
• Task generation.
• Task sizes.
• Static interactions: The tasks and their interactions are known a-priori.
These are relatively simpler to code into programs.
P1 1 5 9 P1 1 2 3
P2 2 6 10 P2 4 5 6
P3 3 7 11 P3 7 8 9
P4 4 8 12 P4 10 11 12
(a (b)
)
Mapping Techniques for Minimum Idling
Mapping techniques can be static or dynamic.
Other factors that determine the choice of techniques include the size of
data associated with a task and the nature of underlying domain.
Schemes for Static Mapping
• Mappings based on data partitioning.
• Hybrid mappings.
Mappings Based on Data Partitioning
We can combine data partitioning with the “owner- computes” rule to
partition the computation into subtasks. The simplest data decomposition
schemes for dense matrices are 1-D block distribution schemes
.
row-wise distribution column-wise distribution
P8 P0
P9 P1
P 10 P2
P 11 P3
P0 P1 P2 P3 P4 P5 P6 P7
P 12 P4
P 13 P5
P 14
P6
P 15
P7
Block Array Distribution Schemes
Block distribution schemes can be generalized to higher
dimensions as well.
P0 P1 P2 P3
P0 P1 P2 P3 P4 P5 P6 P7
P4 P5 P6 P7
P8 P9 P10 P11
P8 P9 P10 P11 P12 P13 P14 P15
(a) (b)
Block Array Distribution Schemes: Examples
• For multiplying two dense matrices A and B, we can partition
the output matrix C using a block decomposition.
• For load balance, we give each task the same number of elements
of C. (Note that each element of C corresponds to a single dot
product.)
A B C
P0 P1 P2 P3
P4 P5 P6 P7
X =
P8 P9 P10 P 11
P 12 P13 P14 P 15
(b)
Graph Partitioning Dased Data Decomposition
• In case of sparse matrices, block decompositions are more complex.
Random Partitioning
P0 P1 P4 P5
P2 P3 P6 P7
P0 P1 P2 P3 P4 P5 P6 P7
P0 P1 P2 P3 P4 P5 P6 P7
Schemes for Dynamic
Mapping
• Dynamic mapping is sometimes also referred to as
dynamic load balancing, since load balancing is the
primary motivation for dynamic mapping.
• When a process runs out of work, it requests the master for more work.
For example, GPU programming has been used to accelerate video, digital
image, and audio signal processing, statistical physics, scientific
computing, medical imaging, computer vision, neural networks and deep
learning, cryptography, and even intrusion detection, among many other
areas.
CPU vs GPU
CPU vs GPU
[Link] CPU GPU
CPU stands for Central Processing While GPU stands for Graphics Processing
1.
Unit. Unit.
CPU consumes or needs more While it consumes or requires less memory
2.
memory than GPU. than CPU.
The speed of CPU is less than
3. While GPU is faster than CPU’s speed.
GPU’s speed.
4. CPU contain powerful cores. While it contain more weak cores.
CPU is suitable for serial While GPU is not suitable for serial
5.
instruction processing. instruction processing.
CPU is not suitable for parallel While GPU is suitable for parallel
6.
instruction processing. instruction processing.
Email : [Link]@[Link]