+++ /dev/null
-AddType text/plain .c
+++ /dev/null
-../../../../content/global_operations/src/print_tree.c
\ No newline at end of file
--- /dev/null
+
+ /* skeleton for a broadcast routine from node 0 */
+
+#include <stdio.h>
+#include <math.h>
+#include <stdlib.h>
+
+
+int main ( )
+{
+ int rank, size;
+ int source, count;
+ double msg;
+ /* scan over hypotetical virtual */
+ /* machine of 15 nodes */
+ size = 15;
+ /* message & source */
+ source = 0;
+ msg = 5.674389;
+ count = 1;
+ /* scan over processes */
+ for ( rank =0 ; rank<size ; rank++ )
+ {
+ my_broadcast( rank, size, source, &msg, count );
+ }
+}
+
+
+
+int my_broadcast( int rank, int size, double *msg, int count )
+{
+ int two_to_generation;
+ int Nto, to, from;
+ int * target;
+
+ target = (int *)malloc( (unsigned) size * sizeof(int) );
+
+ printf( " rank = %d ", rank );
+ /* two_to_generation reflects the */
+ /* steps in the tree broadcast */
+ Nto = 0;
+ 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 );
+ }
+ if ( rank < two_to_generation )
+ { /* send message */
+ to = rank + two_to_generation;
+ if ( to < size )
+ {
+ target[Nto] = to;
+ Nto++;
+ }
+ }
+ two_to_generation = 2 * two_to_generation;
+ }
+ /* done for a given rank */
+ printf("\n");
+
+ if (Nto > 0 )
+ {
+ for ( to=0 ; to<Nto ; to++ )
+ {
+ printf( " -- to %d ", target[ to ] );
+ }
+ printf("\n");
+ }
+
+ free( target );
+
+ return 0;
+}
+++ /dev/null
-
- /* skeleton for a broadcast routine from node 0 */
-
-#include <stdio.h>
-#include <math.h>
-#include <stdlib.h>
-
-
-int main ( )
-{
- int rank, size;
- int source, count;
- double msg;
- /* scan over hypotetical virtual */
- /* machine of 15 nodes */
- size = 15;
- /* message & source */
- source = 0;
- msg = 5.674389;
- count = 1;
- /* scan over processes */
- for ( rank =0 ; rank<size ; rank++ )
- {
- my_broadcast( rank, size, source, &msg, count );
- }
-}
-
-
-
-int my_broadcast( int rank, int size, double *msg, int count )
-{
- int two_to_generation;
- int Nto, to, from;
- int * target;
-
- target = (int *)malloc( (unsigned) size * sizeof(int) );
-
- printf( " rank = %d ", rank );
- /* two_to_generation reflects the */
- /* steps in the tree broadcast */
- Nto = 0;
- 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 );
- }
- if ( rank < two_to_generation )
- { /* send message */
- to = rank + two_to_generation;
- if ( to < size )
- {
- target[Nto] = to;
- Nto++;
- }
- }
- two_to_generation = 2 * two_to_generation;
- }
- /* done for a given rank */
- printf("\n");
-
- if (Nto > 0 )
- {
- for ( to=0 ; to<Nto ; to++ )
- {
- printf( " -- to %d ", target[ to ] );
- }
- printf("\n");
- }
-
- free( target );
-
- return 0;
-}