w07-g03-matrix-inherited
Base Matrix Class
Objective
The overall objective of this assignment is to implement an abstract matrix class BaseMatrix
, and make the current matrix class Matrix
inheritated from the parent class BaseMatrix
. The nodal array class NodalArray
will be another child class of BaseMatrix
. This abstract matrix class makes it possible to extend the project with more matrices without the need of modifying other classes.
Here, you need to implement an abstract class BaseMatrix
in tehpc/src/base_matrix.hpp
. Then you need to modify the matrix class Matrix
in tehpc/src/matrix
(both .hpp
and .cpp
) into a child class of BaseMatrix
. Move as much functionality as possible while keeping the BaseMatrix
class general enough to allow also the NodalArray
to inherit from it.
Implementation
-
load appropriate modules by performing the following command in your terminal:
source tehpc/tools/tehpc_load_modules.sh
. -
If
base_matrix.hpp
is not already included at the appropriate place intehpc/src/CMakeLists.txt
, add it. This makes sure that it is compiled. -
Add
tehpc_add_test(matrix_double_test)
in thetehpc/tests/CMakeLists.txt
to include the test in the compilation. -
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). -
Implement the base matrix class
BaseMatrix
intehpc/src/base_matrix.hpp
and modify the matrixMatrix
into a child class ofBaseMatrix
. Correct all compilation errors.a. compare
Matrix
andNodalArray
, move the shared part into theBaseMatrix
, including the #include directive, members and member functions. Consider using pure virtual methods where appropriate.b. make
Matrix
inheritated fromBaseMatrix
. The use ofvirtual function
could help. Pay attention to the constructor and destructor.c. read
tehpc/tests/matrix_double_test.cpp
, especially the function that has a pointer to the abstract class as one of its arguments, and compare the way of creating an object to last week.d. If you have enough time, repeat the procees of making
Matrix
inheritating fromBaseMatrix
by applying it also onNodalArray
. -
If the code compiles without errors, run the test
matrix_double_test
:a. go into
tehpc/build/tests/
b. type:
./matrix_double_test
-
Make sure that the tests run without error and return success.
-
run valgrind to check for memory leakage:
valgrind --leak-check=full ./matrix_double_test
. Correct memory leakage if you encounter this problem. -
Make sure that your code is well structured and commented.
-
Generate the
doxygen
software catalogue for the entire project:a. go into
tehpc/build/
b. type:
ccmake .
and switch on the option forTEHPC_DOC
, and configure withc
and generate withg
c. type:
make
d. download the generated catalogue files in
tehpc/build/docs/doxygen
to your local computer and view it.e. IMPORTANT: you can use the same approach for your project (i.e. stage II) for that, you need to copy the Doxygen part of
tehpc/CMakeLists.txt
toyour-project/CMakeLists.txt
, and copy thetehpc/docs/CMakeLists.txt
andtehpc/docs/Doxyfile.in
to the equivalent directories of your project.