SlideShare a Scribd company logo
1 of 38
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved.
Chapter 4
Partitioning
and Divide-and-Conquer Strategies
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.1
Partitioning
Partitioning simply divides the problem into parts.
Divide and Conquer
Characterized by dividing problem into sub-problems of
same form as larger problem. Further divisions into still
smaller sub-problems, usually done by recursion.
Recursive divide and conquer amenable to parallelization
because separate processes can be used for divided parts.
Also usually data is naturally localized.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.2
Partitioning/Divide and Conquer
Examples
Many possibilities.
• Operations on sequences of number such as
simply adding them together
• Several sorting algorithms can often be
partitioned or constructed in a recursive fashion
• Numerical integration
• N-body problem
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.3
Partitioning a sequence of numbers
into parts and adding the parts
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.4
Tree construction
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.5
Dividing a list into parts
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.6
Partial summation
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.7
Quadtree
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.8
Dividing an image
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.9
Bucket sort
One “bucket” assigned to hold numbers that fall within each region.
Numbers in each bucket sorted using a sequential sorting algorithm.
Sequential sorting time complexity: O(nlog(n/m).
Works well if the original numbers uniformly distributed across a
known interval, say 0 to a - 1.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.10
Parallel version of bucket sort
Simple approach
Assign one processor for each bucket.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.11
Further Parallelization
Partition sequence into m regions, one region for
each processor.
Each processor maintains p “small” buckets and
separates numbers in its region into its own small
buckets.
Small buckets then emptied into p final buckets for
sorting, which requires each processor to send one
small bucket to each of the other processors
(bucket i to processor i).
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.12
Another parallel version of bucket sort
Introduces new message-passing operation - all-to-all broadcast.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.13
“all-to-all” broadcast routine
Sends data from each process to every other process
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.14
“all-to-all” routine actually transfers rows of an array to columns:
Transposes a matrix.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.15
Numerical integration using rectangles
Each region calculated using an approximation given by
rectangles:
Aligning the rectangles:
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.16
Numerical integration using
trapezoidal method
May not be better!
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.17
Adaptive Quadrature
Solution adapts to shape of curve. Use three areas, A, B,
and C. Computation terminated when largest of A and B
sufficiently close to sum of remain two areas .
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.18
Adaptive quadrature with
false termination.
Some care might be needed in choosing when to terminate.
Might cause us to terminate early, as two large regions are
the same (i.e., C = 0).
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 3.19
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.20
/*********************************************************************************
pi_calc.cpp calculates value of pi and compares with actual
value (to 25digits) of pi to give error. Integrates function f(x)=4/(1+x^2).
July 6, 2001 K. Spry CSCI3145
**********************************************************************************/
#include <math.h> //include files
#include <iostream.h>
#include "mpi.h“
void printit(); //function prototypes
int main(int argc, char *argv[])
{
double actual_pi = 3.141592653589793238462643;
//for comparison later
int n, rank, num_proc, i;
double temp_pi, calc_pi, int_size, part_sum, x;
char response = 'y', resp1 = 'y';
MPI::Init(argc, argv); //initiate MPI
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.21
num_proc = MPI::COMM_WORLD.Get_size();
rank = MPI::COMM_WORLD.Get_rank();
if (rank == 0) printit(); /* I am root node, print out welcome */
while (response == 'y') {
if (resp1 == 'y') {
if (rank == 0) { /*I am root node*/
cout <<"__________________________________" <<endl;
cout <<"nEnter the number of intervals: (0 will exit)" << endl;
cin >> n;}
} else n = 0;
MPI::COMM_WORLD.Bcast(&n, 1, MPI::INT, 0); //broadcast n
if (n==0) break; //check for quit condition
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.22
else {
int_size = 1.0 / (double) n; //calcs interval size
part_sum = 0.0;
for (i = rank + 1; i <= n; i += num_proc)
{ //calcs partial sums
x = int_size * ((double)i - 0.5);
part_sum += (4.0 / (1.0 + x*x));
}
temp_pi = int_size * part_sum;
//collects all partial sums computes pi
MPI::COMM_WORLD.Reduce(&temp_pi,&calc_pi, 1,
MPI::DOUBLE, MPI::SUM, 0);
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.23
if (rank == 0) { /*I am server*/
cout << "pi is approximately " << calc_pi
<< ". Error is " << fabs(calc_pi - actual_pi)
<< endl
<<"_______________________________________"
<< endl;
}
} //end else
if (rank == 0) { /*I am root node*/
cout << "nCompute with new intervals? (y/n)" << endl; cin >> resp1;
}
}//end while
MPI::Finalize(); //terminate MPI
return 0;
} //end main
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.24
//functions
void printit()
{
cout << "n*********************************" << endl
<< "Welcome to the pi calculator!" << endl
<< "Programmer: K. Spry" << endl
<< "You set the number of divisions nfor estimating the
integral:
ntf(x)=4/(1+x^2)"
<< endl
<< "*********************************" << endl;
} //end printit
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.25
Gravitational N-Body Problem
Finding positions and movements of bodies in space
subject to gravitational forces from other bodies, using
Newtonian laws of physics.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.26
Gravitational N-Body Problem Equations
Gravitational force between two bodies of masses ma and mb is:
G is the gravitational constant and r the distance between the
bodies. Subject to forces, body accelerates according to
Newton’s 2nd law:
m is mass of the body, F is force it experiences, and a the
resultant acceleration.
F = ma
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.27
New velocity is:
where vt+1 is the velocity at time t + 1 and vt is the velocity at time t.
Over time interval Dt, position changes by
where xt is its position at time t.
Once bodies move to new positions, forces change.
Computation has to be repeated.
Details
Let the time interval be t. For a body of mass m, the force is:
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 3.28
Sequential Code
Overall gravitational N-body computation can be described by:
for (t = 0; t < tmax; t++) /* for each time period */
for (i = 0; i < N; i++) { /* for each body */
F = Force_routine(i); /* compute force on ith body */
v[i]new = v[i] + F * dt / m; /* compute new velocity */
x[i]new = x[i] + v[i]new * dt; /* and new position */
}
for (i = 0; i < nmax; i++) { /* for each body */
x[i] = x[i]new; /* update velocity & position*/
v[i] = v[i]new;
}
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.29
Parallel Code
The sequential algorithm is an O(N2) algorithm
(for one iteration) as each of the N bodies is
influenced by each of the other N - 1 bodies.
Not feasible to use this direct algorithm for most
interesting N-body problems where N is very
large.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.30
Time complexity can be reduced approximating a
cluster of distant bodies as a single distant body
with mass sited at the center of mass of the cluster:
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.31
Barnes-Hut Algorithm
Start with whole space in which one cube contains
the bodies (or particles).
• First, this cube is divided into eight subcubes.
• If a subcube contains no particles, subcube deleted
from further consideration.
• If a subcube contains one body, subcube retained.
• If a subcube contains more than one body, it is
recursively divided until every subcube contains one body.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.32
Creates an octtree - a tree with up to eight edges
from each node.
The leaves represent cells each containing one
body.
After the tree has been constructed, the total
mass and center of mass of the subcube is stored
at each node.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.33
Force on each body obtained by traversing tree
starting at root, stopping at a node when the
clustering approximation can be used, e.g. when:
where is a constant typically 1.0 or less.
Constructing tree requires a time of O(nlogn), and
so does computing all the forces, so that overall
time complexity of method is O(nlogn).
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.34
Recursive division of 2-dimensional space
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.35
(For 2-dimensional area) First, a vertical line found that divides
area into two areas each with equal number of bodies. For
each area, a horizontal line found that divides it into two areas
each with equal number of bodies. Repeated as required.
Orthogonal Recursive Bisection
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.36
Astrophysical N-body simulation
By Scott Linssen (UNCC student, 1997) using O(N2) algorithm.
Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.37
Astrophysical N-body simulation
By David Messager (UNCC student 1998) using Barnes-Hut algorithm.

More Related Content

Similar to slides4.ppt

workshop_8_c__.pdf
workshop_8_c__.pdfworkshop_8_c__.pdf
workshop_8_c__.pdfAtulAvhad2
 
Mis 589 Success Begins / snaptutorial.com
Mis 589  Success Begins / snaptutorial.comMis 589  Success Begins / snaptutorial.com
Mis 589 Success Begins / snaptutorial.comWilliamsTaylor44
 
Mis 589 Massive Success / snaptutorial.com
Mis 589 Massive Success / snaptutorial.comMis 589 Massive Success / snaptutorial.com
Mis 589 Massive Success / snaptutorial.comStephenson185
 
Microsoft Excel: Applications of the Software in the Architectural Engineerin...
Microsoft Excel: Applications of the Software in the Architectural Engineerin...Microsoft Excel: Applications of the Software in the Architectural Engineerin...
Microsoft Excel: Applications of the Software in the Architectural Engineerin...Mohammad B. Hamida
 
Project format of kampala university for computer science
Project format of kampala university for computer scienceProject format of kampala university for computer science
Project format of kampala university for computer sciencerashid muganga
 
NTC 409 Invent Yourself/newtonhelp.com
NTC 409 Invent Yourself/newtonhelp.comNTC 409 Invent Yourself/newtonhelp.com
NTC 409 Invent Yourself/newtonhelp.comlechenau117
 
Cnd labguide
Cnd labguideCnd labguide
Cnd labguideYahye159
 
Design and Simulation of Local Area Network Using Cisco Packet Tracer
Design and Simulation of Local Area Network Using Cisco Packet TracerDesign and Simulation of Local Area Network Using Cisco Packet Tracer
Design and Simulation of Local Area Network Using Cisco Packet TracerAbhi abhishek
 
SOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITS
SOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITSSOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITS
SOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITSvivatechijri
 
ATI Courses Professional Development Short Course Engineering Systems Modelin...
ATI Courses Professional Development Short Course Engineering Systems Modelin...ATI Courses Professional Development Short Course Engineering Systems Modelin...
ATI Courses Professional Development Short Course Engineering Systems Modelin...Jim Jenkins
 
TEACHING TCP/IP NETWORKING USING HANDS-ON LABORATORY EXPERIENCE
TEACHING TCP/IP NETWORKING USING HANDS-ON  LABORATORY EXPERIENCETEACHING TCP/IP NETWORKING USING HANDS-ON  LABORATORY EXPERIENCE
TEACHING TCP/IP NETWORKING USING HANDS-ON LABORATORY EXPERIENCEFelipe Suarez
 
Special Purpose IBM Center of excellence lab
Special Purpose IBM Center of excellence lab Special Purpose IBM Center of excellence lab
Special Purpose IBM Center of excellence lab Ganesan Narayanasamy
 
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan
 
NTC 409 RANK Education Your Life / ntc409rank.com
NTC 409 RANK Education Your Life / ntc409rank.comNTC 409 RANK Education Your Life / ntc409rank.com
NTC 409 RANK Education Your Life / ntc409rank.comkopiko16
 
computer-systems-servicing-dll.docx
computer-systems-servicing-dll.docxcomputer-systems-servicing-dll.docx
computer-systems-servicing-dll.docxrochelleogatis1
 
Ecet 365 Education Redefined - snaptutorial.com
Ecet 365    Education Redefined - snaptutorial.comEcet 365    Education Redefined - snaptutorial.com
Ecet 365 Education Redefined - snaptutorial.comDavisMurphyC85
 
NTC 409 RANK Lessons in Excellence-- ntc409rank.com
NTC 409 RANK Lessons in Excellence-- ntc409rank.comNTC 409 RANK Lessons in Excellence-- ntc409rank.com
NTC 409 RANK Lessons in Excellence-- ntc409rank.comRoelofMerwe127
 
NTC 409 RANK Inspiring Innovation--ntc409rank.com
NTC 409 RANK Inspiring Innovation--ntc409rank.comNTC 409 RANK Inspiring Innovation--ntc409rank.com
NTC 409 RANK Inspiring Innovation--ntc409rank.comagathachristie61
 

Similar to slides4.ppt (20)

workshop_8_c__.pdf
workshop_8_c__.pdfworkshop_8_c__.pdf
workshop_8_c__.pdf
 
Mis 589 Success Begins / snaptutorial.com
Mis 589  Success Begins / snaptutorial.comMis 589  Success Begins / snaptutorial.com
Mis 589 Success Begins / snaptutorial.com
 
Mis 589 Massive Success / snaptutorial.com
Mis 589 Massive Success / snaptutorial.comMis 589 Massive Success / snaptutorial.com
Mis 589 Massive Success / snaptutorial.com
 
Bca college in bangalore
Bca college in bangaloreBca college in bangalore
Bca college in bangalore
 
Microsoft Excel: Applications of the Software in the Architectural Engineerin...
Microsoft Excel: Applications of the Software in the Architectural Engineerin...Microsoft Excel: Applications of the Software in the Architectural Engineerin...
Microsoft Excel: Applications of the Software in the Architectural Engineerin...
 
Project format of kampala university for computer science
Project format of kampala university for computer scienceProject format of kampala university for computer science
Project format of kampala university for computer science
 
NTC 409 Invent Yourself/newtonhelp.com
NTC 409 Invent Yourself/newtonhelp.comNTC 409 Invent Yourself/newtonhelp.com
NTC 409 Invent Yourself/newtonhelp.com
 
It 241 it241
It 241 it241It 241 it241
It 241 it241
 
Cnd labguide
Cnd labguideCnd labguide
Cnd labguide
 
Design and Simulation of Local Area Network Using Cisco Packet Tracer
Design and Simulation of Local Area Network Using Cisco Packet TracerDesign and Simulation of Local Area Network Using Cisco Packet Tracer
Design and Simulation of Local Area Network Using Cisco Packet Tracer
 
SOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITS
SOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITSSOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITS
SOFTWARE BASED CALCULATION OF CAPACITY OUTAGE OF GENERATING UNITS
 
ATI Courses Professional Development Short Course Engineering Systems Modelin...
ATI Courses Professional Development Short Course Engineering Systems Modelin...ATI Courses Professional Development Short Course Engineering Systems Modelin...
ATI Courses Professional Development Short Course Engineering Systems Modelin...
 
TEACHING TCP/IP NETWORKING USING HANDS-ON LABORATORY EXPERIENCE
TEACHING TCP/IP NETWORKING USING HANDS-ON  LABORATORY EXPERIENCETEACHING TCP/IP NETWORKING USING HANDS-ON  LABORATORY EXPERIENCE
TEACHING TCP/IP NETWORKING USING HANDS-ON LABORATORY EXPERIENCE
 
Special Purpose IBM Center of excellence lab
Special Purpose IBM Center of excellence lab Special Purpose IBM Center of excellence lab
Special Purpose IBM Center of excellence lab
 
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2
 
NTC 409 RANK Education Your Life / ntc409rank.com
NTC 409 RANK Education Your Life / ntc409rank.comNTC 409 RANK Education Your Life / ntc409rank.com
NTC 409 RANK Education Your Life / ntc409rank.com
 
computer-systems-servicing-dll.docx
computer-systems-servicing-dll.docxcomputer-systems-servicing-dll.docx
computer-systems-servicing-dll.docx
 
Ecet 365 Education Redefined - snaptutorial.com
Ecet 365    Education Redefined - snaptutorial.comEcet 365    Education Redefined - snaptutorial.com
Ecet 365 Education Redefined - snaptutorial.com
 
NTC 409 RANK Lessons in Excellence-- ntc409rank.com
NTC 409 RANK Lessons in Excellence-- ntc409rank.comNTC 409 RANK Lessons in Excellence-- ntc409rank.com
NTC 409 RANK Lessons in Excellence-- ntc409rank.com
 
NTC 409 RANK Inspiring Innovation--ntc409rank.com
NTC 409 RANK Inspiring Innovation--ntc409rank.comNTC 409 RANK Inspiring Innovation--ntc409rank.com
NTC 409 RANK Inspiring Innovation--ntc409rank.com
 

More from nazimsattar

Pr.SE2.361101659.pptx
Pr.SE2.361101659.pptxPr.SE2.361101659.pptx
Pr.SE2.361101659.pptxnazimsattar
 
vehiculr networks.ppt
vehiculr networks.pptvehiculr networks.ppt
vehiculr networks.pptnazimsattar
 
ad-hoc 16 4 2018.ppt
ad-hoc 16 4 2018.pptad-hoc 16 4 2018.ppt
ad-hoc 16 4 2018.pptnazimsattar
 
Cellular Wireless Networks p1 chap 2.pptx
Cellular Wireless Networks p1 chap 2.pptxCellular Wireless Networks p1 chap 2.pptx
Cellular Wireless Networks p1 chap 2.pptxnazimsattar
 
Cellular Wireless Networks part2.pptx
Cellular Wireless Networks part2.pptxCellular Wireless Networks part2.pptx
Cellular Wireless Networks part2.pptxnazimsattar
 
parallel programming.ppt
parallel programming.pptparallel programming.ppt
parallel programming.pptnazimsattar
 
DTUI5_chap06.ppt
DTUI5_chap06.pptDTUI5_chap06.ppt
DTUI5_chap06.pptnazimsattar
 
DTUI5_chap05.ppt
DTUI5_chap05.pptDTUI5_chap05.ppt
DTUI5_chap05.pptnazimsattar
 

More from nazimsattar (20)

Pr.SE2.361101659.pptx
Pr.SE2.361101659.pptxPr.SE2.361101659.pptx
Pr.SE2.361101659.pptx
 
ch10.ppt
ch10.pptch10.ppt
ch10.ppt
 
vehiculr networks.ppt
vehiculr networks.pptvehiculr networks.ppt
vehiculr networks.ppt
 
ad-hoc 16 4 2018.ppt
ad-hoc 16 4 2018.pptad-hoc 16 4 2018.ppt
ad-hoc 16 4 2018.ppt
 
Cellular Wireless Networks p1 chap 2.pptx
Cellular Wireless Networks p1 chap 2.pptxCellular Wireless Networks p1 chap 2.pptx
Cellular Wireless Networks p1 chap 2.pptx
 
Cellular Wireless Networks part2.pptx
Cellular Wireless Networks part2.pptxCellular Wireless Networks part2.pptx
Cellular Wireless Networks part2.pptx
 
types of DS.ppt
types of DS.ppttypes of DS.ppt
types of DS.ppt
 
parallel programming.ppt
parallel programming.pptparallel programming.ppt
parallel programming.ppt
 
slides9.ppt
slides9.pptslides9.ppt
slides9.ppt
 
chap2.ppt
chap2.pptchap2.ppt
chap2.ppt
 
351101835.pptx
351101835.pptx351101835.pptx
351101835.pptx
 
351101042.ppt
351101042.ppt351101042.ppt
351101042.ppt
 
331103344.ppt
331103344.ppt331103344.ppt
331103344.ppt
 
381101843.pptx
381101843.pptx381101843.pptx
381101843.pptx
 
372103483.pptx
372103483.pptx372103483.pptx
372103483.pptx
 
pl10ch2.ppt
pl10ch2.pptpl10ch2.ppt
pl10ch2.ppt
 
e3-chap-08.ppt
e3-chap-08.ppte3-chap-08.ppt
e3-chap-08.ppt
 
DTUI5_chap06.ppt
DTUI5_chap06.pptDTUI5_chap06.ppt
DTUI5_chap06.ppt
 
DTUI5_chap05.ppt
DTUI5_chap05.pptDTUI5_chap05.ppt
DTUI5_chap05.ppt
 
ch13.ppt
ch13.pptch13.ppt
ch13.ppt
 

Recently uploaded

NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdfAldoGarca30
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxpritamlangde
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdfKamal Acharya
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxMustafa Ahmed
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Ramkumar k
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessorAshwiniTodkar4
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfsumitt6_25730773
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)ChandrakantDivate1
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsmeharikiros2
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...ronahami
 

