Histogram with pthreads

Due: October 28, 2016

In this assignment, you will calculating an histogram for a given array of numbers and for a given histogram interval. First generate an array of 10,000 integer numbers between 1 and 20 in an input array. Have another array, called the histogram array, whose size will be equal 20/(histogram_interval). For example, if the histogram interval is 4, then the histogram array will be a 5-element array: the count of the input numbers between 1-4 will be stored in histogram_array[0], the count of the input numbers between 5-8 will be stored in histogram_array[1], and so on.

Divide the 10000 integers among 10 pthreads, such that the first pthread takes care of the first 1000 elements, the second pthread takes care of the second array and so on. The histogram array is shared among the pthreads. A pthread traverses its part of the array, and on encountering a number, increments the count of the corresponding element in the histogram_array. The main program finally prints the counts of the histogram array.

Write also a sequential version, using only the main program, to test the correctness of your output. Show the timings of the sequential and the pthread version for different histogram intervals, namely, 2, 4, 5 and 10. Use getimeofday to measure the times.