Question
Write a C program that finds the sum of all the elements in an array. You have to implement 3 versions of the program. The
Write a C program that finds the sum of all the elements in an array. You have to implement 3 versions of the program. The program will have an integer array of 20,000 elements. Populate the array using random values between -100 and 100.
a) The first version of the program is single threaded. Show the sum, and also the time required to execute the program.
b) The second version of the program has 5 threads. Appropriately divide the summation work among the threads, and then use the main thread to find the sum from the partial sums created by the threads. Show the sum and the time required to execute the program.
c) The third version of the program is similar to the second version, except it uses 10 threads.
Write the program in C, and use pthreads to perform the required actions. Also include a print screen of the execution of the program in addition to the source code.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started