Recently uploaded (20)

NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 

slides4.ppt

  • 1. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. Chapter 4 Partitioning and Divide-and-Conquer Strategies
  • 2. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.1 Partitioning Partitioning simply divides the problem into parts. Divide and Conquer Characterized by dividing problem into sub-problems of same form as larger problem. Further divisions into still smaller sub-problems, usually done by recursion. Recursive divide and conquer amenable to parallelization because separate processes can be used for divided parts. Also usually data is naturally localized.
  • 3. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.2 Partitioning/Divide and Conquer Examples Many possibilities. • Operations on sequences of number such as simply adding them together • Several sorting algorithms can often be partitioned or constructed in a recursive fashion • Numerical integration • N-body problem
  • 4. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.3 Partitioning a sequence of numbers into parts and adding the parts
  • 5. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.4 Tree construction
  • 6. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.5 Dividing a list into parts
  • 7. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.6 Partial summation
  • 8. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.7 Quadtree
  • 9. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.8 Dividing an image
  • 10. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.9 Bucket sort One “bucket” assigned to hold numbers that fall within each region. Numbers in each bucket sorted using a sequential sorting algorithm. Sequential sorting time complexity: O(nlog(n/m). Works well if the original numbers uniformly distributed across a known interval, say 0 to a - 1.
  • 11. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.10 Parallel version of bucket sort Simple approach Assign one processor for each bucket.
  • 12. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.11 Further Parallelization Partition sequence into m regions, one region for each processor. Each processor maintains p “small” buckets and separates numbers in its region into its own small buckets. Small buckets then emptied into p final buckets for sorting, which requires each processor to send one small bucket to each of the other processors (bucket i to processor i).
  • 13. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.12 Another parallel version of bucket sort Introduces new message-passing operation - all-to-all broadcast.
  • 14. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.13 “all-to-all” broadcast routine Sends data from each process to every other process
  • 15. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.14 “all-to-all” routine actually transfers rows of an array to columns: Transposes a matrix.
  • 16. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.15 Numerical integration using rectangles Each region calculated using an approximation given by rectangles: Aligning the rectangles:
  • 17. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.16 Numerical integration using trapezoidal method May not be better!
  • 18. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.17 Adaptive Quadrature Solution adapts to shape of curve. Use three areas, A, B, and C. Computation terminated when largest of A and B sufficiently close to sum of remain two areas .
  • 19. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.18 Adaptive quadrature with false termination. Some care might be needed in choosing when to terminate. Might cause us to terminate early, as two large regions are the same (i.e., C = 0).
  • 20. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 3.19
  • 21. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.20 /********************************************************************************* pi_calc.cpp calculates value of pi and compares with actual value (to 25digits) of pi to give error. Integrates function f(x)=4/(1+x^2). July 6, 2001 K. Spry CSCI3145 **********************************************************************************/ #include <math.h> //include files #include <iostream.h> #include "mpi.h“ void printit(); //function prototypes int main(int argc, char *argv[]) { double actual_pi = 3.141592653589793238462643; //for comparison later int n, rank, num_proc, i; double temp_pi, calc_pi, int_size, part_sum, x; char response = 'y', resp1 = 'y'; MPI::Init(argc, argv); //initiate MPI
  • 22. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.21 num_proc = MPI::COMM_WORLD.Get_size(); rank = MPI::COMM_WORLD.Get_rank(); if (rank == 0) printit(); /* I am root node, print out welcome */ while (response == 'y') { if (resp1 == 'y') { if (rank == 0) { /*I am root node*/ cout <<"__________________________________" <<endl; cout <<"nEnter the number of intervals: (0 will exit)" << endl; cin >> n;} } else n = 0; MPI::COMM_WORLD.Bcast(&n, 1, MPI::INT, 0); //broadcast n if (n==0) break; //check for quit condition
  • 23. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.22 else { int_size = 1.0 / (double) n; //calcs interval size part_sum = 0.0; for (i = rank + 1; i <= n; i += num_proc) { //calcs partial sums x = int_size * ((double)i - 0.5); part_sum += (4.0 / (1.0 + x*x)); } temp_pi = int_size * part_sum; //collects all partial sums computes pi MPI::COMM_WORLD.Reduce(&temp_pi,&calc_pi, 1, MPI::DOUBLE, MPI::SUM, 0);
  • 24. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.23 if (rank == 0) { /*I am server*/ cout << "pi is approximately " << calc_pi << ". Error is " << fabs(calc_pi - actual_pi) << endl <<"_______________________________________" << endl; } } //end else if (rank == 0) { /*I am root node*/ cout << "nCompute with new intervals? (y/n)" << endl; cin >> resp1; } }//end while MPI::Finalize(); //terminate MPI return 0; } //end main
  • 25. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.24 //functions void printit() { cout << "n*********************************" << endl << "Welcome to the pi calculator!" << endl << "Programmer: K. Spry" << endl << "You set the number of divisions nfor estimating the integral: ntf(x)=4/(1+x^2)" << endl << "*********************************" << endl; } //end printit
  • 26. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.25 Gravitational N-Body Problem Finding positions and movements of bodies in space subject to gravitational forces from other bodies, using Newtonian laws of physics.
  • 27. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.26 Gravitational N-Body Problem Equations Gravitational force between two bodies of masses ma and mb is: G is the gravitational constant and r the distance between the bodies. Subject to forces, body accelerates according to Newton’s 2nd law: m is mass of the body, F is force it experiences, and a the resultant acceleration. F = ma
  • 28. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.27 New velocity is: where vt+1 is the velocity at time t + 1 and vt is the velocity at time t. Over time interval Dt, position changes by where xt is its position at time t. Once bodies move to new positions, forces change. Computation has to be repeated. Details Let the time interval be t. For a body of mass m, the force is:
  • 29. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 3.28 Sequential Code Overall gravitational N-body computation can be described by: for (t = 0; t < tmax; t++) /* for each time period */ for (i = 0; i < N; i++) { /* for each body */ F = Force_routine(i); /* compute force on ith body */ v[i]new = v[i] + F * dt / m; /* compute new velocity */ x[i]new = x[i] + v[i]new * dt; /* and new position */ } for (i = 0; i < nmax; i++) { /* for each body */ x[i] = x[i]new; /* update velocity & position*/ v[i] = v[i]new; }
  • 30. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.29 Parallel Code The sequential algorithm is an O(N2) algorithm (for one iteration) as each of the N bodies is influenced by each of the other N - 1 bodies. Not feasible to use this direct algorithm for most interesting N-body problems where N is very large.
  • 31. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.30 Time complexity can be reduced approximating a cluster of distant bodies as a single distant body with mass sited at the center of mass of the cluster:
  • 32. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.31 Barnes-Hut Algorithm Start with whole space in which one cube contains the bodies (or particles). • First, this cube is divided into eight subcubes. • If a subcube contains no particles, subcube deleted from further consideration. • If a subcube contains one body, subcube retained. • If a subcube contains more than one body, it is recursively divided until every subcube contains one body.
  • 33. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.32 Creates an octtree - a tree with up to eight edges from each node. The leaves represent cells each containing one body. After the tree has been constructed, the total mass and center of mass of the subcube is stored at each node.
  • 34. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.33 Force on each body obtained by traversing tree starting at root, stopping at a node when the clustering approximation can be used, e.g. when: where is a constant typically 1.0 or less. Constructing tree requires a time of O(nlogn), and so does computing all the forces, so that overall time complexity of method is O(nlogn).
  • 35. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.34 Recursive division of 2-dimensional space
  • 36. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.35 (For 2-dimensional area) First, a vertical line found that divides area into two areas each with equal number of bodies. For each area, a horizontal line found that divides it into two areas each with equal number of bodies. Repeated as required. Orthogonal Recursive Bisection
  • 37. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.36 Astrophysical N-body simulation By Scott Linssen (UNCC student, 1997) using O(N2) algorithm.
  • 38. Slides for Parallel Programming Techniques & Applications Using Networked Workstations & Parallel Computers 2nd ed., by B. Wilkinson & M. Allen, @ 2004 Pearson Education Inc. All rights reserved. 4.37 Astrophysical N-body simulation By David Messager (UNCC student 1998) using Barnes-Hut algorithm.