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.