-
Notifications
You must be signed in to change notification settings - Fork 0
/
breakdownofRecursiveDoubling.c
53 lines (44 loc) · 1.25 KB
/
breakdownofRecursiveDoubling.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Online C compiler to run C program online
#include <stdio.h>
int main() {
int size=9;
int rank=0;
int mask;
while(rank<size){
int adjsize=16;
adjsize >>=1;
int remote;
if (adjsize != size) {
if (rank >= adjsize) {
/* send message to lower ranked node */
remote = rank - adjsize;
printf("*%d-%d\n",rank,remote);
} else if (rank < (size - adjsize)) {
// printf("%d-%d\n",rank,remote);
printf("\n");
}
}
/* exchange messages */
if ( rank < adjsize ) {
mask = 0x1;
while ( mask < adjsize ) {
remote = rank ^ mask;
mask <<= 1;
if (remote >= adjsize) continue;
printf("%d-%d\n",rank,remote);
}
}
/* non-power of 2 case */
if (adjsize != size) {
if (rank < (size - adjsize)) {
/* send enter message to higher ranked node */
remote = rank + adjsize;
// printf("%d-%d\n",rank,remote);
printf("\n");
}
}
rank++;
printf("\n");
}
return 0;
}