Concurrent Programming in C++: Difference between revisions
No edit summary |
No edit summary |
||
Line 49: | Line 49: | ||
* <code>-pthread</code> - Enable posix thread support, which is the underlying thread library used by libstdc++ on linux platforms |
* <code>-pthread</code> - Enable posix thread support, which is the underlying thread library used by libstdc++ on linux platforms |
||
You might well find this [https://github.com/graeme-a-stewart/cpp-concurrency/blob/ |
You might well find this [https://github.com/graeme-a-stewart/cpp-concurrency/blob/gridka14/src/cpp11/Makefile Makefile] |
||
useful. It will compile any <code>.cc</code> file into an executable with the correct |
useful. It will compile any <code>.cc</code> file into an executable with the correct |
||
compiler flags. |
compiler flags. |
||
Line 64: | Line 64: | ||
Compiling against TBB should just work, but linking requires <code>-ltbb</code> and <code>-lrt</code>. |
Compiling against TBB should just work, but linking requires <code>-ltbb</code> and <code>-lrt</code>. |
||
The <code>Makefile</code> [https://github.com/graeme-a-stewart/cpp-concurrency/blob/ |
The <code>Makefile</code> [https://github.com/graeme-a-stewart/cpp-concurrency/blob/gridka14/src/tbb/Makefile here] will add all the flags you need, and enable <code>-std=c++11</code> so it's recommended. |
||
Documentation for TBB is installed into <code>/usr/local/share/tbb/html</code>, |
Documentation for TBB is installed into <code>/usr/local/share/tbb/html</code>, |
||
Line 88: | Line 88: | ||
Introductions to each section of the tutorial are here: |
Introductions to each section of the tutorial are here: |
||
https://github.com/graeme-a-stewart/cpp-concurrency/tree/ |
https://github.com/graeme-a-stewart/cpp-concurrency/tree/gridka14/doc |
||
and exercises are at the end of each document. |
and exercises are at the end of each document. |
||
Line 94: | Line 94: | ||
The file |
The file |
||
https://github.com/graeme-a-stewart/cpp-concurrency/blob/ |
https://github.com/graeme-a-stewart/cpp-concurrency/blob/gridka14/doc/XX-Answers.md |
||
lists the source code that is the solution to each of the exercises. Feel free to look at that if you need a hint or want to check your answer. |
lists the source code that is the solution to each of the exercises. Feel free to look at that if you need a hint or want to check your answer. |
||
You can clone the entire git repository like this: |
|||
<code>git clone https://github.com/graeme-a-stewart/cpp-concurrency.git -b gridka14</code> |
|||
N.B. This will clone the GridKA 2014 version of the repository, if you want to clone the master branch then just do |
|||
<code>git clone https://github.com/graeme-a-stewart/cpp-concurrency.git</code> |
<code>git clone https://github.com/graeme-a-stewart/cpp-concurrency.git</code> |
||
== References == |
== References == |
||
The current github version of this document is here: |
|||
https://github.com/graeme-a-stewart/cpp-concurrency/blob/master/doc/00-TipsReferences.md |
https://github.com/graeme-a-stewart/cpp-concurrency/blob/master/doc/00-TipsReferences.md |
||
Is the current 'master' copy of the introduction, which provides references. |
Revision as of 16:05, 12 September 2014
Introduction
This tutorial consists of two sections:
- C++11 Concurrency
- Intel Threaded Building Blocks
C++11 Concurrency
C++11 introduced direct support in the language for concurrency, with the ability to launch and manage different threads. Support for mutexes and other synchronisation mechanisms are available.
Threaded Building Blocks
Threaded Building Blocks is a higher level C++ that supports many common design patterns for applications to take advantage of multi-threading capabilities. Basic patterns like parallel loops and reductions are available. We'll also look at the TBB graph constructs.
TBB includes useful containers, which are thread safe, as well as a high performance multi-threaded implementation of malloc.
Talk
The introductory talk to this tutorial is here.
Setup
General
It's important to setup the Redhat devtoolset to have access to a modern version of gcc for all of the tutorial exercises.
To do this login and execute this command:
$ scl enable devtoolset-2 bash
You can verify that all is well by asking for the gcc version, which should be 4.8.2:
$ g++ --version
g++ (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
C++11 Compiler Options
To compile concurrent C++11 programs you'll need two flags for g++:
-std=c++11
- Use the new C++11 standards-pthread
- Enable posix thread support, which is the underlying thread library used by libstdc++ on linux platforms
You might well find this Makefile
useful. It will compile any .cc
file into an executable with the correct
compiler flags.
A good reference for C++ concurrency libraries is http://www.cplusplus.com/ (use the reference section, under multi-threading).
Threaded Building Blocks
Intel Threaded Building Blocks has been compiled and installed into
/usr/local
(specifically /usr/local/include
for header files and
/usr/local/lib64
for libraries). Thus you shouldn't need any special
extra setup to use is during the school. (Actually TBB is very easy to install from source.)
Compiling against TBB should just work, but linking requires -ltbb
and -lrt
.
The Makefile
here will add all the flags you need, and enable -std=c++11
so it's recommended.
Documentation for TBB is installed into /usr/local/share/tbb/html
,
but using the
Intel documentation is
more convenient.
Writing Code
You will have been given access to a machine on which to complete the tutorial. There are a suite of editors available and you can pick whichever you like best:
- nano - A very simple text editor (but lacks helpful things such as automatic indentation and code colourisation)
- emacs - The classic Stallman text editor
- vi - The other classic editor from the editor wars
- geany - A nice standalone GUI editor with indentation and code highlighting, but you will need to switch on X forwarding to use it (so
ssh -Y -p 24 multithr@gks-XXX.scc.kit.edu
)
We have also setup working VNC on these machines, if you would prefer to use a VNC client from your laptop.
If you want us to really recommend something then we pick geany
;-)
Exercises
Introductions to each section of the tutorial are here:
https://github.com/graeme-a-stewart/cpp-concurrency/tree/gridka14/doc
and exercises are at the end of each document.
The file
https://github.com/graeme-a-stewart/cpp-concurrency/blob/gridka14/doc/XX-Answers.md
lists the source code that is the solution to each of the exercises. Feel free to look at that if you need a hint or want to check your answer.
You can clone the entire git repository like this:
git clone https://github.com/graeme-a-stewart/cpp-concurrency.git -b gridka14
N.B. This will clone the GridKA 2014 version of the repository, if you want to clone the master branch then just do
git clone https://github.com/graeme-a-stewart/cpp-concurrency.git
References
https://github.com/graeme-a-stewart/cpp-concurrency/blob/master/doc/00-TipsReferences.md
Is the current 'master' copy of the introduction, which provides references.