w06-g02-CGsolver-class
Conjugate Gradient Solver (CGsolver) Class
Objective
The overall objective of this assignment is to implement the Conjugate Gradient Method in a class CGsolver
. This solver will later be part of the class project Direct Stiffness Method.
The code for this class needs to be split into a header file .hpp
and its implementation in the .cpp
file. Most of the interface of the CGsolver
class is already implemented in tehpc/src/conjugate_gradient_solver.hpp
, and is used in a simple test tehpc/tests/CGsolver_test.cpp
. You have to implement the method solve
of the CGsolver
class in tehpc/src/conjugate_gradient_solver.cpp
.
Please recycle the code from last week tehpc/examples/conjugate_gradient_function.cpp
(method described in details in #2 (closed)).
Implementation
-
load appropriate modules by performing the following command in your terminal:
source tehpc/tools/tehpc_load_modules.sh
. -
If
conjugate_gradient_solver.cpp
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(CGsolver_test)
in thetehpc/tests/CMakeLists.txt
to include theCGsolver_test
in compilation. -
Compile your code, use the following steps (this is new):
a. go into
tehpc/build/
b. type: either
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_TESTS:STRING=ON ..
orccmake ..
and make sure that build type isDebug
andTests
are ON (you only have to do this the very first time).c. type:
make
(do this whenever you want to recompile). -
Correct all compilation errors. Use code from
tehpc/basics/conjugate_gradient_function.cpp
and the provided operator overloading (seetehpc/src/matrix.hpp
,tehpc/src/vector.hpp
and others) to implementtehpc/src/conjugate_gradient_solver.cpp
. Important: you are not allowed to change theCGsolver_test.cpp
file. -
If the code compiles without errors, run the test:
a. go into
tehpc/build/tests/
b. type:
./CGsolver_test
-
Make sure that the code runs without error and check printed message to see if it went to the end. Correct errors if needed. Again, you are not allowed to change the
CGsolver_test.cpp
files. -
run valgrind to check for memory leakage:
valgrind --leak-check=full ./CGsolver_test
. -
correct memory leakage
-
Make sure that your code is well structured and commented.