# 随机算法 (Fall 2011)/Routing in a Parallel Network

The problem raises from parallel computing. Consider that we have ${\displaystyle N}$ processors, connected by a communication network. The processors communicate with each other by sending and receiving packets through the network. We consider the following packet routing problem:

• Every processor is sending a packet to a unique destination. Therefore for ${\displaystyle [N]}$ the set of processors, the destinations are given by a permutation ${\displaystyle \pi }$ of ${\displaystyle [N]}$, such that for every processor ${\displaystyle i\in [N]}$, the processor ${\displaystyle i}$ is sending a packet to processor ${\displaystyle \pi (i)}$.
• The communication is synchronized, such that for each round, every link (an edge of the graph) can forward at most one packet.

With a complete graph as the network. For any permutation ${\displaystyle \pi }$ of ${\displaystyle [N]}$, all packets can be routed to their destinations in parallel with one round of communication. However, such an ideal connectivity is usually not available in reality, either because they are too expensive, or because they are physically impossible. We are interested in the case the graph is sparse, such that the number of edges is significantly smaller than the complete graph, yet the distance between any pair of vertices is small, so that the packets can be efficiently routed between pairs of vertices.

# Routing on a hypercube

A hypercube (sometimes called Boolean cube, Hamming cube, or just cube) is defined over ${\displaystyle N}$ nodes, for ${\displaystyle N}$ a power of 2. We assume that ${\displaystyle N=2^{d}}$. A hypercube of ${\displaystyle d}$ dimensions, or a ${\displaystyle d}$-cube, is an undirected graph with the vertex set ${\displaystyle \{0,1\}^{d}}$, such that for any ${\displaystyle u,v\in \{0,1\}^{d}}$, ${\displaystyle u}$ and ${\displaystyle v}$ are adjacent if and only if ${\displaystyle h(u,v)=1}$, where ${\displaystyle h(u,v)}$ is the Hamming distance between ${\displaystyle u}$ and ${\displaystyle v}$.

A ${\displaystyle d}$-cube is a ${\displaystyle d}$-degree regular graph over ${\displaystyle N=2^{d}}$ vertices. For any pair ${\displaystyle (u,v)}$ of vertices, the distance between ${\displaystyle u}$ and ${\displaystyle v}$ is at most ${\displaystyle d}$. (How do we know this? Since it takes at most ${\displaystyle d}$ steps to fix any binary string of length ${\displaystyle d}$ bit-by-bit to any other.) This directly gives us the following very natural routing algorithm.

 Bit-Fixing Routing Algorithm For each packet: Let ${\displaystyle u,v\in \{0,1\}^{d}}$ be the origin and destination of the packet respectively. For ${\displaystyle i=1}$ to ${\displaystyle d}$, do: if ${\displaystyle u_{i}\neq v_{i}}$ then traverse the edge ${\displaystyle (v_{1},\ldots ,v_{i-1},u_{i},\ldots ,u_{d})\rightarrow (v_{1},\ldots ,v_{i-1},v_{i},u_{i+1}\ldots ,u_{d})}$.
Oblivious routing algorithms
This algorithm is blessed with a desirable property: at each routing step, the choice of link depends only on the the current node and the destination. We call the algorithms with this property oblivious routing algorithms. (Actually, the standard definition of obliviousness allows the choice also depends on the origin. The bit-fixing algorithm is even more oblivious than this standard definition.) Compared to the routing algorithms which are adaptive to the path that the packet traversed, oblivious routing is more simple thus can be implemented by smaller routing table (or simple devices called switches).
Queuing policies
When routing ${\displaystyle N}$ packets in parallel, it is possible that more than one packets want to use the same edge at the same time. We assume that a queue is associated to each edge, such that the packets to be delivered through an edge are put into the queue associated with the edge. With some queuing policy (e.g. FIFO, or furthest to do), the queued packets are delivered through the edge by at most one packet per each round.

For the bit-fixing routing algorithm defined above, regardless of the queuing policy, there always exists a bad permutation ${\displaystyle \pi }$ which specifies the destinations, such that it takes ${\displaystyle \Omega ({\sqrt {N}})}$ steps by the bit-fixing algorithm to route all ${\displaystyle N}$ packets to their destinations. (You can prove this by yourself.)

This is pretty bad, because we expect that the routing time is comparable to the diameter of the network, which is only ${\displaystyle d=\log N}$ for hypercube.

