CMSC 216 Exercise #6


CMSC 216 Exercise #6 Spring 2019
Threads Deadline: Wed, May 8 (lab time)
1 Overview
In this exercise you will use threads to write a program that computes the maximum and the sum of data
present in an array. For this assignment:
There are no public, release nor secret tests.
There is no project distribution (usual folder we post).
You need to work with classmates (in groups of 3 students).
You need to show your work to your teaching TA on Wednesday’s lab (May 8). Notice that all members
of your team will receive the same score.
If you don’t show your work to a TA you will not get any credit. Only one member of your group needs
to do the demo (not all of you need to be present). Even if some of your members belong to another
section, only one person needs to present.
You may use any code we have posted for our lectures/labs.
To submit upload a zip file with your code to the submit server using the appropriate entry. Only one
member of your group needs to submit.
If you have questions about this assignment, please post them in Piazza. This will simplify the process

CMSC 216作业代做、program留学生作业代做、代写c/c++课程设计作业、c/c++编程语言作业调试
of keeping the class informed about updates. It is your responsibility to check Piazza often regarding
any possible updates and clarifications.
There is only one deadline (no late submission).
2 Specifications
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.
1
After completing a task (maximum or sum) the program will display the results (maximum value or
sum) if requested by the user.
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.
3 Grading Criteria
Your project grade will be determined by the following:
Maximum using multiple threads 40 pts
Sum using multiple threads 30 pts
Correct sum computation 10 pts
Report 10 pts
Code Style 10 pts
3.1 Style grading
Follow the C style guidelines available at:
http://www.cs.umd.edu/~nelson/classes/resources/cstyleguide/
4 Submission
Create a file named authors.txt with the names and directory ids (e.g., terp1, NOT your student number)
of the members in your group.
Create a folder with the .c code, the report and the authors.txt file. Zip that folder and upload it to the
submit server. Only one member of your team needs to upload the submission. To submit your exercise
use the submit server web interface (you will not be able to submit using the submit command in grace).
2
5 Academic Integrity
Please see the syllabus for project rules and academic integrity information. All programming assignments in
this course are to be written individually (unless explicitly indicated otherwise in a written project handout).
Cooperation between students is a violation of the Code of Academic Integrity.

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或邮箱:99515681@qq.com

微信:codehelp

上一篇:metasploit下Windows的多种提权方法


下一篇:利用银行家算法避免死锁