home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / adaptor / dalib / pvm3 / transps1.c < prev   
Text File  |  1994-01-03  |  5KB  |  129 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. *  Author      : Falk Zimmermann, GMD, I1.HR                              *
  4. *  Copyright   : GMD St. Augustin, Germany                                *
  5. *  Date        : Jun 93                                                   *
  6. *  Last Update : Jun 93                                                   *
  7. *                                                                         *
  8. *  This Module is part of the DALIB                                       *
  9. *                                                                         *
  10. *  Module      : transpose1.c                                             *
  11. *                                                                         *
  12. *  Function    : Transposing of a 2-dimensional distributed array         *
  13. *                                                                         *
  14. *  Export      : dalib_transpose ()                                       *
  15. *                                                                         *
  16. *  void dalib_transpose (target, source, N1, N2, size)                    *
  17. *  unsigned char *source, *target;                                        *
  18. *  int *N1, *N2;                                                          *
  19. *  int *size;                                                             *
  20. *                                                                         *
  21. *                                                                         *
  22. **************************************************************************/
  23.  
  24. # undef DEBUG
  25.  
  26. #include "system.h"
  27.  
  28. # define DIM 4       /* maximal supported dimension */
  29.  
  30.  
  31. void dalib_transpose__ (target, source, N1, N2, size)
  32. unsigned char *source, *target;
  33. int *N1, *N2;
  34. int *size;
  35.  
  36. {
  37.   int lb1,lb2,ub1,ub2,ofstar,ofstar2,ofssou,ofssou2,buffsize;
  38.   int i,j,k,n,m,my_num,my_n,my_m,temp,anz;
  39.  
  40. /*-------------------------------------------------------------------------*
  41.  *                     Evaluation of the local bounds                      *
  42.  *-------------------------------------------------------------------------*/
  43.  
  44.  
  45.   my_num = dalib_pid_ ();
  46.  
  47.   dalib_local_extensions (my_num,*N1,&lb1,&ub1);
  48.   dalib_local_extensions (my_num,*N2,&lb2,&ub2);
  49.  
  50.   my_n = ub1 - lb1;
  51.   my_m = ub2 - lb2;
  52.  
  53. /*-------------------------------------------------------------------------*
  54.  *               Transposition of the local array elements                 *
  55.  *                                                                         *
  56.  * within the constraints of block-distribution the local elements are     *
  57.  * placed always along the main-diagonal in submatrices of size (n+1 x m+1)*
  58.  *                                                                         *
  59.  * ofssou bzw. ofstar describe the individual offset to the local elements *
  60.  * of the source- and targetarray, respectively.                           *
  61.  *-------------------------------------------------------------------------*/
  62.  
  63.   ofssou2 = *N2 * *size;
  64.   ofstar2 = *N1 * *size;
  65.  
  66.   for (j=0;j<=my_m;j++)
  67.     {  ofssou = (lb2-1+j) * *size;
  68.        ofstar = (lb1-1) * *size + j * ofstar2;
  69.  
  70.        for (k=0;k<=my_n;k++)
  71.          dalib_memcpy (target+k* *size+ofstar,source+ofssou2*k+ofssou,*size);
  72.     }
  73.  
  74. /*-------------------------------------------------------------------------*
  75.  *               Transposition of the global array elements                *
  76.  *                                                                         *
  77.  * Transposition requires communication between all processes;             *
  78.  *                                                                         *
  79.  * while sending global elements a buffer is utilized (non-contingious     *
  80.  * section) in which the elements are copied already in transposed order;  *
  81.  * the only task of the receiving part is to copy the contents of the      *
  82.  * buffer in chunks of the targetarray's columns to the corresponding      *
  83.  * target-adresses!                                                        *
  84.  *-------------------------------------------------------------------------*/
  85.  
  86.                               /* SENDING BUFFER */
  87.  
  88.   for (anz=1;anz<=pcb.p;anz++)
  89.      {  if (anz != my_num)
  90.          { dalib_local_extensions (anz, *N2, &lb2,&ub2);
  91.             m = ub2 - lb2;
  92.  
  93.            buffsize = (my_n+1) * (m+1) * *size;
  94.  
  95.            dalib_create_buffer (buffsize, 0);
  96.  
  97.            for (j=0;j<=m;j++)
  98.              { ofssou = (j+lb2-1) * *size;
  99.         for (k=0;k<=my_n;k++)
  100.           dalib_fill_buffer (source+ofssou+(k* *N2)* *size,*size);
  101.              }
  102.            dalib_send_buffer (anz);
  103.            dalib_destroy_buffer ();
  104.          }
  105.       }
  106.  
  107.                               /* RECEIVING BUFFER */
  108.  
  109.   for (anz=1;anz<=pcb.p;anz++)
  110.     { if ((my_num != anz))
  111.        { dalib_local_extensions (anz,*N1,&lb1,&ub1);
  112.          n = ub1 - lb1;
  113.  
  114.          buffsize = (my_m+1) * (n+1) * *size;
  115.  
  116.          dalib_create_buffer (buffsize,1);
  117.          dalib_recv_buffer (anz);
  118.  
  119.          for (j=0;j<=my_m;j++)
  120.              dalib_get_buffer (target+(lb1-1+j* *N1)* *size, *size *(n+1));
  121.  
  122.          dalib_destroy_buffer ();
  123.        }
  124.     }
  125. }
  126.  
  127.  
  128.  
  129.