Ran `indent -linux` on src/global_operations/*.c.
[parallel_computing.git] / src / global_operations / print_tree.c
1 /* skeleton for a broadcast routine from node 0 */
2
3 #include <stdio.h>
4 #include <math.h>
5 int main(int argc, char *argv[])
6 {
7         int two_to_generation;
8         int rank, size;
9         int to, from;
10
11         /* scan over a hypothetical virtual machine of 15 nodes */
12         size = 15;
13         for (rank = 0; rank < size; rank++) {
14                 printf("rank %d", rank);
15
16                 /* two_to_generation reflects the steps in the tree broadcast */
17                 two_to_generation = 1;
18                 while (two_to_generation < size) {
19
20                         /* receive message */
21                         if (rank >= two_to_generation
22                             && rank < two_to_generation * 2) {
23                                 from = rank - two_to_generation;
24                                 if (from < size)
25                                         printf(" -- from %d", from);
26                         }
27
28                         /* send message */
29                         if (rank < two_to_generation) {
30                                 to = rank + two_to_generation;
31                                 if (to < size)
32                                         printf(" -- to %d", to);
33                         }
34                         two_to_generation = 2 * two_to_generation;
35                 }
36
37                 /* done for a given rank */
38                 printf("\n");
39         }
40 }