Full Text
MATHEMATICS
A. P. ERSHOV
REDUCTION OF THE PROBLEM OF MEMORY ALLOCATION IN PROGRAMMING TO THE PROBLEM OF COLORING THE VERTICES OF GRAPHS
(Presented by Academician S. L. Sobolev, 2 X 1961)
The connection between the problems formulated in the title was first considered in the paper [1] for a certain comparatively narrow class of programs. In the present paper this connection is extended practically to all essential types of programs considered below under the name of operator schemes.
$1^\circ$. An operator scheme [1] is a directed graph whose vertices are operators. In what follows, when operator schemes are mentioned, the word “operator” will be omitted. If the scheme contains an oriented pair of operators $(A, B)$, the operator $A$ is called the predecessor of the operator $B$, and the operator $B$ is called the successor of the operator $A$. An operator may have some number of numbered arguments and results. To arguments and results there are assigned quantities, characterized by a positive integer weight, indicating how many consecutive memory cells must be assigned to the given quantity. The same quantity cannot be assigned to several results of one operator. An operator $S$ produces a quantity $x$ if $x$ is a result of the operator $S$, and perceives $x$ if $x$ is an argument of the operator $S$. Quantities with weight $\rho$ greater than one are regarded as arrays consisting of $\rho$ components. For each operator producing some quantity—an array $x$—it is assumed to be known whether the given quantity is produced as a whole (i.e. all its components) or only partially (i.e. a separate component or a partial set of them). The appearance of some quantity $x$ as an argument or result of some operator is called an occurrence $E(x)$ of the quantity $x$ in the scheme. For any occurrence $E(x)$ of a quantity $x$ with weight $\rho$, a partition of $E(x)$ into $k$ $(1 \leq k \leq \rho)$ subquantities may be specified, consisting in the partition of $\rho$ into $k$ summands $\rho_i$ $(i = 1, \ldots, k)$ and in the introduction of $k$ quantities $x_i$ with weight $\rho_i$, with an indication of their belonging to the occurrence $E(x)$. The weight of the scheme is the sum of the weights of the distinct quantities entering into the scheme.
$2^\circ$. The role of different variants of memory allocation is played by different transformations of schemes. A transformation of a scheme consists in partitioning all occurrences of quantities into subquantities and in replacing occurrences of some subquantities by other quantities of the same weight. Economical memory allocation will be achieved with the maximum decrease in the weight of the transformed scheme, which can be attained only by identifying certain subquantities.
Among all possible transformations of a scheme, admissible transformations are singled out. A route [1] $M(x)$ of a quantity $x$ is such an oriented path in the scheme, passing through operators $S_1, S_2, \ldots, S_n$, in which the initial operator $S_1$ produces $x$, the terminal operator $S_n$ perceives $x$, and none of the internal operators ...
$S_2, \ldots, S_{n-1}$ does not produce $x$ as a whole. The internal operators that produce individual components of the quantity $x$ are called operators influencing $x$. Consider a certain $i$-th result of an operator $S$ of the scheme, to which (the result) the quantity $x$ is assigned. The set of routes $M(x)$ with initial operator $S$ is called the storage zone of the $i$-th result of the operator $S$. A transformation of a scheme $Z$ into a scheme $Z'$ is considered admissible when the following conditions are jointly satisfied:
1) The storage zone of any $i$-th result of any operator $S$ in the scheme $Z'$ is an extension of the storage zone of the $i$-th result of the operator $S$ in the scheme $Z$.
2) The set of operators influencing any quantity $x$ in any of its routes $M$ in the scheme $Z$ coincides with the set of operators influencing the quantity $y$ that replaced the quantity $x$ in the same route $M$ in the scheme $Z'$.
3) The set of subquantities in the scheme $Z'$ can be ordered into a sequence $T$ in such a way that, for any occurrence $E(x)$ of the quantity $x$ in the scheme $Z$, the set of subquantities that replaced the subquantities of the occurrence $E(x)$ would form a segment of the sequence $T$.
Let us note that condition 3) follows only from the requirement to place the components of array quantities in consecutive memory cells. For computers with associative memory this condition is superfluous.
$3^\circ$. The carrier of a quantity $x$ in a scheme is the set of all routes of the quantity $x$. Two routes $M_1(x)$ and $M_2(x)$ are called connected if there exists such a sequence of routes of the quantity $x$, beginning with $M_1(x)$ and ending with $M_2(x)$, in which neighboring routes have a common initial or terminal operator. With respect to this definition of connectedness, the carrier of any quantity $x$ in a scheme decomposes into connected components, called the regions of action $D(x)$ of the quantity $x$ ($^1$).
Two routes are called linked if the initial operator of one route is either the initial or an internal operator of the other route. Two regions of action are considered linked if in them one can find one route each that form a linked pair.
Let $Z$ be a scheme in which any $E(x)$ belongs to some $D(x)$, i.e. $E(x)$ enters into an operator that is the initial or terminal operator of some $M(x)$ from $D(x)$.
Criterion of admissibility of a transformation. For the admissibility of a transformation, satisfying condition 3), of a scheme $Z$ into a scheme $Z'$, it is necessary and sufficient that:
1) when some $E(x)$ belonging to some $D(x)$ is split into subquantities $x_1, \ldots, x_k$ and these are replaced by quantities $y_1, \ldots, y_k$, such a splitting and such a replacement would be carried out for all $E(x)$ belonging to the given $D(x)$;
2) replacement of the subquantity $x_i$ of an occurrence of the quantity $x$, belonging to some $D(x)$, by the subquantity $y_j$ of an occurrence of the quantity $y$, belonging to some $D(y)$, would be carried out only when $D(x)$ and $D(y)$ are not linked.
$4^\circ$. Let $B$ and $H$ be, respectively, the sets of internal and initial operators of the routes forming a certain region of action $D$. In this case it can be shown that the regions of action $D_1$ and $D_2$ are linked if and only if the set
\[ (B_1 \cup H_1) \cap H_2 \cup (B_2 \cup H_2) \cap H_1 \]
is nonempty. Leaving aside, because of lack of space, the question of partitioning the carrier into connected components, which can be done on the basis of the idea of “agreement of notations” ($^1$), let us indicate a method for finding, from a scheme,
of the set \(B\) (the set \(H\) is found trivially) for the connected carrier of the quantity \(x\).
Consider two sets of operators of the scheme, \(E\) and \(L\). These sets will be constructed by means of a cyclic process, each stage of which consists in examining all operators of the scheme. When the next operator \(S\) is examined, the following operations are performed:
The set \(L\). In the case when \(S\) either takes in \(x\), or has already been included in \(L\), all predecessors of the operator \(S\) (except for predecessors producing \(x\) as a whole) are included in \(L\).
The set \(E\). In the case when \(S\) either produces \(x\), or has already been included in \(E\), all successors of the operator \(S\) are included in \(E\).
The process of constructing the sets \(E\) and \(L\) terminates as soon as the next examination of all operators of the scheme has not led to an enlargement of \(E\) or \(L\). It follows directly from the definition of the carrier that \(B = E \cap L\).
\(5^\circ\). Associate with the scheme \(Z\) a certain graph \(G(Z)\), called the coupling graph, whose construction is carried out according to the following rule. For each domain of validity \(D\) of each quantity of weight \(\rho\), construct a \(\rho\)-complete graph \(G_\rho\). All vertices of the graph \(G_\rho\) are declared to belong to the domain of validity \(D\). Then, for any pair of coupled domains of validity, all vertices of the corresponding complete graphs are joined to one another by edges; this completes the construction of \(G(Z)\).
Now consider some coloring \(R\) of the vertices of the graph \(G(Z)\). “Glue” into one vertex all vertices colored with the same color. Declare each of the resulting vertices to belong to all those domains of validity to which the glued vertices belonged. Denote the graph obtained by \(g(Z,R)\). The coloring \(R\) is called orderable if the vertices of the graph \(g(Z,R)\) can be ordered into a sequence \(U\) in such a way that the set of vertices of the graph \(g(Z,R)\) belonging to one and the same domain of validity would be a segment of the sequence \(U\).
Theorem. Every orderable coloring of the graph \(G(Z)\) with \(q\) colors defines a certain admissible transformation of the scheme \(Z\) into a scheme of weight \(q\). Conversely, every admissible transformation of the scheme \(Z\) into a scheme of weight \(q\) defines a certain orderable coloring of the graph \(G(Z)\) with \(q\) colors.
Thus, memory allocation in program construction is reduced to finding a certain special coloring of a graph.
Institute of Mathematics with Computing Center
of the Siberian Branch of the Academy of Sciences of the USSR
Received
27 IX 1961
REFERENCES
- S. S. Lavrov, Zhurn. vychisl. matem. i matem. fiz., 1, No. 5 (1961).