ScaLAPACK 2.1  2.1
ScaLAPACK: Scalable Linear Algebra PACKage
BI_GetMpiTrType.c
Go to the documentation of this file.
1 #include "Bdef.h"
2 
3 
4 MPI_Datatype BI_GetMpiTrType(BLACSCONTEXT *ctxt, char uplo, char diag,
5  int m, int n, int lda, MPI_Datatype Dtype,
6  int *N)
7 {
8  BLACBUFF *BI_GetBuff(int);
9  MPI_Datatype TrType;
10  int info, start, i, k;
11  int *len, *disp;
12  BLACBUFF *bp;
13 
14  if (diag == 'u') start = 1;
15  else start = 0;
16 
17 /*
18  * Some versions of mpich and its derivitives cannot handle 0 byte typedefs,
19  * so we set type MPI_BYTE as a flag for a 0 byte message
20  */
21 #ifdef ZeroByteTypeBug
22  if (m > n) i = n * (m-n) + (n*n) - (n*n)/2 + n/2 - n*start;
23  else i = m * (n-m) + (m*m) - (m*m)/2 + m/2 - m*start;
24  if (i < 1)
25  {
26  *N = 0;
27  return (MPI_BYTE);
28  }
29 #endif
30  *N = 1;
31 
32 /*
33  * Get space to hold the length and displacement values
34  */
35  bp = BI_GetBuff( 2 * n * sizeof(int) );
36  len = (int *) bp->Buff;
37  disp = (int *) &bp->Buff[n*sizeof(int)];
38 
39  if (m > n)
40  {
41  if (uplo == 'u')
42  {
43  k = m - n + 1 - start;
44  for (i=0; i < n; i++)
45  {
46  len[i] = k + i;
47  disp[i] = i*lda;
48  }
49  }
50  else /* uplo = 'l' and m > n */
51  {
52  k = m - start;
53  lda++;
54  len[0] = k;
55  disp[0] = start;
56  for (i=1; i < n; i++)
57  {
58  len[i] = k - i;
59  disp[i] = disp[i-1] + lda;
60  }
61  }
62  }
63  else /* m <= n */
64  {
65  if (uplo == 'u')
66  {
67  k = 1 - start;
68  for (i=0; i < m; i++)
69  {
70  len[i] = i + k;
71  disp[i] = i*lda;
72  }
73  for (; i < n; i++)
74  {
75  len[i] = m;
76  disp[i] = i*lda;
77  }
78  }
79  else /* uplo = 'l' and m <= n */
80  {
81  k = n - m;
82  for (i=0; i < k; i++)
83  {
84  len[i] = m;
85  disp[i] = i*lda;
86  }
87  if (i < n)
88  {
89  k = n - start;
90  len[i] = k - i;
91  disp[i] = i*lda + start;
92  lda++;
93  for (i++; i < n; i++)
94  {
95  len[i] = k - i;
96  disp[i] = disp[i-1] + lda;
97  }
98  }
99  }
100  }
101 #ifdef T3ETrError
102 /*
103  * Get rid of 0-length segments to keep T3E happy
104  */
105  for (i=0; i < n; i++)
106  {
107  if (len[i] == 0)
108  {
109  for (k=i+1; k < n; k++)
110  {
111  len[k-1] = len[k];
112  disp[k-1] = disp[k];
113  }
114  if (n > 0) n--;
115  i--; /* check new entry for 0-byte */
116  }
117  }
118 #endif
119 
120  i=MPI_Type_indexed(n, len, disp, Dtype, &TrType);
121  i=MPI_Type_commit(&TrType);
122  return(TrType);
123 }
BI_GetBuff
BLACBUFF * BI_GetBuff(int length)
Definition: BI_GetBuff.c:36
bLaCbUfF::Buff
char * Buff
Definition: Bdef.h:56
BI_GetMpiTrType
MPI_Datatype BI_GetMpiTrType(BLACSCONTEXT *ctxt, char uplo, char diag, int m, int n, int lda, MPI_Datatype Dtype, int *N)
Definition: BI_GetMpiTrType.c:4
bLaCbUfF
Definition: Bdef.h:54
bLaCsCoNtExT
Definition: Bdef.h:23
Bdef.h