cours 9 : concurrence 2 promise, future, async · plan •on a vu au cours précédent :...
TRANSCRIPT
![Page 1: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/1.jpg)
Programmation Répartie
Master 1 Informatique – 4I400
Cours 9 : Concurrence 2
Promise, Future, Async Yann Thierry-Mieg
page 0
![Page 2: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/2.jpg)
Plan
•On a vu au cours précédent :
• Protobuf, un format et un outillage pour la sérialisation
•Aujourd’hui : Concurrence le retour •Retour sur les outils thread : mutex, condition, atomic
•Promise, Future
•Async, packaged task
•Références :
• « Design Patterns », le GOF Gamma, Helm, Vlissides, Johnson
•« C++ concurrency in Action » Anthony Williams
•Slides assemblées de plusieurs sources, citées dans les slides concernées
En particulier Akim Demaille (EPITA) (pas mal de biblio citée)
https://www.lrde.epita.fr/~theo/lectures/CXXA/cxxa_5.pdf
https://www.lrde.epita.fr/~theo/lectures/CXXA/cxxa_6.pdf
Exemple BD : GlobalLogic Ukraine
1
![Page 3: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/3.jpg)
Concurrence, Parallélisme
• Concurrence
• Un Modèle de programmation
• Différents flots de contrôle
• Vise la clarté
• Pas nécessairement l’efficacité
• Certains langages entièrement basés sur la concurrence
• GO, UrbiScript
• Parallélisme
• Exécution simultanée de calculs
• Mécanisme physique
• Hyperthread, Multicore, GPU…
2
![Page 4: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/4.jpg)
Mémoire
• Processus
• Chacun son espace d’adressage
• Communication uniquement via des canaux dédiés (IPC)
• Signaux
• Tubes
• Memory Map
• Sockets
• Threads
• Partagent l’espace d’adressage
• Lectures et écritures concurrentes possibles
• Les variables de la pile (appels) sont locales au thread (en général)
• Accès concurrents
• Attention aux collisions,
• mutex, atomic..
3
![Page 5: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/5.jpg)
Thread vs Taches
• Multithreading
• Création explicite de thread
• Création de thread, affectation du travail, join
• Latence due à la création/destruction des thread
• Problème de passage à l’échelle, trop de thread tue la mule
• Multitask :
• Partitionner le travail en morceaux parallélisables
• Notion de tâche à réaliser
• Parallélisable = concurrent, pas nécessairement parallèle
• Laisse le runtime décider de l’allocation aux threads disponibles
• Connaissance de la machine (compilateur, librairie)
• Passe mieux à l’échelle (massivement multicore)
• Parallélisme à grain plus fin => plus de parallélisme potentiel
4
![Page 6: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/6.jpg)
Communiquer entre Thread
• Mémoire partagée
• Les threads accèdent en concurrence aux données partagées
• Nécessité de synchronisations
• Atomic
• Mutex
• Condition variable
• Passage de messages
• En principe pas de partage mémoire
• Files de messages, channels, boite aux lettres…
• Passe bien à l’échelle
• Sur multi processus
• Sur infrastructure distribuée
• Mais plus lent que le partage mémoire direct
• Copies, ou risque de réintroduction de data race.
5
![Page 7: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/7.jpg)
Data Race
• Conflit d’accès
• Deux (ou plus) threads accèdent en même temps au même
emplacement mémoire
• Au moins un d’entre eux est un écrivain
• Résultats non définis
• Data Race
• Un conflit d’accès non protégé
• « les threads font la course »
• Mauvaise idée, on ne contrôle pas qui gagnera
• Synchronisations bloquantes pour corriger
• Utilisation de mutex, lecteurs et écrivains partagent le lock
• Possibilité de structures « lock free » cependant très difficiles à réaliser
correctement
6
![Page 8: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/8.jpg)
Modèle Mémoire
• Les différents processeurs
• Ont une vision distincte de la mémoire
• Chaque processeur a son propre cache
• Les garanties pour la propagation entre caches sont relaxées
• Des instructions dédiées (barrières mémoires) pour contrôler la
cohérence
• Accessibles en C++
• Les variables atomic
• Disposent d’opération atomiques simples : incrément, compare and
swap
• Permettent l’introduction de barrières mémoire explicites
• Sont la base de toutes les autres primitives de synchronisation
7
![Page 9: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/9.jpg)
Absence de Data Race
• L’objectif est la cohérence « séquentielle »
• Les langages/architectures modernes permettent de la contourner
• Les raisonnements normaux s’écroulent
8
X=0 ; Y =0
(Thread A)
X=1
R1=Y
(Thread B)
Y=1
R2=X
![Page 10: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/10.jpg)
Absence de Data Race
• L’objectif est la cohérence « séquentielle »
• Les langages/architectures modernes permettent de la contourner
• Les raisonnements normaux s’écroulent
• Ici on peut terminer avec : R1=R2=0
• L’absence de Data Race garantit la cohérence séquentielle
• Donc toujours prévenir les conflits d’accès
9
X=0 ; Y =0
(Thread A)
X=1
R1=Y
(Thread B)
Y=1
R2=X
![Page 11: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/11.jpg)
Risques liés à la concurrence
• Nombre exponentiel d’entrelacements possibles
• Si N processus indépendants, chacun pouvant prendre K états
possibles, N^K états du programme entier
• Difficile pour le raisonnement
• Difficile à vérifier/contrôler pour les outils
• Erreurs et bugs de concurrence
• Data race, violation de section critique, deadlocks, famines
• Difficile à trouver
• Difficile à reproduire (tests !)
• Difficile à debugger
10
![Page 12: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/12.jpg)
PROMISE, FUTURE
11
![Page 13: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/13.jpg)
Motivation
12
![Page 14: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/14.jpg)
Version thread
• Mise en place lourde
• Échange de données limité (terminaison par join)
13
![Page 15: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/15.jpg)
Pool de threads ?
14
![Page 16: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/16.jpg)
Pool + Barrières
15
![Page 17: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/17.jpg)
Programmation par Tâches
• Lancer un traitement puis obtenir sa réponse • Calculée par un autre thread
• Directement en mémoire
• Nécessité de synchronisation
• Comment communiquer le résultat de la tâche • Un canal de communication<T> standard pour échanger un résultat
• Un état partagé, variable(s) accédées par les deux threads
• promise : on doit la tenir, et écrire dedans le résultat
• Extrémité en écriture
• set_value(T)
• future : on obtient la valeur au bout d’un moment
• Extrémité en lecture
• wait(), get()
• Le future est bloquant tant que la promise n’est pas encore tenue
16
![Page 18: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/18.jpg)
Promise/Future
17
void hello(std::promise<std::string>& prm)
{
std::string res{"Hello from future"};
prm.set_value(res);
}
int main()
{
std::promise<std::string> prm;
std::future<std::string> fut(prm.get_future());
std::thread t(hello, std::ref(prm));
std::cout <<"Hello from main\n";
std::cout << fut.get() <<’\n’;
t.join();
}
![Page 19: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/19.jpg)
Promise/ future
18
![Page 20: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/20.jpg)
Promise / Future
• Permet aussi de loger des exceptions
• set_exception au lieu de set_value
• Le get() va lever l’exception
• Utile même en mono thread
• L’état partagé accessible via le future
• Est consommé par get(), s’il n’est pas trivial
• shared_future peut être construit à partir de future
• Permet d’attendre à plusieurs une résultat
• Invalide l’objet future sous jacent
19
![Page 21: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/21.jpg)
Opérations du future
• valid()
• Vrai si le future est encore utilisable (associé à un état partagé)
• get()
• Rend la valeur associée
• Bloquant si elle n’est pas disponible
• wait()/wait_for()/wait_until()
• Attente bloquante ou avec timeout
• share(), ou simplement construire un shared_future<T>(f)
• Construire une version partagée
• Invalide le future
20
![Page 22: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/22.jpg)
Taches : async
• L’exemple est encore assez lourd syntaxiquement
21
void hello(std::promise<std::string>& prm)
{
std::string res{"Hello from future"};
prm.set_value(res);
}
int main()
{
std::promise<std::string> prm;
std::future<std::string> fut(prm.get_future());
std::thread t(hello, std::ref(prm));
std::cout <<"Hello from main\n";
std::cout << fut.get() <<’\n’;
t.join();
}
![Page 23: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/23.jpg)
Async
• Du code parasite • Sur la fonction appelée
• Signature prend un « promise<T>» au lieu de T
• Signature rend void (forcé par thread)
• Nécessaire de set_value explicite
• Sur le code appelant
• Création de thread
• Join explicite
• Solution : • async : même signature que thread
• Engendre automatiquement une paire promise/future
• Encapsule les invocations pour avoir des signatures « normales »
• Encapsule la création/fin de thread
• Gère le degré de parallélisme indépendamment de la concurrence
22
![Page 24: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/24.jpg)
Hello revisité
23
#include<future>
#include<iostream>
std::string hello()
{
return"Hellofromfuture";
}
Int main()
{
auto future =std::async(hello);
std::cout <<"Hellofrommain\n";
std::cout << future.get() <<’\n’;
}
![Page 25: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/25.jpg)
Exemple BD revisité
24
![Page 26: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/26.jpg)
Politiques d’exécution
• On peut spécifier une politique • launch::async : exécution dans un nouveau thread
• launch::defferred : le future qui est retourné n’est pas concurrent • L’invocation à get() va faire calculer le résultat par le thread
appelant
• launch::defferred | launch::async : défaut, laisser le runtime décider
25
![Page 27: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/27.jpg)
Politiques d’exécution : test
PR Cours 8 et 9 : sockets 26
![Page 28: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/28.jpg)
Politique défaut
27
![Page 29: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/29.jpg)
Politique Deferred
28
![Page 30: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/30.jpg)
Politique async • Sensiblement pareil que le défaut
29
![Page 31: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/31.jpg)
Packaged_task
• Elément support pour la construction de async
• Encapsule une fonction dans une paire future/promise
• Pas de création de thread ou de concurrence
• Construction similaire à async ou thread
• Fonction + arguments en nombre et type arbitraire
PR Cours 8 et 9 : sockets 30
![Page 32: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/32.jpg)
Sort séquentiel
31
![Page 33: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/33.jpg)
Sort Concurrent
32
![Page 34: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/34.jpg)
Tris
33
![Page 35: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/35.jpg)
Bilan ?
• Pour 4000 entrées
• Attention au grain et au coût de mise en place
• Le coût est amorti par des jeux de données plus importants
34
![Page 36: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/36.jpg)
TASK BASED Exemple : Intel TBB
35
![Page 37: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/37.jpg)
Introduction à Intel TBB
• Librairie pour le parallélisme grain fin • Très utilisée, industriellement et académiquement
• Très efficace et bien organisée
• Contient • Des algorithmes parallèles
• Des structures de données concurrentes (lock free si possible)
• Des primitives de synchronisation avancées
• Gestion efficace des allocations mémoire concurrentes
• Passage à l’échelle sur grand nombre de tâches, scheduling avancé
• Bénéfices • Bibliothèque C++, tous compilateurs, tous OS, protable
• « icc » évidemment à privilégier + support architectures intel Atom, Core, Xeon … particulièrement bon
36
![Page 38: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/38.jpg)
Vue d’ensemble
37
![Page 39: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/39.jpg)
Exemple Mandelbrot
38
![Page 40: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/40.jpg)
Exemple QuickSort
• Version de base :
• pose la comparaison par défaut
• Trie de début à end
39
![Page 41: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/41.jpg)
QuickSort Parallèle (2)
40
• Tester : taille > 500 ou on laisse tomber le parallélisme
![Page 42: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/42.jpg)
Quicksort (3)
• Cœur « internal » : • construire un « range »
• Utiliser « parallel_for »
• Lancer avec un « partitioner » (découpe)
41
![Page 43: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/43.jpg)
QuickSort (4)
• Tri des paquets d’éléments trop petits pour le parallélisme
42
![Page 44: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/44.jpg)
QuickSort (5)
• Classe support : un range, sans copie
43
![Page 45: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/45.jpg)
QuickSort (6)
• Tri + découpe
44
![Page 46: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/46.jpg)
Résultat ?
45
![Page 47: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/47.jpg)
TBB : autres éléments
46
![Page 48: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/48.jpg)
Taches, Flots
• Exprimer les dépendances entre tâches
47
![Page 49: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/49.jpg)
Types de Noeuds
• Un jeu flexible, incluant des relations 1-*
48
![Page 50: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/50.jpg)
Algorithme = flow graph
49
![Page 51: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/51.jpg)
Flow Graph (exemple 2)
50
![Page 52: Cours 9 : Concurrence 2 Promise, Future, Async · Plan •On a vu au cours précédent : •Protobuf, un format et un outillage pour la sérialisation •Aujourd’hui : Concurrence](https://reader036.vdocument.in/reader036/viewer/2022071007/5fc419664850a76932083762/html5/thumbnails/52.jpg)
Conclusion
• De nombreux autres features • Structures de données concurrentes e.g. lock free concurrent hash
table
• L’approche parallélisme par tâches • Permet d’exprimer la concurrence de l’application
• A niveau d’abstraction élevé
• En retardant la réflexion sur le parallélisme effectif
• Plus la description est abstraite • Plus il y a de la place pour l’optimisation par les outils
• A condition de leur faire confiance
• Les outils e.g. TensorFlow très spécialisés
• Très bonne « compilation » dédiée au hardware disponible
• Les librairies génériques par tâche
• Bon compromis, bonne base, n’exclut pas de devoir être plus fin
51