The lower bound actually applies generally for any deterministic oblivious routing algorithms:

 Theorem [Kaklamanis, Krizanc, Tsantilas, 1991] In any ${\displaystyle N}$-node communication network with maximum degree ${\displaystyle d}$, any deterministic oblivious algorithm for routing an arbitrary permutation requires ${\displaystyle \Omega ({\sqrt {N}}/d)}$ parallel communication steps in the worst case.

The proof of the lower bound is rather technical and complicated. However, the intuition is quite clear: for any oblivious rule for routing, there always exists a permutation which causes a very high congestion, such that many packets have to be delivered through the same edge, thus no matter what queuing policy is used, the maximum delay must be very high.

# Average-case Analysis for Independent Destinations

We analyze the average-case performance of the bit-fixing routing algorithm. We relax the problem to non-permutation destinations. That is, instead of restricting that every processor has a distinct destination, we now allow each processor choose an arbitrary destination in ${\displaystyle \{0,1\}^{d}}$.

For the average case, for each node ${\displaystyle v\in \{0,1\}^{d}}$, its destination is a uniformly and independently random node from ${\displaystyle \{0,1\}^{d}}$.

For each node ${\displaystyle v\in \{0,1\}^{d}}$, let ${\displaystyle P_{v}}$ denote the route for ${\displaystyle v}$ to its random destination ${\displaystyle r}$. ${\displaystyle P_{v}}$ is a sequence of edges along the bit-fixing route from ${\displaystyle v}$ to ${\displaystyle r}$.

## Reduce the delay of a route to the number of packets that pass through the route

We consider the delay incurred by each node, which is the total time that its packet is waiting in the queue. The total running time of the algorithm is bounded by the maximum delay plus ${\displaystyle d}$.

We assume that the queueing policy satisfies a very natural requirement:

Natural queuing assumption
If a queue is not empty at the beginning of a time step, some packet is sent along the edge associated with that queue during that time step.
 Lemma 2.1 With the above assumption of the queuing policy, the delay inccured by ${\displaystyle u}$ is at most the number of packets whose routes pass through at least one edge in ${\displaystyle P_{u}}$.
Proof.
 See Lemma 4.5 in the textbook [MR].
${\displaystyle \square }$

## Represent the delay as the sum of independent trials

Let the random variable ${\displaystyle H_{uv}}$ indicate whether ${\displaystyle P_{u}}$ and ${\displaystyle P_{v}}$ share at least one edge. That is,

${\displaystyle H_{uv}={\begin{cases}1&{\text{if }}P_{u}{\text{ and }}P_{v}{\text{ share at least one edge}},\\0&{\text{otherwise}}.\end{cases}}}$

Fix a node ${\displaystyle u\in \{0,1\}^{d}}$ and the corresponding route ${\displaystyle P_{u}}$. The random variable ${\displaystyle H_{u}=\sum _{v\in \{0,1\}^{d}}H_{uv}}$ gives the total number of packets whose routes pass through ${\displaystyle P_{u}}$. Due to Lemma 2.1, ${\displaystyle H_{u}}$ gives an upper bound on the delay inccured by ${\displaystyle u}$.

We will then bound ${\displaystyle H_{u}}$. Note that for ${\displaystyle v\neq u}$, ${\displaystyle H_{uv}}$ are independent trials (because the destinations of ${\displaystyle u}$ and ${\displaystyle v}$ are independent), thus we can apply the Chernoff bound. To do so, we must estimate the expectation ${\displaystyle \mathbf {E} [H_{u}]}$.

## Estimate the expectation of the sum

For any edge ${\displaystyle e}$ in the hypercube, let the random variable ${\displaystyle T(e)}$ denote the number of routes that pass through ${\displaystyle e}$. As we argued above that ${\displaystyle H_{u}}$ is the number of packets that pass though the route ${\displaystyle P_{u}}$, then obviously

${\displaystyle H_{u}\leq \sum _{e\in P_{u}}T(e),}$

where we abuse the notation ${\displaystyle e\in P_{u}}$ to denote the edge ${\displaystyle e}$ appeared in the route ${\displaystyle P_{u}}$.

Therefore,

${\displaystyle \mathbf {E} [H_{u}]\leq \sum _{e\in P_{u}}\mathbf {E} [T(e)].\qquad \qquad (*)}$

