22
Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD - 12h TP TC1- CPPOO 96h - 9 Ects BE 12h TP CPOOP

Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Embed Size (px)

Citation preview

Page 1: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Matière 2:4,5 EctsConception et programmation

Orientée-objet 12h cours -14h TD -12h TP

Matière 1: 4,5 EctsProgrammation Parallèle

16h cours -18h TD - 12h TP

TC1- CPPOO 96h - 9 Ects

BE 12h TPCPOOP

Page 2: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

TC1: Conception et programmation parallèle et orientée objetVolume horaire: 96hRépartition:

Cours: 28hTD: 32hTP: 24hBE: 12h

Objectif: Ce cours a pour but de présenter les concepts de base de la programmation orientée objet et parallèle. Ils sont illustrés à travers une démarche de développement et des applications de synthèse.

Plan:1. Conception et Programmation Orientée Objets

- Concepts fondamentaux de la POO Rappels et compléments sur les concepts de la POO (classes, objets, héritage, polymorphisme, ...)

- Conception Orientée Objets - Introduction au langage de modélisation UML - Démarche d'analyse et de conception- Schémas de conception

- Mise en œuvre - Modélisation d'une application- Implantation avec Java

2. Programmation Parallèle- Expression des activités parallèles: processus et threads- Modèles de parallélisme: synchrone, asynchrone- Mécanismes de communication et de synchronisation

- variables partagées, envoi de messages - verrou, sémaphore, moniteur, rendez-vous

- Problèmes et applications- Exclusion mutuelle - Allocation de ressources- Schéma producteur-consommateur, lecteur-rédacteur, ...

- Eléments de spécification et de vérification- Mise en œuvre (UNIX et Java)

3. Travaux de synthèse - Réalisation d'objets synchronisés - Etude et réalisation d'interfaces graphiques

Cette partie sera assurée dans le cadre de bureaux d'études et travaux-pratiques. Elle doit permettre de faire le lien entre les deux premières parties.

Page 3: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Programmation Parallèle

Pourquoi ?

Systèmecomplexe

Exigence:Décomposition en activités « indépendantes »

Matériel

multiprocesseur

réseaux

monoprocesseur

Page 4: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Plateforme

Centralisé Distribué

Pseudo-parallélisme Parallélisme réel

----------------

----------------

Multiprocesseur: UC1..UCn

Monoprocesseur: UCréseaux

MC

P0 P1

Passage de contrôle

S1 S2 S3 Sn

----------------

----------------

----------------

----------------

Page 5: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Expression du parallélisme

Processus

Définition utilisateur

Programme en cours d’exécution

Définition système

Descripteuridentitéétatpcontexte:

Pile du processus__:_Ad_SDonnéesAd_Code

S_Données__

Ad_Code__

Processus

Page 6: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

États d’un processus

• Selon implantations, sous-états possibles

PRÊT BLOQUÉ

ACTIF

TERMINÉ

Créé

AllocationPréemption

Attente

Fin, destruction

Plusieurs processusPrêts attendent l’UC

Le processus élu est choisit selon une politique de schedulling

Page 7: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Processus UnixS_Données_PèreX 0Pid Num_Fils

S_Code

S_Pile_Père

Main(){ int x, pid;

x=0; pid = fork();if (!pid) x=1;else x=2;

}

S_Données_filsX 0Pid 0

S_Pile_Fils

Page 8: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Processus Unix

S_Code

S_Pile_Père

Main(){ int x, pid;

x=0; pid = fork();if (!pid) x=1;else x=2;

}

S_Pile_FilsS_Données_filsX 1Pid 0

S_Données_PèreX 2Pid Num_Fils

Page 9: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Thread « processus léger »

Expression du parallélisme

de partager l’espace d’adressage avec d’autres

Permettre à une activité parallèle

contrairement aux processus

processus

t1 t2 t3 tn

S_Données_processus

_

Page 10: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Un thread est crée, seulement, par un processus

Un processus peut créer plusieurs threads

Les threads s’exécutent d’une façon général en multiprogrmmé

• Ils partagent le temps du processus père

• Le contrôle passe à un autre thread si le thread courant:

• se termine

• se bloque

• Lance une opération E/S

D’autres politiques de schedulling sont possibles

Le processus père joue le rôle du processeur / à ses threads

Page 11: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

États d’un thread

• Selon implantations, sous-états possibles

PRÊT BLOQUÉ

ACTIF

TERMINÉ

Créé

AllocationPréemption

Attente

Fin, destruction

les threads Prêts attendent dans le processus

