User:Armin Wiebigke/sandbox

The two-tree broadcast (abbreviated 2tree-broadcast or 23-broadcast) is an algorithm to implement a broadcast communication pattern. The algorithm can also be adapted to perform a reduction or prefix sum.

Algorithm
A broadcast sends a message from a specified root processor to all other processors. Binary tree broadcasting uses a binary tree to model the communication between the processors. Each processor corresponds to one node in the tree, and the root processor is the root of the tree. To broadcast a message $M$, the root sends $M$ to its two children (child nodes). Each processor waits until it receives $M$ and then sends $M$ to its children. Because leaves have no children, they don't have to send any messages. The broadcasting process can be pipelined by splitting the message into $k$ blocks, which are then broadcasted consecutively. In such a binary tree, the leaves of the tree only receive data, but never send any data themselves. If the communication is bidirectional (full-duplex), meaning each processor can send a message and receive a message at the same time, the leaves only use halve of the available bandwidth.

The idea of the two-tree broadcast is to use two binary trees $T_{1}$ and $T_{2}$ and communicate on both concurrently. The trees are constructed so that the interior nodes of one tree correspond to leaf nodes of the other tree. The data that has to be broadcasted is split into blocks of equal size. In each step of the algorithm, each processor receives one block and sends the previous block to one of its children in the tree in which it is an interior node. A schedule is needed so that no processor has to send or receive two messages in the same step. To create such a schedule, the edges of both trees are colored with 0 and 1 such that Edges with color 0 are used in even steps, edges with color 1 are used in odd steps. This schedule allows each processor to send one message and receive one message in each step, fully utilizing the available bandwidth. Assume that processor $T_{1}$ wants to broadcasts a message. The two trees are constructed for the remaining processors. Processor $T_{2}$ sends blocks alternating to the roots of the two trees, so each tree broadcasts one half of the message.
 * no processor is connected to its parent nodes in $T_{1}$ and $T_{2}$ using edges of the same color
 * no processor is connected to its children nodes in $T_{1}$ or $T_{2}$ using edges of the same color.

Analysis
(maybe different communication models)

Let $i$ be the number of processes, numbered from $i$ to $p$.

Construction of the trees
Let $0$. $p - 1$ and $T_{1}$ can be constructed as trees of height $T_{2}$, such that both trees form an in-order numbering of the processors, with the following method:

If $h = &lceil;log(p + 2)&rceil;$, $T_{1}$ is a complete binary tree of height $T_{2}$ expect that the rightmost leaf is missing. Otherwise, $h - 1$ consists of a complete binary tree of height  $p = 2^{h} - 2$ covering PEs $T_{1}$, a recursively constructed tree covering PEs $h - 1$, and a root at PE  $T_{1}$ whose children are the roots of the left and the right subtree.

There are two ways to construct $h - 2$. With shifting, $[0, 2^{h-1} - 2]$ is first constructed like $[2^{h-1}, p - 1]$, except that it contains an additional processor. Then $2^{h-1} - 1$ is shifted by one position to the left and the leftmost leaf is removed. With mirroring, $T_{2}$ is the mirror image of $T_{2}$ (with the mirror axis between processes $T_{1}$ and $T_{2}$). Mirroring only works for even $T_{2}$.

It can be proven that a coloring with the desired properties exists for all $T_{1}$. When mirroring is used to construct $p⁄2-1$, each processor can independently compute the color of its incident edges in $p⁄2$ time.

Communication Time
Communication model: A messeage of size $p$ has a communication time of $p$. $T_{2}$ represents the startup overhead to send the message, $O(log p)$ represents the transmission time per data element.

Suppose the message of size $n$ is split into $&alpha; + &beta;n$ blocks. Each communication step takes time $&alpha;$. Let $&beta;$ be the height of the communication structure with the root at processor $m$ and the two trees below it. After $2k$ steps, the first data block has reached every node in both trees. Afterwards, each processor receives one block in every step until it received all blocks. The total number of steps is $&alpha; + &beta;m⁄2k$ resulting in a total communication time of $h=log p$. Using an optimal $i$,the total communication time is $2h$

Comparison to similar algorithms
In a linear pipeline broadcast, the message is split into $2h + 2k$ blocks. In each step, each processor $(2h + 2k)(&alpha; + &beta;m⁄2k)$ receives one block from the processor $k = k^{*} = (&beta;mh⁄2&alpha;)^{&frac12;}$ and sends one block to the processor $&beta;m + 2&alpha;log p + √8&alpha;&beta;mlog p$. Linear pipeline has optimal throughput, but has a startup time in $k$. For large $i$, the $i-1$ startup time of the two-tree broadcast is faster while the throuput is identical.

A binomial tree broadcast communicates along a binomial tree. Each process receives the message that is broadcasted (the root already has the message) and then sends the message to its children. A binomial tree broadcast has only half the startup time of the Two-Tree broadcast, but a factor of $i+1$ more communication. The binomial tree broadcast is faster than the two-tree broadcast for small messages, but slower for large messages.

A pipelined binary tree broadcast splits the message into $O(p)$ blocks and broadcasts the blocks consecutively over a binary tree. By using a Fibonacci tree instead of a simple complete binary tree, the startup latency can be reduced to $p$. A Fibonacci tree of height $O(log p)$ consists of a root that has a a Fibonacci tree of height $log(p)$ as its left child and a Fibonacci tree of $k$ as its right child. The pipelined Fibonacci tree broadcast has half the startup time of the two-tree broadcast, but also only half of the bandwidth. It is faster for small messages, while the two-tree broadcast is faster for large messages.

ESBT
If p is a power of two, there is an elegant optimal broadcasting algorithm [11] based on log p edge disjoint spanning binomial trees (ESBT) in a hypercube.

Reduction
A reduction computes $$\bigoplus_{i=0}^{p-1} M_i$$ where $&alpha;log(p)$ is a vector of length $h$ originally available at processor $h-1$ and $$\bigoplus$$ is a binary operation that is associative, but not necessarily commutative. The result is stored at a specified root processor $h-2$.

Assume that $T_{1}$ or $T_{2}$. In this case the communication is identical to the broadcast, except that the communication direction is reversed. Each process receives two blocks from its children, reduces them with its own block, and sends the result to its parent. The root takes turns receiving blocks from the roots of $M_{i}$ and $m$ and reduces them with its own data. The communication time is the same as for the Broadcast and the amount of data reduced per processor is $i$. If the reduce operation is commutative, the result can be achieved for any root by renumbering the processors. If the operation is not commutative and the root is not $r$ or $r = 0$, then $r = p-1$ is a lower bound for the communitation time. In this case the result is first computed with processor $T_{1}$ as the root, and then the result is send to processor $T_{2}$.

Prefix sum
A prefix sum computes $$\bigoplus_{i=0}^{j} M_i$$ for each processor $2m$ where $0$ is a vector of length $p-1$ originally available at processor $2&beta;m$ and $$\bigoplus$$ is a binary associative operation. Using an inorder binary tree, a prefix sum can be computed by first performing an up-phase in which each interior node computes a partial sum $$\bigoplus_{i=l}^{r} M_i$$ for left- and rightmost leaves $0$ and $r$, followed by a down-phase in which prefixes of the form $$\bigoplus_{i=0}^{l-1} M_i$$ are sent down the tree and allow each processor to finish computing its prefix sum. The communication in the up-phase is equivalent to a reduction to processor $j$ and communication in the down-phase is equivalent to a broadcast from the processor $M_{i}$. The total communication time is about twice the communication time of the two-tree broadcast.