For every node ${\displaystyle v\in \{0,1\}^{d}}$, the length of the route ${\displaystyle P_{v}}$, denoted ${\displaystyle |P_{v}|}$, is the number of different bits between ${\displaystyle v}$ and the last node in the route (because of the "bit-fixing"). For the uniformly random destination, ${\displaystyle \mathbf {E} [|P_{v}|]=d/2}$ (a random node in ${\displaystyle \{0,1\}^{d}}$ expectedly flips ${\displaystyle d/2}$ bits in any fixed ${\displaystyle v\in \{0,1\}^{d}}$). Thus,

${\displaystyle \sum _{v\in \{0,1\}^{d}}\mathbf {E} [|P_{v}|]={\frac {dN}{2}}.}$

It is obvious that we can count the sum of lengths of a set of routes by accumulating their passes through edges, that is

${\displaystyle \sum _{v\in \{0,1\}^{d}}|P_{v}|=\sum _{e}T(e),}$

Therefore,

${\displaystyle \sum _{e}\mathbf {E} [T(e)]=\sum _{v\in \{0,1\}^{d}}\mathbf {E} [|P_{v}|]={\frac {dN}{2}},}$

where the sum ${\displaystyle \sum _{e}\mathbf {E} [T(e)]}$ is taken over all edges in the hypercube.

An important observation is that the distribution of ${\displaystyle T(e)}$'s are all symmetric, thus all ${\displaystyle \mathbf {E} [T(e)]}$'s are equal. The number of edges in the hypercube is ${\displaystyle {\frac {dN}{2}}}$. Therefore, for every edge ${\displaystyle e}$ in the hupercube,

${\displaystyle \mathbf {E} [T(e)]={\frac {2}{dN}}\cdot {\frac {dN}{2}}=1.}$

The length of ${\displaystyle P_{u}}$ is at most ${\displaystyle d}$. Due to ${\displaystyle (*)}$, the expectation of ${\displaystyle H_{u}}$ is ${\displaystyle \mathbf {E} [H_{u}]\leq \sum _{e\in P_{u}}\mathbf {E} [T(e)]\leq d}$.

## Apply the Chernoff bound

We apply the following form of the Chernoff bound:

 Chernoff bound Let ${\displaystyle X=\sum _{i=1}^{n}X_{i}}$, where ${\displaystyle X_{1},X_{2},\ldots ,X_{n}}$ are independent Poisson trials. Let ${\displaystyle \mu =\mathbf {E} [X]}$. Then for ${\displaystyle t\geq 2e\mu }$, ${\displaystyle \Pr[X\geq t]\leq 2^{-t}.}$

It holds that ${\displaystyle 6d>2e\mathbf {E} [H_{u}]=2ed}$. By applying the Chernoff bound,

${\displaystyle \Pr[H_{u}>6d]<2^{-6d}}$.

Note that ${\displaystyle H_{u}}$ only gives the bound on the delay incurred by a particular node ${\displaystyle u}$. By the union bound,

{\displaystyle {\begin{aligned}\Pr[{\text{the maximum delay of Phase I}}>6d]&\leq \Pr[\max _{u\in \{0,1\}^{d}}H_{u}>6d]\\&\leq N\Pr[H_{u}>6d]\\&

The running time is the maximum delay plus the length of a route, thus is ${\displaystyle >7d}$ with probability ${\displaystyle <2^{-5d}}$.

# A two-phase randomized routing algorithm

The above analysis of the performance of bit-fixing for independent random destinations hints us that we can first route the packets to random "relay"s to avoid the high congestion. This was first discovered by Leslie Valiant who uses the idea to give a simple and elegant randomized routing algorithm for permutation routing.

The algorithm works in two phases.

 Two-Phase Routing Algorithm For each packet: Phase I: Route the packet to a random destination using the bit-fixing algorithm. Phase II: Route the packet from the random location to its final destination using the bit-fixing algorithm.

It looks counter-intuitive that first routing the packets to irrelevant intermediate nodes actually improves the overall performance.

To simplify the analysis, we assume that no packet is sent in Phase II before all packets have finished Phase I.

Phase I is exactly the bit-fixing routing for uniformly and independently random destinations, which as we analyzed in the last section, has a running time within ${\displaystyle 7d}$ for probability at least ${\displaystyle 1-2^{-5d}}$.

The Phase II is a "backward" running of Phase I. All the analysis of Phase I can be directly applied to Phase II. Thus, the running time of Phase II is ${\displaystyle >7d}$ with probability ${\displaystyle <2^{-5d}}$. By the union bound, the total running time of the randomized routing algorithm is no more than ${\displaystyle 14d=O(\log N)}$ with high probability.