Le thread élu est choisit selon une politique de schedulling.Il s’exécute quand le processus est actif

Page 12: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

S_Code

int x; /*-------------------------------------------------------------------------*/void *traitementThread () {/*------------------------------------------------------------------------*/ int i; x++; printf(…) x++;}

main() { int etat; int numThreads; pthread_t idThread; pthread_attr_t attribut; /* Creation d’un thread */ x = 1;etat = pthread_create(&idThreads, &attribut, traitementThread, &numThreads);Printf (…..);X--; }

X == 1

Page 13: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

S_Code

int x; /*-------------------------------------------------------------------------*/void *traitementThread () {/*------------------------------------------------------------------------*/ int i; x++; printf(…) x++;}

main() { int etat; int numThreads; pthread_t idThread; pthread_attr_t attribut; /* Creation d’un thread */ x = 1;etat = pthread_create(&idThreads, &attribut, traitementThread, &numThreads);Printf (…..);X--; }

X == 2

Page 14: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

S_Code

int x; /*-------------------------------------------------------------------------*/void *traitementThread () {/*------------------------------------------------------------------------*/ int i; x++; printf(…) x++;}

main() { int etat; int numThreads; pthread_t idThread; pthread_attr_t attribut; /* Creation d’un thread */ x = 1;etat = pthread_create(&idThreads, &attribut, traitementThread, &numThreads);Printf (…..);X--; }

X == 1

Page 15: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

S_Code

int x; /*-------------------------------------------------------------------------*/void *traitementThread () {/*------------------------------------------------------------------------*/ int i; x++; printf(…) x++;}

main() { int etat; int numThreads; pthread_t idThread; pthread_attr_t attribut; /* Creation d’un thread */ x = 1;etat = pthread_create(&idThreads, &attribut, traitementThread, &numThreads);Printf (…..);X--; }

X == 2

Page 16: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Créer un thread

int pthread_create(pthread_t *thread,

const pthread_attr_t *attr,

void *(*start_routine)(void*),

void *arg);– start_routine = fonction exécutée par le thread– arg = argument de cette fonction– attr = attributs optionnels de création– thread = identificateur

• Toutes les ressources nécessaires au thread doivent avoir été initialisées. • Erreurs possibles :

– EINVAL : attributs invalide– EAGAIN : ressources insuffisantes

Exemple: Thread Unix

Page 17: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Autres opérations sur un thread

int pthread_detach(pthread_t thread);• Détacher un thread• Erreurs :

– (EINVAL : thread non « joignable »– ESRCH : thread invalide)

pthread_t pthread_self(void);• Retourne l’identificateur de l’appelant

int pthread_yield(void);• <sched.h>, TR• Rend prêt l’appelant, élection nouveau thread• Erreur :

– Retour -1 + errno– ENOSYS : non supporté

Page 18: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Terminer un thread

void pthread_exit(void *value_ptr);• Terminaison de l’appelant

– value_ptr = valeur (non adr) de retour pour jointure

int pthread_join(pthread_t thread, void **value_ptr);• Attente de la terminaison d’un thread non détaché

– thread = identificateur du thread concerné– value_ptr = valeur retournée (si non NULL)

• Erreurs :– EINVAL : thread non « joignable »– ESRCH : thread invalide– (EDEADLK : join avec self)

• Exemple : create, exit/join

Page 19: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

2 Modèles du parallélisme

I- Modèle Synchrone

Flot de données

Flot de contrôle

P0--------------------------------

P1--------------------------------

Pn--------------------------------

Horloge

t0

t1

t2

t3

t4

• Une seule horloge

• A chaque top tous les processus s’activent

• exécution // entre 2 top

• interaction 0

Lustre

Esterel

Page 20: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

2 Modèles du parallélisme

II- Modèle Asynchrone

H0 H1 H2 ……. Hn

• Indépendance

• interaction 0

Page 21: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Quelques Problèmes Causes

coopération Partage de ressources

Communication&

Synchronisation

Synchrone

Asynchrone

Variables partagées

Envoie de messages

Page 22: Matière 2:4,5 Ects Conception et programmation Orientée-objet 12h cours -14h TD -12h TP Matière 1: 4,5 Ects Programmation Parallèle 16h cours -18h TD -

Quelques Problèmes

Exclusion MutuelleCommunication Synchrone

Communication Asynchrone

Attendre & Signaler un événement

Diffuser un événement

Allocation de Ressources

Fichier Partagé

Pilote d’Entrée /Sortie

::::::::

Propriétés Comportementales

SûretéSection Critique

Non Inter blocage

VivacitéNon Famine

Équité