w09-tsk1-basic-example-debug
Basic Example and Debug: Putting everything together
Objective
The overall objective of this task is to implement a basic example, which combines the various parts that we have been implementing over the past weeks. This basic example will be able to solve a problem of our choice. Furthermore, you will likely have to find bugs.
Implementation
-
load appropriate modules by performing the following command in your terminal:
source tehpc/tools/tehpc_load_modules.sh
. -
Consider the file named
basic_example.cpp
which is provided in thetehpc/examples/
directory. -
Modifytehpc/examples/CMakeLists.txt
such that it will compile thebasic_example
. -
Compile your code, use the following steps:
a.
go intotehpc/build/
b.
type: eithercmake -DCMAKE_BUILD_TYPE:STRING=Debug -DTEHPC_EXAMPLES:STRING=ON ..
orccmake ..
to configure (you only have to do this the very first time).c.
type:make
(do this whenever you want to recompile). -
Check that all the tests pass:
a. go into
tehpc/build/tests/
b. to run all tests at once, type:
make test
-
Likely, you will have at least one test failing. Correct the code such that all tests pass.a.
at this point, your model does not have any solver. Make sure that theModel
constructor calls the appropriate method (ofModel
) to register a solver based on information received in the input file.b.
despite calling the register method, there is still no solver initiated. To solve this, have a look at the functioninit_solver(...)
innonlinear_solver.cpp
and complete it following indications provided in the file. -
Implement thebasic_example
. It should do the following things:a.
complete thebasic_example.cpp
file following the indications in the file. You will have to call various methods of theModel
class. Some are new and provided with the preparation of the task. You can use the Doxygen-produced code catalogue to find appropriate methods. -
Correct all compilation errors.
-
If the code compiles without errors, run the example
basic_example
:a. go into
tehpc/build/examples/
b. type:
./basic_example
(this will run it with default input file)c. one can run the example for other input files with type:
./basic_example hancock .
with the relevant arguments. You can run it for the2dtruss
and thehancock
example, for both of which the input files are provided already in tehpc. -
Use the following different strategies to find the bug (or if you already found it, improve the code)
a. go through the code step-wise
usingfollowing the instructions from the demonstration (see other issue)gdb
b. you can decide to print more information to the screen. However, you do not want to permanently print information that the user does not need. For this, we included an option.
i.
Go into(use the crtl-shift-p >ccmake .
and putTEHPC_VERBOSE
ONCMake: Edit CMake Cache (UI)
and select the optionTEHPC_VERBOSE
ONii. recompile
iii. wherever in the code, you would like to print information, you can add
#ifdef TEHPC_VERBOSE
thenstd::cout << ... << std::endl;
, and end with#endif
. (just for your information, this was possible because of option intehpc/tehpc_config.hpp.in
file.) When you want to run clean simulations, you simply put theTEHPC_VERBOSE
option in cmake onOFF
.iv. Add such verbose printing at appropriate places in the important functions for this debugging case.
-
At some points, it might be good to check values to satisfy known conditions. You can use the
throw
command to throw a relevant error, if the conditions are not satisfied. You can then use thetry
functionality andcatch
the error to deal with it appropriately. -
Once your code runs through and converges, check if the results are reasonable (use the
analysis.ipynb
notebook to do so). -
run valgrind to check for memory leakage:
valgrind --leak-check=full ./basic_example
. Correct memory leakage if you encounter problems. -
In previous tasks over the past weeks, we added print statements to various functions in various classes (e.g., model, solvers, ...). Many of them are only needed when debugging. Please place them now between
#ifdef TEHPC_VERBOSE
and#endif
statements. -
Make sure that your code is well structured and commented.