An average value of the waitings in the words of the synchronized language is determined by .... We consider now the bivariate generating function of L: F(x,y) =.
Using generating functions to compute concurrency
Dominique Geniet & Loÿs Thimonier L.R.I. Orsay, Bât. 490, Universite Paris XI, 91405 ORSAY CEDEX, FRANCE U.F.R. de Mathematiques et Informatique, Universite de Picardie, 33 rue Saint Leu, 80039 AMIENS CEDEX
Abstract We present succinctly the Arnold-Nivat's model for the synchronization of sequential preocesses, and we recall the concurrency measure defined by Beauquier, Dérard and Thimonier. We present here a new technics for the computation of this measure avoiding very often a very expensive part of the computation. We illustrate this method by the mutual exclusion example.
Introduction The aim of this work is to improve the computing of the concurrency measure presented in [BBT86][BT87] for systems of concurrent processes.The only known technics, based on Darboux's theorem, is in fact unusuable in the frame of a software.By means of structural properties of generating functions of synchronized languages, we show that a large part of the computing can be omited... The evaluation of the concurrency must be independant of software datas, because the operating system is one of the parameters of the computing. Many authors [F86][BBT86] proposed some evaluations, linked to different models. We'll use here this introduced in 1986 by Beauquier, Bérard and Thimonier. The main idea consists in the evaluation of the average waiting time for each process. The less processes wait, the more concurrent are the computations. The modeling of concurrent processes used here is introduced in [AN82]. It is based on rational languages: every program is represented by a finite automaton, each process generated by the program corresponds to a word accepted by the automaton. The parallelization of a collection of programs (pi) i[ is modeled by the concurrent automaton: the cartesian product of the automata associated to the programs. Each transition of the concurrent automaton is labelled by a ntuple of letters (xi) i[. For each j, the jth component of (xi) i[ is the action executed by the p j. Nevertheless, the accesses to the critical sections of the system must be controlled (writing on a memory blok, access to a resource, precedence constraints, etc...). It's the aim of synchronization. In our model, it is performed by eliminating some transitions of the concurrent automaton. The language accepted by the result automaton will be call synchronized language. An average value of the waitings in the words of the synchronized language is determined by the computing of the concurrency measure. This involves the knowledge of their distribution. The multivariate generating functions [GJ83] constitute a very powerfull tool for the combinatorial study of a given sequence according to a given criterium. A language can be interpreted as a sequence of words, and its generating function f(z) =
∑ a n.z
n
is a way of counting them. Whe an
n[N
alphabet is partitionned in A and B, we can consider a bivariate generating function, the coefficient ap,q of the monomial x p yq being for instance the number of words of the language containing p letters of A and q letters of B. In a general way, if we call π the mapping which associate to each word w of the language the coefficient which take it into account, then the family (π -1(i))i[N must be a partition of the language, so that each word is couted only once. Thanks to ChomskySchützenberger's theorem [CS63], the determination of generating functions of non-ambiguous rational languages is simple as well theoritically as pratically. This enables to limit the complexity of the computations. However, this algorithm gives the generating functions of languages as the ratio of two polynomials. In order to determine the general term an of the associated serie, the most efficient method is this of Darboux [Ben74]: it uses the asymptotic approximation of an , by means of the poles of the considered function (a pole is a singularity with maximal multiplicity on the convergence circle). The complexity (as well in time as in memory space) is extremely high. To solve this problem, we introduce a new algorithm, based on the structural properties of the generating function, which cancels the computing of poles. We define a probability law on the set of convergence radius of generating functions of rational languages. Then, we show that quite surely, the sigularities used by Darboux's formula are of multiplicity 1. The concurrency measure is expressed with the only help of the convergence radius, which can be easily computed by Newton's method.
Proc. of Fundamentals of Computation Theory, Szeged, Hungary, 8/1989 LNCS 380, pp 185-196 Springer-Verlag
186 As an example, we present the access to a critical section by many processes. Many possible configurations (many processes, many resources) are considered. This enables a discussion on the best configuration.
I) Representation of concurrent processes
1) The processes and their behaviours [AN82] We define a processus by the set of its behaviours, finite or infinite. We are interesting in rational processes, who are represented by the concept of finite automaton (deterministic or non deterministic) or right linear grammar [G89]: each word accepted by the automaton is one of the possible behaviours for the processus, the alphabet of the language accepted by the automaton being the set of the actions executed by the processus. For a process p, we denote L(p) the rational language associated to p et A(p) the alphabet on which is built L(p). The interpretation of the automaton structure may be: -
The current state of the automaton represents the state of the process according to its context (the trace of the path from the initial state to the current state), and its issued transitions represent its possibilities.
-
During the initialization, the process is obligatorily at the initial state of the automaton.
-
When the process ends (correctly) it session, it is obligatorily in a final state of the automaton.
-
The actions performed by the process are modeled by the labels of the transitions of the automaton. Thus, the associated alphabet is the set of possible actions. Physically, the most detailled alphabet is the set of binary actions, but it is possible to consider alphabets in which many elementary actions are grouped in a single letter. This last case corresponds to hight-level languages.
This model of representation is synchronous, because it impose the performing of one elementary action at each time unit. Each action endures exactly one time unit. Thus, the real systems can be approached by considering the gcd of the duration of the elementary actions of the alphabet as the time unit. For instance, if a endures 3.5ms, b endures 4.2ms and c endures 8.4ms, the gcd is 0.7ms, each occurrence of a may be replaced by a5, each occurrence of b by b 6 and each occurrence of c by c 12. To simplify, we'll consider here that all the elementary actions endure the same time (this time will be our time unit).
2) Representation of multi-processes systems [AN82] We consider now several processes (pi) i[ running concurrently. Each of them is associated to a finite automaton. The functionment of the system is the following: at each time unit, each process executes an action. Then, the system (pi) i[ executes a vector of actions. For each process, any sequential behaviour must be possible. The length of the sequential behaviours of the processes may be different, hence all the processes don't obligatorily begin and end their execution simultaneously. This property obliges us to prefix and suffix the sequential behaviours with a special action we name inactive waiting, and we represent with the character @. The associated language to such a system is the set of words w on the alphabet composed by the vectors v with n components such that ∀i[, v[i][L(pi)'{@}. The constitutive elements of the result automaton can be interpreted like that: -
Each state of the automaton represents the present state of the system composed by the n processes. So, we can consider it as the vector of the individual states of each process p i.
-
All the processes start their execution in the same state of the distributes automaton: the initial state. Some of the (pi) i[ may have to execute the @ action to their effective start.
-
In the same way, all the processes end their execution in the final state of the automaton, with the possibility of executing @ after their effective end.
-
The system (pi) i[ uses a transition as one of the p is acts (the others may be acting, or executing the @). Each label of transition is a vector composed of n individual action, the ith composant being performed by p i. So, the firing of a transition impose each process to act. Then, we define the projection of a concurrent behaviour on an execution: Definition: Let w be a word of L((pi) i[). v is the projection of w on its ith execution
187 if and only if
{
|w| = |v|,∀j[ w[j][i] = v[j].
Example Let us consider the concurrent behaviour a @ a a
c @ @ a
c a @ a
a c @ c
a c @ c
a c @ a
a b @ @
@ b @ @
@ c @ @
@ a @ @
At the time 4, the performed vector of instructions is (a,c,@,a). So, the process number 3 is inactive (executing @), the processes 1 and 4 executing simultaneously the same action a, the process 2 executing c. The sequential behaviour of p 2 is represented by the projection of this concurrent behaviour on its second execution: @
@
a
c
c
c
b
b
c
a
We consider now the concurrent behaviours of systems of processes who must synchronize them during certain actions (communication, exclusion mutual acces to a resource, precedence constraints, etc...). The set of the synchronized behaviours is a subset of the concurrent behaviours of the system where the processes are considered independant. We model the synchronization constraints with a centralized control, that is an automaton which restricts the number of possible vectors of actions at each time unit. This is equivalent to consider a collection of vectors of actions (the forbidden instantaneous configurations) and build the automaton C who accepted language is i=n
( ∏ A(p ) ) \ S. Let L be the language of the concurrent behaviours of the system (pi) i[ and A(L) the i
i=1
associated automaton. We call synchronized language associated to the system (pi)i[ the language L(L(C). Example Let us consider two sequential processes p 1 and p 2 associated to the same automaton r,w,#
1
the cartesian square of this automaton recognize the language of the concurrent behaviours of the system (p1,p2): rr,rw,wr, r#,#r,w#, #w,##,ww 1
We want to synchronize this system with the constraint at each time unit, at most one process can execute the action w. To perform that, we consider the synchronization set S={ww,r#,#r,##}. The synchronized automaton is built from the previous one by removing all the transitions labelled by an element of S: rr,rw,wr, w#,#w
1
4) Power of the model Most of the programming languages use simple statements, loops and recursivity (which can always be removed using memory management [PMS88]). Then, the most complex programs can be represented in Arnold-Nivat's model. So, this model allows the representation of any usual program.
II) The concurrency measure
188
Fot the moment, we own a representation model for concurrent processes system. So, it seems natural to compare the different possible solutions to a given problem. To perform that, we compare the average waiting time per time unit and per process. Our evaluation mode will be a measure of the average of the waiting time.
1) Definition of the measure Let L be the language accepted by a synchronized finite automaton associated to the system (pi) i[. For each n, we denote λ n (L) the number of words of L of length n: λ n (L)=|L(∑n | (∑ is the alphabet of L). n.λ n (L) is the sommation of the lengths of such words. In the same way, we denote µn (L) the number of # in the words of L of ∑ n |w | #. The expression u L(n) = µ n(L) represents exactly the length n. One can see that µ n( L) = w[ L( (∑ L) n . λ n(L) frequency of # in the words of L of length n. We remark that the u L(n) is not defined if none of the words of L is of length n. [BT87] profs that it exists many subsequence of the form (uL(n.p+k))n[N (p is a caracteristic integer of the sequence) who admit limits t k . The concurrency measure t // is the average of the t k : it represents the average number of # per time unit for the words of L.
2) Using generating functions to compute t// Let f be the generating function of a language L. We have f(z) =
∑
λ
n.z
n
with, for each n, λ n is the number
n[ N
of words of length n [E76]. Let µn be the number of # in all the words of L of length n. We call ap,q the number of words of L of length p+q of L which contain exactly p occurences of #. So, the number q.a p,q is the number of # in q=n
all such words of L. Thus, the number
∑ q.a n-q, q is exactly the total number of #
in the words of L of length n,
q=0
that is µn . We consider now the bivariate generating function of L: F(x,y) =
∑
a p, q.x .y . From the expression of
∑µ
nz
p
q
p[ N , q[ N
∂ F (z,z) = F, we compute g(z) = z . dy
∑ ∑ ( p[N , q[N
n[N
p+q = n
*
q.a p,q
).z
n
=
n
. Using the generating function,s,
n[N
it is possible to compote t //: -
Computation of F(x,y) from the synchronized automaton (algorithm described above).
-
Computation of the serie f(z) = F(z,z). It is exactly the univariate generating function
∑
λ
n.z
n
of the
n[ N
language, because λ
∑
n = p+q = n a p,q. n[N
-
Computation of g(z) = z . ∂ F (z,z). We prooved above that the general term of the serie g() if µn . ∂y
-
For each n, we compute u L(n) =
-
The average of the defined values of the limits t k of (uL(n.p+k))n[N gives t //.
µ
n
. We know that the computation of the p general terms u L(n.p+k)n n.λ n is sufficient (with k in ) [BT87].
3) Determination of the generating function The determination of the generating function presented here is given by Chomsky and Schützenberger [CS63]. Let A= be a synchronized finite automaton. Chomsky and Schützenberger prooved that its bivariate generating function can be computed by the following algorithm: -
For each i in , the generating function F i(x,y) of the language L i accepted by the automaton is associated to the state i.
189 -
For each i in , the following statements are executed: * F i(x,y) is initialized to 0. * If the state i is a final state, the word ε is element of L i: it is a word of length 0 without any #. So, the value 1.x0.y0 must be added to F i(x,y). * Let t be a transition starting in the state i, w its label and a the state pointed by t. The set of the words of |w|-|w|#
|w|#
L i labelled by a path which first letter is t is w.La . So, its generating function is x .y .F a(x,y). So, if we call TS(i) the set of the transitions starting from i and e(j) and a(j) the label and the pointed state of the transition j, it's necessary to add to F i(x,y) the quantity
∑
x
|e(j)|-|e(j)|#
.y
|e(j)|#
.F a(j)(x,y) .
j[TS(i)
If L is a rational language, this algorithm built a system M.X=B, M being a matrix and B a vector with coefficients if Z[X,Y], and X the vector (F i(x,y))i[. Chomsky and Schützenberger prooved that this system always admits as a solution a vector of rational fractions on Z[X,Y] (a rational fraction on K[X] is the ratio of two polynomials on K[X]), and that the generating function F(x,y) can be obtained as the sum of the F i(x,y) for all the i who are initial states. However, the considered language must be non-ambiguous (the same word recognized by different ways), because some words may be couted for different ways, that falsify the generating function. It is knew (Kleene theorem) that a rational language can be recognized by a deterministic finite automaton. Every non deterministic automaton being nonambiguous, a rational language is non-ambiguous.
4) Computing of the measure using the technics of Darboux Now, we dispose of the bivariate generating function F of the considered synchronized language. It is a sum of P(x,y) rational fractions. So, it can be put of the form , where (P,Q)[Z[X,Y]2. Beauquier, Bérard and Thimnoier Q(x,y) give in [BT87] a method for the computing of t // based on the asymptotic development of the generating function. This technics needs important and expensive computing [G89]. The global functionning of the computing is: -
Computing of f(z) = F(z,z) and of g(z) = z . ∂ F (z,z). ∂y
-
We call λ n and µn the general terms of the serial developments of f and g.
It is shone in [BT87] that ∃N[N* such that there are integers in the interval for which the sequence µ N.i+k u L(N.i+k) = congerges with limit t k . We then get the measure t // as the average (N.i+k).λ N.i+k i[N of the t k . The difficulties bound to this computing are explained in [GT88]. -
(
)
III) Fast computing of the measure 1) Property of the generating functions of rationnal languages The Mac Naughton-Yamada's algorithm [MY60] gives the rational expression of the language accepted by a given automaton. In a general way, such languages (non ambiguous) are constituted of disjointed unions of languages M of the form w 1 .L1 * .w2 L 2 * ...wn .Ln * .wn+1, where (wi) i∈ is a collection of finite words and (L i) i∈ a collection of rational languages of the form w i,1.Li,1* .wi,2L i,2* ...wi,ni.Li,ni* .wi,ni+1, where (wi,j) j∈ is again a collection of finite words, and (L i,j) j∈ a collection of rational languages defined in the same way, etc... Hence, the univariate generating function of such a language is of the form pi * f(z) = z .∏ f j (z) , where I and Ji are finite sets, (pi) i∈I a collection of integers, and f i* the generating
∑( i[I
j[J i
)
1 , if f i(z) is the generating function of L i). 1 - f i(z) A consequence of a classical theorem on positive analytic functions [E76] is that every singularity of f i* on its convergence circle (R (i) will denote the convergence radius of f i*) are simple poles located on a regular polygone that
function of L i* (that is to say
admits R (i) as a vertix. Thus, the convergence radius of f is R = Min { R
, k['i[I (J i) }. Let us consider two
(k)
190 generating functions f i* and f j* used in the expression of the above generating function. Their convergence radius are R (i) and R (j) and their convergence circles are disposed as shown on the following diagram (the polygones indicate the respective positions of the poles of f i* and f j*):
Ri
Rj
Hence, a pole of the generating function isn't a simple one if there are three integer i, j and j' with j≠j' such that (j,j')[Ji2 and R (j)=R(j') (that is to say their convergence circles are the sames), and R (j)=R(j')=R = Min { R
, k['i[I (J i) }. Let E denote this event. Intuitively, it's clear that this property is rare.
(k)
In fact, we'll show that this quite never happends. In the following, we'll call rational star any language L * where L is a rational one. We consider the uniform probability on the cartesian square of the set of convergence radius of generating functions of rational stars. If we prove that the probability to get two equals convergence radius is zero, then it will follow that E (that is included in this previous event) is also of probability zero: theorem: Let L1* and L2* be two rational stars. The probability that their generating functions f 1* and f2* have the same convergence radius is nul. Proof This property can be shown in two steps: (i)
The set C of the convergence radius of rational stars is infinitely countable, which implies for the probability that two random elements of C are equals to be nul.
(ii)
Let R be an element of C. The set SR of the rational stars whose generating functions admit R as convergence radius is infinite.
Proof of (i) P(z) . Hence its convergence radius is an Q(z) algebraic number (solution of Q(z)=0, if the ratio is irreducible). The set of algebraic numbers is infinitely countable. Thus C is at most infinitely countable. The generating function of a rational language is of the form
Let us show that C is infinite: we consider the language L k ={ak ,a2k}. The language L k * admits F(z) =
1 k
2k
as generating function, and
Rk =
(
5 -1 2
1 - z - z (Rk ) k[N is strictly ascending with limit 1. Thus, C is infinite.
)
1 k
as convergence radius. The sequence
qed Proof of (ii) Let L be a rational language and f its generating function, such that f(0)=0 and f≠0. The generating series of the languages ((L k ) *)k[N* have the same convergence radius: their sums are of the form * 1 φ k(z) = k k[N . f k verifies the same properties that f (f k (0)=0 and f k ≠0). The common 1 - (f(z) ) radius is the smallest positive root r of the equation f k (z)=1.
(
)
191 f(z) is of the form
∑ a n.z
n
with ∀n[N, an >0. Therefore, r>0 implies f(r)>0. We get
n[N
( f(r) )
p
- 1 = 0 ⇔ f(r) = 1, which yields
( f(r) )
p
- 1 = 0 ⇔ f(r) = 1.
However, the languages ((L k ) *)k[N may be ambiguous. For instance, if L={a,ab,ba}, the product L 2 is ambiguous, because aba=a.ba=ab.a. We'll use code theory to solve this problem [BT85]: L is replaced by L#, where # is a letter out of the alphabet of L. Each word w of (L#)* may be decomposed in an unique way: ∃! (wi) i[ [ (L#)p | w=w1.w2...wp . For such a language (we assume L to admit the generating function f(z) =
n
∑ a n.z
, L# admits the generating function f #(z) = z.f(z) =
n[N
∑ a n.z
n+1
, with the same
n[N
convergence radius. Therefore, we built an infinitely countable collection of rational stars which generating functions admit the same convergence radius. qed From the result (i), the number of effectively reached convergence radius is infinite. Thus, the probability that two tossed convergence radius will be equal is zero. The result (ii) shows the uniformity of the repartition of the languages on the convergence radius. Hence, the probability that to tossed rational stars will have the same convergence radius is nul. qed
2) A useful formula From now, we consider (because of the previous result) the case where f only admits simple poles. Then, a non obvious part of the general computing of the concurrency measure can be avoided: the determination of the multiplicities of the poles. Even with this simplification, the computing remains difficult in its second part (determining precisely the arguments rj.π of the poles z j). In fact, for many examples, the generating function f is the product of a polynomial N by f 1* (f 1* is a positive generating function). The period of a generating function f 1(z) =
∑ a n.z
n
is the higher common factor of the set of integers n such that
n[N
an ≠0. Then, if f is of period p, we get f 1(z) =
∑ a n.p.z
n.p
. Such a function presents the following interesting
n[N
property: Let w be a pth root of 1, we get f 1(zw)=f1(z) [E76]. That yields the following classical results [E76]: (i)
Let f be a non nul positive rational function of period p such that f(0)=0. The function * n 1 f (z) = = ∑ c n.z is also of period p and verifies (R * is its convergence radius) 1 - f(z) n[N * np
Lim ( c n.p.(R )
n→ +∞
(ii)
p
)=
*
*
.
R .f'(R )
R * is the unique solution of f(z)=1, with 0