Computer Science 320 - PowerPoint PPT Presentation

Loading...

PPT – Computer Science 320 PowerPoint presentation | free to download - id: 73704f-ZDgyO



Loading


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation
Title:

Computer Science 320

Description:

Computer Science 320 Clumping in Parallel Java Sequential vs Parallel Program Initial setup Execute the computation Clean up Initial setup Create a parallel team Have ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 15
Provided by: KenL96
Learn more at: http://home.wlu.edu
Category:
Tags: computer | java | science

less

Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Computer Science 320


1
Computer Science 320
  • Clumping in Parallel Java

2
Sequential vs Parallel Program
Initial setup Execute the computation Clean up
Initial setup Create a parallel team Have the
team execute the computation Clean up
3
Ways to Create a Team
new ParallelTeam(n) . . .
new ParallelTeam() . . .
Either specify the number of threads or you get
the same number of threads as there are
processors on your computer
4
Whats Inside the Box
new ParallelTeam(4) . . .
5
The ParallelRegion Class
  • An abstract class with default implementations of
    the start, run, and finish methods
  • Override these methods in a new subclass to
    implement your program

6
Template for Parallel Region
new ParallelTeam().execute(new ParallelRegion()
public void start() public void
run() public void finish() )
Note start() and finish() are called just once,
by main. After start() completes, run() is
called in each thread simultaneously and main
blocks. When all of the threads have signaled
main that theyre done, main resumes and calls
finish().
7
(No Transcript)
8
The Parallel for Loop
  • Used to slice data into clumps to distribute to
    threads for parallel processing
  • IntegerForLoop is an abstract class with a
    run(first, last) method that will execute loop
    code over a range of values from first through
    last

9
Template for Parallel for Loop
new ParallelTeam().execute(new ParallelRegion()
public void run() execute(lower,
upper, new IntegerForLoop() public
void run(int first, int last) //
Loop code ) )
Each thread creates its own instance of
IntegerForLoop with the same lower and upper
bounds of the entire loop The parallel regions
execute method partitions this range into the
appropriate subranges for each thread Each
threads loop/run method executes with its own
range from first to last
10
The Parallel for Loop
  • Each thread executes the start, run, and finish
    methods within its own instance of IntegerForLoop
  • At the end of its finish(), each thread waits at
    a barrier until all the threads have finished
    their loops
  • Parallel execution of the regions run method
    then resumes

11
Whats Inside the Box
new ParallelTeam(4) . . . new
ParallelForLoop(0, 99, . . .)
12
Variables
  • Shared typically declared static
  • Per-thread declared in a for loop instance
  • Loop local declared in a loops run method
  • main local for the use of main only, cannot be
    accessed with threads

13
Variables
14
Sharing and Synchronization
If threads only read from memory, no problem But
if threads must write or update memory, then we
must synchronize them to avoid conflict and
inconsistency
About PowerShow.com