Hypercube (communication pattern)

This is an old revision of this page, as edited by Danielmyr (talk | contribs) at 15:08, 31 March 2019 (Gossip / All-Reduce). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

The -dimensional hypercube is a network topology for parallel computers with processing elements. The topology allows for an efficient implementation of some basic communication primitives such as Broadcast, All-Reduce and Prefix sum.[1] The processing elements are numbered from to . Each processing elements is then adjacent to processing elements whose numbers differ in exactly one bit. The algorithms described on this page utilize this structure efficiently.

Algorithm Outline

Most of the communication primitives presented in this article share a common template.[2] 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  .
Output: depends on initialization, operation und output.
Initialization
 
for   do
     
    Send   to  
    Recieve   from  
    Operation 
endfor
Output

Each processing element iterates over its neighbors (the expression   negates the  -th bit in  's binary representation, therefore obtaining the numbers of its neighbors). During an 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  -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

Prefixsum

At the beginng of a prefixsum operation each processing unit   owns a message  . At the end each processing unit   should recieve  , where   is an associative operation. The following pseudo code describes the algorithmn.

input: message   of processor  .
output: prefixsum   of processor  .
  
 
for   do
     
    Send   to  
    Recieve   from  
     
    if bit   in   is set then  
endfor

Bei der Präfixsumme besitzt jeder Prozessor   zu Beginn eine Nachricht  . Das Ziel ist es, dass jeder Prozessor   am Ende   für eine assoziative Operation   erhält. Der Algorithmus kann wie folgt in die Algorithmenskizze eingebettet werden:

Eingabe: Nachricht   auf Prozessor  .
Ausgabe: Präfixsumme   auf Prozessor  .
  
 
for   do
     
    Sende   an  
    Empfange   von  
     
    if Bit   in   gesetzt then  
endfor

Ein Hyperwürfel der Dimension   kann in zwei Hyperwürfel der Dimension   zerlegt werden. Dazu wird im Weiteren der Teilwürfel aller Knoten, deren Nummer in Binärdarstellung mit 0 beginnen, als 0-Teilwürfel bezeichnet. Die restlichen Knoten bilden analog den 1-Teilwürfel. Nachdem in beiden Teilwürfeln die Präfixsumme berechnet wurde, muss die Gesamtsumme der Elemente im 0-Teilwürfel noch auf alle Elemente des 1-Teilwürfels aufaddiert werden. Das liegt daran, dass nach Definition die Rechner im 0-Teilwürfel einen kleineren Rang als die Rechner im 1-Teilwürfel besitzen. In der Implementierung speichert jeder Knoten deswegen neben seiner Präfixsumme (Variable  ) außerdem die Summe über alle Elemente im Teilwürfel (Variable  ). So können in jedem Schritt alle Knoten im 1-Teilwürfel die Gesamtsumme über den 0-Teilwürfel beziehen.

Bei der Laufzeit ergibt sich ein Faktor von   für   und ein Faktor von   für  :  .

Hypercubes of dimension   can be split into two hypercubes of dimension  .

 
Beispiel für eine Präfixsummenberechnung. Jeder Knoten startet mit seiner eigenen Knotennummer als Nachricht, d.h.  . Die obere Zeile eines Knotens zeigt  , die untere Zeile  . Die Operation ist Addition.

Gossip / All-Reduce

Gossip operations start with each processing unit having a message  . After the operation is finished each processing unit knows the messages of all other processing units, so has the message  . The operation can be implemented following the algorithmn template.

input: message   at processing unit .
output: all messages  .
 
for   do
     
    Send   to  
    Recieve   from  
     
endfor

With each iteration the transfered message doubles in length. This leads to a run-time of  .

The same principle applies to the All-Reduce operations, but instead of concancating the messages, it performs an operation on the two messages. So it is a Reduce operation, where all processing units know the result. In Hypercubes a modified Gossip reduces the number of communications compared to Reduce and Broadcast.

All-to-All

Bei der All-to-All Kommunikation hat jeder Prozessor eine eigene Nachricht für alle anderen Prozessoren.

Eingabe: Nachrichten   auf Prozessor   an Prozessor  .
for   do
   Erhalte von Prozessor  :
       alle Nachrichte für meinen  -dimensionalen Teilwürfel
   Sende an Prozessor  :
       alle Nachrichte für seinen  -dimensionalen Teilwürfel
endfor

Eine Nachricht kommt in jedem Iterationsschritt eine Dimension näher an ihr Ziel, sollte sie es noch nicht erreicht haben. Demnach werden nur maximal   viele Schritte benötigt. In jedem Schritt werden   Nachrichten verschickt. Für den ersten Schritt liegen genau die Hälfte der Nachrichten nicht im eigenen Teilwürfel. In den allen folgenden Schritten ist der Teilwürfel nur noch halb so groß wie davor, allerdings wurden im vorhergegangenem Schritt genauso viele Nachrichten von einem anderen Prozessor erhalten, die auch für diesen Teilwürfel bestimmt sind.

Insgesamt bedeutet dies eine Laufzeit von:  

ESBT-Broadcast

Der ESBT-Broadcast (Edge-disjoint Spanning Binomial Tree) Algorithmus[3] ist ein zeitoptimaler Broadcast für Rechnerbündel mit Hyperwürfel-Netztopologie. Dazu wird das Netz ausgehend von der Quelle (im Folgendem der  -Rechner) in   kantendisjunkte Binomialbäume aufgeteilt, so dass jeder Nachbar der Quelle die Wurzel eines Binomialbaums mit   Rechnern ist. Die Quelle zerteilt ihre Nachricht nun in   Teilnachrichten, die dann zyklisch an die Wurzeln der Binomialbäume verteilt werden. Jeder Binomialbaum führt anschließend einen Broadcast aus.

Verteilt die Quelle in jedem Schritt eine Teilnachricht, hat sie nach   Schritten alle Teilnachrichten verteilt. Der Broadcast in einem Binomialbaum benötigt   Schritte. Insgesamt werden somit   Schritte benötigt, bis der Broadcast für die letzte Nachricht abgeschlossen ist und die Laufzeit ergibt sich zu  . Das optimale   minimiert die Laufzeit zu  .

Aufbau der Binomialbäume

 
A  -dimensional hypercubes with three ESBT embedded.

Die   Binomialbäume können systematisch nach der folgender Vorschrift konstruiert werden. Dazu wird zunächst ein Binomialbaum mit   Knoten definiert. Anschließend werden durch Translation und Rotation   kantendisjunkte Kopien des Binomialbaums in den Hyperwürfel eingebettet.

Ein einzelner Binomialbaum hat Knoten   als Wurzel. Die Kinder eines Knotens ergeben sich durch Negation der führenden Nullen in der Binärdarstellung der Knotennummer. Der so resultierende Graph ist offensichtlich ein Binomialbaum. Die Kantenmenge des  -ten Binomialbaums im Hyperwürfel erhält man nun wie folgt: auf jeden Knoten wendet man eine XOR-Operation mit   an und verschiebt die Binärdarstellung der Knotennummer anschließend um   Stellen zyklisch nach rechts. Die so entstehenden   Kopien des ausgehenden Binomialbaums sind kantendisjunkt und erfüllen somit die Voraussetzungen des ESBT-Broadcast Algorithmus.

Referenzen

  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.