Misplaced Pages

Hypercube (communication pattern)

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

d {\displaystyle d} -dimensional hypercube is a network topology for parallel computers with 2 d {\displaystyle 2^{d}} processing elements. The topology allows for an efficient implementation of some basic communication primitives such as Broadcast, All-Reduce, and Prefix sum. The processing elements are numbered 0 {\displaystyle 0} through 2 d 1 {\displaystyle 2^{d}-1} . Each processing element is adjacent to processing elements whose numbers differ in one and only one bit. The algorithms described in this page utilize this structure efficiently.

Algorithm outline

Most of the communication primitives presented in this article share a common template. Initially, each processing element possesses one message that must reach every other processing element during the course of the algorithm. The following pseudo code sketches the communication steps necessary. Hereby, Initialization, Operation, and Output are placeholders that depend on the given communication primitive (see next section).

Input: message 
  
    
      
        m
      
    
    {\displaystyle m}
  
.
Output: depends on Initialization, Operation and Output.
Initialization

  
    
      
        s
        :=
        m
      
    
    {\displaystyle s:=m}
  

for 
  
    
      
        0
        
        k
        <
        d
      
    
    {\displaystyle 0\leq k<d}
  
 do
    
  
    
      
        y
        :=
        i
        
           XOR 
        
        
          2
          
            k
          
        
      
    
    {\displaystyle y:=i{\text{ XOR }}2^{k}}
  

    Send 
  
    
      
        s
      
    
    {\displaystyle s}
  
 to 
  
    
      
        y
      
    
    {\displaystyle y}
  

    Receive 
  
    
      
        m
      
    
    {\displaystyle m}
  
 from 
  
    
      
        y
      
    
    {\displaystyle y}
  

    Operation
  
    
      
        (
        s
        ,
        m
        )
      
    
    {\displaystyle (s,m)}
  

endfor
Output

