The Chemical Abstract Machine
Total Page:16
File Type:pdf, Size:1020Kb
The Chemical Abstract Machine GCrard Berry* G6rard Boudol Ecole des Mines INRIA Sophia-Antipolis Sophia-Antipolis 06560 Valbonne, France 06560 Valbonne, France Abstract The situation is much less clear in the field of con- current programming. Models such as Petri Nets, We introduce a new kind of abstract machine based Communicating Automata, or Data Flow Networks on the chemical metaphor used in the l? language of can be considered as abstract machines, but certainly Ban%tre & al. States of a machine are chemical solu- they lack expressive power. More expressive models tions where floating molecules can interact according such as Algebraic Process Calculi (18,6] are intended to reaction rules. Solutions can be stratified by encap- to be specification formalisms for distributed systems sulating subsolutions within membranes that force re- rather than abstract machines. Implementation mod- actions to occur locally. We illustrate the use of this els of Concurrent Programming Languages such as model by describing the operational semantics of the CSP [IS] are conceptually based on standard sequen- TCCS and CCS process calculi. We also show how tial machine models augmented with scheduling facil- to extract a higher-order concurrent &calculus out of ities, not on specific abstract machines. the basic concepts of the chemical abstract machine. Most available concurrency models are based on architectural concepts, e.g. networks of processes 1 Introduction communicating by means of ports or channels. Such concepts convey a rigid geometrical vision of concur- We present the notion of a Chemical Abstract Ma- rency. Our chemical abstract machine model is based chine, suited to model asynchronous concurrent com- on a radically different paradigm, which originated putations. We show that chemical abstract machines in the I’ language of Banstre and Le Metayer [2,3]. can 5nplement” known models of concurrent com- These authors pointed out that parallel programming putation such as algebraic process calculi [18,6] and with control threads is more difficult to manage than a concurrent X-calculus similar to the one presented sequential programming, a fact that contrasts with in [7). the common expectation that parallelism should ease Abstract machines are widely used in the classical program design. They argued that a high-level par- theory of sequential computations. Turing Machines allel programming methodology should be liberated or Random Access Machines are primary tools within from control management. A similar idea motivates the theories of recursive functions and computational the UNITY model of Chandy and Misra [9]. Then complexity. The SECD machine 117) and the Cate- they proposed a model where the concurrent Comp+ gorical Abstract Machine [lo] are used to study and nents are freely “moving” in the system and commu- implement the X-calculus, while the SMC machine nicate when they come in contact. [19] may be used to describe the semantics of usual Intuitively, the state of a system is like a chemi- imperative constructs. cal solution in which floating molecules can interact *presently at LIX, Ecole Polytechnique, 91 128 Palaiseau, with each other according to reaction rules; a mag- France ical mechanism stirs the solution, allowing for pos- Work supported by the french Programme de Rechercher Coordonn&es C3. sible contacts between molecules. In chemistry, this is the result of Brownian motion, but we don’t insist on any particular mechanism, this being an imple- mentation matter not studied here, see (2,91. The so- Permission to copy without fee all or part of this material is granted lution transformation process is obviously truly par- provided that the copies are not made or distributed for direct allel: any number of reactions can be performed in commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy other- wise or to republish, requires a fee and/or specific permission. @ 1990 ACM 089791-3434/90/0001/0081 $1.50 81 parallel, provided that they involve disjoint sets of 2 Handling a Subset of CCS molecules. Notice that the tuple space model of Linda !8] is based on very similar concepts and bears the Our first illustrative example is a fragment CCS- same degree of potential parallelism, as well as the of Milner’s process caIculus CCS (181, containing the sets of assignments used in UNITY 191. most basic operators 0 (inaction), ‘.’ (prefixing), and Let us give a simple but striking example from [2,3]. ‘ ( ’ (parallel), as well as the restriction operator ‘\’ to Assume the solution is originally made of all integers make the example non-trivial. from 2 to n, along with the rule that any integer b e a set of namea and destroys its multiples. Then the solution will end Let U= {a,b,...} up containing the prime numbers between 2 and n. L = (a,?i ] a f U} be the set of labels built on U. See [2,3] for more examples and for implementation We use the symbols cy, /3, etc., to range over labels, techniques. with ?%z CY. The CCS- agents p, q, etc., are given by the syntax: TechnicaUy, a I program is defined by the struc- ture of the molecules it handles and by a set of re- action rules. Solutions are represented by multisets P ::= 0 I a.~ I (P I P) I p\a of molecules: this accounts for the associativity and commutativity of parallel composition, that is the im- plicit stirring mechanism. The reaction rules are mul- tiset rewritings. 2.1 The Semantics of TCCS We keep the same basic notions for chemical ab- stract machines, We elaborate on the original I’ lan- Process calculi semantics are usually defined by in- guage by presenting molecules in a systematic way ference rules in Plotkin’s structural operational se- as terms of algebras and refining the classification of mantics style, called SOS for short. Milner’s origi- rules. Some molecules do not exhibit interaction ca- nal rules involve an additional T label representing pabilities; those which are ready to interact are called internal communication. This happens to be quite ions. A solution can be heated to break complex unnatural with respect to abstract machine execu- molecules into smaller ones up to ions. Conversely, a tions, where internal transitions should not be visible solution can be coaled to rebuild heavy molecules from to the user. We prefer to use the De Nicola - Hen- components. Furthermore, to deal with abstraction nessy TCCS rules [13] that define two kinds of transi- and hierarchical programming, we allow a molecule to tions between agents: the internal transitions p ----)p’ contain a subsolution enclosed in a membrane, which and the labelled transitions p 4 p’. Intuitively, p -+ p’ can be somewhat porous to allow communication be- means that p can become p’ by executing an internal tween the encapsulated solution and its environment. action, and p 3 p’ means that p can offer its environ- The chemical abstract machines all obey a simple ment to accept the action a and then become pt. set of structural laws. Each particular machine is Both transitions systems are defined in a structural given by adding a set of simple rules that specify how way: the behavior of an agent is deduced from the to produce new molecules from old ones. Unlike the behaviors of its components. Since internal commu- inference rules classically used in structural opera- nications generate internal transitions, the inference tional semantics, the specific rules have no premisses systems for -+ invokes the one for 5: and are purely local. In this paper, we concentrate on the descriptive power of chemical abstract machines. The strength a.p 4 p I of the model lies in the membrane notion. Membranes P-+P make it possible to build chemical abstract machines PIti--+ p’lq and ~lp--vld that have the power of classical process calculi or that p-s, t behave as concurrent generalisations of the lambda- plq~:‘(q and qlp~:lp’ calculus. a t ?i t To familiarise the reader with our concepts, the next section presents a simple machine for a subset ii!? + P’i+cf of CCS. Section 3 gives some formal definitions. In Section 4, we treat the full TCCS 1131 calculus and fi indicate how to handle other process calculi. Section P s P’ a fZ {a,5 5 is devoted to a concurrent lambda-calculus similar p\a 4 $\a to that of [7]. We conclude in section 6. a2 2.2 Basic Chemistry: Concurrency The final solution (1 O,O,O b only contains the in- and Communication ert molecule 0. It is natural to clean it up by using the following rule, which says that 0 evaporates when We now take the chemical abstract machine point of heated: view, limiting us to internal transitions of restriction- inaction cleanup: free agents in this section. Restriction and external communication will be treated in the next section. o- Instead of composing their behaviors, we make the A last cleaning step yields the empty solution {ID. agents or molecules directly react with each other Generally speaking, chemical executions are non- within a solution, that is a multiset S = {Ip, Q, . 5. deterministic. For example, in the solution There are only two basic rules: {Ia.O, ‘ii.b.0, E.c.OD, the a.0 ion can react with any parallel: of the two others ions, yielding either {I b.0, Ti.c.0) or (IE.b.0, c.0 D after cleanup. PIQ “P, 4 The reader will appreciate the simplicity of the reaction: chemical executions compared to the sequence of proofs and simplifications involved in the SOS seman- a.p, if*q --+ p, q tics.