PaStiX Handbook  6.3.2
cpucblk_zdiff.c
Go to the documentation of this file.
1 /**
2  *
3  * @file cpucblk_zdiff.c
4  *
5  * Precision dependent routines to differentiate two solver matrix structures
6  * when debuging.
7  *
8  * @copyright 2015-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
9  * Univ. Bordeaux. All rights reserved.
10  *
11  * @version 6.3.2
12  * @author Pierre Ramet
13  * @author Xavier Lacoste
14  * @author Gregoire Pichon
15  * @author Mathieu Faverge
16  * @author Esragul Korkmaz
17  * @date 2023-07-21
18  *
19  * @generated from /builds/solverstack/pastix/kernels/cpucblk_zdiff.c, normal z -> z, Wed Dec 13 12:09:17 2023
20  *
21  **/
22 #include "common/common.h"
23 #include "blend/solver.h"
24 #include <lapacke.h>
25 #include "pastix_zcores.h"
26 #include "pastix_zlrcores.h"
27 
28 /**
29  *******************************************************************************
30  *
31  * @brief Compare two column blocks in full-rank format.
32  *
33  * The second cblk is overwritten by the difference of the two column blocks.
34  * The frobenius norm of the difference is computed and the functions returns 0
35  * if the result:
36  * || B - A || / ( || A || * eps )
37  *
38  * is below 10. Otherwise, an error message is printed and 1 is returned.
39  *
40  *******************************************************************************
41  *
42  * @param[in] side
43  * Define which side of the cblk must be tested.
44  * @arg PastixLCoef if lower part only
45  * @arg PastixUCoef if upper part only
46  * @arg PastixLUCoef if both sides.
47  *
48  * @param[in] cblkA
49  * The column block of the A matrix.
50  *
51  * @param[inout] cblkB
52  * The column block of the B matrix that matches the A matrix in
53  * stucture.
54  * On exit, cblkB coefficient arrays are overwritten by the result of
55  * (B-A).
56  *
57  *******************************************************************************
58  *
59  * @return 0 if the test is passed, >= 0 otherwise.
60  *
61  *******************************************************************************/
62 int
64  const SolverCblk *cblkA,
65  SolverCblk *cblkB )
66 {
67  pastix_complex64_t *coefA;
68  pastix_complex64_t *coefB;
69  pastix_int_t ncols = cblk_colnbr( cblkA );
70  pastix_int_t stride = cblkA->stride;
71  double normdiff, normfull, normlowr, res, eps;
72  int rc = 0;
73 
74  assert( ncols == cblk_colnbr( cblkB ) );
75  assert( stride == cblkB->stride );
76 
77  eps = LAPACKE_dlamch_work( 'e' );
78 
79  if ( side != PastixUCoef ) {
80  coefA = cblkA->lcoeftab;
81  coefB = cblkB->lcoeftab;
82 
83  assert( (coefA != NULL) && (coefB != NULL) );
84 
85  normfull = LAPACKE_zlange_work( LAPACK_COL_MAJOR, 'f', stride, ncols,
86  coefA, stride, NULL );
87  normlowr = LAPACKE_zlange_work( LAPACK_COL_MAJOR, 'f', stride, ncols,
88  coefB, stride, NULL );
89  core_zgeadd( PastixNoTrans, stride, ncols,
90  -1., coefA, stride,
91  1., coefB, stride );
92 
93  normdiff = LAPACKE_zlange_work( LAPACK_COL_MAJOR, 'M', stride, ncols,
94  coefB, stride, NULL );
95  res = (normfull == 0.) ? 0. : (normdiff / (normfull * eps));
96 
97  if ( res > 10 ) {
98  fprintf(stderr, "KO on L: ||full(A)||_f=%e, ||comp(A)||_f=%e, ||comp(A)-full(A)||_0=%e, ||comp(A)-full(A)||_0 / (||full(A)||_2 * eps)=%e\n",
99  normfull, normlowr, normdiff, res );
100  rc++;
101  }
102  }
103 
104  if ( side != PastixLCoef ) {
105  coefA = cblkA->ucoeftab;
106  coefB = cblkB->ucoeftab;
107 
108  assert( (coefA != NULL) && (coefB != NULL) );
109 
110  normfull = LAPACKE_zlange_work( LAPACK_COL_MAJOR, 'f', stride, ncols,
111  coefA, stride, NULL );
112  normlowr = LAPACKE_zlange_work( LAPACK_COL_MAJOR, 'f', stride, ncols,
113  coefB, stride, NULL );
114  core_zgeadd( PastixNoTrans, stride, ncols,
115  -1., coefA, stride,
116  1., coefB, stride );
117 
118  normdiff = LAPACKE_zlange_work( LAPACK_COL_MAJOR, 'M', stride, ncols,
119  coefB, stride, NULL );
120  res = (normfull == 0.) ? 0. : (normdiff / (normfull * eps));
121 
122  if ( res > 10 ) {
123  fprintf(stderr, "KO on U: ||full(A)||_f=%e, ||comp(A)||_f=%e, ||comp(A)-full(A)||_0=%e, ||comp(A)-full(A)||_0 / (||full(A)||_2 * eps)=%e\n",
124  normfull, normlowr, normdiff, res );
125  rc++;
126  }
127  }
128 
129  return rc;
130 }
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
int core_zgeadd(pastix_trans_t trans, pastix_int_t M, pastix_int_t N, pastix_complex64_t alpha, const pastix_complex64_t *A, pastix_int_t LDA, pastix_complex64_t beta, pastix_complex64_t *B, pastix_int_t LDB)
Add two matrices together.
Definition: core_zgeadd.c:78
int cpucblk_zdiff(pastix_coefside_t side, const SolverCblk *cblkA, SolverCblk *cblkB)
Compare two column blocks in full-rank format.
Definition: cpucblk_zdiff.c:63
enum pastix_coefside_e pastix_coefside_t
Data blocks used in the kernel.
@ PastixLCoef
Definition: api.h:478
@ PastixUCoef
Definition: api.h:479
@ PastixNoTrans
Definition: api.h:445
void * ucoeftab
Definition: solver.h:172
static pastix_int_t cblk_colnbr(const SolverCblk *cblk)
Compute the number of columns in a column block.
Definition: solver.h:324
pastix_int_t stride
Definition: solver.h:164
void * lcoeftab
Definition: solver.h:171
Solver column block structure.
Definition: solver.h:156