Develop a program in either C or C++ that calculates the sum of elements of an array using POSIX threads for concurrent execution. Provide a makefile or place build instructions in a comment at the start of your main source file. 1. Create a program that has a global array of 25 integers, you may use predefined values or generate random values. 2. Create 5 POSIX (worker) 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 4. The second will calculate the sum of elements 5 to 9, the third will sum elements 10 to 14, the fourth will sum elements 15 to 19, and the fifth will sum elements 20 to 24. 3. Each of the 5 worker threads must print out the values that it is summing. 4. The main program will wait for these threads. a. Use pthread_join(3) to wait for a thread b. Collect the partial sum for that thread from the "retval" 5. After the threads have finished, the main thread shall combine the partial sums computed by each thread to obtain the final sum. 6. The main thread shall display the partial sums from each child, and the total sum. Program needs to meet the following criteria: → Thread Creation ◆ Proper creation of the five threads. ◆ Threads access only their assigned region in the array. ◆ Properly joining on ALL threads. The main thread must create 5 worker threads and inform the thread of the range of array indices it may access. Note that when you create a thread you may pass in a single pointer to whatever data structure you wish. For example, you could pass in a pointer to a structure with whatever values you want in that structure. Worker threads may only access the array indices that they are assigned. The main thread must perform a join on each of the worker threads and recover the partial sum from that thread. Note that each thread may return an integer exit status, and this will be available as the "retval" in a call to pthread_join(3). → Thread Execution ◆ Accurately calculating the partial sums by each thread. ◆ Returning the proper value to the main thread. ◆ Each worker thread must calculate the partial sum of its assigned array values. Each worker thread must return its partial sum as its exit status. Note that the exit status for a thread is available as the "retval" in a call to pthread_join(3). The main thread must collect the partial sums from each thread. Note that an integer exit status is available in the "retval" parameter to pthread_join(3). → Collection and Display of Results Properly collecting the values from the threads and displaying the sum. The main thread should display the partial sums collected, add them together, and display the final sum. → Code Structure Good quality code with appropriate functions, variable names, and comments. ◆ Design the program to use appropriate functions. At the very least, the program should have one function that each of the worker threads will execute. That means that each worker thread executes the same function, but the call to that function may pass in different parameters. ◆ Any variables that are used must have appropriate data types and be given a reasonable name which would be meaningful to someone unfamiliar with your code. Properly document the code so that it can be understood by someone unfamiliar with your code. Please avoid including "obvious" comments. → Error Handling Checking for errors from system calls and major library routines. Proper error messages if they occur. Any system calls or major library routines should be checked for errors upon their return. You do not want a call to fail and then blindly continue running. If any errors occur, issue meaningful error messages. Use the perror(3) library routine when appropriate. Note that system calls and library routines indicate errors differently. Be sure to read the manual pages for these calls!
Develop a program in either C or C++ that calculates the sum of elements of an array using POSIX threads for concurrent execution. Provide a makefile or place build instructions in a comment at the start of your main source file. 1. Create a program that has a global array of 25 integers, you may use predefined values or generate random values. 2. Create 5 POSIX (worker) 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 4. The second will calculate the sum of elements 5 to 9, the third will sum elements 10 to 14, the fourth will sum elements 15 to 19, and the fifth will sum elements 20 to 24. 3. Each of the 5 worker threads must print out the values that it is summing. 4. The main program will wait for these threads. a. Use pthread_join(3) to wait for a thread b. Collect the partial sum for that thread from the "retval" 5. After the threads have finished, the main thread shall combine the partial sums computed by each thread to obtain the final sum. 6. The main thread shall display the partial sums from each child, and the total sum. Program needs to meet the following criteria: → Thread Creation ◆ Proper creation of the five threads. ◆ Threads access only their assigned region in the array. ◆ Properly joining on ALL threads. The main thread must create 5 worker threads and inform the thread of the range of array indices it may access. Note that when you create a thread you may pass in a single pointer to whatever data structure you wish. For example, you could pass in a pointer to a structure with whatever values you want in that structure. Worker threads may only access the array indices that they are assigned. The main thread must perform a join on each of the worker threads and recover the partial sum from that thread. Note that each thread may return an integer exit status, and this will be available as the "retval" in a call to pthread_join(3). → Thread Execution ◆ Accurately calculating the partial sums by each thread. ◆ Returning the proper value to the main thread. ◆ Each worker thread must calculate the partial sum of its assigned array values. Each worker thread must return its partial sum as its exit status. Note that the exit status for a thread is available as the "retval" in a call to pthread_join(3). The main thread must collect the partial sums from each thread. Note that an integer exit status is available in the "retval" parameter to pthread_join(3). → Collection and Display of Results Properly collecting the values from the threads and displaying the sum. The main thread should display the partial sums collected, add them together, and display the final sum. → Code Structure Good quality code with appropriate functions, variable names, and comments. ◆ Design the program to use appropriate functions. At the very least, the program should have one function that each of the worker threads will execute. That means that each worker thread executes the same function, but the call to that function may pass in different parameters. ◆ Any variables that are used must have appropriate data types and be given a reasonable name which would be meaningful to someone unfamiliar with your code. Properly document the code so that it can be understood by someone unfamiliar with your code. Please avoid including "obvious" comments. → Error Handling Checking for errors from system calls and major library routines. Proper error messages if they occur. Any system calls or major library routines should be checked for errors upon their return. You do not want a call to fail and then blindly continue running. If any errors occur, issue meaningful error messages. Use the perror(3) library routine when appropriate. Note that system calls and library routines indicate errors differently. Be sure to read the manual pages for these calls!
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
Related questions
Question
please help with this
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education