272003/39: A ring of computers that wait for their neighbors
27.1Problem
Buying PC farms is getting more and more popular these days. Lettice Lettuce would like to buy one, to have her programs run parallelly. She would like to buy an even \((n)\) number of computers and connect them in a ring topology (in which each computer can communicate with its two neighbours). The state of each machine is described by a number showing the number of operations already performed. The states of computers of even (odd) index can take on non-negative integer (half-integer) values. The initial state is 0, \(\frac{1}{2}\), 0, \(\frac{1}{2}\), … Computation is performed in discrete steps; with probability \(p\) the machine performs the step in one unit of time, and with probability \(1-p\), in \(k\) units of time. A machine can carry on its computations only if its neighbours are both ahead of it, otherwise it stays idle. The performance of the farm is defined as the average number of computers working simultaneously. Help Lettice to predict the performance of the farm.
a) Lettice can afford to buy 4 computers. Calculate the performance as a function of \(p\), if \(k=2\).
b) Lettice expands the farm. What performance will she get for \(n=6, 8, \dots\), if \(k=2\)?
c) Find the performance for arbitrary values of \(k\) and \(n\).
Note: Lettice is happy with exact as well as approximate results. However, she considers the results of simulations as mere illustrations.
27.2Explanation
We number the machines \(i = 0, 1, \dots, n-1\) around the ring, so that machine \(n-1\) is a neighbor of machine \(0\), and call the state \(h_i\) of machine \(i\) its height. A machine works on its next step only while both of its neighbors are higher than it; when the step ends, its height grows by 1. Each step lasts 1 time unit with probability \(p\) and \(k\) time units with probability \(1-p\), independently of all other steps, and a machine starts a step as soon as it is allowed to. The performance \(P\) is the number of working machines averaged over a long time, and \(P/n\) is the fraction of the time that an average machine works. We have to find \(P\) for \(n = 4\) and \(k = 2\) as a function of \(p\), then for larger rings with \(k = 2\), and then for any \(k\) and \(n\).
For \(p = 0\) and for \(p = 1\) all steps have the same length, the machines of even and of odd index work in turns, and exactly \(n/2\) machines work at every moment. For \(0 < p < 1\) some machines wait for slow neighbors, and the question is how much the random step lengths reduce \(P\) below \(n/2\). The same rule is used in parallel computing. In a parallel simulation of a physical system, each processor computes one region of the system, and it may advance its own simulated time only when its neighbors are ahead of it in simulated time, so that no neighbor can later send it a message about an earlier moment [58]. We show below that the long-time average does not depend on the random history, so \(P\) is a function of \(n\), \(k\) and \(p\) only.
27.3Theory
Markov chains. A Markov chain is a random process that moves in discrete time steps between the states of a set, here a finite set, such that the probability \(T_{ab}\) of moving from state \(a\) to state \(b\) in one step depends only on \(a\) and \(b\) and not on the earlier history. A probability distribution \(\pi_a\) over the states is stationary if one step of the chain leaves it unchanged:
\[ \pi_b = \sum_a \pi_a T_{ab}, \qquad \sum_a \pi_a = 1 . \tag{183}\]If some state can be reached from every state, the stationary distribution is unique, and whatever the starting state, the fraction of time steps that the chain spends in state \(a\) tends to \(\pi_a\) with probability 1 (the ergodic theorem for Markov chains). The long-time average of a quantity \(W\) that depends on the state is therefore \(\sum_a \pi_a W_a\). The equations (183) are linear; for a few states we solve them by hand, for thousands of states by computer.
Working time and completion rate. Suppose that a machine completes on average \(\nu\) steps per unit time over a long run, and that the length of each step is drawn independently of the moment at which the step starts, with mean \(\langle\tau\rangle\). In a long time \(T\) the machine completes about \(\nu T\) steps, and by the law of large numbers their total length is about \(\nu T \langle\tau\rangle\). The machine therefore works during the fraction \(\nu\langle\tau\rangle\) of the time.
Directed percolation. Take the sites of a square lattice rotated by \(45^\circ\), arranged in rows, so that every site has two neighbors in the row below it and two in the row above it. Each site is open with probability \(q\), independently of the others. A directed path goes from a site to one of its two neighbors in the next row, and so on. Directed percolation is the question whether there are infinitely long directed paths through open sites only. There is a threshold \(q_c\): for \(q < q_c\) every directed path of open sites ends after a finite number of rows, while for \(q > q_c\), with probability 1, infinitely long ones start from some sites of an infinite bottom row. The threshold is known only numerically, \(q_c = 0.705485\) [59]. Directed percolation is the standard model of spreading processes, such as an epidemic in which each row is a generation [60].
Longest increasing chains. Scatter \(N\) random points independently and uniformly in a square. A chain is a sequence of these points in which each point lies above and to the right of the previous one. For large \(N\) the longest chain contains \(2\sqrt N\) points, up to a relative error that goes to zero as \(N\to\infty\). This is Hammersley’s problem; the constant 2 was found by Vershik and Kerov and by Logan and Shepp [61].
27.4Solutions
27.4.1Markov chain of the relative state
Neighbors differ by one half. At the start, neighboring heights differ by \(\frac12\), and we show that this remains true. A height changes only when a step ends. Machine \(i\) starts a step only when \(h_{i-1}\) and \(h_{i+1}\) are larger than \(h_i\), that is, by our claim, when both equal \(h_i + \frac12\). While machine \(i\) works, neither neighbor can work, because machine \(i\) is lower than each of them. When the step ends, \(h_i\) grows by 1 and becomes \(h_{i\pm1} + \frac12\), so the claim holds again. This has four consequences.
A machine may work exactly when it is a local minimum of the heights, and it starts a step at the moment it becomes one.
Two neighbors never work at the same time, so at most \(n/2\) machines work. A working machine remains a local minimum until its step ends, so no step is interrupted.
The heights form a zigzag line around the ring (Figure 50). A step turns a local minimum into a local maximum, so the line is a surface that grows by one layer at a time, which is how Korniss and coworkers study parallel simulations [58].
All step lengths are integers, and the machines of even index all start at \(t = 0\), so every step starts and ends at an integer time. The set of working machines is the same during each interval \(t \le t' < t+1\), and \(P\) is the average over \(t = 0, 1, 2, \dots\) of the number \(W(t)\) of machines that work in this interval.
The state. The rule compares heights, so the future depends only on the differences \(h_{i+1} - h_i\), not on the heights themselves. At an integer time \(t\), after the steps that end at \(t\) have ended and the new ones have started, we describe the farm by the signs of the \(n\) differences \(h_{i+1} - h_i\), together with the remaining time \(r \in \{1, \dots, k\}\) of the step of each working machine. No machine has a special place on the ring, so two states that differ by a rotation of the ring have the same future, and we count them as one state. In one time unit, the remaining time of each working machine decreases by 1, the machines whose remaining time reaches 0 end their step and their heights grow by 1, and each machine that has become a local minimum starts a step with remaining time 1 (probability \(p\)) or \(k\) (probability \(1-p\)). This is a Markov chain whose transition probabilities are products of factors \(p\) and \(1-p\), and \(W\) is the number of working machines in the state.
For \(0 < p < 1\) the chain has a single stationary distribution. To see this, start from any state and suppose that every new step is fast. After at most \(k-1\) time units the steps already running have ended, and from then on all local minima rise by 1 in every time unit. A machine at the largest height is never a local minimum unless the heights form the zigzag, so the largest height stays fixed, while all machines at the smallest height are local minima and rise, so the smallest height grows by \(\frac12\) per time unit. After a finite time the heights form a zigzag in which all \(n/2\) lowest machines have just started fast steps. This state can be reached from every state, so by the ergodic theorem \(P = \sum_a \pi_a W_a\) for every random history.
(a) Four machines, \(k = 2\). For \(n = 4\) the heights either form a zigzag, with two opposite machines working, or have one local minimum and one local maximum. Starting from \(0, \frac12, 0, \frac12\), the chain visits only four states:
- A:
zigzag, both working machines have 2 units left;
- B:
zigzag, one working machine has 1 unit left, the other 2;
- C:
zigzag, both working machines have 1 unit left;
- D:
one working machine, with 1 unit left.
From A the chain moves to C with probability 1. From B, the fast machine ends its step and becomes a local maximum, while the two idle machines still have the slow machine as a lower neighbor, so the slow machine works alone: B moves to D. From C both steps end, the two other machines become local minima and start new steps, and the chain moves to C with probability \(p^2\) (both fast), to B with probability \(2p(1-p)\), and to A with probability \((1-p)^2\). From D the last step of the pair ends, and the chain moves on exactly as from C. Let \(s = \pi_C + \pi_D\) be the probability that a new pair of steps starts at a given time. The stationary equations (183) read
\[ \pi_A = (1-p)^2 s, \qquad \pi_B = 2p(1-p)\, s, \qquad \pi_C = p^2 s + \pi_A, \qquad \pi_D = \pi_B , \]and from the normalization, \(s\,[(1-p)^2 + 2p(1-p) + p^2 + (1-p)^2 + 2p(1-p)] = s\,(2-p^2) = 1\). Two machines work in A, B and C, and one in D, so
\[ P_4 = 2 - \pi_D = 2 - \frac{2p(1-p)}{2-p^2} = \frac{2(2-p)}{2-p^2} . \tag{184}\]The performance is 2 at \(p = 0\) and at \(p = 1\), and \(12/7 = 1.714\) at \(p = \frac12\). Its derivative vanishes where \(p^2 - 4p + 2 = 0\), so the smallest performance, \(P_4 = 1 + 1/\sqrt2 = 1.707\), occurs at \(p = 2 - \sqrt2 = 0.586\), where each machine works \(42.7\%\) of the time. A direct check: after a pair of steps starts together, the next pair starts when the longer of the two ends, on average after \(p^2\cdot 1 + (1-p^2)\cdot 2 = 2 - p^2\) time units, while the two machines work for \(2(2-p)\) units in total on average; the ratio of the two is (184).
(b) Larger rings, \(k = 2\). For \(n \ge 6\) we build the chain by computer. Starting from the initial state, we apply the transition rule to every state found so far, until no new state appears. The number of states is 10, 32, 117, 479, 2044 and 9051 for \(n = 6, 8, \dots, 16\). For \(n \le 8\) we solve (183) with exact rational arithmetic at rational values of \(p\). By Cramer’s rule, \(P_n\) is then the ratio of two polynomials in \(p\) of degree at most \((N-1)\,n/2\), where \(N\) is the number of states, because each transition probability is a product of at most \(n/2\) factors \(p\) or \(1-p\). We fitted ratios of polynomials of increasing degree to the exact values, and checked the result at more rational points than the degree of the difference of the two cross-multiplied expressions (34 points for \(n = 6\), 139 for \(n = 8\)), which proves the identity for all \(p\). For six machines
\[ P_6 = \frac{3(2-p)(1 - 2p + 5p^2 - 3p^3)}{2 - 4p + 10p^2 - 7p^3 - p^4 + p^5} , \tag{185}\]with \(P_6(\frac12) = 42/17 = 2.471\), and for eight machines \(P_8(\frac12) = 5312/1637 = 3.245\). The formula for \(n = 8\) has polynomials of degree 13; we give it in a shorter form in Section 27.4.2. For \(n = 10\) to 16 we solve (183) in floating point, by repeating \(\pi \to (\pi + \pi T)/2\) until no component changes by more than \(10^{-14}\); for \(n \le 8\) this agrees with the exact values to \(10^{-12}\). The results for three values of \(p\) are in Table 21, and \(P_n/n\) for all \(p\) is plotted in Figure 51.
| \(n\) | states | \(P_n/n\) at \(p = 0.25\) | \(p = 0.5\) | \(p = 0.75\) |
|---|---|---|---|---|
| 4 | 4 | 0.4516 | 0.4286 | 0.4348 |
| 6 | 10 | 0.4429 | 0.4118 | 0.4108 |
| 8 | 32 | 0.4402 | 0.4056 | 0.4007 |
| 10 | 117 | 0.4390 | 0.4025 | 0.3955 |
| 12 | 479 | 0.4384 | 0.4006 | 0.3924 |
| 14 | 2044 | 0.4381 | 0.3993 | 0.3903 |
| 16 | 9051 | 0.4379 | 0.3983 | 0.3887 |
| \(\infty\) | 0.4375 | 0.393 | 0.379 |
The performance per machine decreases as the ring grows, and its difference from the large-ring limit shrinks roughly like \(1/n\). The lowest value of \(P_n/n\) moves to larger \(p\) as \(n\) grows: it is \(0.4268\) at \(p = 0.586\) for \(n = 4\), \(0.4068\) at \(p = 0.641\) for \(n = 6\), and \(0.3985\) at \(p = 0.669\) for \(n = 8\). We explain this trend with the next method: in a larger ring there are more sequences of steps along which the delays caused by slow steps add up.
27.4.2The critical path
Levels. Machine \(i\) of even index takes its height from \(j-1\) to \(j\) in its \(j\)-th step; a machine of odd index takes it from \(j - \frac12\) to \(j + \frac12\). We assign the level \(\ell = 2j - 1\) to the \(j\)-th step of an even machine and \(\ell = 2j\) to the \(j\)-th step of an odd machine. An even machine can start its \(j\)-th step when both neighbors have reached the height \(j - \frac12\), that is, when they have ended their steps at level \(2j - 2\); an odd machine can start its \(j\)-th step when both neighbors have reached \(j\), that is, ended their steps at level \(2j - 1\). So a step at level \(\ell \ge 2\) starts exactly when both neighboring steps at level \(\ell - 1\) have ended, and the steps at level 1 start at \(t = 0\). (The machine’s own step at level \(\ell - 2\) has ended earlier, because the neighboring steps at level \(\ell - 1\) waited for it.) With \(\tau(\ell, i)\) for the length of the step of machine \(i\) at level \(\ell\), its end time is
\[ E(\ell, i) = \tau(\ell, i) + \max\bigl(E(\ell-1, i-1),\, E(\ell-1, i+1)\bigr), \qquad E(0, i) = 0 . \tag{186}\]Applying (186) repeatedly, \(E(\ell, i)\) is the largest total length along a sequence of steps \((\ell, i), (\ell-1, i\pm1), \dots\) down to level 1, in which each step is at a neighboring machine one level lower. The sequence with the largest total length is the critical path: each step on it started at the moment the previous one ended. The levels and machines form exactly the rotated square lattice of directed percolation. A short run is drawn in Figure 52. In it, 9 of the 28 steps that ended by \(t = 12\) were slow, but the critical path ending at \(t = 12\) contains 5 slow steps out of 7.
Performance from the critical path. A machine completes one step per two levels. Neighboring heights differ by \(\frac12\), so all machines of the ring complete steps at the same long-run rate \(\nu_n\), which is the stationary mean number of steps ending per time unit in the chain of Section 27.4.1, divided by \(n\). Hence \(E(\ell, i)/\ell\) tends to \(\gamma_n = 1/(2\nu_n)\) for every \(i\). Each step length is drawn independently of when the step starts, with mean \(\langle\tau\rangle = p + k(1-p)\), so each machine works the fraction \(\nu_n \langle\tau\rangle\) of the time, and
\[ P_n = \frac{n\,\langle\tau\rangle}{2\gamma_n} . \tag{187}\]The performance is \(n/2\) times the ratio of the mean step length to the mean time per level.
Separating \(k\). Write the length of each step as \(\tau = k - (k-1)a\), where \(a = 1\) for a fast step and \(a = 0\) for a slow one. Every path from level \(\ell\) down to level 1 contains exactly \(\ell\) steps, so its total length is \(k\ell - (k-1)\) times the number of fast steps on it. For every \(k > 1\), the longest path is therefore the path with the fewest fast steps, and it depends only on which steps are fast, not on \(k\). Let \(\delta_n(p)\) be the long-run fraction of fast steps on the critical path. Then \(\gamma_n = k - (k-1)\delta_n(p)\), and
\[ P_n(p, k) = \frac{n\,[p + k(1-p)]}{2\,[k - (k-1)\,\delta_n(p)]} . \tag{188}\]All dependence on \(k\) is explicit, and a single function \(\delta_n(p)\) for each \(n\) answers the problem for every \(k\). We obtain \(\delta_n\) from the chain at \(k = 2\) by solving (188) for it. As a check, we built the chain also for \(k = 3\) and \(k = 5\) and found exact agreement with (188) for \(n = 4\), 6 and 8 at several rational values of \(p\).
(a) revisited. For \(n = 4\) each level has two steps, and each of them waits for both steps of the level below. The time per level is the longer of two independent step lengths, so \(\gamma_4 = p^2 + k(1-p^2)\) and \(\delta_4 = p^2\). From (188),
\[ P_4 = \frac{2\,[p + k(1-p)]}{p^2 + k(1-p^2)} , \]which is (184) for \(k = 2\).
(b) revisited. From the exact \(P_6\) and \(P_8\),
\begin{align*} \delta_6(p) &= \frac{p^3(1 + p - p^2)}{1 - 2p + 5p^2 - 3p^3} , \\ \delta_8(p) &= \frac{p^4(1 + 4p - 7p^2 - 5p^3 + 27p^4 - 27p^5 + p^6 + 15p^7 - 10p^8 + 2p^9)}{1 - 4p + 9p^2 - p^3 - 21p^4 + 53p^5 - 99p^6 + 155p^7 - 174p^8 + 122p^9 - 48p^{10} + 8p^{11}} , \end{align*}with \(\delta_4(\frac12) = 1/4\), \(\delta_6(\frac12) = 5/28\) and \(\delta_8(\frac12) = 401/2656\). For small \(p\), \(\delta_n \approx p^{n/2}\), which we checked at \(p = 0.001\) for \(n = 4\), 6 and 8. The reason is that each level has \(n/2\) steps: when slow steps are common, the critical path can continue through slow steps, and it is forced through a fast step essentially only when all \(n/2\) steps of a level are fast.
(c) Arbitrary \(k\) and \(n\). The answer is (188), with \(\delta_n(p)\) from Table 22: exact formulas for \(n \le 8\), the chain for \(n \le 16\), and the limit \(\delta_\infty\) of large rings. The values of \(\delta_n\) decrease with \(n\), and \(\delta_n - \delta_\infty\) shrinks roughly like \(1/n\). We estimate \(\delta_\infty\) by fitting a quadratic polynomial in \(1/n\) through the values for \(n = 12\), 14 and 16 and taking its value at \(1/n = 0\). To check this, we iterated (186) for \(n = 1024\) machines and \(16\,000\) levels and measured the fraction of slow steps on the critical path at \(p = 0.5\), 0.7 and 0.9; the two estimates of \(\delta_\infty\) differ by at most \(0.0014\).
| \(p\) | \(\delta_4\) | \(\delta_6\) | \(\delta_8\) | \(\delta_{12}\) | \(\delta_{16}\) | \(\delta_\infty\) |
|---|---|---|---|---|---|---|
| 0.1 | 0.0100 | 0.0013 | 0.0002 | 0.0000 | 0.0000 | 0 |
| 0.2 | 0.0400 | 0.0120 | 0.0046 | 0.0009 | 0.0002 | 0 |
| 0.3 | 0.0900 | 0.0425 | 0.0261 | 0.0136 | 0.0088 | 0.0002 |
| 0.4 | 0.1600 | 0.0982 | 0.0753 | 0.0566 | 0.0487 | 0.030 |
| 0.5 | 0.2500 | 0.1786 | 0.1510 | 0.1276 | 0.1172 | 0.091 |
| 0.6 | 0.3600 | 0.2813 | 0.2493 | 0.2216 | 0.2091 | 0.176 |
| 0.7 | 0.4900 | 0.4065 | 0.3702 | 0.3388 | 0.3246 | 0.287 |
| 0.8 | 0.6400 | 0.5582 | 0.5186 | 0.4837 | 0.4680 | 0.427 |
| 0.9 | 0.8100 | 0.7475 | 0.7093 | 0.6715 | 0.6545 | 0.613 |
Two limits of large rings can be found without numerics. Call a slow step an open site of the lattice of levels and machines; this is directed percolation with \(q = 1 - p\). If \(q > q_c\), that is \(p < 1 - q_c = 0.2945\), there are infinitely long directed paths of slow steps, so in a large ring the critical path consists of slow steps apart from a fraction that tends to zero as \(n \to\infty\), and \(\delta_\infty = 0\). Then
\[ \lim_{n\to\infty} \frac{P_n}{n} = \frac{p + k(1-p)}{2k} = \frac12 - \frac{(k-1)\,p}{2k}, \qquad p < 0.2945 . \tag{189}\]In this range the ring completes one level every \(k\) time units, as if every step were slow, and a fast step only lengthens the wait of the machine that made it. For a finite ring \(\delta_n\) is positive but small: \(\delta_{16}(0.2) = 0.0002\). For \(p > 0.2945\) the slow steps no longer form infinite paths, and \(\delta_\infty > 0\); we do not know a closed formula for it. Near \(p = 1\) the slow steps are rare. A path from level \(\ell\) down to level 1 consists of \(x\) moves to the left neighbor and \(y\) moves to the right neighbor, with \(x + y = \ell - 1\), so it is a staircase in a block of \(x\) by \(y\) sites. The slow steps are scattered in the block with density \(1-p\), and a path collects those that form an increasing chain. For \(x = y = \ell/2\), which gives the most points, the block contains about \((1-p)\,\ell^2/4\) slow steps, and the longest chain has about \(2\sqrt{(1-p)\,\ell^2/4} = \sqrt{1-p}\;\ell\) of them. Hence
\[ 1 - \delta_\infty(p) \approx \sqrt{1-p} \qquad (p \to 1). \]This is only the leading term: at \(p = 0.9\), \(1 - \delta_\infty = 0.388\) while \(\sqrt{0.1} = 0.316\). As a consequence, for large rings \(P/n\) rises to \(\frac12\) at \(p = 1\) with infinite slope (Figure 51), while for every finite \(n\) the curve is a smooth rational function.
The large-ring performance for several values of \(k\) is plotted in Figure 53. For \(k = 2\) it is lowest, \(P/n = 0.379\), at \(p \approx 0.73\). For large \(k\), (188) tends to \(P/n = (1-p)/[2(1 - \delta_\infty)]\), half the ratio of the fraction of slow steps among all steps to the fraction of slow steps on the critical path. With \(k = 10\) and \(p = 0.8\), \(P/n = 0.227\): a slow step is rare, but the time per level is determined by the slow steps on the critical path, and an average machine is idle \(77\%\) of the time.
27.4.3Simulation
As an illustration and a check of the two methods, we simulated the farm exactly as stated in the problem. The program stores the heights and, for each future time, the list of machines whose step ends then. At each integer time it ends those steps, raises the heights, examines the two neighbors of each machine that has just ended a step, and starts a step at every neighbor that has become a local minimum, drawing its length. We average the number of working machines over the last four fifths of the run. For \(n = 16\), \(p = \frac12\) and four runs of \(50\,000\) time units, the simulated performance is \(6.372 \pm 0.002\) for \(k = 2\), where the chain gives \(6.3735\), and \(5.291 \pm 0.008\) for \(k = 5\), where (188) with \(\delta_{16}(\frac12)\) gives \(5.2966\) (the \(\pm\) values are standard errors of the mean of the four runs). For \(n = 512\) machines and \(p = 0.2\), 0.5 and 0.8, the simulated \(P/n\) is \(0.4500\), \(0.3931\) and \(0.3813\) for \(k = 2\) and \(0.4198\), \(0.3239\) and \(0.2740\) for \(k = 5\), while the large-ring values from (188) and Table 22 are \(0.4500\), \(0.3928\), \(0.3814\) and \(0.4200\), \(0.3235\), \(0.2734\). The differences are at most \(0.0006\), comparable to the statistical errors of the simulations and to the difference between \(n = 512\) and \(n \to\infty\). The \(k = 2\) points are the circles in Figure 51.
References
- [58] G. Korniss, Z. Toroczkai, M. A. Novotny and P. A. Rikvold. From massively parallel algorithms and fluctuating time horizons to nonequilibrium surface growth. Physical Review Letters 84, 1351–1354, 2000.
- [59] I. Jensen. Low-density series expansions for directed percolation: I. A new efficient algorithm with applications to the square lattice. Journal of Physics A: Mathematical and General 32, 5233–5249, 1999.
- [60] H. Hinrichsen. Non-equilibrium critical phenomena and phase transitions into absorbing states. Advances in Physics 49, 815–958, 2000.
- [61] D. Aldous and P. Diaconis. Longest increasing subsequences: from patience sorting to the Baik–Deift–Johansson theorem. Bulletin of the American Mathematical Society 36, 413–432, 1999.