w08-tsk1-templates
Templates
Objective
In this task, we aim to template the class BaseMatrix
and the two inherited classes Matrix
and NodalArray
.
To accomplish this task, you need to modify the BaseMatrix
and the two inherited classes such that they are templated for the type of data stored in the matrix. One should be able to use Matrix
and NodalArray
for double
and for unsigned int
(you can use UInt
).
Implementation
-
load appropriate modules by performing the following command in your terminal:
source tehpc/tools/tehpc_load_modules.sh
. -
By modifying the relevant
CMakeLists.txt
, make sure that theUInt
versions of theBaseMatrix
,Matrix
, andNodalArray
are not compiled anymore. You will modify thedouble
version of those classes to create the templated generalized code. -
Add
tehpc_add_test(matrix_test)
in thetehpc/tests/CMakeLists.txt
to include the test in the compilation, and make sure that the old matrix tests are not compiled anymore. -
Compile your code, use the following steps:
a. go into
tehpc/build/
b. type:
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_TESTS:STRING=ON ..
or useccmake ..
to configure (you only have to do this the very first time).c. type:
make
(do this whenever you want to recompile). -
Change
BaseMatrix
to be templated by stored data type fordouble
andUInt
. Correct all compilation errors. -
If the code compiles without errors, run the test
matrix_test
and all other compiled tests:a. go into
tehpc/build/tests/
b. type:
./matrix_test
-
Make sure that ALL (compiled) tests run without error and return success. Correct all errors.
-
run valgrind to check for memory leakage:
valgrind --leak-check=full ./matrix_test
. Correct memory leakage if you encounter this problem. -
Make sure that your code is well structured and commented.