.. Watlab documentation file, created by
Pierre-Yves Gousenbourger on Wed Aug 2, 2023.
.. _compile:
Compile the code
================
There are two ways to compile the code : directly with the C++ compiler or with `CMake `_. We highly recommand CMake as it is system independant.
It it recommended to use C++20 (C++17 accepted). There is no backward compatibility for older versions.
Note that the python library for Watlab permits to run the code without hitting the following nauseous lines. Check our :ref:`Tutorials ` for more information.
.. _Cmake-install:
Build the code with CMake
-------------------------
Make sure you installed `CMake `_ properly.
Open a shell and hit the two following command.
.. code-block::
cmake -S . -B _build/
cmake --build _build
The code will generate by itself and the executables will be created in `bin/` (for programs) and in `tests/` for test executables.
On **windows**, you may need to specify the C++ Makefiles. If you installed MinGW as recommended in this documentation, you should hit
.. code-block::
cmake -S . -G "MinGW Makefiles" -B _build/
cmake --build _build/
To help you, we created scripts in `scripts/`. It is called `scripts/Build-Binaries`.
.. _with-the-compiler:
Compile the code with the C++ compiler
--------------------------------------
The command lines to create the cpp code without parallelization is
.. code-block::
g++ -o hydroflow src/cpp/*.cpp src/cpp/writer/*.cpp src/cpp/physicalmodels/*.cpp src/cpp/interfaces/*.cpp src/cpp/helpers/*.cpp -std=c++20
This will create an executable hydroflow.exe.
To compile the code with parallelization, make sure that :ref:`OpenMP ` is installed with your compiler. Now hit the following lines
.. code-block::
g++ -O3 -fopenmp -pthread -o hydroflow src/cpp/*.cpp src/cpp/writer/*.cpp src/cpp/physicalmodels/*.cpp src/cpp/interfaces/*.cpp src/cpp/helpers/*.cpp -std=c++20
This will create an executable hydroflow.exe, but now it is parallelizable.
If no error is thrown, you have successfully compiled the code.
Execute the code
================
When your `data.json` is exported, you can directly execute the C++ code as follows
.. code-block::
./hydroflow -f path/to/data.json
If you wish no verbose, you can also add the command ``-nodisplay`` to your line:
.. code-block::
./hydroflow -f path/to/data.json -nodisplay