PaStiX Handbook  6.3.2
core_ctradd.c
Go to the documentation of this file.
1 /**
2  *
3  * @file core_ctradd.c
4  *
5  * @copyright 2012-2014 Univ. of Tennessee, Univ. of California Berkeley and
6  * Univ. of Colorado Denver. All rights reserved.
7  * @copyright 2012-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.3.2
11  * @author Mathieu Faverge
12  * @date 2023-07-21
13  * @generated from /builds/solverstack/pastix/kernels/core_ztradd.c, normal z -> c, Wed Dec 13 12:09:13 2023
14  *
15  **/
16 #include "common.h"
17 #include "blend/solver.h"
18 #include "pastix_ccores.h"
19 #include "cblas.h"
20 
21 /**
22  ******************************************************************************
23  *
24  * @brief Add two triangular matrices together as in PBLAS pctradd.
25  *
26  * B <- alpha * op(A) + beta * B,
27  *
28  * where op(X) = X, X', or conjf(X')
29  *
30  *******************************************************************************
31  *
32  * @param[in] uplo
33  * Specifies the shape of A and B matrices:
34  * @arg PastixUpperLower: A and B are general matrices.
35  * @arg PastixUpper: op(A) and B are upper trapezoidal matrices.
36  * @arg PastixLower: op(A) and B are lower trapezoidal matrices.
37  *
38  * @param[in] trans
39  * Specifies whether the matrix A is non-transposed, transposed, or
40  * conjugate transposed
41  * @arg PastixNoTrans: op(A) = A
42  * @arg PastixTrans: op(A) = A'
43  * @arg PastixConjTrans: op(A) = conjf(A')
44  *
45  * @param[in] M
46  * Number of rows of the matrices op(A) and B.
47  *
48  * @param[in] N
49  * Number of columns of the matrices op(A) and B.
50  *
51  * @param[in] alpha
52  * Scalar factor of A.
53  *
54  * @param[in] A
55  * Matrix of size LDA-by-N, if trans = PastixNoTrans, LDA-by-M
56  * otherwise.
57  *
58  * @param[in] LDA
59  * Leading dimension of the array A. LDA >= max(1,M) if trans =
60  * PastixNoTrans, LDA >= max(1,N) otherwise.
61  *
62  * @param[in] beta
63  * Scalar factor of B.
64  *
65  * @param[inout] B
66  * Matrix of size LDB-by-N.
67  * On exit, B = alpha * op(A) + beta * B
68  *
69  * @param[in] LDB
70  * Leading dimension of the array B. LDB >= max(1,M)
71  *
72  *******************************************************************************
73  *
74  * @retval PASTIX_SUCCESS successful exit
75  * @retval <0 if -i, the i-th argument had an illegal value
76  *
77  ******************************************************************************/
78 int
80  pastix_trans_t trans,
81  pastix_int_t M,
82  pastix_int_t N,
83  pastix_complex32_t alpha,
84  const pastix_complex32_t *A,
85  pastix_int_t LDA,
86  pastix_complex32_t beta,
88  pastix_int_t LDB )
89 {
90  int i, j;
91 
92  if (uplo == PastixUpperLower){
93  int rc = core_cgeadd( trans, M, N, alpha, A, LDA, beta, B, LDB );
94  if (rc != PASTIX_SUCCESS)
95  return rc-1;
96  else
97  return rc;
98  }
99 
100 #if !defined(NDEBUG)
101  if ((uplo != PastixUpper) &&
102  (uplo != PastixLower))
103  {
104  return -1;
105  }
106 
107  if ((trans < PastixNoTrans) ||
108  (trans > PastixConjTrans))
109  {
110  return -2;
111  }
112 
113  if (M < 0) {
114  return -3;
115  }
116  if (N < 0) {
117  return -4;
118  }
119  if ( ((trans == PastixNoTrans) && (LDA < pastix_imax(1,M)) && (M > 0)) ||
120  ((trans != PastixNoTrans) && (LDA < pastix_imax(1,N)) && (N > 0)) )
121  {
122  return -7;
123  }
124  if ( (LDB < pastix_imax(1,M)) && (M > 0) ) {
125  return -9;
126  }
127 #endif
128 
129  /**
130  * PastixLower
131  */
132  if (uplo == PastixLower) {
133  switch( trans ) {
134 #if defined(PRECISION_z) || defined(PRECISION_c)
135  case PastixConjTrans:
136  for (j=0; j<N; j++, A++) {
137  for(i=j; i<M; i++, B++) {
138  *B = beta * (*B) + alpha * conjf(A[LDA*i]);
139  }
140  B += LDB-M+j+1;
141  }
142  break;
143 #endif /* defined(PRECISION_z) || defined(PRECISION_c) */
144 
145  case PastixTrans:
146  for (j=0; j<N; j++, A++) {
147  for(i=j; i<M; i++, B++) {
148  *B = beta * (*B) + alpha * A[LDA*i];
149  }
150  B += LDB-M+j+1;
151  }
152  break;
153 
154  case PastixNoTrans:
155  default:
156  for (j=0; j<N; j++) {
157  for(i=j; i<M; i++, B++, A++) {
158  *B = beta * (*B) + alpha * (*A);
159  }
160  B += LDB-M+j+1;
161  A += LDA-M+j+1;
162  }
163  }
164  }
165  /**
166  * PastixUpper
167  */
168  else {
169  switch( trans ) {
170 #if defined(PRECISION_z) || defined(PRECISION_c)
171  case PastixConjTrans:
172  for (j=0; j<N; j++, A++) {
173  int mm = pastix_imin( j+1, M );
174  for(i=0; i<mm; i++, B++) {
175  *B = beta * (*B) + alpha * conjf(A[LDA*i]);
176  }
177  B += LDB-mm;
178  }
179  break;
180 #endif /* defined(PRECISION_z) || defined(PRECISION_c) */
181 
182  case PastixTrans:
183  for (j=0; j<N; j++, A++) {
184  int mm = pastix_imin( j+1, M );
185  for(i=0; i<mm; i++, B++) {
186  *B = beta * (*B) + alpha * (A[LDA*i]);
187  }
188  B += LDB-mm;
189  }
190  break;
191 
192  case PastixNoTrans:
193  default:
194  for (j=0; j<N; j++) {
195  int mm = pastix_imin( j+1, M );
196  for(i=0; i<mm; i++, B++, A++) {
197  *B = beta * (*B) + alpha * (*A);
198  }
199  B += LDB-mm;
200  A += LDA-mm;
201  }
202  }
203  }
204  return PASTIX_SUCCESS;
205 }
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
float _Complex pastix_complex32_t
Definition: datatypes.h:76
int core_ctradd(pastix_uplo_t uplo, pastix_trans_t trans, pastix_int_t M, pastix_int_t N, pastix_complex32_t alpha, const pastix_complex32_t *A, pastix_int_t LDA, pastix_complex32_t beta, pastix_complex32_t *B, pastix_int_t LDB)
Add two triangular matrices together as in PBLAS pctradd.
Definition: core_ctradd.c:79
int core_cgeadd(pastix_trans_t trans, pastix_int_t M, pastix_int_t N, pastix_complex32_t alpha, const pastix_complex32_t *A, pastix_int_t LDA, pastix_complex32_t beta, pastix_complex32_t *B, pastix_int_t LDB)
Add two matrices together.
Definition: core_cgeadd.c:78
enum pastix_uplo_e pastix_uplo_t
Upper/Lower part.
enum pastix_trans_e pastix_trans_t
Transpostion.
@ PastixUpper
Definition: api.h:466
@ PastixUpperLower
Definition: api.h:468
@ PastixLower
Definition: api.h:467
@ PastixConjTrans
Definition: api.h:447
@ PastixNoTrans
Definition: api.h:445
@ PastixTrans
Definition: api.h:446
@ PASTIX_SUCCESS
Definition: api.h:367