introduction à linda béat hirsbrunner references nicholas carriero, david gelernter : "linda...

15
Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989) p. 444-458. Nicholas Carriero, David Gelernter : "How to write parallel programs: a first course", The MIT Press, 1990. Béat Hirsbrunner: "Introduction à Linda", Université de Fribourg, Suisse, Notes de cours, mai 1991. Ubiquitous Systems Béat Hirsbrunner (Fribourg) and Peter Kropf (Neuchâtel)) Autumn Semester 2007, Lecture 1, 28 September 2006

Upload: honorine-bouvier

Post on 04-Apr-2015

104 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

Introduction à Linda

Béat Hirsbrunner

ReferencesNicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989) p. 444-458.

Nicholas Carriero, David Gelernter : "How to write parallel programs: a first course", The MIT Press, 1990.

Béat Hirsbrunner: "Introduction à Linda", Université de Fribourg, Suisse, Notes de cours, mai 1991.

Ubiquitous SystemsBéat Hirsbrunner (Fribourg) and Peter Kropf (Neuchâtel))Autumn Semester 2007, Lecture 1, 28 September 2006

Page 2: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

2

1. Remarque préliminaire

• Langage de programmation vs

Langage de coordination

• Modèle de calcul vs

Modèle de communication

• Indépendance totale “progr.” - “coord.” possible?

Page 3: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

3

2. Définition de Linda

• Modèle de mémoire composé Collection de tuples, appelé espace des tuples Ensemble d’opérations

• Rajout, retrait et lecture de tuples

Mécanisme d’unification qui permet d’accéder aux tuples

Page 4: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

4

3. Définition d’un tuple

• Suite finie et ordonnée de champs typés• Chaque champs contient soit une valeur typée, soit un

processus• Exemple:

<“un tuple de données”, 3.14) > <“un type de processus”, cos(3.14)>

Page 5: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

5

4. Définition d’un anti-tuple

• Suite finie et ordonnées de champs typés• Chaque champs contient soit une valeur typée, soit

une place libre typée susceptible d’accueillir une valeur du même type

• Exemple: <“un anti-tuple”, ?x>

Page 6: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

6

5. Opérations de lecture

• rd(a) bloquant équité garantie

• n tuples candidats, m processus en attente• problème: définition pécise et non ambiguë de la notion d’équité

(notamment lorsque l’espace des tuples est réparti!!!)

• rdp(a) non bloquant

Page 7: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

7

6. Opérations de retrait

• in(a) idem à rd(a), mais le tuple t qui a été unifié à l’anti-tuple a est retiré

de l’espace des tuples

• inp(a) idem à rdp(a), mais si un tuple t a été unifié à l’anti-tuple a alors ce

tuple t est retiré de l’espace des tuples

Page 8: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

8

7. Opérations de rajout

• out(t) le tuple t est d’abord évalué, puis rajouté à Ts, et finalement

le processus appelant reprend son exécution

• eval(t) un processus p permettant d’évaluer le tuple t est créé tous les processus s’exécute en parallèle si le tuple t contient n champs de processus, le choix de

créé 1 ou n+1 processus est laissé au choix de l’implémentation

Page 9: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

9

8. Modèle d’unification

• Le modèle d’unification n’est pas précisé au niveau du modèle Linda !!!

• Ce modèle doit être définie pour chaque réalisation de Linda dans un langage de programmation donné

• A méditer : programmation = calcul + communication ?!

Page 10: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

10

Exemple 1. Calcul des nombres premiers (1)

% création de n-1 tuples de processus,

% un par nombre entier ≤ n

for i := 2 to n do

eval("nombre premier", i, est_premier(i));

end for;

% lecture des nombres premiers ≤ n

for i := 2 to n do

rd("nombre premier", i, ? ok);

end for;

Page 11: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

11

% définition de la procédure est_premierprocedure est_premier(i:integer) : boolean;var j: integer;begin for j := 2 to sqrt(i) do rd("nombre premier", j, ? ok); if ok and (i mod j = 0) then return false end if; end for; return true;end est_premier;

Exemple 1. Calcul des nombres premiers (2)

Page 12: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

12

Exemple 2. Problème des philosophes (1)

% création de n baguettes, n philosophes

% et n-1 tickets

for i := 1 to n do

out("baguette", i);

eval(philosophe(i));

if i < n then out("ticket") end if;

end for;

Page 13: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

13

% définition d'un philosopheprocedure philosophe(i:integer);begin loop forever penser; in("ticket"); in("baguette", i); in("baguette", (i+1) div n); manger; out("baguette", i); out("baguette", (i+1) div n); out("ticket"); end loop;end philosophe;

Exemple 2. Problème des philosophes (2)

Page 14: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

14

The Sleeping Barber Problem (1)

Andrew S. Tanenbaum: "Modern Operating Systems"; Prince Hall 2001, chap. 2.4.3

Page 15: Introduction à Linda Béat Hirsbrunner References Nicholas Carriero, David Gelernter : "Linda in context", Communications of ACM, vol. 32 (n° 4, April 1989)

15

The Sleeping Barber Problem (2)

Solution to sleeping barber problem