Skip to content

Commit 19ff3b6

Browse files
authored
Merge pull request #732 from sebproell/developer-docs
Make the developer docs nicer
2 parents 9b1d4e3 + 4a455b7 commit 19ff3b6

File tree

8 files changed

+158
-162
lines changed

8 files changed

+158
-162
lines changed

doc/documentation/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ if(FOUR_C_BUILD_DOCUMENTATION)
3636

3737
add_custom_target(
3838
documentation ALL
39+
COMMAND ${CMAKE_COMMAND} -E remove_directory "${PROJECT_BINARY_DIR}/doc/tmp"
40+
COMMAND ${CMAKE_COMMAND} -E remove_directory "${_sphinx_HTML_DIR}"
3941
COMMAND create_rtd
4042
COMMAND ${FOUR_C_EXECUTABLE_NAME} -h > ${_sphinx_OUT_DIR}/reference_docs/4C-help.txt
4143
COMMAND
42-
cmake ${PROJECT_SOURCE_DIR} --list-presets >
44+
${CMAKE_COMMAND} ${PROJECT_SOURCE_DIR} --list-presets >
4345
${_sphinx_OUT_DIR}/reference_docs/4C-cmake-presets.txt
4446
COMMAND
4547
bash ${CMAKE_CURRENT_SOURCE_DIR}/scripts/extract_cmake_variables.sh

doc/documentation/src/_static/html_extensions.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88

99
.underline {
1010
text-decoration: underline;
11-
}
11+
}
12+
13+
.wy-table-responsive table td, .wy-table-responsive table th {
14+
white-space: normal;
15+
}

doc/documentation/src/developer_guide/codingguidelines.rst

Lines changed: 79 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ in the future.
2828
.. _avoid-define-flags:
2929

3030
Avoid define flags
31-
^^^^^^^^^^^^^^^^^^
31+
~~~~~~~~~~~~~~~~~~
3232

3333
Do not introduce new define flags. They complicate testing and lead to untested code.
3434

@@ -40,7 +40,7 @@ Do not introduce new define flags. They complicate testing and lead to untested
4040
flags are all managed via CMake.
4141

4242
Avoid header-in-header inclusion
43-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4444

4545
Avoid and actively resolve header-in-header inclusion to speed up compilation time. Use forward declarations instead.
4646

@@ -49,7 +49,7 @@ want to avoid including an (expensive) header file via a forward declaration, pu
4949
file and include this header. This way, the forward declaration is only in one place.
5050

5151
Use of smart pointers
52-
^^^^^^^^^^^^^^^^^^^^^
52+
~~~~~~~~~~~~~~~~~~~~~
5353

