1 / 28

Coordination Models and Languages

Coordination Models and Languages. Part I: Coordination Languages and Linda Part II: Technologies based on Tuple space concept beyond Linda Part III: Comparison of coordination languages. Conclusions. Coordination Languages and Linda. Natalya Abraham CS854. Problem.

jariah
Télécharger la présentation

Coordination Models and Languages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Coordination Models and Languages Part I: Coordination Languages and Linda Part II: Technologies based on Tuple space concept beyond Linda Part III: Comparison of coordination languages. Conclusions.

  2. Coordination Languages and Linda Natalya Abraham CS854

  3. Problem In concurrent and distributed programming: • We prefer to look at each component as a black box. • We need a mechanism for controlling interactions between the components.

  4. Candidate technologies: • Concurrent OOP • Concurrent logic programming • Functional programming

  5. Concurrent Object Oriented Programming: Limitations • Based on message-passing • The process structure - the number of processes and their relationships - determines the program structure. Concurrent Logic Programming: Limitations • Too policy-laden and inflexible to serve as a good basis for most parallel programs. Functional Programming: Limitations • Fail to provide the expressivity we need • Gains nothing in terms of machine independence

  6. The way out - Coordination “Coordination is managing dependencies between activities.” (From Coordination Theory) “Coordination is the process of building programs by gluing together active pieces.” (Carriero and Gelernter, Linda creators)

  7. Programming = Computation + Coordination (Carriero and Gelernter, Linda creators)

  8. In programming coordination is expressed by: • Coordination models Triple (E, L, M) E – entities being coordinated (agents, processes, tuples) L – media used to coordinate the entities (channels, shared variables, tuple spaces) M – semantic framework of the model (guards, synchr. constraints) • Coordination languages “The Linguistic embodiment of a coordination model”

  9. Coordination Languages must support: • Separation between computation and coordination. • Distribution (decentralization) • Dynamics(no need to link the activities before runtime) • Interoperability • Encapsulation (implementation details are hidden from other components)

  10. Leading coordination models and languages • Tuple Space Model (coordination through Shared Data Space) Linda, TSpaces, JavaSpaces, Jini • IWIM (coordination through channels) Manifold

  11. Tuple spaces and Linda • Based on generative communication: Processes communicate by inserting or retrieving data objects (called Tuples) from shared Data Space ( called Tuple space) • Interoperability is achieved: Linda places no constraints on the underlying language or platform

  12. Tuple Space Concept P Out() P In/Rd() Eval() P Tuple Tuple Space

  13. Tuple space operations • Tuple is a series of typed fields. Example: (“a string”, 15.01, 17) (10) • Operations out (t) insert a tuple t into the Tuple space (non-blocking) in(t) find and remove a “matching” tuple from the tuple space; block until a matching tuple is found rd(t) like in(t) except that the tuple is not removed eval(t) add the active tuple t to the tuple space The model is structurally recursive: a tuple space can be one field of a tuple.

  14. Tuple matching Let t(i) denote the ith field in the tuple t. A tuple t given in a in(t) or rd(t) operation “matches” a tuple t’ in the tuple space iff: 1. t and t’ have the same number of fields, and 2. for each field if t(i) is a value then t(i) = t’(i) or if t(i) is of the form ?x then t’(i) is a valid value for the type of variable x If more than one tuple in the tuple space matches, then one is selected nondeterministically. As a result of tuple matching if t(i) is of the form ?x, then x := t’(i)

  15. Example of Tuple matching N-element vector stored as n tuples in the Tuple space: (“V”, 1, FirstElt) (“V”, 2, SecondElt) … (“V”, n, NthElt) To read the jth element and assign it to x, use rd ( “V”, j, ?x ) To change the ith element, use in (“V”, i, ?OldVal) // Note: It is impossible to update a tuple without out (“V”, I, NewVal); // delete/add

  16. Example 1: Sending and Receiving messages

  17. Manifold: p.out-> q.in Linda: channel (p, out, q, in) { while (1) { in (p, out, Index, Data) out (p, in, Index, Data); } } Sending and Receiving messages (Cont.)

  18. Sending and Receiving messages (Cont.) • Message-passing model contains tree separate parts: • Tag (message Id) • Target • Communication • In Linda, Tuple is a set of fields, any of which may be a tag (message Id) or target (address) or communication (data).

  19. Sending and Receiving messages (Cont.) • In message-passing model a process and a message are separate structures. • In Linda, a process becomes a tuple.

  20. Example 2: Semaphores • Semaphores Initialize: out(“sem”) wait orP-operation: in(“sem”) signal or V-operation: out(“sem”) For counting semaphore execute out(“sem”) n times

  21. Example 3: Loop Turn a conventional loop into a parallel loop – all instances of <something> execute simultaneously. for <loop control> <something> In Linda: for <loop control> // creates many processes to execute eval(“this loop”, something( )); // the loop in parallel for <loop control> // Forces all executions to be complete in(“this loop”, 1); // before proceeding Where something( ) – function, returns 1

  22. Example 4: Masters and Workers • Master divides work into discrete tasks and puts into global space (tuple space) • Workers retrieve tasks, execute, and put results back into global space • Workers notified of work completion by having met some condition • Master gatherers results from global space

  23. Masters and Workers (Cont.) master() { for all tasks { …/* build task structure*/ out (“task”, task_structure); } for all tasks { in (“result”, ? &task_id, ? &result_structure); } } worker() { while (inp (“task”, ? &task_structure) { …/* exec task */ out (“result”, task_id, result_structure); } }

  24. Example 5: Barrier Synchronization Each process within some group must wait at a barrier until all processes in the group have reached the barrier; then all can proceed. • Set up barrier: out (“barrier”, n); • Each process does the following: in(“barrier”, ? val); out(“barrier”, val-1); rd(“barrier”, 0).

  25. phil(i) int i; { while (1) { think(); in (“room ticket”); in (“chopstick”, i) in (“chopstick”, (i+1)% Num); eat (); out (“chopstick”, i); out(“chopstick”, (i+1)%Num); out (“room ticket”); } } initialize() { int i; for (i=0; i< Num; i++){ out (“chopstick”, i); eval ( phil(i) ); if (i< (Num-1)) out(“room ticket”); } } Example 6: Dining Philosophers Problem

  26. server() { int index = 1; … while (1){ in (“request”, index, ? req) … out (“response”, index++, response); } } client() { int index; … in (“server index”,? index); out (“server index”, index +1); … out (“server”, index, request); in (“response”, index, ? response); … } Example 7: Client-Server

  27. Linda achieves: • Nondetermenism • Structured naming. Similar to “select” in relational DB, pattern matching in AI. in(P, i:integer, j:boolean) in(P, 2, j:boolean) • Time uncoupling (Communication between time-disjoint processes) • Distributed sharing (Variables shared between disjoint processes)

  28. Linda: Limitations • The language is although intuitive, but minimal • Security (no encapsulation) • New problems: How is the tuple space to be implemented in the absence of shared memory? • Linda is not fault-tolerant - Processes are assumed not to fail - If process fails, it tuples can be lost - Reading operation is bloking, without timeout

More Related