From 708a51f60c4551308a1c1a0f5cbfd507c4aef0fd Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 30 Oct 2010 15:52:19 -0400 Subject: [PATCH] Add explanatory comment and clean up src/global_operations/print_tree.c output. --- src/global_operations/print_tree.c | 47 ++++++++++++++++++------------ 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/global_operations/print_tree.c b/src/global_operations/print_tree.c index f7383cd..b5510f2 100644 --- a/src/global_operations/print_tree.c +++ b/src/global_operations/print_tree.c @@ -2,10 +2,24 @@ #include #include + +/* 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 */ -- 2.26.2