Calculating the average of a list of integers by exploiting parallelism: Suppose we have an array of integers: 1, 10, 9, 100, 23, 4, 11, 12, 3, and 1. The size of this array is 10. Now if we want to calculate the average, we can simply do: average = sum of elements/ total elements. Now, if we have a large number of elements, then it will take a lot of time to calculate the average. We can utilize parallelism by dividing the task of finding the sum among different threads. Suppose a thread t1 finds the sum of first 4 elements: sum1=1+10+9+100= 120 count=4 And another thread t2 calculates the sums of remaining 6 elements: sum2=23+4+11+12+3=53 count=6 Then average calculated as: Total Sum = sum1+sum2= 120+53= 173 Total Count= count1 + count2= 4+6=10 Average= Total Sum/Total Count= 173/10= 17.3 Assume that we want to compute the average of a list of numbers. The numbers are not in a single file, but they are placed in several files. Now write a program that is passed the names of files containing integers as command line arguments. The program will then create as many threads as the number of files. Each thread will be passed as the name of a file as an argument. All threads will then work in parallel to compute the sum of all the numbers in the file passed to them as argument. Each thread will then return the sum and the count of numbers to the main thread. The main thread will then compute the average as given below and print the average on the screen. School of Computer SciencePage 1TotalSum= sum1+ sum2+ sum3+………+sumn TotalCount=count1+count2+count3+…….+countn Average= TotalSum/TotalCount

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Calculating the average of a list of integers by exploiting parallelism:
Suppose we have an array of integers: 1, 10, 9, 100, 23, 4, 11, 12, 3, and 1. The size of this array is 10.
Now if we want to calculate the average, we can simply do:
average = sum of elements/ total elements.
Now, if we have a large number of elements, then it will take a lot of time to calculate the average. We
can utilize parallelism by dividing the task of finding the sum among different threads. Suppose a thread
t1 finds the sum of first 4 elements:
sum1=1+10+9+100= 120
count=4
And another thread t2 calculates the sums of remaining 6 elements:
sum2=23+4+11+12+3=53
count=6
Then average calculated as:
Total Sum = sum1+sum2= 120+53= 173
Total Count= count1 + count2= 4+6=10
Average= Total Sum/Total Count= 173/10= 17.3
Assume that we want to compute the average of a list of numbers. The numbers are not in a single file,
but they are placed in several files. Now write a program that is passed the names of files containing
integers as command line arguments. The program will then create as many threads as the number of
files. Each thread will be passed as the name of a file as an argument. All threads will then work in
parallel to compute the sum of all the numbers in the file passed to them as argument. Each thread will
then return the sum and the count of numbers to the main thread. The main thread will then compute
the average as given below and print the average on the screen.
School of Computer SciencePage 1TotalSum= sum1+ sum2+ sum3+………+sumn
TotalCount=count1+count2+count3+…….+countn
Average= TotalSum/TotalCount

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY