In this assignment, you will implement two C functions, one for performing 2-dimensional matrix-matrix multiplication, and the other for matrix vector multiplication. The function signatures are already given as follows and you can use the class examples (mm.c and matvec.c) as the starting point for creating your implementation.
/* C[N][M] = A[N][K] * B[K][M] */
void mm(int N, int K, int M, REAL * A, REAL * B, REAL * C, int A_rowMajor, int B_rowMajor);
/* C[N] = A[N][M] * B[M] */
void mv(int N, int M, REAL *A, REAL *B, REAL *C, int A_rowMajor);
The memory of each matrix (A, B, or C) is provided using REAL * A
, and its dimensions are specified as function parameters (N, K, or M). The elements of a 2-dimensional matrix could be stored in either row major or column major, identified using A_rowMajor
(or B_rowMajor
). If A_rowMajor
is non-zero, elements of A are stored in row major, otherwise, they are stored in column major. Your function should be able to handle any combination of the storage type of each matrix in the arguments, e.g. there are four cases for mm function and two cases for mv function. The results in matrix C should be always in row major.
The two source files provided include helper functions for initializing the matrix and for timing the execution, and a skeleton main function. You can compile and build the executable using gcc compiler (e.g. gcc -fopenmp -O0 mm.c -o mm
), in which –O0 is the flag optimization level 0 (no optimization). You can try –O2 or –O3 optimization flag. The output of your program should include both the time of computation (ms) and FLOPS performance. Please ignore the OpenMP parallel function (e.g. mm_omp_parallel
) at the moment.
In this assignment, you will implement two image processing algorithms, Image Histogram and Smoothing. OpenCV will be used for reading, writing and displaying images, and for getting and setting pixel values of an image. The read_timer()
function provided in mm.c
or matvec.c
can be used for timing purpose. The output of your program should include both the time of computation (ms) and FLOPS performance.
Image histogram provides a graphical representation of the intensity distribution of an image by quantifying the number of pixels for each intensity value considered. The description of image histogram and an OpenCV example for calcualting histogram can be found from OpenCV Tutorial for Histogram Calculation, and this C code provide a very concise implementation for the algorithm.
Image smoothing, which also referred to as image blurring is a simple and frequently used image processing operation. Depending the effects we want the smoothing operation to be applied to an image, we can apply different filter (coefficients matrix) to an image using the same algorithms. The description and an OpenCV example can be found from OpenCV Tutorial for Smoothing Images, and this C code provide concise code for image filtering algorithms.
For your implementation, while you can look at the OpenCV’s implementation for Histogram calculation and Image smoothing, they are much more complicated that we we need for the purpose of this assignment. It would be much easier you adapt the implmentation in the two C codes to the OpenCV image processing framework.
The methods for reading/writing/displaying an image and for getting/setting a pixel value of an image are pretty simple in OpenCV, which can be found from this short description with code sample for operating images. For your implementation, the recommendation is to start with the program for changing the contrast and brightness of an image, which provides executable codes for those operations.
The Assignment_1.zip package contains all the files you need, including mm.c, matvec.c, Histogram.cpp, and Smoothing.cpp, cmake CMakeLists.txt, image data, other sample souce files, an excel file for creating figures, this webpage, and a README.md file. The HistogramOpenCV.cpp, SmoothingOpenCV.cpp and DisplayImage.cpp files for OpenCV image processing are all from the OpenCV tutorial mentioned above and they are for your reference only. For your Histogram and Smoothing implementation, you should start with the ContractBrightness.cpp file and modify the code according to the implementation done in HIST.C and FILTER.C. README.md provide instructions for how to build each executable.
Your submission should be a single zipped file named LastNameFirstName.zip that include source code files and one report document file named as LastNameFirstNameAssignment1.pdf. The easiest way is to do your implementation in a folder unpacked from Assignment_1.zip. After that, add the report file and re-package the folder and submit it. The source files contain your implementations, and each file should be invidually compiled to generate executables. The report is max 3-page report that includes:
cat /proc/cpuinfo
command.