File: BI_GetMpiTrType.c

package info (click to toggle)
scalapack 2.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 37,012 kB
  • sloc: fortran: 339,113; ansic: 74,517; makefile: 1,494; sh: 34
file content (122 lines) | stat: -rw-r--r-- 2,635 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "Bdef.h"

MPI_Datatype BI_GetMpiTrType(BLACSCONTEXT *ctxt, char uplo, char diag,
                                Int m, Int n, Int lda, MPI_Datatype Dtype,
                                Int *N)
{
   BLACBUFF *BI_GetBuff(Int);
   MPI_Datatype TrType;
   Int info, start, i, k;
   MpiInt *len, *disp;
   BLACBUFF *bp;

   if (diag == 'u') start = 1;
   else start = 0;

/*
 * Some versions of mpich and its derivitives cannot handle 0 byte typedefs,
 * so we set type MPI_BYTE as a flag for a 0 byte message
 */
#ifdef ZeroByteTypeBug
   if (m > n) i = n * (m-n) + (n*n) - (n*n)/2 + n/2 - n*start;
   else i = m * (n-m) + (m*m) - (m*m)/2 + m/2 - m*start;
   if (i < 1)
   {
      *N = 0;
      return (MPI_BYTE);
   }
#endif
   *N = 1;

/*
 * Get space to hold the length and displacement values
 */
   bp = BI_GetBuff( 2 * n * sizeof(MpiInt) );
   len = (MpiInt *) bp->Buff;
   disp = (MpiInt *) &bp->Buff[n*sizeof(MpiInt)];

   if (m > n)
   {
      if (uplo == 'u')
      {
         k = m - n + 1 - start;
         for (i=0; i < n; i++)
         {
            len[i] = k + i;
            disp[i] = i*lda;
         }
      }
      else  /* uplo = 'l' and m > n */
      {
         k = m - start;
         lda++;
         len[0] = k;
         disp[0] = start;
         for (i=1; i < n; i++)
         {
            len[i] = k - i;
            disp[i] = disp[i-1] + lda;
         }
      }
   }
   else /* m <= n */
   {
      if (uplo == 'u')
      {
         k = 1 - start;
         for (i=0; i < m; i++)
         {
            len[i] = i + k;
            disp[i] = i*lda;
         }
         for (; i < n; i++)
         {
            len[i] = m;
            disp[i] = i*lda;
         }
      }
      else  /* uplo = 'l' and m <= n */
      {
         k = n - m;
         for (i=0; i < k; i++)
         {
            len[i] = m;
            disp[i] = i*lda;
         }
         if (i < n)
         {
            k = n - start;
            len[i] = k - i;
            disp[i] = i*lda + start;
            lda++;
            for (i++; i < n; i++)
            {
               len[i] = k - i;
               disp[i] = disp[i-1] + lda;
            }
         }
      }
   }
#ifdef T3ETrError
/*
 * Get rid of 0-length segments to keep T3E happy
 */
   for (i=0; i < n; i++)
   {
      if (len[i] == 0)
      {
         for (k=i+1; k < n; k++)
         {
            len[k-1] = len[k];
            disp[k-1] = disp[k];
         }
         if (n > 0) n--;
         i--;   /* check new entry for 0-byte */
      }
   }
#endif

   i=MPI_Type_indexed(n, len, disp, Dtype, &TrType);
   i=MPI_Type_commit(&TrType);
   return(TrType);
}