Develop a program that calculates the sum of elements of an array using POSIX threads for concurrent execution. Please write it using C++ or C. 1. Create a program that has a global array of 20 integers, you may use predefined values or generate random values. 2. Create 5 POSIX threads. Each of these will be responsible for calculating the sum of a specific region in the array. The first thread will calculate the sum of elements 0 to 3. The second will calculate the sum of elements 4 to 7, the third will sum elements 8 to 11, the fourth will sum elements 12 to 15, and the fifth will sum elements 16 to 19. 3. The main program will wait for these threads. a. Use pthread_join(3) 4. After the threads have finished, the main thread shall combine the partial sums computed by each thread to obtain the final sum. 5. The main thread shall display the partial sums from each child, and the total sum

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please make sure that the program has the following

  1. Thread Creation
    1. Proper creation of the five threads.
    2. Threads access only their assigned region in the array.
    3. Properly joining on ALL threads.
  2. Thread Execution
    1. Accurately calculating the partial sums by each thread.
    2. Returning the proper value to the main thread.
  3. Collection and Display of Results
    1. Properly collecting the values from the threads and displaying the sum.
  4. Code Structure
    1. Good quality code with appropriate functions, variable names, and comments.
  5. Error Handling
    1. Checking for errors from system calls and major library routines.
    2. Proper error messages if they occur.
Develop a program that calculates the sum of elements of an array using POSIX
threads for concurrent execution.
Please write it using C++ or C.
1. Create a program that has a global array of 20 integers, you may use
predefined values or generate random values.
2. Create 5 POSIX threads. Each of these will be responsible for calculating the
sum of a specific region in the array. The first thread will calculate the sum of
elements 0 to 3. The second will calculate the sum of elements 4 to 7, the
third will sum elements 8 to 11, the fourth will sum elements 12 to 15, and the
fifth will sum elements 16 to 19.
3. The main program will wait for these threads.
a. Use pthread_join(3)
4. After the threads have finished, the main thread shall combine the partial
sums computed by each thread to obtain the final sum.
5. The main thread shall display the partial sums from each child, and the total
sum
Transcribed Image Text:Develop a program that calculates the sum of elements of an array using POSIX threads for concurrent execution. Please write it using C++ or C. 1. Create a program that has a global array of 20 integers, you may use predefined values or generate random values. 2. Create 5 POSIX threads. Each of these will be responsible for calculating the sum of a specific region in the array. The first thread will calculate the sum of elements 0 to 3. The second will calculate the sum of elements 4 to 7, the third will sum elements 8 to 11, the fourth will sum elements 12 to 15, and the fifth will sum elements 16 to 19. 3. The main program will wait for these threads. a. Use pthread_join(3) 4. After the threads have finished, the main thread shall combine the partial sums computed by each thread to obtain the final sum. 5. The main thread shall display the partial sums from each child, and the total sum
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 1 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education