You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorial_basics.rst
+22-4Lines changed: 22 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -417,7 +417,7 @@ We extend our C++ "Hello, World!" example to print the greetings from multiple t
417
417
:language: cpp
418
418
:lines: 6-
419
419
420
-
This program takes as argument the number of threads it will create and it uses ``std::thread``, which is C++11 addition, meaning that we will need to pass ``-std=c++11`` to our compilers.
420
+
This program takes as argument the number of threads it will create and it uses ``std::thread``, which is a C++11 addition, meaning that we will need to pass ``-std=c++11`` to our compilers.
421
421
Here is the corresponding ReFrame test, where the new concepts introduced are highlighted:
422
422
423
423
.. code-block:: console
@@ -429,12 +429,30 @@ Here is the corresponding ReFrame test, where the new concepts introduced are hi
429
429
:lines: 6-
430
430
:emphasize-lines: 11-13
431
431
432
+
433
+
In order to compile applications using ``std::thread`` with GCC and Clang, the ``-pthread`` option has to be passed to the compiler.
434
+
Since the above option might not be valid for other compilers, we use pipeline hooks to differentiate based on the programming environment as follows:
435
+
436
+
.. code-block:: python
437
+
438
+
@rfm.run_before('compile')
439
+
defset_threading_flags(self):
440
+
environ =self.current_environ.name
441
+
if environ in {'clang', 'gnu'}:
442
+
self.build_system.cxxflags += ['-pthread']
443
+
444
+
445
+
.. note::
446
+
447
+
The pipeline hooks, as well as the regression test pipeline itself, are covered in more detail later on in the tutorial.
448
+
449
+
432
450
ReFrame delegates the compilation of a test to a *build system*, which is an abstraction of the steps needed to compile the test.
433
451
Build systems take also care of interactions with the programming environment if necessary.
434
452
Compilation flags are a property of the build system.
435
453
If not explicitly specified, ReFrame will try to pick the correct build system (e.g., CMake, Autotools etc.) by inspecting the test resources, but in cases as the one presented here where we need to set the compilation flags, we need to specify a build system explicitly.
436
-
In this example, we instruct ReFrame to compile a single source file using the ``-std=c++11 -Wall`` compilation flags.
437
-
Finally, we set the arguments to be passed to the generated executable in :attr:`~reframe.core.pipeline.RegressionTest.executable_opts`.
454
+
In this example, we instruct ReFrame to compile a single source file using the ``-std=c++11 -pthread -Wall`` compilation flags.
455
+
Finally, we set the arguments to be passed to the generated executable in :attr:`executable_opts <reframe.core.pipeline.RegressionTest.executable_opts>`.
438
456
439
457
440
458
.. code-block:: console
@@ -1075,7 +1093,7 @@ Let's see and comment the changes:
1075
1093
First of all, we need to add the new programming environments in the list of the supported ones.
1076
1094
Now there is the problem that each compiler has its own flags for enabling OpenMP, so we need to differentiate the behavior of the test based on the programming environment.
1077
1095
For this reason, we define the flags for each compiler in a separate dictionary (``self.flags``) and we set them in the :func:`setflags` pipeline hook.
1078
-
Let's explain what is this all about.
1096
+
We have first seen the pipeline hooks in the multithreaded "Hello, World!" example and now we explain them in more detail.
1079
1097
When ReFrame loads a test file, it instantiates all the tests it finds in it.
1080
1098
Based on the system ReFrame runs on and the supported environments of the tests, it will generate different test cases for each system partition and environment combination and it will finally send the test cases for execution.
1081
1099
During its execution, a test case goes through the *regression test pipeline*, which is a series of well defined phases.
0 commit comments