Commit 9f2cba75 authored by CHAMONT David's avatar CHAMONT David
Browse files

Prepare C++ On Demand

parent d9bbf1f5
# Where to chat about this course ?
We currently use [this discord server]( So that we can better know each other, please add some information into your discord profile. Also, you can say a few words about why you care about C++, in the welcome channel.
## Tips and tricks
A key features in Discord : most important & everlasting messages are "pinned". So to see those messages, one should click on the "pinned messages" icon on the top right corner of the main frame.
\ No newline at end of file
# Use of predefined docker images
If you want to run the notebooks locally on your workstation, the image to be used for most notebooks and examples is ``.
In case you need a more advanced compiler features, which cannot be handled by the xeus-cling notebook kernel, you should rather rely on ``. This image should be used for the advanced notebooks where the kernel is a Python one, and the extracts execution is delegated to the underlying system, through %%file and ! magic instructions.
So to start a container with any of those images :
docker run -it --rm -p 8888:8888 -v $PWD:/work -w /work <THE-IMAGE-PATH> bash
Then you can start the usual notebook server:
jupyter notebook --no-browser --allow-root --ip=
Or the lab:
jupyter-lab --no-browser --allow-root --ip=
\ No newline at end of file
Also install `git-lfs`.
# Prepare yourself for the lessons
The prerequisites for this lesssons are given in ``, together with links to courses and online tutorials which may help to fill the gaps.
For communication with the teachers and other students, you are asked to connect on this server: ``. Some more information is given in ``.
As better described in ``, the material will be made available, progressively, on [this public project](
The file `` try to sum up what to install if you want to run the examples on your machine, with or without notebooks, barebone or through docker (in the later case, additional instructions are found in ``). You can also, at least at the beginning, simply use Finally, if you have an account in the RENATER federation, you may use `` (see ``).
# What should I install ?
## For raw compilation : a C++17 compiler
The more we progress in the lessons, the more advanced C++ features we will use: mostly C++17, and C++20 for few demonstrations. It is therefore adviced to have a recent enough compiler, such as **gcc 9**, or even **gcc 11.2** which we use for the preparation of this course. You will find [here]( the table of which C++ feature is supported by which compiler version. You should be aware that there is often a distinction between language syntax and standard library : a compiler version which supports C++17 language features does not necessarily supports the C++17 standard library. Generally, the support for syntax is implemented first, and the library novelties comes with a later version.
## GNU time
For some of the exercices, you will need to have **GNU time** installed where you want to execute the scripts. Try the command `\time -f "%U" echo toto` to check if it works fine. The `\` is there to avoid that bash use its own internal time command. If it does not work properly, try `conda install -c conda-forge time` (for example).
## If you want to work with thenotebooks
Most of the education materials is given as notebooks. You can read them on the [public project](, and copy/paste the C++ extracts. Yet, if you want to play the notebooks directly on your machine, you will need to install:
1. `git` and `git-lfs` so to dowload the files (see ;
2. [jupyter]( ecosystem ;
3. [xeus-cling]( C++ kernels for notebooks.
The jupyter notebooks tools are part of the [anaconda3 distribution]( One can also use `miniconda` for a more focused installation (see below).
## Basic installation and setup with miniconda
[Miniconda]( may be installed this way:
bash -b -p ${MINICONDA_ROOT}
${MINICONDA_ROOT}/bin/conda init bash
Thus, the following installation should bring you anything listed before:
conda update -y conda
conda install -y -c conda-forge mamba
mamba install -y -c conda-forge jupyter
mamba install -y -c conda-forge notebook
mamba install -y -c conda-forge jupyterlab
mamba install -y -c conda-forge xeus-cling
mamba install -y -c conda-forge nbdime
mamba install -y -c conda-forge time
mamba install -y -c conda-forge gxx
## With docker
We have also prepared some docker images with anything pre-installed, if you have docker on your machine. See .
# How to use ``
\ No newline at end of file
# About this course notebooks
The use of notebooks is not completely mandatory : you can read them on the [public project](, and copy/paste the C++ extracts to your prefered editor. Else, if you want to play with the notebooks,
please look at the notebook section in file ``.
## Two kind of notebooks
Most of the notebooks are relying on the **xeus-cling** C++17 kernel, which will directly "interpret" the code.
For few features which are not supported by the xeus-cling kernel (user defined literals, execution strategies, C++20 features), we use the magic command `%%file` and `!` so that the code is written to a temporary file, and the code compiled and executed by the underlying shell. In such a case, a python kernel is enough.
## Notebooks vs git versioning
One issue when working with notebooks : when using a notebook, you generally modifies it (at least the output of the code cells). If the teacher ask you to `git pull` a new version of it, you may face merging confilcts.
The usual dirty workaround applies : before pulling, either move globally your modified notebooks to a private git branch, or move/copy them to a backup directory.
If you prefer to solve the conflicts, `git diff` will not help much. The right command is rather `nbdiff` , which is not available by default (till now) in the linux distributions. You will need to install the `nbdime` package first, for example with the command `conda install -y -c conda-forge nbdime` .
\ No newline at end of file
# Pre-requisites: not for beginners
So to take full profit of the lessons and exercices in this project, you are expected to have regularly programmed in old (<11) C++. If not, some events and resources for beginners are given below.
## HSF training
- [HEP C++ Course and Hands-on Training](
- [Basic Modern C++](
## Online free resources
- [Zeste de Savoir](
- [Learn Cpp](
- [begin(c++)](
## Private courses
- In Paris-Saclay area, [Code Reckons](
- At CERN, [C++ Introduction](
- At CERN, [Advanced C++](
# Pedagogic material
## Html
The material will be made available, progressively, on [this public project]( of the IN2P3 gitlab server. There, one cam download a `zip` or `tar`file with anything included : lessons, videos, notebooks, exercises.
## Git
Also, on can clone the project with the command `git clone`. If you want to get the videos, previously install `git-lfs` on top of `git`.
## Problem: `server certificate verification failed. CAfile: none CRLfile: none`
This problem is rather common. It means your machine is probably not up to date for the package ca-certificates, and lack the recent letsencrypt certficates. Can be solved with something like `apt upgrade ca-certificates` (to be investiogated).
# Starting point of the course
Depending on your prefered language:
* [Français](
* [English](
# Credits
This project is mainly made of content written by David Chamont (CNRS) over many years. Vincent Rouvreau (INRIA) has contributed few documents when helping for a 2018 session. Olga Abramkina and Karim Hasnaoui (CNRS) have transated into english a large part of the course, for the PRACE session at the beginning of 2021.
The final common day, more dedicated to the scientific computing facets, largely benefits from debates and experiments with the members of the IN2P3 project [Reprises]( only): Hadrien Grasland, Pierre Aubert, Vincent Lafage, etc.
\ No newline at end of file
# Modern Scientific C++
This set of notebooks will guide you through the modern C++ syntax. It will be the basement for the later understanding of modern C++ standard library, your first tool for scientific computing. You can download this training materials thanks to the commmand:
git clone ModernScientificCpp
The course is organized as an alternation of days in common (physically or virtually) and weeks of intersession during which you have to do exercises individually, at a rate of 1h30 per day.
## [First collective day](1-ClassRoom/
Revisions and first introduction to new syntax. We take this opportunity to get to know each other, create accounts on the forum that will be used during the intersessional period, and to become familiar with notebooks.
* Morning 1 (1h30) : [Get in touch](1-ClassRoom/1-GetInTouch/)
* Morning 2 (1h30) : [Revisions](1-ClassRoom/2-Reminders/en.0-index.ipynb)
* Afternoon 1 (1h30) : [New syntax](1-ClassRoom/3-NewSyntaxes/en.0-index.ipynb)
* Afternoon 2 (1h30) : [Coding dojo](1-ClassRoom/4-CodingDojo/
## [First inter-session](2-HomeWork/
More in-depth study of **new C++ syntax**, and work on **personal code**.
* Day 1 (1h30) : [General modernization](2-HomeWork/1-ModernizeYourCode/en.0-index.ipynb)
* Day 2 (1h30) : [Better use of references and pointers](2-HomeWork/2-ReferencesAndPointers/en.0-index.ipynb)
* Day 3 (1h30) : [Always more templates](2-HomeWork/3-Generic/en.0-index.ipynb)
* Day 4 (1h30) : [First steps in functional programming](2-HomeWork/4-Functional/en.0-index.ipynb)
## [Second collective day](3-ClassRoom/
Topics more focused on the standard library, new good practices, and various programming styles.
* Morning 1 (1h30) : [Cpp Core Guidelines & Guideline Support Library](3-ClassRoom/1-CoreGuidelines/
* Morning 2 (1h30) : [Template meta-programming](3-ClassRoom/2-TemplateMetaProgramming/
* Afternoon 1 (1h30) : [Functional programming](3-ClassRoom/3-FunctionalProgramming/
* Afternoon 2 (1h30) : [Concurrent programming](3-ClassRoom/4-ConcurrentProgramming/
## [Second intersession](4-HomeWork/
Read the [core guidelines](,
practice the **new standard library**, and work on your **personal code**.
## [Third collective day](5-ClassRoom/
Some themes more specific to scientific computing: giving units to values, control the accuracy of its calculation, optimize its data structure. Plus an overview of C++20.
* Morning 1 (1h30) : [Quantities and units](1-QuantitiesAndUnits/en.0-index.ipynb)
* Morning 2 (1h30) : [Floating point computing](2-FloatingPointComputing/en.0-index.ipynb)
* Afternoon 1 (1h30) : [Optimisation](3-Optimisation/en.0-index.ipynb)
* Afternoon 2 (1h30) : [A glimpse to C++20](4-Cpp20Glimpse/en.0-index.ipynb)
## Some external resources
* [Cpp Reference](
* [Learn Cpp](
* [CoLiRu](
* [Compiler Explorer](
* [Modernes Cpp](
* [Simplify C++](
* [Fluent C++](
\ No newline at end of file
# Cpp Scientifique Moderne
Dans un premier temps, cet ensemble de feuilles Jupyter va vous guider à travers la syntaxe du C++ moderne. Cela vous servira de base pour pour comprendre la bibliothèque standard, dans un deuxième temps. Enfin, nous terminerons avec des thématiques spécifiques au calcul scientifique en C++. Vous pouvez récupérez le contenu de ce cours à l'aide de la commande :
git clone ModernScientificCpp
Le cours est organisé comme une alternance de journées en commun (phyisquement ou virtuellement) et de semaines d'intersession pendants lesquelles vous devez effectuer des exercices individuellement, à raison d'1h30 par jour.
## [1er jour ensemble](1-ClassRoom/
Révisions et première introduction aux nouvelles syntaxes.
On en profite pour faire connaissance, créer les comptes sur
le forum qui servira pendant les intersessions, et se familiariser
avec les notebooks.
* Matin 1 (1h30) : [Contact](1-ClassRoom/1-GetInTouch/)
* Matin 2 (1h30) : [Révisions](1-ClassRoom/2-Reminders/
* Aprem 1 (1h30) : [Nouvelles syntaxes](1-ClassRoom/3-NewSyntaxes/fr.0-index.ipynb)
* Aprem 2 (1h30) : [Coding dojo](1-ClassRoom/4-CodingDojo/
## [1ere inter-session, 4 jours](2-HomeWork/
Retour plus appronfondi sur la **nouvelle syntaxe** C++,
et travail sur vos **codes personnels**.
* Jour 1 (1h30) : [Modernisation générale](2-HomeWork/1-ModernizeYourCode/
* Jour 2 (1h30) : [Amélioration des réferences et des pointeurs](2-HomeWork/2-ReferencesAndPointers/)
* Jour 3 (1h30) : [Développement des patrons](2-HomeWork/3-Generic/)
* Jour 4 (1h30) : [Premiers pas fonctionels](2-HomeWork/4-Functional/)
## [2eme jour ensemble](3-ClassRoom/
Thèmes plus axés sur la bibliothèque standard, les nouvelles bonnes
pratiques, et les styles de programmation.
* Matin 1 (1h30) : [Cpp Core Guidelines & Guideline Support Library](3-ClassRoom/1-CoreGuidelines/
* Matin 2 (1h30) : [Meta-programmation à base de patrons](3-ClassRoom/2-TemplateMetaProgramming/
* Aprem 1 (1h30) : [Programmation fonctionnelle](3-ClassRoom/3-FunctionalProgramming/
* Aprem 2 (1h30) : [Programmation concurrente](3-ClassRoom/4-ConcurrentProgramming/
## [2eme inter-session, 4 jours](4-HomeWork/
Lecture des [consignes de codage](,
entrainement à la **nouvelle bibliotheque** C++, et travail sur les **codes personnels**.
## [3eme jour ensemble](5-ClassRoom/
Quelques thèmes plus spécifiques au calcul scientifique : donner des unités aux valeurs,
controler la précision de son calcul, optimiser sa structure de données. Plus un apercu
de C++20.
* Matin 1 (1h30) : [Grandeurs et unites](1-QuantitiesAndUnits/fr.0-index.ipynb)
* Matin 2 (1h30) : [Precision flottante](2-FloatingPointComputing/fr.0-index.ipynb)
* Aprem 1 (1h30) : [Optimisation des performances](3-Optimisation/
* Aprem 2 (1h30) : [Apercu de C++20](4-Cpp20Glimpse/
## Quelques ressources extérieures
* [Cpp Reference](
* [Learn Cpp](
* [Zeste de Savoir](
Outils en ligne
* [CoLiRu](
* [Compiler Explorer](
* [Modernes Cpp](
* [Simplify C++](
* [Fluent C++](
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment