PLASMA  2.4.5
PLASMA - Parallel Linear Algebra for Scalable Multi-core Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
core_ztsrfb.c
Go to the documentation of this file.
1 
17 #include <cblas.h>
18 #include <lapacke.h>
19 #include "common.h"
20 
21 /***************************************************************************/
114 #if defined(PLASMA_HAVE_WEAK)
115 #pragma weak CORE_ztsrfb = PCORE_ztsrfb
116 #define CORE_ztsrfb PCORE_ztsrfb
117 #endif
118 int CORE_ztsrfb(int side, int trans, int direct, int storev,
119  int M1, int N1, int M2, int N2, int K,
120  PLASMA_Complex64_t *A1, int LDA1,
121  PLASMA_Complex64_t *A2, int LDA2,
122  PLASMA_Complex64_t *V, int LDV,
123  PLASMA_Complex64_t *T, int LDT,
124  PLASMA_Complex64_t *WORK, int LDWORK)
125 {
126  static PLASMA_Complex64_t zone = 1.0;
127  static PLASMA_Complex64_t mzone = -1.0;
128 
129  int j;
130 
131  /* Check input arguments */
132  if (M1 < 0) {
133  coreblas_error(5, "Illegal value of M1");
134  return -5;
135  }
136  if (N1 < 0) {
137  coreblas_error(6, "Illegal value of N1");
138  return -6;
139  }
140  if ( (M2 < 0) ||
141  ( (M2 != M1) && (side == PlasmaRight) ) ){
142  coreblas_error(7, "Illegal value of M2");
143  return -7;
144  }
145  if ( (N2 < 0) ||
146  ( (N2 != N1) && (side == PlasmaLeft) ) ){
147  coreblas_error(8, "Illegal value of N2");
148  return -8;
149  }
150  if (K < 0) {
151  coreblas_error(9, "Illegal value of K");
152  return -9;
153  }
154 
155  /* Quick return */
156  if ((M1 == 0) || (N1 == 0) || (M2 == 0) || (N2 == 0) || (K == 0))
157  return PLASMA_SUCCESS;
158 
159  if (storev == PlasmaColumnwise) {
160  if (direct == PlasmaForward) {
161  if (side == PlasmaLeft) {
162  /*
163  * B = A1 + V' * A2
164  */
165  LAPACKE_zlacpy_work(LAPACK_COL_MAJOR,
167  K, N1,
168  A1, LDA1, WORK, LDWORK);
169 
170  cblas_zgemm(
172  K, N2, M2,
173  CBLAS_SADDR(zone), V, LDV,
174  A2, LDA2,
175  CBLAS_SADDR(zone), WORK, LDWORK);
176  /*
177  * A2 = A2 - V*T*B -> B = T*B, A2 = A2 - V*B
178  */
179  cblas_ztrmm(
181  (CBLAS_TRANSPOSE)trans, CblasNonUnit, K, N2,
182  CBLAS_SADDR(zone), T, LDT, WORK, LDWORK);
183 
184  cblas_zgemm(
186  M2, N2, K,
187  CBLAS_SADDR(mzone), V, LDV,
188  WORK, LDWORK,
189  CBLAS_SADDR(zone), A2, LDA2);
190  /*
191  * A1 = A1 - B
192  */
193  for(j = 0; j < N1; j++) {
194  cblas_zaxpy(
195  K, CBLAS_SADDR(mzone),
196  &WORK[LDWORK*j], 1,
197  &A1[LDA1*j], 1);
198  }
199  }
200  /*
201  * Columnwise / Forward / Right
202  */
203  else {
204  /*
205  * B = A1 + A2 * V
206  */
207  LAPACKE_zlacpy_work(LAPACK_COL_MAJOR,
209  M1, K,
210  A1, LDA1, WORK, LDWORK);
211 
212  cblas_zgemm(
214  M2, K, N2,
215  CBLAS_SADDR(zone), A2, LDA2,
216  V, LDV,
217  CBLAS_SADDR(zone), WORK, LDWORK);
218  /*
219  * A2 = A2 - B*T*V' -> B = B*T, A2 = A2 - B*V'
220  */
221  cblas_ztrmm(
223  (CBLAS_TRANSPOSE)trans, CblasNonUnit, M1, K,
224  CBLAS_SADDR(zone), T, LDT, WORK, LDWORK);
225 
226  cblas_zgemm(
228  M2, N2, K,
229  CBLAS_SADDR(mzone), WORK, LDWORK,
230  V, LDV,
231  CBLAS_SADDR(zone), A2, LDA2);
232  /*
233  * A1 = A1 - B
234  */
235  for(j = 0; j < K; j++) {
236  cblas_zaxpy(
237  M1, CBLAS_SADDR(mzone),
238  &WORK[LDWORK*j], 1,
239  &A1[LDA1*j], 1);
240  }
241  }
242  }
243  else {
244  coreblas_error(3, "Not implemented (ColMajor / Backward / Left or Right)");
246  }
247  }
248  else {
249  if (direct == PlasmaForward) {
250  /*
251  * Rowwise / Forward / Left
252  */
253  if (side == PlasmaLeft) {
254  /*
255  * B = A1 + V * A2
256  */
257  LAPACKE_zlacpy_work(LAPACK_COL_MAJOR,
259  K, N1,
260  A1, LDA1, WORK, LDWORK);
261 
262  cblas_zgemm(
264  K, N2, M2,
265  CBLAS_SADDR(zone), V, LDV,
266  A2, LDA2,
267  CBLAS_SADDR(zone), WORK, LDWORK);
268  /*
269  * A2 = A2 - V'*T*B -> B = T*B, A2 = A2 - V'*B
270  */
271  cblas_ztrmm(
273  (CBLAS_TRANSPOSE)trans, CblasNonUnit, K, N2,
274  CBLAS_SADDR(zone), T, LDT, WORK, LDWORK);
275 
276  cblas_zgemm(
278  M2, N2, K,
279  CBLAS_SADDR(mzone), V, LDV,
280  WORK, LDWORK,
281  CBLAS_SADDR(zone), A2, LDA2);
282  /*
283  * A1 = A1 - B
284  */
285  for(j=0; j<N1; j++) {
286  cblas_zaxpy(
287  K, CBLAS_SADDR(mzone),
288  &WORK[LDWORK*j], 1,
289  &A1[LDA1*j], 1);
290  }
291  }
292  /*
293  * Rowwise / Forward / Right
294  */
295  else {
296  /*
297  * B = A1 + A2 * V'
298  */
299  LAPACKE_zlacpy_work(LAPACK_COL_MAJOR,
301  M1, K,
302  A1, LDA1, WORK, LDWORK);
303 
304  cblas_zgemm(
306  M2, K, N2,
307  CBLAS_SADDR(zone), A2, LDA2,
308  V, LDV,
309  CBLAS_SADDR(zone), WORK, LDWORK);
310  /*
311  * A2 = A2 - B*T*V -> B = B*T, A2 = A2 - B*V'
312  */
313  cblas_ztrmm(
315  (CBLAS_TRANSPOSE)trans, CblasNonUnit, M1, K,
316  CBLAS_SADDR(zone), T, LDT, WORK, LDWORK);
317 
318  cblas_zgemm(
320  M2, N2, K,
321  CBLAS_SADDR(mzone), WORK, LDWORK,
322  V, LDV,
323  CBLAS_SADDR(zone), A2, LDA2);
324  /*
325  * A1 = A1 - B
326  */
327  for(j = 0; j < K; j++) {
328  cblas_zaxpy(
329  M1, CBLAS_SADDR(mzone),
330  &WORK[LDWORK*j], 1,
331  &A1[LDA1*j], 1);
332  }
333  }
334  }
335  else {
336  coreblas_error(3, "Not implemented (RowMajor / Backward / Left or Right)");
338  }
339  }
340  return PLASMA_SUCCESS;
341 }