CS211 Homework 4

This homework combines the threaded and matrix assignments originally listed as separate in the syllabus. I thought that you would get more out of the experience this way. The goal of the homework is to learn how instructions are optimized to run on a CPU. The task of the homework is simple: write a function to count the number of times a specified number appears in a provided matrix. The function signature is defined in hw04.h and is this:

// Search for value in the matrix, returning the number of times it is found.
int count(int** matrix, size_t rows, size_t columns, int value);

Place your definition of that function in a file “hw04.c”. Your file must have a comment block at the top like this:

/*
 * Author: your name
 * Netid: your netid
 * Aid: If in doubt, list anything you referenced. A stack overflow post, chatgpt, gemini, your friend Bob, etc. If referring to an LLM, you must included a link to a particular session. Just saying "I asked chatgpt" isn't a get out of trouble free statement. If two submissions are nearly identical and nothing is listed, I will have to assume that there was copying with an attempt at obfuscation.
 */

Mechanics

A makefile is provided. It will both compile and test your code. Compile your code with make hw04. Test your code make running make. Please be aware that the make command uses timestamps to decide if it needs to recompile, so moving files around may confuse it. If in doubt, remove you hw04 manually to be sure it is rebuilt after making changes.

Grading

Your program must achieve speed improvements over the simplistic search. Ways to improving the program come from things we’ve learned in class, such as computer architecture optimizations and multithreading. Note that you can each improvement in either the total CPU time taken, or the wall time. As we’ve discussed, those are different when threads are in use. When the provided matrix is small, you will find it easier to improve CPU time, and when the matrix is very large you are asked to make a larger improvement, which you will find easier to do in wall time.

For consistency, testing will be done in the ilab machines ilab03 or ilab04 (which are both using AMD EPYC 7352 CPUs).

Submission

Submit your hw04.c file through Canvas.

Extra Credit

There are two sources of extra credit in this assignment.

First, anyone who greatly outperforms the target times can receive some extra for their efforts, up to an extra point depending upon your improvement’s magnitude relative to the best improvements in the class.

Second, there is a way to hack this assignment using knowledge we’ve gained in this class. Another point of extra credit is available, although if more than 15 students find a solution then the rewards will diminish (e.g. rewards will be 15/n, where n is the number of students). To submit a solution, upload a second file named hw04_hack.c along with the regular solution hw04.c. This does not replace doing the ordinary, non-hack version of the assignment.