|
||
| Author: Blaise Barney, Lawrence Livermore National Laboratory | UCRL-MI-133316 | |
| Abstract |
This is the first tutorial in the "Livermore Computing Getting Started" workshop. It is intended to provide only a very quick overview of the extensive and broad topic of Parallel Computing, as a lead-in for the tutorials that follow it. As such, it covers just the very basics of parallel computing, and is intended for someone who is just becoming acquainted with the subject and who is planning to attend one or more of the other tutorials in this workshop. It is not intended to cover Parallel Programming in depth, as this would require significantly more time. The tutorial begins with a discussion on parallel computing - what it is and how it's used, followed by a discussion on concepts and terminology associated with parallel computing. The topics of parallel memory architectures and programming models are then explored. These topics are followed by a series of practical discussions on a number of the complex issues related to designing and running parallel programs. The tutorial concludes with several examples of how to parallelize simple serial programs.
| Overview |
Serial Computing:
For example:
Parallel Computing:
For example:
Parallel Computers:
IBM BG/Q Compute Chip with 18 cores (PU) and 16 L2 Cache units (L2) |
Source: Top500.org
| Overview |
The Real World is Massively Parallel:
|
Main Reasons:
|
| Overview |
Science and Engineering:
|
Global Applications:
| Click on images below for larger version | |
![]() |
![]() |
| Concepts and Terminology |
![]() |
|
John von Neumann circa 1940s (Source: LANL archives) |
| Concepts and Terminology |
Single Instruction, Single Data (SISD):
![]() |
![]() |
|
UNIVAC1 |
IBM 360 |
CRAY1 |
CDC 7600 |
PDP1 |
Dell Laptop |
Single Instruction, Multiple Data (SIMD):
![]() |
![]() |
|
ILLIAC IV |
MasPar |
![]() |
Cray X-MP |
Cray Y-MP |
Thinking Machines CM-2 |
Cell Processor (GPU) |
Multiple Instruction, Single Data (MISD):
![]() |
![]() |
Multiple Instruction, Multiple Data (MIMD):
![]() |
![]() |
|
IBM POWER5 |
HP/Compaq Alphaserver |
Intel IA32 |
AMD Opteron |
Cray XT3 |
IBM BG/L |
| Concepts and Terminology |
Synchronization usually involves waiting by at least one task, and can therefore cause a parallel application's wall clock execution time to increase.
wall-clock time of serial execution ----------------------------------- wall-clock time of parallel execution |
One of the simplest and most widely used indicators for a parallel program's performance.
| Concepts and Terminology |
Amdahl's Law:
|
![]() |
speedup
-------------------------------------
N P = .50 P = .90 P = .95 P = .99
----- ------- ------- ------- -------
10 1.82 5.26 6.89 9.17
100 1.98 9.17 16.80 50.25
1,000 1.99 9.91 19.62 90.99
10,000 1.99 9.91 19.96 99.02
100,000 1.99 9.99 19.99 99.90
|
"Famous" quote: You can spend a lifetime getting 95% of your code to be parallel, and never achieve better than 20x speedup no matter how many processors you throw at it!
2D Grid Calculations 85 seconds 85%
Serial fraction 15 seconds 15%
|
We can increase the problem size by doubling the grid dimensions and halving the time step. This results in four times the number of grid points and twice the number of time steps. The timings then look like:
2D Grid Calculations 680 seconds 97.84%
Serial fraction 15 seconds 2.16%
|
Complexity:
Portability:
Resource Requirements:
Scalability:
| Parallel Computer Memory Architectures |
General Characteristics:
|
Shared Memory (UMA)
Shared Memory (NUMA) |
Disadvantages:
| Parallel Computer Memory Architectures |
General Characteristics:
Advantages:
Disadvantages:
| Parallel Computer Memory Architectures |
General Characteristics:
![]() |
![]() |
Advantages and Disadvantages:
| Parallel Programming Models |
|
SHARED memory model on a DISTRIBUTED memory machine:
Kendall Square Research (KSR) ALLCACHE approach. Machine memory was physically distributed across networked machines, but appeared to the user as a single shared memory global address space. Generically, this approach is referred to as "virtual shared memory". | |
![]() |
![]() |
|
DISTRIBUTED memory model on a SHARED memory machine:
Message Passing Interface (MPI) on SGI Origin 2000. The SGI Origin 2000 employed the CC-NUMA type of shared memory architecture, where every task has direct access to global address space spread across all machines. However, the ability to send and receive messages using MPI, as is commonly done over a network of distributed memory machines, was implemented and commonly used. | |
![]() |
![]() |
| Parallel Programming Models |
Implementations:
| Parallel Programming Models |
Implementations:
In both cases, the programmer is responsible for determining the parallelism (although compilers can sometimes help).
More Information:
| Parallel Programming Models |
Implementations:
More Information:
| Parallel Programming Models |
Implementations:
| Parallel Programming Models |
|
|
| Parallel Programming Models |
Single Program Multiple Data (SPMD):
Multiple Program Multiple Data (MPMD):
| Designing Parallel Programs |
Fully Automatic
Programmer Directed
| Designing Parallel Programs |
| Calculate the potential energy for each of several thousand independent conformations of a molecule. When done, find the minimum energy conformation. |
This problem is able to be solved in parallel. Each of the molecular conformations is independently determinable. The calculation of the minimum energy conformation is also a parallelizable problem.
|
Calculation of the Fibonacci series (0,1,1,2,3,5,8,13,21,...) by use of
the formula:
F(n) = F(n-1) + F(n-2)
|
The calculation of the F(n) value uses those of both F(n-1) and F(n-2), which must be computed first.
|
![]() |
| Designing Parallel Programs |
Domain Decomposition:
Functional Decomposition:
![]() |
![]() |
| Designing Parallel Programs |
Who Needs Communications?
The need for communications between tasks depends upon your problem:
You DON'T need communications:
|
You DO need communications:
|
![]() |
![]() |
Factors to Consider:
There are a number of important factors to consider when designing your program's inter-task communications:
| Designing Parallel Programs |
Types of Synchronization:
| Designing Parallel Programs |
Definition:
Examples:
DO J = MYSTART,MYEND A(J) = A(J-1) * 2.0 END DO |
The value of A(J-1) must be computed before the value of A(J), therefore A(J) exhibits a data dependency on A(J-1). Parallelism is inhibited.
If Task 2 has A(J) and task 1 has A(J-1), computing the correct value of A(J) necessitates:
task 1 task 2 ------ ------ X = 2 X = 4 . . . . Y = X**2 Y = X**3 |
As with the previous example, parallelism is inhibited. The value of Y is dependent on:
How to Handle Data Dependencies:
| Designing Parallel Programs |
![]() |
![]() |
How to Achieve Load Balance:
![]() |
![]() |
![]() |
| Sparse arrays - some tasks will have actual data to work on while others have mostly "zeros". | Adaptive grid methods - some tasks may need to refine their mesh while others don't. | N-body simulations - particles may migrate across task domains requiring more work for some tasks. |
| Designing Parallel Programs |
Computation / Communication Ratio:
Fine-grain Parallelism:
|
![]() |
| Designing Parallel Programs |
The Bad News:
The Good News:
| Designing Parallel Programs |
| Designing Parallel Programs |
| Parallel Examples |
|
|
do j = mystart, myend
do i = 1, n
a(i,j) = fcn(i,j)
end do
end do
|
for i (i = mystart; i < myend; i++) {
for j (j = 0; j < n; j++) {
a(i,j) = fcn(i,j);
}
}
|
One Possible Solution:
find out if I am MASTER or WORKER
if I am MASTER
initialize the array
send each WORKER info on part of array it owns
send each WORKER its portion of initial array
# calculate my portion of array
do j = my first column,my last column
do i = 1,n
a(i,j) = fcn(i,j)
end do
end do
receive from each WORKER results
else if I am WORKER
receive from MASTER info on part of array I own
receive from MASTER my portion of initial array
# calculate my portion of array
do j = my first column,my last column
do i = 1,n
a(i,j) = fcn(i,j)
end do
end do
send MASTER results
endif
|
Example Programs:
Pool of Tasks Scheme:
Master Process:
Worker Process: repeatedly does the following
find out if I am MASTER or WORKER
if I am MASTER
do until no more jobs
if request send to WORKER next job
else receive results from WORKER
end do
else if I am WORKER
do until no more jobs
request job from MASTER
receive from MASTER next job
calculate array element: a(i,j) = fcn(i,j)
send results to MASTER
end do
endif
|
Discussion:
| Parallel Examples |
|
|
|
|
Example Programs:
| Parallel Examples |
|
|
find out if I am MASTER or WORKER
if I am MASTER
initialize array
send each WORKER starting info and subarray
receive results from each WORKER
else if I am WORKER
receive from MASTER starting info and subarray
# Perform time steps
do t = 1, nsteps
update time
send neighbors my border info
receive from neighbors their border info
update my portion of solution array
end do
send MASTER results
endif
|
Example Programs:
| Parallel Examples |
A(i,t+1) = (2.0 * A(i,t)) - A(i,t-1)
+ (c * (A(i-1,t) - (2.0 * A(i,t)) + A(i+1,t)))
|
where c is a constant
find out number of tasks and task identities
#Identify left and right neighbors
left_neighbor = mytaskid - 1
right_neighbor = mytaskid +1
if mytaskid = first then left_neigbor = last
if mytaskid = last then right_neighbor = first
find out if I am MASTER or WORKER
if I am MASTER
initialize array
send each WORKER starting info and subarray
else if I am WORKER`
receive starting info and subarray from MASTER
endif
#Perform time steps
#In this example the master participates in calculations
do t = 1, nsteps
send left endpoint to left neighbor
receive left endpoint from right neighbor
send right endpoint to right neighbor
receive right endpoint from left neighbor
#Update points along line
do i = 1, npoints
newval(i) = (2.0 * values(i)) - oldval(i)
+ (sqtau * (values(i-1) - (2.0 * values(i)) + values(i+1)))
end do
end do
#Collect results and write to file
if I am MASTER
receive results from each WORKER
write results to file
else if I am WORKER
send results to MASTER
endif
|
Example Programs:
This completes the tutorial.
|
Please complete the online evaluation form. |
Where would you like to go now?
| References and More Information |