|
TRUST 1.9.8
HPC thermohydraulic platform
|
When using TRUST code, you can create a module named Baltik for your own application that will be based on TRUST. That is what we will do here.
First, load TRUST environment and create your first project from a basic project template using TRUST command:
You can see that you have now:
You have now to add source files to your Baltik. These source files may be either patches (some TRUST source files that you will edit or in which you'll fix some bugs), or specific to your developments (i.e. new classes/....).
Here, we will just copy a source file from TRUST (in this tutorial we will add some prints to this file). To do so, copy the following TRUST .cpp file into your baltik project:
For versionning purpose, you will have to create a git repository:
Remark: If you are not able to commit files, you should first configure your username and email in git with :
Only README.BALTIK and configure script (automatically generated) are not added to your git repository.
Edit your project file project.cfg to specify name, author and executable.
Then configure your project: baltik_build_configure -execute this command launches both scripts: the ./baltik_build_configure and ./configure.
Check the status of your git repository with the - -ignored option to see the status of all files:
You can see that :
You can see information about your first commit and actual untracked changes.
You will now to make a basic build of your Baltik:
Try to build build the following versions:
Notice that TRUST optimized binary for profiling or a TRUST optimized binary for test coverage must exist in order to be able to compile your baltik's profiling or test coverage executable.
Now you have to initialize your baltik environnement:
For the sequel, we recommand you the Eclipse IDE editor linked to your TRUST repository, see Link Eclipse.
You can now launch a first computation:
Now we will start to do some modifications of the C++. Let's start by creating a new class:
Important remark: each time a source file is added to the project, you need to reconfigure your project to take new files into account when building the exectuable:
You can now build your project with Eclipse or in the terminal. Edit the two files with your favorite editor.
Note: If you are using Eclispe, you have to refresh your project to see your new files.
Now, we want to change the inheritance of the class in order that it inherits from the Interprete class instead of Objet_U. Interprete class is the base class of all the keywords doing tasks when read from the datafile, example (read, associate, solve, ...). You 'll have to:
In Eclipse: highlight the string Interprete and push the F3 button of your keyboard to open the declaration file of this class.
You can now test you new class:
You will have the following message:
The error occurs because this test case is not in your baltik but in TRUST project. To be able to copy it, you have to load the full environment (TRUST+your baltik).
You can now edit the data file:
Add the keywords my_first_class and End after the line where the problem is discretized.
You can eventually run this datafile with your baltik binary and check that this new keyword is recognized:
→ In the project explorer, right click on my_project and select Debug As/Debug configurations...
→ In Main tab, check Disable auto build then click on Apply
→ In Arguments tab, fill Program arguments: with Cx
→ Working directory: Copy the path to datafile matching $project_directory/build/Cx → Apply and Debug → Click on Yes to switch to the debug view → Click on Resume button (or F8) to run the calculation until the end.
Now, we want you to read this syntax from the datafile:
The recommended way is to use Param objects.
As an example, this is how it is done for
Then build et run your case in debug:
With Eclipse:
Or in a terminal:
Look for help inside the Domaine, Bord, Frontiere classes in Eclipse or in the HTML documentation to access to the:
Print these information in the terminal:
Afterwards, compute the sum of the control volumes of a domain discretized in VEF. Information about control volumes is in the Domaine_VF class (discretized domain) which can't be accessed from the domain, but only from the problem. So, you need to read another parameter from your datafile:
Where control_volumes is a DoubleVect returned by the Domaine_VF::volumes_entrelaces() method.
Now, compute and print the sum of the control volumes with a for loop.
We want now to add XD tags to create the automated documentation of your new code.
First, we have to create this documentation for the first time.
Open the documentation:
Now will add XD tags (keyword documentation) in cpp files. For this open trustify - guide for TRUST/baltik developers
Add a first tag (in comments) into your cpp file just after the openning brace of the 'interpreter_()' method: // XD english_class_name base_class_name TRUST_class_name mode description
Follow the instructions on trustify - guide for TRUST/baltik developers to document your developments.
You can now rebuild the documentation:
You can also use the following to check that the documentation is validated:
Notice that you must have XD commands in all your cpp classes.
TRUST uses also doxygen in order to build a C++ API documentation. Therefore, you need to add doxygen markers. Here are the classical markers:
| Command | Description |
|---|---|
| @brief | Short description (one line) |
| @param[in] | Input parameter description |
| @param[out] | Output parameter description |
| @param[in,out] | Input/output parameter description |
| @return / @returns | Return value description |
| @retval | Specific return value meaning |
| @throw / @throws | Exception that may be thrown |
| @pre | Precondition |
| @post | Postcondition |
| @note | Important note |
| @warning | Warning message |
| @see | Reference to related items |
| @since | Version information |
| @deprecated | Deprecation notice |
| @code / @endcode | Code example block |
| @author | Author information |
| @date | Date information |
| @version | Version information |
The best doxygen practices in TRUST are quite light:
You can also add some more printings, and here is how:
Then, in a terminal, rebuild the code:
To test your last developpements:
First sequentially:
Then in parallel:
and see the differences.
Here are the explanations:
Remark: during a parallel run, the Journal() output can be disabled. To try it, first clean your folder:
and run computation with -journal=0 option:
In practice, other options are available. To get the list, run:
Let's suppose that you now want to print something inside a file, let's say the volume of the sum of every control volumes. You would want to write a file with a name close to DataFileName_result.txt where DataFileName is the name of the data file.
To do so, you have to:
When this is done, compile your project and run the Cx datafile:
You should find in $project_directory/build/Cx/ your new file with the wanted information in it.
Now let's try to do the same for a parallel computation. Run your test case Cx in parallel mode:
and compare the files: Cx_result.txt, PAR_Cx_result.txt. Differences come from the fact that the 2 processors write into the file one after the other one. So the final content will be the value calculated on the last processor which will acces to the file.
You can try to launch one more time the calculation, the result may even differ.
A first fixo could be to apply the mp_sum() method on the sum obtained and add the print in the .txt file.
If you compare it to the sum obtained in the sequential run, the result is closer but we counted several times faces that belongs to the joint and to the virtual zones.
To completly parallelize the algorithm, rewrite it with the help of the mp_somme_vect(DoubleVect&) method. Add this print in the .txt file, you should now find the same value for the sequential and parallel calculation.
Remark: To validate parallelization in TRUST, you can use the command compare_lata:
You can see that there is no now differences and the maximal relative error encountered is about 4.e-12.
To see the performances, you can check the .TU files:
In TRUST, there are also deog test cases, such as Debog_VEF. Copy this test case to see what it does:
The, open the Debog_VEF.data file and search the Debog command. You can also try it by running a sequential calculation:
You should get two new files: seq and faces.
Then let's try a parallel run to see the differences:
Verify the data file, you should have now:
Moreover, you should also get a debog*.log and other DEBOG files next to your data file.
Inside the log file, you will have the message ERROR if the difference of an array value between you sequential and parallel run is greater than 1.e-6. Otherwise, you will have read OK.
You can add a debog instruction in your file mon_main.cpp located in $project_directory/Trust_fixes. After the Hello world prints put:
Do not forget to add the #include <Debog.h>!
Then re-compile and do run sequential calculation and a parallel calculation and check thedebog.log file. Becarefull the debog instruction in the data file must be between the Discretize and Read pb lines.
For more information, go check Keywords Reference Manual and search for the Debog Keyword.
For each of your new deceloppement in TRUST, if you want them to be integrated, tt is mandatory to create a validation form. They are based on Jupyter Notebooks. Let's try to create one.
First, go the the directory where to notekook are stored:
Now, create a new directory for your new validation form:
Then, add the following files:
To create the Jupyter Notebook, run the following:
Now you should have a upwind.ipynb file, i.e. a new Jupyter notebook. Do not forget to add it to your git repository.
You can now run the validation for by doing:
Or even build directly a PDF report from the notebook:
You can now add it to the non-regression test case base:
Howevern you can see error occuring in PAR_upwind_jdd1. Let us fix that error.
First, copy the test case:
An error should occur. It is because it has not been taken into account in the ./configure, so you need to do it again and do again the previous step.
Now, you have to re-run the configure script to take into account the newtest case:
And analyse the error:
Correct the data file PAR_upwind_jdd1.data and re-run it.
If it works, update the data file in $project_directory/share/Validation/Rapports_automatiques/upwind/src: (Scatter ../upwind/DOM.Zones dom → ScatterDOM.Zones dom)
Then, relaunch the last test cases which did not run:
Do not forget to add it to you git project.
Eventually, run all the non regression tests with a optimized binary:
You can also do it in debug:
GDB is a vital tool for each and every TRUST developper. It will help you a lot for debugging. You can use it from Eclipse or with th terminal:
→ in Arguments, Program arguments: upwind
→ Working directory: MY_FIRST_BALTIK/upwind/
→ Apply and Debug
For more information about GDB commands, refer to the help menu.
Run a test case with GDB:
You are now in GDB.
An other usefull tool is valgrind. It will help you find memory leaks. To use valgrind with TRUST, you need to do as follows:
The Valgrind messages appear on the screen with the beginning of each line the same number. For example:
The simulation will take way more time. The last line indicates if errors have occurred. An example with 0 error:
Now we will modify the sources in your baltik project to generate a Valgrind error on the Cx test case:
You can find the commented solution of the exercise:
You can practice on this other tutorial: Build a BALTIK application — convection-diffusion tutorial.