C++ is widely used in many contexts. This training focusses on using C++ for scientific programming and on the way Bjarne Stroustrup advocates modern C++ in his book “A tour of C++”. Some C++17 features and third-party libraries will also be discussed.
Learning outcomes
When you complete this training you will be able to
- read and understand well-written C++ code;
- write small to medium C++ programs in an idiomatic style;
- use user-defined types, classes, templates, and STL facilities effectively;
- recognize some best practices and common pitfalls for C++ programmers;
- have a working knowledge of the Standard Template Library (STL);
- know how to use third-party libraries such as Armadillo or Eigen for linear algebra;
- have a solid foundation for follow-up work in scientific and high-performance C++ programming.
Schedule
Total duration: 16 hours, split over four sessions.
Session one
Total duration: 4 hours
| Subject | Duration |
|---|---|
| introduction and motivation | 5 min. |
| basics: control flow statements, data types | 85 min. |
| hands-on session | 20 min. |
| coffee break | 10 min. |
| functions | 15 min. |
| simple I/O | 10 min. |
| user defined types and classes | 85 min. |
| hands-on session | 20 min. |
Session two
Total duration: 4 hours
| Subject | Duration |
|---|---|
| modular code and the build process | 80 min. |
| hands-on session | 20 min. |
| error handling | 10 min. |
| coffee break | 10 min. |
| inheritance | 60 min. |
| templates | 20 min. |
| functional programming | 20 min. |
| hands-on session | 20 min. |
Session three
Total duration: 4 hours
| Subject | Duration |
|---|---|
| string and regular expressions | 70 min. |
| I/O streams | 20 min. |
| hands-on session | 20 min. |
| coffee break | 10 min. |
| STL containers | 70 min. |
| STL algorithms | 30 min. |
| hands-on session | 20 min. |
Session four
Total duration: 4 hours
| Subject | Duration |
|---|---|
| numerical computing | 70 min. |
| hands-on session | 40 min. |
| coffee break | 10 min. |
| linear algebra | 30 min. |
| Boost for numerics | 10 min. |
| Gnu Scientific Library (GSL) | 30 min. |
| hands-on session | 40 min. |
| wrap up | 10 min. |
Training materials
Slides are available in the GitHub repository, as well as example code and hands-on material.
Target audience
This training is for you if you already know how to program in another language and want to learn modern C++ for scientific applications.
Prerequisites
You will need experience programming in another programming language. This is not a training that starts from scratch.
If you plan to do C++ programming in a Linux or HPC environment you should be familiar with these as well.
More concretely, participants should already be comfortable with the following:
- variables, expressions, control flow, and writing functions in some other programming language;
- basic data structures such as arrays/lists, maps/dictionaries, or sets;
- reading short programs and understanding how data flows through them;
- basic problem decomposition into helper functions or modules;
- compiling or running programs from the command line at a basic level;
- working in a shell environment well enough to edit files, run commands, and inspect output.
You do not need prior experience with C++ itself, templates, inheritance, the STL, CMake, Eigen, Armadillo, Boost, or GSL. Those are part of the training itself.
Quick self-assessment
If you can do most of the tasks below in some programming language, you are likely ready for this training.
- write a function that computes the average of a list of numbers;
- loop over a collection and compute a derived result such as a sum or count;
- use
if/elseor aswitch-like construct to classify values into cases; - split a program into a few helper functions or files;
- read data from a text file and print a simple summary;
- read a short program and explain what it does;
- compile or run a small program from the command line;
- make a small change to an existing program and run it again.
If several of these items still feel difficult, the training will probably move too fast. In that case, it is better to first take a short introductory programming course.
To follow hands-on, you need a computer with a C++ development environment installed. You can of course use an HPC system you have access to as well.
Level of the Material
For participants who already have programming experience in another language, the material in this training is approximately
- Introductory: 35 %
- Intermediate: 45 %
- Advanced: 20 %
These percentages describe the level of the C++ and scientific-computing topics covered in the training, not the participants’ general programming background.
Trainer(s)
- Geert Jan Bex (geertjan.bex@uhasselt.be)