home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / adaptor.zip / adapt.zip / adaptor / dalib / pvm3 / overlap1.c < prev    next >
Text File  |  1993-12-02  |  8KB  |  196 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. *  Author      : Dr. Thomas Brandes, GMD, I1.HR                           *
  4. *  Copyright   : GMD St. Augustin, Germany                                *
  5. *  Date        : Apr 93                                                   *
  6. *  Last Update : Apr 93                                                   *
  7. *                                                                         *
  8. *  This Module is part of the DALIB / UNILIB                              *
  9. *                                                                         *
  10. *  Module      : overlap1.c                                               *
  11. *                                                                         *
  12. *  Function    : fill out overlapping areas for distributed arrays        *
  13. *                                                                         *
  14. *   source  : is a source array                                           *
  15. *   target  : is the target, conform with source, but has an overlap      *
  16. *                                                                         *
  17. **************************************************************************/
  18.  
  19. #undef DEBUG
  20.  
  21. #include "system.h"
  22.  
  23.      /*********************************************************
  24.      *                                                        *
  25.      *  Exchange the overlap area                             *
  26.      *                                                        *
  27.      *   l1      N1                              r1           *
  28.      *  -----------------------------------------------       *
  29.      *  |T    | Sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |     |       *
  30.      *  -----------------------------------------------       *
  31.      *                                                        *
  32.      *********************************************************/
  33.  
  34. void dalib_communicate_overlap (target, source, N1, l1, r1)
  35.  
  36. unsigned char *target, *source;
  37. int N1, l1, r1;
  38.  
  39. { int left, right;
  40.  
  41. #ifdef DEBUG
  42.   printf ("%d comm overlap, %d (%d - %d)\n", pcb.i, N1, l1, r1);
  43. #endif
  44.  
  45.   /* make sure that overlap area is not too big */
  46.  
  47.   if (N1 < l1)
  48.    { printf ("left overlap area (size = %d) too big, only %d bytes\n", l1, N1);
  49.      exit (-1);
  50.    }
  51.   if (N1 < r1)
  52.    { printf ("right overlap area (size = %d) too big, only %d bytes\n",r1,N1);
  53.      exit (-1);
  54.    }
  55.  
  56.   left  = pcb.i - 1;
  57.   if (left == 0) left = pcb.p;
  58.   right = pcb.i + 1;
  59.   if (right == pcb.p +1) right = 1;
  60.  
  61.   if (target+l1 != source)
  62.      dalib_memcpy (target+l1, source, N1);
  63.  
  64.   asend (pcb.i, left, source, r1);
  65.   areceive (pcb.i, right, target + l1 + N1, r1);
  66.  
  67.   asend (pcb.i, right, source + N1 - l1, l1);
  68.   areceive (pcb.i, left, target, l1);
  69.  
  70. }  /* dalib_communicate_overlap */
  71.  
  72.      /*********************************************************
  73.      *                                                        *
  74.      *  Overlapping of one-dimensional arrays                 *
  75.      *                                                        *
  76.      *   with communication                                   *
  77.      *                                                        *
  78.      *                                                        *
  79.      *   l1      N1                              r1           *
  80.      *  -----------------------------------------------       *
  81.      *  |T    | Sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |     |       *
  82.      *  -----------------------------------------------       *
  83.      *                                                        *
  84.      *********************************************************/
  85.  
  86. void dalib_coverlap1__ (target, source, N1, l1, r1, size)
  87.  
  88. unsigned char *target, *source;
  89. int *N1, *l1, *r1, *size;
  90.  
  91. /*   source is (N1), target is (N1+l1+r1), size is number of bytes */
  92.  
  93. { int bytes, myN;
  94.  
  95.   bytes     = *size;
  96.   myN       = dalib_local_size (*N1);
  97.   dalib_communicate_overlap (target, source, myN*bytes, *l1*bytes, *r1*bytes);
  98.  
  99. }  /* dalib_coverlap1 */
  100.  
  101.      /*********************************************************
  102.      *                                                        *
  103.      *  Overlapping of two-dimensional arrays                 *
  104.      *                                                        *
  105.      *   with communication                                   *
  106.      *                                                        *
  107.      *      l2      N2                              r2        *
  108.      *     -----------------------------------------------    *
  109.      *     |T      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,       |    *
  110.      * l1  |       ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,       |    *
  111.      *     |     | Sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |     |    *
  112.      * N1  |     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |     |    *
  113.      *     |     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |     |    *
  114.      *     |       ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,       |    *
  115.      * r1  |       ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,       |    *
  116.      *     -----------------------------------------------    *
  117.      *                                                        *
  118.      *********************************************************/
  119.  
  120. void dalib_coverlap2__ (target, source, N1, l1, r1, N2, l2, r2, size)
  121.  
  122. unsigned char *target, *source;
  123. int *N1, *l1, *r1, *N2, *l2, *r2, *size;
  124.  
  125. { int bytes, myN;
  126.  
  127.   bytes     = *size;
  128.   myN       = dalib_local_size (*N2);
  129.   dalib_overlap_seg2 (0, target, source, *N1*bytes, *l1*bytes, *r1*bytes,
  130.                                       myN, *l2, *r2);
  131.  
  132.   /* last dimension will be overlapped by communication */
  133.  
  134.   bytes *= (*N1 + *l1 + *r1);
  135.   dalib_communicate_overlap (target, target + *l2 * bytes,
  136.                              myN * bytes, *l2 * bytes, *r2 * bytes);
  137.  
  138. } /* dalib_coverlap2_ */
  139.  
  140.      /*********************************************************
  141.      *                                                        *
  142.      *  Overlapping of three-dimensional arrays               *
  143.      *                                                        *
  144.      *********************************************************/
  145.  
  146. void dalib_coverlap3__ (target, source, N1, l1, r1, N2, l2, r2, N3, l3, r3, size)
  147.  
  148. unsigned char *target, *source;
  149. int *N1, *l1, *r1, *N2, *l2, *r2, *N3, *l3, *r3, *size;
  150.  
  151. { int bytes, myN;
  152.  
  153.   bytes     = *size;
  154.   myN       = dalib_local_size (*N3);
  155.  
  156.   dalib_overlap_seg3 (0, target, source, *N1*bytes, *l1*bytes, *r1*bytes,
  157.                                       *N2, *l2, *r2, myN, *l3, *r3);
  158.  
  159.   /* last dimension will be overlapped by communication */
  160.  
  161.   bytes *= (*N1 + *l1 + *r1) * (*N2 + *l2 + *r2);
  162.   dalib_communicate_overlap (target, target + *l3 * bytes,
  163.                              myN * bytes, *l3 * bytes, *r3 * bytes);
  164.  
  165. } /* dalib_coverlap3_ */
  166.  
  167.      /*********************************************************
  168.      *                                                        *
  169.      *  Overlapping of four-dimensional arrays                *
  170.      *                                                        *
  171.      *********************************************************/
  172.  
  173. void dalib_coverlap4__ (target, source, N1, l1, r1, N2, l2, r2,
  174.                                       N3, l3, r3, N4, l4, r4, size)
  175.  
  176. unsigned char *target, *source;
  177. int *N1, *l1, *r1, *N2, *l2, *r2, *N3, *l3, *r3, *N4, *l4, *r4, *size;
  178.  
  179. { int bytes, myN;
  180.  
  181.   bytes     = *size;
  182.   myN       = dalib_local_size (*N4);
  183.  
  184.   dalib_overlap_seg4 (0, target, source, *N1*bytes, *l1*bytes, *r1*bytes,
  185.                       *N2, *l2, *r2, *N3, *l3, *r3, myN, *l4, *r4);
  186.  
  187.   /* last dimension will be overlapped by communication */
  188.  
  189.   bytes *= (*N1 + *l1 + *r1) * (*N2 + *l2 + *r2) * (*N3 + *l3 + *r3);
  190.   dalib_communicate_overlap (target, target + *l4 * bytes,
  191.                              myN * bytes, *l4 * bytes, *r4 * bytes);
  192.  
  193.  
  194. } /* dalib_coverlap4_ */
  195.  
  196.