PaStiX Handbook  6.2.1
core_dtradd.c
Go to the documentation of this file.
1 /**
2  *
3  * @file core_dtradd.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-2021 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8  * Univ. Bordeaux. All rights reserved.
9  *
10  * @version 6.1.0
11  * @author Mathieu Faverge
12  * @date 2019-11-12
13  * @generated from /builds/solverstack/pastix/kernels/core_ztradd.c, normal z -> d, Tue Apr 12 09:38:35 2022
14  *
15  **/
16 #include "common.h"
17 #include "blend/solver.h"
18 #include "pastix_dcores.h"
19 #include "cblas.h"
20 
21 /**
22  ******************************************************************************
23  *
24  * @brief Add two triangular matrices together as in PBLAS pdtradd.
25  *
26  * B <- alpha * op(A) + beta * B,
27  *
28  * where op(X) = X, X', or (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 PastixTrans: op(A) = (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
79 core_dtradd( pastix_uplo_t uplo, pastix_trans_t trans, pastix_int_t M, pastix_int_t N,
80  double alpha, const double *A, pastix_int_t LDA,
81  double beta, double *B, pastix_int_t LDB)
82 {
83  int i, j;
84 
85  if (uplo == PastixUpperLower){
86  int rc = core_dgeadd( trans, M, N, alpha, A, LDA, beta, B, LDB );
87  if (rc != PASTIX_SUCCESS)
88  return rc-1;
89  else
90  return rc;
91  }
92 
93 #if !defined(NDEBUG)
94  if ((uplo != PastixUpper) &&
95  (uplo != PastixLower))
96  {
97  return -1;
98  }
99 
100  if ((trans < PastixNoTrans) ||
101  (trans > PastixTrans))
102  {
103  return -2;
104  }
105 
106  if (M < 0) {
107  return -3;
108  }
109  if (N < 0) {
110  return -4;
111  }
112  if ( ((trans == PastixNoTrans) && (LDA < pastix_imax(1,M)) && (M > 0)) ||
113  ((trans != PastixNoTrans) && (LDA < pastix_imax(1,N)) && (N > 0)) )
114  {
115  return -7;
116  }
117  if ( (LDB < pastix_imax(1,M)) && (M > 0) ) {
118  return -9;
119  }
120 #endif
121 
122  /**
123  * PastixLower
124  */
125  if (uplo == PastixLower) {
126  switch( trans ) {
127 #if defined(PRECISION_z) || defined(PRECISION_c)
128  case PastixTrans:
129  for (j=0; j<N; j++, A++) {
130  for(i=j; i<M; i++, B++) {
131  *B = beta * (*B) + alpha * (A[LDA*i]);
132  }
133  B += LDB-M+j+1;
134  }
135  break;
136 #endif /* defined(PRECISION_z) || defined(PRECISION_c) */
137 
138  case PastixTrans:
139  for (j=0; j<N; j++, A++) {
140  for(i=j; i<M; i++, B++) {
141  *B = beta * (*B) + alpha * A[LDA*i];
142  }
143  B += LDB-M+j+1;
144  }
145  break;
146 
147  case PastixNoTrans:
148  default:
149  for (j=0; j<N; j++) {
150  for(i=j; i<M; i++, B++, A++) {
151  *B = beta * (*B) + alpha * (*A);
152  }
153  B += LDB-M+j+1;
154  A += LDA-M+j+1;
155  }
156  }
157  }
158  /**
159  * PastixUpper
160  */
161  else {
162  switch( trans ) {
163 #if defined(PRECISION_z) || defined(PRECISION_c)
164  case PastixTrans:
165  for (j=0; j<N; j++, A++) {
166  int mm = pastix_imin( j+1, M );
167  for(i=0; i<mm; i++, B++) {
168  *B = beta * (*B) + alpha * (A[LDA*i]);
169  }
170  B += LDB-mm;
171  }
172  break;
173 #endif /* defined(PRECISION_z) || defined(PRECISION_c) */
174 
175  case PastixTrans:
176  for (j=0; j<N; j++, A++) {
177  int mm = pastix_imin( j+1, M );
178  for(i=0; i<mm; i++, B++) {
179  *B = beta * (*B) + alpha * (A[LDA*i]);
180  }
181  B += LDB-mm;
182  }
183  break;
184 
185  case PastixNoTrans:
186  default:
187  for (j=0; j<N; j++) {
188  int mm = pastix_imin( j+1, M );
189  for(i=0; i<mm; i++, B++, A++) {
190  *B = beta * (*B) + alpha * (*A);
191  }
192  B += LDB-mm;
193  A += LDA-mm;
194  }
195  }
196  }
197  return PASTIX_SUCCESS;
198 }
solver.h
PastixTrans
@ PastixTrans
Definition: api.h:425
pastix_uplo_t
enum pastix_uplo_e pastix_uplo_t
Upper/Lower part.
pastix_trans_t
enum pastix_trans_e pastix_trans_t
Transpostion.
PastixLower
@ PastixLower
Definition: api.h:445
PastixNoTrans
@ PastixNoTrans
Definition: api.h:424
PastixUpper
@ PastixUpper
Definition: api.h:444
pastix_dcores.h
PASTIX_SUCCESS
@ PASTIX_SUCCESS
Definition: api.h:346
core_dtradd
int core_dtradd(pastix_uplo_t uplo, pastix_trans_t trans, pastix_int_t M, pastix_int_t N, double alpha, const double *A, pastix_int_t LDA, double beta, double *B, pastix_int_t LDB)
Add two triangular matrices together as in PBLAS pdtradd.
Definition: core_dtradd.c:79
core_dgeadd
int core_dgeadd(pastix_trans_t trans, pastix_int_t M, pastix_int_t N, double alpha, const double *A, pastix_int_t LDA, double beta, double *B, pastix_int_t LDB)
Add two matrices together.
Definition: core_dgeadd.c:78
PastixUpperLower
@ PastixUpperLower
Definition: api.h:446