Each processing element iterates over its neighbors (the expression i  XOR  2 k {\displaystyle i{\text{ XOR }}2^{k}} negates the k {\displaystyle k} -th bit in i {\displaystyle i} 's binary representation, therefore obtaining the numbers of its neighbors). In each iteration, each processing element exchanges a message with the neighbor and processes the received message afterwards. The processing operation depends on the communication primitive.

Algorithm outline applied to the 3 {\displaystyle 3} -dimensional hypercube. In the first step (before any communication), each processing element possesses one message (blue). Communication is marked red. After each step, the processing elements store the received message, but other operations are also possible.

Communication primitives

Prefix sum

In the beginning of a prefix sum operation, each processing element i {\displaystyle i} owns a message m i {\displaystyle m_{i}} . The goal is to compute 0 j i m j {\displaystyle \bigoplus _{0\leq j\leq i}m_{j}} , where {\displaystyle \oplus } is an associative operation. The following pseudo code describes the algorithm.

Input: message 
  
    
      
        
          m
          
            i
          
        
      
    
    {\displaystyle m_{i}}
  
 of processor 
  
    
      
        i
      
    
    {\displaystyle i}
  
.
Output: prefix sum 
  
    
      
        
          
          
            0
            
            j
            
            i
          
        
        
          m
          
            j
          
        
      
    
    {\displaystyle \bigoplus _{0\leq j\leq i}m_{j}}
  
 of processor 
  
    
      
        i
      
    
    {\displaystyle i}
  
.

  
    
      
        x
        :=
        
          m
          
            i
          
        
      
    
    {\displaystyle x:=m_{i}}
  
 

  
    
      
        σ

        :=
        
          m
          
            i
          
        
      
    
    {\displaystyle \sigma :=m_{i}}
  

for 
  
    
      
        0
        
        k
        
        d
        
        1
      
    
    {\displaystyle 0\leq k\leq d-1}
  
 do
    
  
    
      
        y
        :=
        i
        
           XOR 
        
        
          2
          
            k
          
        
      
    
    {\displaystyle y:=i{\text{ XOR }}2^{k}}
  

    Send 
  
    
      
        σ

      
    
    {\displaystyle \sigma }
  
 to 
  
    
      
        y
      
    
    {\displaystyle y}
  

    Receive 
  
    
      
        m
      
    
    {\displaystyle m}
  
 from 
  
    
      
        y
      
    
    {\displaystyle y}
  

    
  
    
      
        σ

        :=
        σ

        
        m
      
    
    {\displaystyle \sigma :=\sigma \oplus m}
  

    if bit 
  
    
      
        k
      
    
    {\displaystyle k}
  
 in 
  
    
      
        i
      
    
    {\displaystyle i}
  
 is set then 
  
    
      
        x
        :=
        x
        
        m
      
    
    {\displaystyle x:=x\oplus m}
  

endfor

The algorithm works as follows. Observe that hypercubes of dimension d {\displaystyle d} can be split into two hypercubes of dimension d 1 {\displaystyle d-1} . Refer to the sub cube containing nodes with a leading 0 as the 0-sub cube and the sub cube consisting of nodes with a leading 1 as 1-sub cube. Once both sub cubes have calculated the prefix sum, the sum over all elements in the 0-sub cube has to be added to the every element in the 1-sub cube, since every processing element in the 0-sub cube has a lower rank than the processing elements in the 1-sub cube. The pseudo code stores the prefix sum in variable x {\displaystyle x} and the sum over all nodes in a sub cube in variable σ {\displaystyle \sigma } . This makes it possible for all nodes in 1-sub cube to receive the sum over the 0-sub cube in every step.

This results in a factor of log p {\displaystyle \log p} for T start {\displaystyle T_{\text{start}}} and a factor of n log p {\displaystyle n\log p} for T byte {\displaystyle T_{\text{byte}}} : T ( n , p ) = ( T start + n T byte ) log p {\displaystyle T(n,p)=(T_{\text{start}}+nT_{\text{byte}})\log p} .

Example for a prefix sum calculation. Upper number: tentatetive prefix sum (variable x {\displaystyle x} ). Lower number: sum over all elements in the sub cube (variable σ {\displaystyle \sigma } ).

All-gather / all-reduce

All-gather operations start with each processing element having a message m i {\displaystyle m_{i}} . The goal of the operation is for each processing element to know the messages of all other processing elements, i.e. x := m 0 m 1 m p {\displaystyle x:=m_{0}\cdot m_{1}\dots m_{p}} where {\displaystyle \cdot } is concatenation. The operation can be implemented following the algorithm template.

Input: message 
  
    
      
        x
        :=
        
          m
          
            i
          
        
      
    
    {\displaystyle x:=m_{i}}
  
 at processing unit 
  
    
      
        i
      
    
    {\displaystyle i}
  
.
Output: all messages 
  
    
      
        
          m
          
            1
          
        
        
        
          m
          
            2
          
        
        
        
          m
          
            p
          
        
      
    
    {\displaystyle m_{1}\cdot m_{2}\dots m_{p}}
  
.

  
    
      
        x
        :=
        
          m
          
            i
          
        
      
    
    {\displaystyle x:=m_{i}}
  

for 
  
    
      
        0
        
        k
        <
        d
      
    
    {\displaystyle 0\leq k<d}
  
 do
    
  
    
      
        y
        :=
        i
        
           XOR 
        
        
          2
          
            k
          
        
      
    
    {\displaystyle y:=i{\text{ XOR }}2^{k}}
  

    Send 
  
    
      
        x
      
    
    {\displaystyle x}
  
 to 
  
    
      
        y
      
    
    {\displaystyle y}
  

    Receive 
  
    
      
        
          x
          
        
      
    
    {\displaystyle x'}
  
 from 
  
    
      
        y
      
    
    {\displaystyle y}
  

    
  
    
      
        x
        :=
        x
        
        
          x
          
        
      
    
    {\displaystyle x:=x\cdot x'}
  

endfor

With each iteration, the transferred message doubles in length. This leads to a runtime of T ( n , p ) j = 0 d 1 ( T start + n 2 j T byte ) = log ( p ) T start + ( p 1 ) n T byte {\displaystyle T(n,p)\approx \sum _{j=0}^{d-1}(T_{\text{start}}+n\cdot 2^{j}T_{\text{byte}})=\log(p)T_{\text{start}}+(p-1)nT_{\text{byte}}} .

The same principle can be applied to the All-Reduce operations, but instead of concatenating the messages, it performs a reduction operation on the two messages. So it is a Reduce operation, where all processing units know the result. Compared to a normal reduce operation followed by a broadcast, All-Reduce in hypercubes reduces the number of communication steps.

All-to-all

Here every processing element has a unique message for all other processing elements.

Input: message 
  
    
      
        
          m
          
            i
            j
          
        
      
    
    {\displaystyle m_{ij}}
  
 at processing element 
  
    
      
        i
      
    
    {\displaystyle i}
  
 to processing element 
  
    
      
        j
      
    
    {\displaystyle j}
  
.
for 
  
    
      
        d
        >
        k
        
        0
      
    
    {\displaystyle d>k\geq 0}
  
 do
    Receive from processing element 
  
    
      
        i
        
           XOR 
        
        
          2
          
            k
          
        
      
    
    {\displaystyle i{\text{ XOR }}2^{k}}
  
:
        all messages for my 
  
    
      
        k
      
    
    {\displaystyle k}
  
-dimensional sub cube
    Send to processing element 
  
    
      
        i
        
           XOR 
        
        
          2
          
            k
          
        
      
    
    {\displaystyle i{\text{ XOR }}2^{k}}
  
:
        all messages for its 
  
    
      
        k
      
    
    {\displaystyle k}
  
-dimensional sub cube
endfor

With each iteration a messages comes closer to its destination by one dimension, if it hasn't arrived yet. Hence, all messages have reached their target after at most d = log p {\displaystyle d=\log {p}} steps. In every step, p / 2 {\displaystyle p/2} messages are sent: in the first iteration, half of the messages aren't meant for the own sub cube. In every following step, the sub cube is only half the size as before, but in the previous step exactly the same number of messages arrived from another processing element.

This results in a run-time of T ( n , p ) log p ( T start + p 2 n T byte ) {\displaystyle T(n,p)\approx \log {p}(T_{\text{start}}+{\frac {p}{2}}nT_{\text{byte}})} .

ESBT-broadcast

The ESBT-broadcast (Edge-disjoint Spanning Binomial Tree) algorithm is a pipelined broadcast algorithm with optimal runtime for clusters with hypercube network topology. The algorithm embeds d {\displaystyle d} edge-disjoint binomial trees in the hypercube, such that each neighbor of processing element 0 {\displaystyle 0} is the root of a spanning binomial tree on 2 d 1 {\displaystyle 2^{d}-1} nodes. To broadcast a message, the source node splits its message into k {\displaystyle k} chunks of equal size and cyclically sends them to the roots of the binomial trees. Upon receiving a chunk, the binomial trees broadcast it.

Runtime

In each step, the source node sends one of its k {\displaystyle k} chunks to a binomial tree. Broadcasting the chunk within the binomial tree takes d {\displaystyle d} steps. Thus, it takes k {\displaystyle k} steps to distribute all chunks and additionally d {\displaystyle d} steps until the last binomial tree broadcast has finished, resulting in k + d {\displaystyle k+d} steps overall. Therefore, the runtime for a message of length n {\displaystyle n} is T ( n , p , k ) = ( n k T byte + T start ) ( k + d ) {\displaystyle T(n,p,k)=\left({\frac {n}{k}}T_{\text{byte}}+T_{\text{start}}\right)(k+d)} . With the optimal chunk size k = n d T byte T start {\displaystyle k^{*}={\sqrt {\frac {nd\cdot T_{\text{byte}}}{T_{\text{start}}}}}} , the optimal runtime of the algorithm is T ( n , p ) = n T byte + log ( p ) T start + n log ( p ) T start T byte {\displaystyle T^{*}(n,p)=n\cdot T_{\text{byte}}+\log(p)\cdot T_{\text{start}}+{\sqrt {n\log(p)\cdot T_{\text{start}}\cdot T_{\text{byte}}}}} .

Construction of the binomial trees

A 3 {\displaystyle 3} -dimensional hypercubes with three ESBT embedded.

This section describes how to construct the binomial trees systematically. First, construct a single binomial spanning tree von 2 d {\displaystyle 2^{d}} nodes as follows. Number the nodes from 0 {\displaystyle 0} to 2 d 1 {\displaystyle 2^{d}-1} and consider their binary representation. Then the children of each nodes are obtained by negating single leading zeroes. This results in a single binomial spanning tree. To obtain d {\displaystyle d} edge-disjoint copies of the tree, translate and rotate the nodes: for the k {\displaystyle k} -th copy of the tree, apply a XOR operation with 2 k {\displaystyle 2^{k}} to each node. Subsequently, right-rotate all nodes by k {\displaystyle k} digits. The resulting binomial trees are edge-disjoint and therefore fulfill the requirements for the ESBT-broadcasting algorithm.

References

  1. Grama, A.(2003). Introduction to Parallel Computing. Addison Wesley; Auflage: 2 ed. ISBN 978-0201648652.
  2. Foster, I.(1995). Designing and Building Parallel Programs: Concepts and Tools for Parallel Software Engineering. Addison Wesley; ISBN 0201575949.
  3. Johnsson, S.L.; Ho, C.-T. (1989). "Optimum broadcasting and personalized communication in hypercubes". IEEE Transactions on Computers. 38 (9): 1249–1268. doi:10.1109/12.29465. ISSN 0018-9340.
Category: