PaStiX Handbook 6.4.0
Loading...
Searching...
No Matches
bcsc_snorm.c
Go to the documentation of this file.
1/**
2 *
3 * @file bcsc_snorm.c
4 *
5 * @copyright 2004-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
6 * Univ. Bordeaux. All rights reserved.
7 *
8 * @version 6.4.0
9 * @author Mathieu Faverge
10 * @author Theophile Terraz
11 * @date 2024-07-05
12 * @generated from /builds/2mk6rsew/0/solverstack/pastix/bcsc/bcsc_znorm.c, normal z -> s, Tue Feb 25 14:36:02 2025
13 *
14 **/
15#include "common.h"
16#include "bcsc/bcsc.h"
17#include <math.h>
18#include "frobeniusupdate.h"
19
20/**
21 *******************************************************************************
22 *
23 * @ingroup bcsc_internal
24 *
25 * @brief Compute the max norm of a bcsc matrix.
26 *
27 *******************************************************************************
28 *
29 * @param[in] bcsc
30 * TODO
31 *
32 *******************************************************************************
33 *
34 * @retval The norm of the matrix.
35 *
36 *******************************************************************************/
37float
38bcsc_snorm_max( const pastix_bcsc_t *bcsc )
39{
40 float temp;
41 float norm = 0.;
42 float *valptr = (float*)bcsc->Lvalues;
43 pastix_int_t i, j, bloc;
44
45 for( bloc=0; bloc < bcsc->cscfnbr; bloc++ )
46 {
47 for( j=0; j < bcsc->cscftab[bloc].colnbr; j++ )
48 {
49 for( i = bcsc->cscftab[bloc].coltab[j]; i < bcsc->cscftab[bloc].coltab[j+1]; i++ )
50 {
51 temp = fabsf(valptr[i]);
52 if(norm < temp)
53 {
54 norm = temp;
55 }
56 }
57 }
58 }
59
60 return norm;
61}
62
63/**
64 *******************************************************************************
65 *
66 * @ingroup bcsc_internal
67 *
68 * @brief Compute the infinity norm of a bcsc matrix.
69 * The infinity norm is equal to the maximum value of the sum of the
70 * absolute values of the elements of each rows.
71 *
72 *******************************************************************************
73 *
74 * @param[in] bcsc
75 * The Pastix bcsc.
76 *
77 *******************************************************************************
78 *
79 * @retval The norm of the matrix.
80 *
81 *******************************************************************************/
82float
83bcsc_snorm_inf( const pastix_bcsc_t *bcsc )
84{
85 float norm = 0.;
86 float *valptr;
87 int i, j, bloc;
88
89 if( bcsc->Uvalues != NULL )
90 {
91 float sum;
92
93 valptr = (float*)(bcsc->Uvalues);
94 for( bloc=0; bloc<bcsc->cscfnbr; bloc++ )
95 {
96 for( j=0; j<bcsc->cscftab[bloc].colnbr; j++ )
97 {
98 sum = 0.;
99 for( i = bcsc->cscftab[bloc].coltab[j]; i < bcsc->cscftab[bloc].coltab[j+1]; i++ )
100 {
101 sum += fabsf(valptr[i]);
102 }
103 if( sum > norm ) {
104 norm = sum;
105 }
106 }
107 }
108 }
109 else {
110 float *sumrow;
111 valptr = (float*)bcsc->Lvalues;
112
113 MALLOC_INTERN( sumrow, bcsc->gN, float);
114 memset( sumrow, 0, bcsc->gN * sizeof(float) );
115
116 for( bloc=0; bloc < bcsc->cscfnbr; bloc++ )
117 {
118 for( j=0; j < bcsc->cscftab[bloc].colnbr; j++ )
119 {
120 for( i = bcsc->cscftab[bloc].coltab[j]; i < bcsc->cscftab[bloc].coltab[j+1]; i++ )
121 {
122 sumrow[ bcsc->rowtab[i] ] += fabsf(valptr[i]);
123 }
124 }
125 }
126
127 for( i=0; i<bcsc->gN; i++)
128 {
129 if(norm < sumrow[i])
130 {
131 norm = sumrow[i];
132 }
133 }
134 memFree_null( sumrow );
135 }
136
137 return norm;
138}
139
140/**
141 *******************************************************************************
142 *
143 * @ingroup bcsc_internal
144 *
145 * @brief Compute the norm 1 of a bcsc matrix.
146 * Norm 1 is equal to the maximum value of the sum of the
147 * absolute values of the elements of each columns.
148 *
149 *******************************************************************************
150 *
151 * @param[in] bcsc
152 * The Pastix bcsc.
153 *
154 *******************************************************************************
155 *
156 * @retval The norm of the matrix.
157 *
158 *******************************************************************************/
159float
160bcsc_snorm_one( const pastix_bcsc_t *bcsc )
161{
162 float *valptr = (float*)bcsc->Lvalues;
163 float sum, norm = 0.;
164 int i, j, bloc;
165
166 for( bloc=0; bloc<bcsc->cscfnbr; bloc++ )
167 {
168 for( j=0; j<bcsc->cscftab[bloc].colnbr; j++ )
169 {
170 sum = 0.;
171 for( i = bcsc->cscftab[bloc].coltab[j]; i < bcsc->cscftab[bloc].coltab[j+1]; i++ )
172 {
173 sum += fabsf(valptr[i]);
174 }
175 if( sum > norm ) {
176 norm = sum;
177 }
178 }
179 }
180
181 return norm;
182}
183
184/**
185 *******************************************************************************
186 *
187 * @ingroup bcsc_internal
188 *
189 * @brief Compute the frobenius norm of a bcsc matrix.
190 *
191 *******************************************************************************
192 *
193 * @param[in] bcsc
194 * The Pastix bcsc.
195 *
196 *******************************************************************************
197 *
198 * @retval The norm of the matrix
199 *
200 *******************************************************************************/
201float
202bcsc_snorm_frobenius( const pastix_bcsc_t *bcsc )
203{
204 float scale = 0.;
205 float sum = 1.;
206 float norm;
207 float *valptr = (float*)bcsc->Lvalues;
208 pastix_int_t i, j, bloc;
209
210 for( bloc=0; bloc < bcsc->cscfnbr; bloc++ )
211 {
212 for( j=0; j < bcsc->cscftab[bloc].colnbr; j++ )
213 {
214 for( i = bcsc->cscftab[bloc].coltab[j]; i < bcsc->cscftab[bloc].coltab[j+1]; i++, valptr++ )
215 {
216 frobenius_update( 1, &scale, &sum, valptr);
217#if defined(PRECISION_z) || defined(PRECISION_c)
218 valptr++;
219 frobenius_update( 1, &scale, &sum, valptr);
220#endif
221 }
222 }
223 }
224
225 norm = scale*sqrtf(sum);
226
227 return norm;
228}
229
230/**
231 *******************************************************************************
232 *
233 * @brief Compute the norm of an bcsc matrix
234 *
235 *******************************************************************************
236 *
237 * @param[in] ntype
238 * = PastixMaxNorm: Max norm
239 * = PastixOneNorm: One norm
240 * = PastixInfNorm: Infinity norm
241 * = PastixFrobeniusNorm: Frobenius norm
242 *
243 * @param[in] bcsc
244 * The bcsc structure describing the matrix.
245 *
246 *******************************************************************************
247 *
248 * @retval The norm of the matrix.
249 *
250 *******************************************************************************/
251float
253 const pastix_bcsc_t *bcsc )
254{
255 float norm = 0.;
256
257 if(bcsc == NULL)
258 {
259 return -1.;
260 }
261
262 switch( ntype ) {
263 case PastixMaxNorm:
264 norm = bcsc_snorm_max( bcsc );
265 break;
266
267 case PastixInfNorm:
268 norm = bcsc_snorm_inf( bcsc );
269 break;
270
271 case PastixOneNorm:
272 norm = bcsc_snorm_one( bcsc );
273 break;
274
276 norm = bcsc_snorm_frobenius( bcsc );
277 break;
278
279 default:
280 fprintf(stderr, "bcsc_snorm: invalid norm type\n");
281 return -1.;
282 }
283
284 return norm;
285}
BEGIN_C_DECLS typedef int pastix_int_t
Definition datatypes.h:51
float bcsc_snorm_frobenius(const pastix_bcsc_t *bcsc)
Compute the frobenius norm of a bcsc matrix.
Definition bcsc_snorm.c:202
float bcsc_snorm_max(const pastix_bcsc_t *bcsc)
Compute the max norm of a bcsc matrix.
Definition bcsc_snorm.c:38
float bcsc_snorm_inf(const pastix_bcsc_t *bcsc)
Compute the infinity norm of a bcsc matrix. The infinity norm is equal to the maximum value of the su...
Definition bcsc_snorm.c:83
float bcsc_snorm_one(const pastix_bcsc_t *bcsc)
Compute the norm 1 of a bcsc matrix. Norm 1 is equal to the maximum value of the sum of the absolute ...
Definition bcsc_snorm.c:160
float bcsc_snorm(pastix_normtype_t ntype, const pastix_bcsc_t *bcsc)
Compute the norm of an bcsc matrix.
Definition bcsc_snorm.c:252
enum pastix_normtype_e pastix_normtype_t
Norms.
@ PastixInfNorm
Definition api.h:505
@ PastixOneNorm
Definition api.h:503
@ PastixFrobeniusNorm
Definition api.h:504
@ PastixMaxNorm
Definition api.h:506