Answer the questions below according to the lab specification. Write
your answers directly in this text file and submit it to complete the
PROBLEM 1: Code Overview
(A) Vector and Matrix
Examine the header file `matvec.h’ which gives type definitions and
declares functions associated with a simple matrix and vector type.
For the matrix type `matrix_t’ with R rows and C columns, how is a 2D
matrix actually laid out in memory?
(B) Getting and Setting Elements
For the `matrix_t’ and `vector_t’ types, convenient means to get and
set elements is provided. This mechanism is used in the utility
functions in `matvec_util.c’ and defined in `matvec.h’.
Describe how one would get element (R,C) of `matrix_t’ or set it to
value Z. Why are these mechanisms not functions?
PROBLEM 2: Timing Rows vs Columns
(A) row_sums vs col_sums Timing
Compile and run the `matsums_main’ executable using the provided
`Makefile’ (typing `make’ should suffice).
Run this program with differing parameters which control the number of
rows and columns in the matrix which is summed. Show some example runs
with different parameters including on large square matrix with 8000
rows and 8000 columns.
Note any speed differences between the two on large matrices.
(B) row_sums vs col_sums speed
Examine the source code for the functions `row_sums()’ and
`col_sums()’ in the file `matsums_funcs.c’. Describe why the
timing/speed differences you observed previously are occurring based
on features of the source code you see and the layout of the
`matrix_t’ that is being summed.
PROBLEM 3: opt_col_sums()
Complete the function `opt_col_sums()’ in file `matsums_funcs.c’. This
function should have identical behavior to `col_sums()’ (it sums the
columns of the matrix into a provided array). However, it should be
*optimized* so that it achieves performance near to that of the
`row_sums()’ function. To achieve this, re-arrange the loops to
iterate as efficiently as possible with respect to the memory
system. Feel free to ask course staff for hints on how to do this or
do some online research.
To time `opt_col_sums()’, uncomment relevant blocks in the
`matsums_main.c’ program that are provided for it.
Paste your source code and a copy of the timing results of running
`matsums_main’ on an 8000 by 8000 matrix.