Part -1

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:

  • numthreads an integer value that specifies how many threads will be created, and
  • increment the number of integer values that each thread will work with.

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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.