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 and channels. Each channel is a queue of values from a set 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 , ordered by prefix: when is a prefix of . The empty sequence is the least element, and every increasing chain 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 , let map the vector of histories of its input channels to the vector of histories it writes when it runs alone and is fed . The run is unique, since is deterministic and decides by itself which channel to read next. The run on stops when halts, or when it asks for a value that does not have, or never.
Lemma 1. is monotone and continuous: implies , and of the limit of a chain is the limit of the images.
Proof. If , the run on does the same steps as the run on until the run on stops. If it stops by halting, the two runs are equal. If it stops because ran out on some channel, the run on continues from there. In both cases the run on is a prefix of the run on , 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 of the chain, so the run on writes it too.
Collect the channels into one vector . Fix the input channels to the given input , and for a channel written by let . By Lemma 1, 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
where gives the empty history to every channel that is not an input. Every vector with satisfies , since by induction for every .
Theorem 1 (determinacy, Kahn 1974). In every fair run of the network on the input , the history of every channel is the entry of for that channel.
Proof. First, at every moment of every run, finite or not, the histories so far are below . By induction on the steps: when writes, it has read some values , and by induction is below the entries of on its inputs. The run of so far is a prefix of its run on , which by Lemma 1 is a prefix of its run on , so what has written is a prefix of . Taking limits, the final histories of the run satisfy .
Next, is a fixed point of . Fix a process and let be all that it reads in the whole run. Its run is the complete run of on : otherwise would be able to move from some moment on and never move, which fairness forbids. So writes . If , this is . Otherwise some value is written on an input channel of and never read. Then the run of on does not stop by asking for that value, since 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 already equals , or never; in each case the run on is the same run, and . So for every , that is . Then , and with the first part, .
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 is not empty, copy one value from to ; else if is not empty, copy one value from to " with inputs and writes on if the value on arrives first and if the value on arrives first. Its input-output relation is not a function, so it has no , 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 values for some , are both undecidable.
Proof. Termination: one process with no channels is any program, so this is the halting problem. Bounded memory: given a program , build a network with two processes. Process runs ; if halts, then writes a value to channel again and again forever. Process first reads from a channel that nobody writes, so it blocks forever, and it is the reader of . In every fair run, is never blocked, so it keeps moving, and channel grows without bound exactly when halts. So a decision procedure for bounded memory would decide the halting problem.
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 . 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 , the input, and one from channel , and writes their sum to , again and again. Process Delay writes 0 to and then copies every value it reads from to . The output is . For the input the Kleene iterates of , with held fixed, are:
| iterate | ||
|---|---|---|
| () | () | |
| () | (0) | |
| (1) | (0) | |
| (1) | (0, 1) | |
| (1, 3) | (0, 1) | |
| (1, 3) | (0, 1, 3) | |
| (1, 3, 6) | (0, 1, 3) | |
| (1, 3, 6) | (0, 1, 3, 6) |
From on, nothing changes, so gives . 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 , since Add blocks on before it reads it; the run ends with Add blocked on the input and Delay blocked on .
References
- 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
- 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
- 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
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag D5ET3Q Edit this page History Report an error Markdown