5454
If necessary, use smart pointers for their memory management capabilities, e.g., ``std::shared_ptr``, ``std::unique_ptr``
5555
(you may find more information on passing smart pointers
@@ -60,7 +60,7 @@ By default, pass parameters by const reference and only expose smart pointers if
6060
See also `<https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rr-owner>`_.
6161

6262
Use of ``Teuchos::ParameterList``
63-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
63+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6464

6565
Prefer parameter container classes over ``Teuchos::ParameterList`` for passing parameters to functions. Often,
6666
a simple struct with all necessary data as public, non-const members is sufficient.
@@ -69,15 +69,15 @@ Reason: ``Teuchos::ParameterList`` is a flexible container for input(!) paramete
6969
In addition, the string-based lookup is not compile-time checked.
7070

7171
Const-correctness
72-
^^^^^^^^^^^^^^^^^
72+
~~~~~~~~~~~~~~~~~
7373

7474
Make code const-correct. Const-correctness is mainly relevant for function parameters and member functions.
7575

7676
**Note:** The member fields of a struct or class should often not be ``const``, as this would prevent the struct or
7777
class from being moved or copied. Instead, use ``const`` member functions to access the fields in a ``const`` context.
7878

7979
Enums
80-
^^^^^
80+
~~~~~
8181

8282
- By default, use scoped ``enum class`` instead of unscoped ``enum``.
8383
- Use enums instead of strings for parameters that take one from a fixed set of values.
@@ -90,7 +90,7 @@ See also `Enum.3 <https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#e
9090

9191

9292
|FOURC|-specific Naming Conventions
93-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93+
-----------------------------------
9494

9595
- **Namespaces** use CamelCase: ``LinAlg::``
9696
- **class**, **struct** and **enum** types use CamelCase: ``ClassName``, ``StructName``, ``EnumName``
@@ -108,3 +108,75 @@ The full specification of the naming convention is listed in the
108108

109109
Variable names must not be just a single letter, because they are impossible to find in a global search operation.
110110
(Exception: loop indices such as i, j, but remember that even loop indices could/should have descriptive names.)
111+
112+
113+
Directory structure
114+
--------------------
115+
The |FOURC| code comes with documentation, example input files and
116+
support scripts. The important subdirectories are the following:
117+
118+
.. list-table::
119+
:header-rows: 1
120+
121+
* - Directory
122+
- Description
123+
* - ``apps``
124+
- Contains executables built on top of the |FOURC| library code.
125+
* - ``cmake``
126+
- Contains the CMake configuration files to build |FOURC|.
127+
* - ``dependencies``
128+
- Contains installation scripts for the external dependencies of |FOURC|.
129+
* - ``doc``
130+
- Contains the sources of the documentation you are currently reading.
131+
* - ``docker``
132+
- Contains the setup files for docker images for running |FOURC| inside of it.
133+
* - ``presets``
134+
- Contains preset files for CMake.
135+
* - ``src``
136+
- Contains the bulk of the |FOURC| code organized into several modules.
137+
* - ``tests``
138+
- Contains end-to-end tests that run |FOURC| as a whole with optional pre- and post-processing steps. The tests are not directly related to one specific feature (these reside next to the sources).
139+
* - ``tests/input_files``
140+
- Contains various valid and running input files. These input files are also used for automated testing.
141+
* - ``unittests``
142+
- [Legacy] Contains the source files for stand-alone tests aka unittests. These tests will move closer to the source code into the respective modules.
143+
* - ``utilities``
144+
- Contains useful scripts to develop and test |FOURC|.
145+
146+
The top-level directory should only contain files that are commonly expected in this location,
147+
such as the README, LICENSE, and configuration files for tools like clang-format and clang-tidy.
148+
149+
Details of the ``src`` directory
150+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
151+
152+
The ``src`` directory contains the modules that make up the |FOURC| library. Each module is
153+
split into a ``src`` and ``tests`` directory. The ``src`` directory contains the production code
154+
of the module, while the ``tests`` directory contains the module-related tests.
155+
156+
Types of source files used within |FOURC|
157+
"""""""""""""""""""""""""""""""""""""""""
158+
159+
The code base consists almost exclusively of C++ source files. To better indicate the intended usage
160+
of a file, both to the build system and developers, the following file extensions are used:
161+
162+
.. list-table::
163+
:header-rows: 1
164+
165+
* - File Extension
166+
- Description
167+
* - ``.cpp``
168+
- C++ source files. These files are compiled.
169+
* - ``.hpp``
170+
- C++ header files. These files are included in other source files.
171+
* - ``.fwd.hpp``
172+
- C++ forward declaration header files. These files contain forward declarations of classes and functions that appear over and over again. They are especially useful for external dependencies to isolate the exposed surface area of the dependency. This type of file is usually included in other header files.
173+
* - ``.templates.hpp``
174+
- C++ header files which contain additional template definitions. The reason why you might want to separate certain expensive template definitions from the main header file is to speed up compilation times. Sometimes a template definition requires additional expensive includes, which are not necessary for the main header file. In this case, the template definition is best moved to a ``.templates.hpp`` file.
175+
* - ``.inst.hpp``
176+
- C++ header files which contain explicit template instantiations. These files are included in the corresponding ``.cpp`` file to instantiate the templates. These files are not strictly necessary as you can also instantiate the templates directly in the ``.cpp`` file. However, by moving the instantiations to a separate file, you can reuse the same instantiations in multiple ``.cpp`` files which contain parts of the implementation of the same classes.
177+
* - ``.<ext>.in``
178+
- These files are templates (not in the C++ sense!) requiring additional configuration via CMake. The CMake script will generate the actual file by replacing placeholders in the template file. The generated file will be placed in the build directory with the extension ``.<ext>``.
179+
180+
181+
182+

doc/documentation/src/developer_guide/debugging_profiling.rst

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ In the following various debugging and profiling tools are described that may be
1717
- Debugging/MPI debugging with :ref:`VS Code <visualstudiocode>`
1818

1919

20-
Useful options for Debugging with gdb (or your ide)
20+
Useful options for Debugging with gdb (or your IDE)
2121
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2222

2323
Build debug version
@@ -135,14 +135,14 @@ and connect to each process individually.
135135
.. _profiling_callgrind:
136136

137137
Code profiling with ``callgrind``
138-
--------------------------------------
138+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139139

140140
"Callgrind is a profiling tool that records the call history among functions in a program's run as a call-graph.
141141
By default, the collected data consists of the number of instructions executed, their relationship to source lines,
142142
the caller/callee relationship between functions, and the numbers of such calls."
143143
(from `callgrind <http://valgrind.org/docs/manual/cl-manual.html>`_)
144144

145-
Configure and build with profiling flag
145+
Configure and build for profiling
146146
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
147147

148148
**Note:** For general information about configuring and building of |FOURC| refer to :ref:`Configure and Build <4Cinstallation>` and the ``README.md``.
@@ -205,3 +205,64 @@ It is also possible to only open the output of a specific mpi rank with processo
205205
.. figure:: /_assets/kcachegrind.png
206206
:alt: Picture of kcachegrind
207207
:width: 100%
208+
209+
210+
.. _teuchos-time-monitor:
211+
212+
Teuchos Time Monitor
213+
~~~~~~~~~~~~~~~~~~~~
214+
215+
The ``TimeMonitor`` from ``Trilinos`` package ``Teuchos`` provides MPI collective timer statistics.
216+
Refer to the ``Teuchos::TimeMonitor`` Class Reference https://trilinos.org/docs/dev/packages/teuchos/doc/html/classTeuchos_1_1TimeMonitor.html for a detailed documentation.
217+
218+
Add a timer for a method in |FOURC|
219+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220+
221+
In order to get parallel timing statistics of a method in |FOURC| include the following header
222+
223+
::
224+
225+
#include <Teuchos_TimeMonitor.hpp>
226+
227+
228+
in the ``.cpp``-file that contains the implementation of the method and add the macro ``TEUCHOS_FUNC_TIME_MONITOR``
229+
with the name of the method in the implementation of the method:
230+
231+
.. code-block:: cpp
232+
233+
void <NAMESPACE>::<FunctionName>(...)
234+
{
235+
TEUCHOS_FUNC_TIME_MONITOR("<NAMESPACE>::<FunctionName>");
236+
237+
/* implementation */
238+
}
239+
240+
241+
Running a simulation on 3 processors for example yields the following ``TimeMonitor`` output in the terminal:
242+
243+
::
244+
245+
============================================================================================================
246+
247+
TimeMonitor results over 3 processors
248+
249+
Timer Name MinOverProcs MeanOverProcs MaxOverProcs MeanOverCallCounts
250+
------------------------------------------------------------------------------------------------------------
251+
<NAMESPACE>::<FunctionName> 0.1282 (1000) 0.2134 (1000) 0.2562 (1000) 0.0002132 (1001)
252+
============================================================================================================
253+
254+
255+
The output gives the minimum, maximum, and mean ``execution time (number of counts)`` for all processors and also the mean execution time over all counts.
256+
257+
**Note:** The ``TimeMonitor`` output of a |FOURC| simulation in general already contains a variety of methods that are monitored, meaning there is a line with timings for each method in the output.
258+
259+
How to interpret the output of the ``TimeMonitor``
260+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
261+
262+
Examining the output of the ``TimeMonitor`` is probably one of the easiest steps in profiling the behaviour of a program. The information given in the output of the `TimeMonitor` may server for
263+
264+
- getting an idea of the execution time of a method
265+
- knowing how often a method is called during the runtime of the program
266+
- investigating the parallel load balancing of a method (compare ``MinOverProcs`` with ``MaxOverProcs``)
267+
268+
and thereby helps identifying bottlenecks in the overall program.

doc/documentation/src/developer_guide/developer_addedinformation.rst

Lines changed: 0 additions & 14 deletions
This file was deleted.

doc/documentation/src/developer_guide/developer_dirstructure.rst

Lines changed: 0 additions & 75 deletions
This file was deleted.

doc/documentation/src/developer_guide/developmentguide.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ Developer guide
77
.. toctree::
88
:maxdepth: 2
99

10-
testing
1110
codingguidelines
11+
testing
12+
developer_cmake
13+
debugging_profiling
14+
doxygen
15+
coverage_report
16+
developer_ccache
17+
developer_cluster
1218
petra_object_model
13-
developer_addedinformation
1419
development_parts

0 commit comments

Comments
 (0)