Add explanatory comment and clean up src/global_operations/print_tree.c output.
authorW. Trevor King <wking@drexel.edu>
Sat, 30 Oct 2010 19:52:19 +0000 (15:52 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 30 Oct 2010 19:52:19 +0000 (15:52 -0400)
src/global_operations/print_tree.c

index f7383cd5737cdf2648db99a629c8964067f4f7e2..b5510f215baef17cb252c04df907da7150c9baf2 100644 (file)
@@ -2,10 +2,24 @@
 
 #include <stdio.h>
 #include <math.h>
+
+/* tree broadcast routine:
+ * 0 -(gen=1)-> 1
+ *
+ * 0 -(gen=2)-> 2
+ * 1 -(gen=2)-> 3
+ *
+ * 0 -(gen=4)-> 4
+ * 1 -(gen=4)-> 5
+ * 2 -(gen=4)-> 6
+ * 3 -(gen=4)-> 7
+ * ...
+ *
+ * In gen, processes (gen <= rank < 2*gen) will receive the broadcast data.
+ */
 int main(int argc, char *argv[])
 {
-       int two_to_generation;
-       int rank, size;
+       int gen, rank, size;
        int to, from;
 
        /* scan over a hypothetical virtual machine of 15 nodes */
@@ -13,25 +27,20 @@ int main(int argc, char *argv[])
        for (rank = 0; rank < size; rank++) {
                printf("rank %d", rank);
 
-               /* two_to_generation reflects the steps in the tree broadcast */
-               two_to_generation = 1;
-               while (two_to_generation < size) {
-
-                       /* receive message */
-                       if (rank >= two_to_generation
-                           && rank < two_to_generation * 2) {
-                               from = rank - two_to_generation;
-                               if (from < size)
-                                       printf(" -- from %d", from);
-                       }
-
-                       /* send message */
-                       if (rank < two_to_generation) {
-                               to = rank + two_to_generation;
+               /* gen reflects the generation (depth) in the tree broadcast */
+               gen = 1;
+               while (gen < size) {
+                       if (rank >= 2 * gen) {  /* wait for the data to come out */
+                               printf("\t");
+                       } else if (rank >= gen && rank < 2 * gen) {     /* receive message */
+                               from = rank - gen;
+                               printf("\tfrom %d", from);
+                       } else if (rank < gen) {        /* send message */
+                               to = rank + gen;
                                if (to < size)
-                                       printf(" -- to %d", to);
+                                       printf("\tto %d", to);
                        }
-                       two_to_generation = 2 * two_to_generation;
+                       gen *= 2;
                }
 
                /* done for a given rank */