using threads to write a program that computes the maximum and the sum of data present in an array

You need to write a program that will create an array with random integer values. Then one of two possible processings will be applied to this array:

– Max – You need to compute the maximum value in the array. Notice that for a number of threads greater than one, you need to assign to each thread an array segment. Just divide the array in equal length segments (when possible) based on the number of threads. For example, for an array of 1001 elements and 2 threads, the first thread can process the first half (500) and the second thread the rest (501).

– Sum – You need to correctly compute the sum of elements in the array based on the following formula: sum = (sum + a[i]) % 1000000, where a[i] represents an array element.

• The program relies on command line arguments to provide the following information: – Number of elements – Number of threads – Seed (for random number generator) – Task (1 for max, 2 for sum) – Print Results (Y or N)

• Feel free to provide any additional parameters you understand you need. • After completing a task (maximum or sum) the program will display the results (maximum value or sum) if requested by the user.

1 • After completing a task, the program will display the wall clock time, the user time and the system/kernel time that it took to compute the maximum or the sum. Notice that this time information does not include the time to generate the random array.

• You need to have threads that run concurrently. For example, starting a thread and executing a join on it and repeating the process for each thread is not valid (you are executing threads sequentially.)

• The time information should follow the results.

• Report – Run experiments where you explore the impact of threads while computing the maximum value and the sum. Create a table where you increase the number of threads and the data sets. Your goal is to see whether using additional threads improves performance. Provide a short (one paragraph) explanation of your results. The information in this report is what you will be discussing with your TA in lab. You can create this report in a text file (report.txt)

• Remember that you may not use code from the internet.

• The current limits in grace will not allow you to create a large number of threads. You can change those limits (assuming you are using tcsh) by executing ”limit maxproc” followed by a number (e.g., limit maxproc 400). • Make sure you check the values returned by Pthreads functions; this will allow you to identify whether your code is failing. • An example of using the srand() and rand() functions can be found in the lecture example (dyn realloc.c) discussed while covering dynamic memory allocation.

Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code "Newclient" for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.