SlideShare a Scribd company logo
1 of 15
Parallel Algorithms
Why Parallel Algorithms
• It is the most important element of parallel
computation, without no problem could be
solved in parallel.
• A parallel algorithm defines how a problem can
be solved on the given parallel computer.
• Specifically, specifying how the problem is
divided into sub-problems, and how the partial
solutions are combined to produce the final
answer.
Changing our assumptions
• So far most or all of our study has assumed the
sequential programming: Each statement
executes in sequence.
• Removing this assumption creates challenges
and opportunities:
• Programming: How can we divide work among
threads of execution and coordinate (synchronize)
among them?
• Algorithms: How can activities in parallel speed-up a
program? (more throughput: work done per unit time)
Brief Arch. history
• From ~1980-2005, CPU speed (GHz) got exponentially
faster.
• Roughly doubled every 1.5 years ("Moore's Law").
• But we are reaching limits of classic CPU design.
• Increasing speeds further generates too much heat.
• Any singleCPU over ~3-4 GHz crashes or burns out in normal
usage.
• Current work-around: Use multiple processors.
• Or, more recently, produce one CPU containing many processors
in it.
• core: A processor-within-a-processor.
• A "multi-core" processor is one with several cores inside.
Using many cores
• Run multiple different programs at the same time (processes).
• Example: Core 1 runs Firefox; Core 2 runs iTunes; Core 3 runs
Eclipse...
• Technically, programs receive "time slices" of attention from
cores.
• The OS (Windows, OSX, Linux) already does this for you.
• Do multiple things at once within the same program (threads).
• Requires rethinking everything about our algorithms, from how to
implement data-structure operations, to Big-Oh, to ...
• Writing correct/fast parallel code is much harder than
sequential.
• Especially in common languages like Java and C++.
Parallel vs Distributed
• In both parallel and distributed systems, the events are
partially ordered.
• The distinction between parallel and distributed is not
always very clear.
• In parallel systems, the primarily issues are
• speed-up and increased data handling capability.
• Using multiple processing resources (CPUs, cores) at once to
solve a problem faster. Example:A sorting algorithm that has
several threads each sort part of the array.
• In distributed systems the primary issues are
• fault-tolerance, synchronization, scalability, etc.
Algorithm example
• Write a method named sum that computes the total sum
of all elements in an array of integers.
• For now, just write a normal solution that doesn't use parallelism.
// normal sequential solution
int total = 0;
for (int i = 0; i < a.length; i++) {
total += a[i];
Parallelizing the algorithm
• How can we parallelize this algorithm if we have 2
CPUs/cores?
• Compute sum of each half of array in a thread.
• Add the two sums together.
Thread and Runnable
• To run some code in its own thread:
• Write a class that implements the Runnable interface.
• Its run method contains the code you want to execute.
• Construct a newThread object, passing your runnable to it.
• Then start the thread.
public interface Runnable { // implement this
public void run();
}
public class Thread { // construct one
public Thread(Runnable runnable)
public void start()
Cont.
• First, write a method that sums a partial range of the array:
// normal sequential solution
public static int sumRange(int[] a, int min, int max) {
int total = 0;
for (int i = min; i < max; i++) {
total += a[i];
}
return total;
}
Cont.
• Now write a runnable class that can sum a partial array:
public class Summer implements Runnable {
private int[] a;
private int min, max, sum;
public Summer(int[] a, int min, int max) {
this.a = a;
this.min = min;
this.max = Math.min(max, a.length);
}
public int getSum() {
return sum;
}
public void run() {
sum = Sorting.sumRange(a, min, max);
}
}
Parallel vs Distributed
• Now write the sum method to run Summers in threads:
// Parallel version (two threads)
public static int sum(int[] a) {
Summer firstHalf = new Summer(a, 0, a.length/2);
Summer secondHalf = new Summer(a, a.length/2, a.length);
Thread thread1 = new Thread(firstHalf);
thread1.start();
Thread thread2 = new Thread(secondHalf);
thread2.start();
try {
thread1.join();
thread2.join();
} catch (InterruptedException ie) {}
return firstHalf.getSum() + secondHalf.getSum();
}
How many threads to use?
• You can find out how many cores/CPUs your machine has:
int cores = Runtime.getRuntime().availableProcessors();
• You'd think that would be the ideal number of threads.
• Your program does not always get all of the cores to use.
• Too few threads can be bad (core(s) sit idle).
• Too many threads can be bad (overhead of creatingThreads).
• A bad ratio can slow the algorithm: e.g. 8 threads for 6
cores.
• If threads are lightweight to create, making tons of
threads can be very effective (e.g. make 1000 threads, set
them all loose!).
• Java'sThreads are too heavy-weight for this to be practical.
Amdahl's Law
• Amdahl's Law:The speedup that can be achieved by
parallelizing a program is limited by the sequential
fraction of the program.
• Example: If 33% of the program must be performed sequentially,
no matter how many processors you use, you can only get a 3x
speedup.
• An example of diminishing returns from adding more
processors.
• "Nine couples can't make a baby in one month."
• Therefore, part of the trick becomes learning how to
minimize the portion of the program that must be
performed sequentially.
• Making better parallel algorithms.
Map/Reduce
• Map/Reduce: A strategy for implementing parallel algorithms.
• map:A master worker takes the problem input, divides it into
smaller sub-problems, and distributes the sub-problems to
workers (threads).
• reduce:The master worker collects sub-solutions from the
workers and combines them in some way to produce the overall
answer.
• Frameworks and tools have been written to perform
map/reduce.
• MapReduce framework by Google
• Hadoop framework byYahoo!
• related to the ideas of
Big Data and Cloud Computing
• also related to functional programming

More Related Content

Similar to 12. Parallel Algorithms.pptx

Multicore_Architecture Book.pdf
Multicore_Architecture Book.pdfMulticore_Architecture Book.pdf
Multicore_Architecture Book.pdfSwatantraPrakash5
 
DA lecture 3.pptx
DA lecture 3.pptxDA lecture 3.pptx
DA lecture 3.pptxSayanSen36
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxSyed Zaid Irshad
 
6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptx6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptxSimRelokasi2
 
parallel Questions &amp; answers
parallel Questions &amp; answersparallel Questions &amp; answers
parallel Questions &amp; answersMd. Mashiur Rahman
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structureSelf-Employed
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Akhila Prabhakaran
 
Interactions complicate debugging
Interactions complicate debuggingInteractions complicate debugging
Interactions complicate debuggingSyed Zaid Irshad
 
Lecture 1
Lecture 1Lecture 1
Lecture 1Mr SMAK
 
Asynchronous and parallel programming
Asynchronous and parallel programmingAsynchronous and parallel programming
Asynchronous and parallel programmingAnil Kumar
 
Parallel Algorithms Advantages and Disadvantages
Parallel Algorithms Advantages and DisadvantagesParallel Algorithms Advantages and Disadvantages
Parallel Algorithms Advantages and DisadvantagesMurtadha Alsabbagh
 
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingConcurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingSachintha Gunasena
 
Migration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsMigration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsZvi Avraham
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdfNayanChandak1
 
ICS 2410.Parallel.Sytsems.Lecture.Week 3.week5.pptx
ICS 2410.Parallel.Sytsems.Lecture.Week 3.week5.pptxICS 2410.Parallel.Sytsems.Lecture.Week 3.week5.pptx
ICS 2410.Parallel.Sytsems.Lecture.Week 3.week5.pptxjohnsmith96441
 

Similar to 12. Parallel Algorithms.pptx (20)

Cs 331 Data Structures
Cs 331 Data StructuresCs 331 Data Structures
Cs 331 Data Structures
 
Multicore_Architecture Book.pdf
Multicore_Architecture Book.pdfMulticore_Architecture Book.pdf
Multicore_Architecture Book.pdf
 
DA lecture 3.pptx
DA lecture 3.pptxDA lecture 3.pptx
DA lecture 3.pptx
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Chap5 slides
Chap5 slidesChap5 slides
Chap5 slides
 
6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptx6-9-2017-slides-vFinal.pptx
6-9-2017-slides-vFinal.pptx
 
04 performance
04 performance04 performance
04 performance
 
parallel Questions &amp; answers
parallel Questions &amp; answersparallel Questions &amp; answers
parallel Questions &amp; answers
 
Algorithm and C code related to data structure
Algorithm and C code related to data structureAlgorithm and C code related to data structure
Algorithm and C code related to data structure
 
Nbvtalkatjntuvizianagaram
NbvtalkatjntuvizianagaramNbvtalkatjntuvizianagaram
Nbvtalkatjntuvizianagaram
 
Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)Introduction to OpenMP (Performance)
Introduction to OpenMP (Performance)
 
Interactions complicate debugging
Interactions complicate debuggingInteractions complicate debugging
Interactions complicate debugging
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Asynchronous and parallel programming
Asynchronous and parallel programmingAsynchronous and parallel programming
Asynchronous and parallel programming
 
Parallel Algorithms Advantages and Disadvantages
Parallel Algorithms Advantages and DisadvantagesParallel Algorithms Advantages and Disadvantages
Parallel Algorithms Advantages and Disadvantages
 
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingConcurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
 
RAJAT PROJECT.pptx
RAJAT PROJECT.pptxRAJAT PROJECT.pptx
RAJAT PROJECT.pptx
 
Migration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsMigration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming Models
 
Algorithm Analysis.pdf
Algorithm Analysis.pdfAlgorithm Analysis.pdf
Algorithm Analysis.pdf
 
ICS 2410.Parallel.Sytsems.Lecture.Week 3.week5.pptx
ICS 2410.Parallel.Sytsems.Lecture.Week 3.week5.pptxICS 2410.Parallel.Sytsems.Lecture.Week 3.week5.pptx
ICS 2410.Parallel.Sytsems.Lecture.Week 3.week5.pptx
 

Recently uploaded

Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 

Recently uploaded (20)

Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 

12. Parallel Algorithms.pptx

  • 2. Why Parallel Algorithms • It is the most important element of parallel computation, without no problem could be solved in parallel. • A parallel algorithm defines how a problem can be solved on the given parallel computer. • Specifically, specifying how the problem is divided into sub-problems, and how the partial solutions are combined to produce the final answer.
  • 3. Changing our assumptions • So far most or all of our study has assumed the sequential programming: Each statement executes in sequence. • Removing this assumption creates challenges and opportunities: • Programming: How can we divide work among threads of execution and coordinate (synchronize) among them? • Algorithms: How can activities in parallel speed-up a program? (more throughput: work done per unit time)
  • 4. Brief Arch. history • From ~1980-2005, CPU speed (GHz) got exponentially faster. • Roughly doubled every 1.5 years ("Moore's Law"). • But we are reaching limits of classic CPU design. • Increasing speeds further generates too much heat. • Any singleCPU over ~3-4 GHz crashes or burns out in normal usage. • Current work-around: Use multiple processors. • Or, more recently, produce one CPU containing many processors in it. • core: A processor-within-a-processor. • A "multi-core" processor is one with several cores inside.
  • 5. Using many cores • Run multiple different programs at the same time (processes). • Example: Core 1 runs Firefox; Core 2 runs iTunes; Core 3 runs Eclipse... • Technically, programs receive "time slices" of attention from cores. • The OS (Windows, OSX, Linux) already does this for you. • Do multiple things at once within the same program (threads). • Requires rethinking everything about our algorithms, from how to implement data-structure operations, to Big-Oh, to ... • Writing correct/fast parallel code is much harder than sequential. • Especially in common languages like Java and C++.
  • 6. Parallel vs Distributed • In both parallel and distributed systems, the events are partially ordered. • The distinction between parallel and distributed is not always very clear. • In parallel systems, the primarily issues are • speed-up and increased data handling capability. • Using multiple processing resources (CPUs, cores) at once to solve a problem faster. Example:A sorting algorithm that has several threads each sort part of the array. • In distributed systems the primary issues are • fault-tolerance, synchronization, scalability, etc.
  • 7. Algorithm example • Write a method named sum that computes the total sum of all elements in an array of integers. • For now, just write a normal solution that doesn't use parallelism. // normal sequential solution int total = 0; for (int i = 0; i < a.length; i++) { total += a[i];
  • 8. Parallelizing the algorithm • How can we parallelize this algorithm if we have 2 CPUs/cores? • Compute sum of each half of array in a thread. • Add the two sums together.
  • 9. Thread and Runnable • To run some code in its own thread: • Write a class that implements the Runnable interface. • Its run method contains the code you want to execute. • Construct a newThread object, passing your runnable to it. • Then start the thread. public interface Runnable { // implement this public void run(); } public class Thread { // construct one public Thread(Runnable runnable) public void start()
  • 10. Cont. • First, write a method that sums a partial range of the array: // normal sequential solution public static int sumRange(int[] a, int min, int max) { int total = 0; for (int i = min; i < max; i++) { total += a[i]; } return total; }
  • 11. Cont. • Now write a runnable class that can sum a partial array: public class Summer implements Runnable { private int[] a; private int min, max, sum; public Summer(int[] a, int min, int max) { this.a = a; this.min = min; this.max = Math.min(max, a.length); } public int getSum() { return sum; } public void run() { sum = Sorting.sumRange(a, min, max); } }
  • 12. Parallel vs Distributed • Now write the sum method to run Summers in threads: // Parallel version (two threads) public static int sum(int[] a) { Summer firstHalf = new Summer(a, 0, a.length/2); Summer secondHalf = new Summer(a, a.length/2, a.length); Thread thread1 = new Thread(firstHalf); thread1.start(); Thread thread2 = new Thread(secondHalf); thread2.start(); try { thread1.join(); thread2.join(); } catch (InterruptedException ie) {} return firstHalf.getSum() + secondHalf.getSum(); }
  • 13. How many threads to use? • You can find out how many cores/CPUs your machine has: int cores = Runtime.getRuntime().availableProcessors(); • You'd think that would be the ideal number of threads. • Your program does not always get all of the cores to use. • Too few threads can be bad (core(s) sit idle). • Too many threads can be bad (overhead of creatingThreads). • A bad ratio can slow the algorithm: e.g. 8 threads for 6 cores. • If threads are lightweight to create, making tons of threads can be very effective (e.g. make 1000 threads, set them all loose!). • Java'sThreads are too heavy-weight for this to be practical.
  • 14. Amdahl's Law • Amdahl's Law:The speedup that can be achieved by parallelizing a program is limited by the sequential fraction of the program. • Example: If 33% of the program must be performed sequentially, no matter how many processors you use, you can only get a 3x speedup. • An example of diminishing returns from adding more processors. • "Nine couples can't make a baby in one month." • Therefore, part of the trick becomes learning how to minimize the portion of the program that must be performed sequentially. • Making better parallel algorithms.
  • 15. Map/Reduce • Map/Reduce: A strategy for implementing parallel algorithms. • map:A master worker takes the problem input, divides it into smaller sub-problems, and distributes the sub-problems to workers (threads). • reduce:The master worker collects sub-solutions from the workers and combines them in some way to produce the overall answer. • Frameworks and tools have been written to perform map/reduce. • MapReduce framework by Google • Hadoop framework byYahoo! • related to the ideas of Big Data and Cloud Computing • also related to functional programming

Editor's Notes

  1. Parallel Computing: In parallel computing multiple processors performs multiple tasks assigned to them simultaneously. Memory in parallel systems can either be shared or distributed. Parallel computing provides concurrency and saves time and money. Distributed Computing: In distributed computing we have multiple autonomous computers which seems to the user as single system. In distributed systems there is no shared memory and computers communicate with each other through message passing. In distributed computing a single task is divided among different computers. Fault tolerance can be built into a system to remove the risk of it having a single point of failure. To do so, the system must have no single component that, if it were to stop working effectively, would result in the entire system failing. Fault tolerance is reliant on aspects like load balancing and failover, which remove the risk of a single point of failure. It will typically be part of the operating system’s interface, which enables programmers to check the performance of data throughout a transaction.  Cloud Scalability is the ability to scale on-demand the facilities and services as and when they are required by the user. Cloud Fault Tolerance is tolerating the faults by the cloud that are done by mistake by the user.