Algorithm Search⌘K

Modelcore

Kahn process network

Also called KPN, Kahn network.

Kahn's model of deterministic processes that talk through unbounded FIFO channels with blocking reads, so the output depends only on the input, not the schedule.

A Kahn process network is a set of sequential processes that communicate only through FIFO channels. Each channel has one writer and one reader, holds any number of values, and is read with a blocking read: a process that wants a value from an empty channel waits until one arrives. A process may not test whether a channel is empty, and it may not wait on two channels at once. Gilles Kahn defined the model in 1974 and proved that it is determinate: for a given input, the sequence of values that passes through every channel is the same in every run, whatever order the processes run in. This page defines the model and proves determinacy and the undecidability of termination and of bounded memory. Synchronous dataflow is the special case with fixed rates, in which those questions become decidable.

The machine

A network has processes P1,…,PmP_1, \ldots, P_m and channels. Each channel is a queue of values from a set AA with exactly one writer and exactly one reader. A channel whose writer is the environment is an input of the network, and a channel whose reader is the environment is an output.

Each process is a deterministic sequential program with local memory. One step of a process is one of three actions:

  • Write a value to one of its output channels. Channels have no bound, so a write never waits.
  • Read from one of its input channels. Which channel is read next is fixed by the local state, not by the contents of the channels. If that channel is empty, the process is blocked and takes no step until a value arrives.
  • Compute on the local memory.

A run is a sequence of steps, each by some process that is not blocked. A run is fair when no process stays able to move forever without moving, and the environment supplies all of its input. The scheduler is free; a single processor that runs the processes as coroutines and a network of processors are both runs of the model.

The history of a channel in a run is the sequence of all values written to it. Histories are finite or infinite sequences in S=A∗∪AωS = A^* \cup A^\omega, ordered by prefix: x⊑yx \sqsubseteq y when xx is a prefix of yy. The empty sequence is the least element, and every increasing chain x0⊑x1⊑⋯x_0 \sqsubseteq x_1 \sqsubseteq \cdots has a least upper bound, its limit. Vectors of histories are ordered entry by entry.

What it counts

  • Histories. The values that pass through each channel. Determinacy says that they depend only on the input.
  • Memory. The largest number of values that a channel holds at one time in a run. Unlike the histories, this depends on the schedule.
  • Termination. Whether all processes eventually halt or block forever.

Time and the cost of a step play no part in the theorems. A process network is a model of what a parallel program computes; the cost model comes from the scheduler that runs it.

Relation to other models

  • Dataflow. An actor with a fixed rate, as in synchronous dataflow, is a Kahn process that reads a fixed number of values from each input and then writes a fixed number to each output. Lee and Parks (1995) describe dataflow actors with firing rules as Kahn processes, so all of these models inherit determinacy.
  • Turing machines. One process is any program, so a network can compute any computable function, and a process with a channel from itself to itself is a queue machine. This is the reason for Theorem 3.
  • Models with choice. Petri nets, and process models in which a process may wait on whichever of two channels has data first, are not determinate. The determinacy of Kahn networks is bought by giving up such a choice.
  • Hardware. A latency-insensitive design is a network of synchronous blocks that talk through bounded queues with back pressure. With unbounded queues it would be a Kahn network.

Known results in the model

For a process PP, let FPF_P map the vector xx of histories of its input channels to the vector of histories it writes when it runs alone and is fed xx. The run is unique, since PP is deterministic and decides by itself which channel to read next. The run on xx stops when PP halts, or when it asks for a value that xx does not have, or never.

Lemma 1. FPF_P is monotone and continuous: x⊑yx \sqsubseteq y implies FP(x)⊑FP(y)F_P(x) \sqsubseteq F_P(y), and FPF_P of the limit of a chain is the limit of the images.

Proof. If x⊑yx \sqsubseteq y, the run on yy does the same steps as the run on xx until the run on xx stops. If it stops by halting, the two runs are equal. If it stops because xx ran out on some channel, the run on yy continues from there. In both cases the run on xx is a prefix of the run on yy, and so are its writes. For continuity, each value written by the run on the limit is written after a finite number of reads, which all lie in some xix_i of the chain, so the run on xix_i writes it too. □\square

Collect the channels into one vector XX. Fix the input channels to the given input II, and for a channel cc written by PP let F(X)c=FP(Xin(P))cF(X)_c = F_P(X_{\mathrm{in}(P)})_c. By Lemma 1, FF is monotone and continuous on a set in which every increasing chain has a limit, so by the Kleene fixed-point theorem it has a least fixed point

μF=lim⁡k→∞Fk(⊥),\mu F = \lim_{k \to \infty} F^k(\bot),

where ⊥\bot gives the empty history to every channel that is not an input. Every vector HH with F(H)⊑HF(H) \sqsubseteq H satisfies μF⊑H\mu F \sqsubseteq H, since by induction Fk(⊥)⊑HF^k(\bot) \sqsubseteq H for every kk.

Theorem 1 (determinacy, Kahn 1974). In every fair run of the network on the input II, the history of every channel is the entry of μF\mu F for that channel.

Proof. First, at every moment of every run, finite or not, the histories so far are below μF\mu F. By induction on the steps: when PP writes, it has read some values uu, and by induction uu is below the entries of μF\mu F on its inputs. The run of PP so far is a prefix of its run on uu, which by Lemma 1 is a prefix of its run on μFin(P)\mu F_{\mathrm{in}(P)}, so what PP has written is a prefix of FP(μFin(P))=μFout(P)F_P(\mu F_{\mathrm{in}(P)}) = \mu F_{\mathrm{out}(P)}. Taking limits, the final histories HH of the run satisfy H⊑μFH \sqsubseteq \mu F.

