The aim of this part of the assignment is to create multiple threads and perform a timing analysis on when and how the threads are being executed in a time sharing multiprogramming system.
The program requires two command line arguments to execute and they are:
The program creates the specified number of threads and assigns to each one of them an interval of integer values, say (a, b), where a is the starting value and (b-1) is the end value. Each thread computes a value s, which is based on your student+id, choose one of the following for implementation:
If your student-id mod 3 = 0, then do this: the summation of the integers in its interval, that is:
a + (a+1) + (a+2) + . . . + (b-2) + (b-1). In other words you compute the sum of the integers.
If your student-id mod 3 = 1, then do this: the summation of the squares of integers in its interval, that is :
a2 + (a+1) 2 + (a+2 )2 + . . . + (b-2)2 + (b-1)2. In other words you compute the sum of squares.
If your student-id mod 3 = 2, then do this: the product of integers in its interval, that is:
a (a+1) (a+2) . . . (b-2) (b-1) . In other words you compute the factorial.
Essentially, this program parallelizes the computation of sum, sum of squares or factorial, in the interval [0, numthreads * increment), balancing the load equally among the number of threads specified. We say parallelizes in quotes because in a single-core machine, the threads would execute concurrently, that is, sharing the same processors time. Only if this program is run on a multi-core machine, then the threads would really run in parallel.
Once this program is working, compute the time it takes to execute the program. You can use the time function in Unix. Extend the program further so that each thread will compute the time it takes to execute individually and print the result. For this you may want to use the gettimeofday and ctime functions in the C programming language, or any other appropriate time functions.