home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adaptor.zip / adapt.zip / adaptor / dalib / pvm3 / broadcst.c < prev    next >
C/C++ Source or Header  |  1993-11-29  |  4KB  |  113 lines

  1. /*******************************************************************
  2. *                                                                  *
  3. *  MODULE : broadcast.c                                            *
  4. *                                                                  *
  5. *  Function: Realization of Broadcast Operations                   *
  6. *                                                                  *
  7. *******************************************************************/
  8.  
  9. #include "system.h"
  10.  
  11. #define WITH_HOST 1
  12. #define NO_HOST   0 
  13.  
  14. /*******************************************************************
  15. *                                                                  *
  16. *  IMPORT :                                                        *
  17. *                                                                  *
  18. *      asend, areceive from MAILBOX                                *
  19. *                                                                  *
  20. *******************************************************************/
  21.  
  22. void general_broadcast (data,size,j,host_opt)
  23.  
  24. char *data;   /* pointer to the data element */
  25. int j, size;  /* process j sends data of size bytes */
  26. int host_opt; /* indicates participation of host    */
  27.  
  28. /*   Communication Patterns for broadcast of process j
  29.  
  30.      0    1    2    3    4    5    j    7    8    9   10  
  31.             <----------------------
  32.        <-   ------------------------------------->
  33.             -----------------> 
  34.             ------->            -------->
  35.             ->        ->        ->        ->        ->
  36.  
  37.     if host_opt == NO_HOST, host gets no copy
  38.  
  39. */
  40.  
  41. { int steph, distance;
  42.   int i, n;
  43.  
  44.   i = pcb.i;  /* number of the calling process */
  45.  
  46.   n = pcb.p;    /* total number of processes     */
  47.  
  48.   if (j!=1)   /* send value to process 1 */
  49.     { if (i==j) asend (j,1,data,size);     /* j sends to 1 */
  50.       if (i==1) areceive (1,j,data,size);  /* 1 recvs form j */
  51.     }
  52.  
  53.   if ((i==0)&&(j!=0))  /* host get its result from process 1 */
  54.     { if (host_opt == WITH_HOST)
  55.          areceive (0,1,data,size);   /* 0 gets from 1 */
  56.       return;
  57.     }
  58.  
  59.   distance = 1;
  60.   while (distance < n)    /* log n (base 2) loop */
  61.     distance = 2*distance;
  62.  
  63.   /* send to host */
  64.  
  65.   if ((host_opt == WITH_HOST) && (i==1) && (j!=0) && (target_model == 0))
  66.      asend (1,0,data,size);
  67.  
  68.   /* send values back to all processors */
  69.  
  70.   while (distance > 1)
  71.     { steph = distance;
  72.       distance = distance / 2;
  73.       if ( ((i-1) % steph) == 0)
  74.          { /* if i+distance exists send the new result */
  75.            if ( (i+distance) <= n)
  76.              asend (i,i+distance,data,size);
  77.          }
  78.       if ( ((i-1) % steph) == distance)
  79.          areceive (i,i-distance,data,size);
  80.     }
  81.  
  82.   /* now all processes have in data the broadcast value */
  83. }
  84.  
  85. process_broadcast (data,size,j)
  86. char *data;  /* pointer to the data element */
  87. int j, size;  /* process j sends data of size bytes */
  88. { general_broadcast (data,size,j,WITH_HOST); }
  89.  
  90. /*******************************************************************
  91. *                                                                  *
  92. *  FORTRAN - Interface                                             *
  93. *                                                                  *
  94. *    dalib_broadcast (data, size, j)                               *
  95. *      - broadcast to host and all node from process j             *
  96. *                                                                  *
  97. *    dalib_node_broadcast (data, size, j)                          *
  98. *      - broadcast to host and all node from process j             *
  99. *                                                                  *
  100. *******************************************************************/
  101.  
  102. void dalib_broadcast__ (data,size,j)
  103. int *data, *size, *j;
  104. { int pos;
  105.   general_broadcast (data, *size, *j, WITH_HOST);
  106. }
  107.  
  108. void dalib_node_broadcast__ (data,size,j)
  109. int *data, *size, *j;
  110. { int pos;
  111.   general_broadcast (data, *size, *j, NO_HOST);
  112. }
  113.