Next, HH is a fixed point of FF. Fix a process PP and let uu be all that it reads in the whole run. Its run is the complete run of PP on uu: otherwise PP would be able to move from some moment on and never move, which fairness forbids. So PP writes FP(u)F_P(u). If u=Hin(P)u = H_{\mathrm{in}(P)}, this is FP(Hin(P))F_P(H_{\mathrm{in}(P)}). Otherwise some value is written on an input channel cc of PP and never read. Then the run of PP on uu does not stop by asking for that value, since PP would then be able to read it forever and never do so. So it stops by halting, or by asking for a value on a channel on which uu already equals HH, or never; in each case the run on Hin(P)H_{\mathrm{in}(P)} is the same run, and FP(u)=FP(Hin(P))F_P(u) = F_P(H_{\mathrm{in}(P)}). So Hout(P)=FP(Hin(P))H_{\mathrm{out}(P)} = F_P(H_{\mathrm{in}(P)}) for every PP, that is F(H)=HF(H) = H. Then μF⊑H\mu F \sqsubseteq H, and with the first part, H=μFH = \mu F. □\square

Kahn stated the result in the language of fixed points; the match between the runs of the processes and the fixed point was later treated in detail for more general settings (Kahn and MacQueen 1977, and later work cited by Lee and Parks 1995). The proof above assumes the simple process language of this page: deterministic programs, one writer and one reader per channel, and reads whose channel the process picks by itself.

Theorem 2 (no determinacy without blocking reads). If a process may test a channel for emptiness, the histories can depend on the schedule. A merge process that loops "if channel aa is not empty, copy one value from aa to cc; else if bb is not empty, copy one value from bb to cc" with inputs a=(1)a = (1) and b=(2)b = (2) writes (1,2)(1, 2) on cc if the value on aa arrives first and (2,1)(2, 1) if the value on bb arrives first. Its input-output relation is not a function, so it has no FPF_P, and Lemma 1 fails.

Theorem 3 (undecidability). Whether a Kahn network terminates, and whether it has a fair run in which every channel holds at most BB values for some BB, are both undecidable.

Proof. Termination: one process with no channels is any program, so this is the halting problem. Bounded memory: given a program MM, build a network with two processes. Process PP runs MM; if MM halts, PP then writes a value to channel cc again and again forever. Process QQ first reads from a channel c′c' that nobody writes, so it blocks forever, and it is the reader of cc. In every fair run, PP is never blocked, so it keeps moving, and channel cc grows without bound exactly when MM halts. So a decision procedure for bounded memory would decide the halting problem. □\square

Parks (1995) states both results and gives a policy for bounded channels: run with small capacities, make a write wait while its channel is full, and when every process waits and at least one of them waits to write, raise the capacity of the full channel with the least capacity among those that block a write. A write that waits changes only the timing, so by the first part of the proof of Theorem 1 the histories of such a run are always prefixes of μF\mu F. Parks shows that the policy produces the complete histories, and that it stays in bounded memory whenever some fair run does. Such questions are decidable in synchronous dataflow, whose fixed rates make the memory of a periodic schedule computable.

Example

A network computes the running sums of its input. Process Add reads one value from channel XX, the input, and one from channel ZZ, and writes their sum to YY, again and again. Process Delay writes 0 to ZZ and then copies every value it reads from YY to ZZ. The output is YY. For the input X=(1,2,3)X = (1, 2, 3) the Kleene iterates of FF, with XX held fixed, are:

iterate YY ZZ
F0(⊥)F^0(\bot) () ()
F1(⊥)F^1(\bot) () (0)
F2(⊥)F^2(\bot) (1) (0)
F3(⊥)F^3(\bot) (1) (0, 1)
F4(⊥)F^4(\bot) (1, 3) (0, 1)
F5(⊥)F^5(\bot) (1, 3) (0, 1, 3)
F6(⊥)F^6(\bot) (1, 3, 6) (0, 1, 3)
F7(⊥)F^7(\bot) (1, 3, 6) (0, 1, 3, 6)

From F7F^7 on, nothing changes, so μF\mu F gives Y=(1,3,6)Y = (1, 3, 6). A schedule that runs Delay as far as it can before Add, and one that alternates the two, both write exactly these histories. At the end, the value 6 stays on ZZ, since Add blocks on XX before it reads it; the run ends with Add blocked on the input and Delay blocked on YY.

References

  1. Gilles Kahn, The semantics of a simple language for parallel programming, Information Processing 74, Proceedings of the IFIP Congress 74, North-Holland, 471 to 475, 1974, the language of processes and channels, streams ordered by prefix, processes as continuous functions, and the network as the least fixed point of its equations
  2. Gilles Kahn and David B. MacQueen, Coroutines and networks of parallel processes, Information Processing 77, North-Holland, 993 to 998, 1977, an operational implementation of the networks with coroutines and demand-driven scheduling
  3. Thomas M. Parks, Bounded Scheduling of Process Networks, PhD thesis, University of California, Berkeley, 1995, the undecidability of termination and of bounded buffering for Kahn networks, and a scheduling policy that runs in bounded memory whenever that is possible
  4. Edward A. Lee and Thomas M. Parks, Dataflow process networks, Proceedings of the IEEE 83(5), 773 to 801, 1995, the place of Kahn networks among the dataflow models, and dataflow actors with firing rules as Kahn processes

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/D5ET3Q/text.yaml