Newer
Older

Mathieu Faverge
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/**
*
* @file z_spm_genrhs.c
*
* PaStiX csc routines
* PaStiX is a software package provided by Inria Bordeaux - Sud-Ouest,
* LaBRI, University of Bordeaux 1 and IPB.
*
* @version 5.1.0
* @author Mathieu Faverge
* @author Theophile Terraz
* @date 2015-01-01
*
* @precisions normal z -> c s d
**/
#include <lapacke.h>
#include "common.h"
#include "csc.h"
#include "z_spm.h"
#include "kernels/pastix_zcores.h"
#define Rnd64_A 6364136223846793005ULL
#define Rnd64_C 1ULL
#define RndF_Mul 5.4210108624275222e-20f
#define RndD_Mul 5.4210108624275222e-20
static inline unsigned long long int
Rnd64_jump(unsigned long long int n, unsigned long long int seed ) {
unsigned long long int a_k, c_k, ran;
int i;
a_k = Rnd64_A;
c_k = Rnd64_C;
ran = seed;
for (i = 0; n; n >>= 1, ++i) {
if (n & 1)
ran = a_k * ran + c_k;
c_k *= (a_k + 1);
a_k *= a_k;
}
return ran;
}
#if defined(PRECISION_z) || defined(PRECISION_c)
#define NBELEM 2
#else
#define NBELEM 1
#endif
/**
*******************************************************************************
*
* @ingroup pastix_csc
*
* z_spmRndVect generates a random vector for testing purpose.
*
*******************************************************************************
*
* @param[in] m
* The number of rows of the tile A. m >= 0.
*
* @param[in] n
* The number of columns of the tile A. n >= 0.
*
* @param[in,out] A
* On entry, the m-by-n tile to be initialized.
* On exit, the tile initialized in the mtxtype format.
*
* @param[in] lda
* The leading dimension of the tile A. lda >= max(1,m).
*
* @param[in] gM
* The global number of rows of the full matrix, A is belonging to. gM >= (m0+M).
*
* @param[in] m0
* The index of the first row of tile A in the full matrix. m0 >= 0.
*
* @param[in] n0
* The index of the first column of tile A in the full matrix. n0 >= 0.
*
* @param[in] seed
* The seed used for random generation. Must be the same for
* all tiles initialized with this routine.
*
******************************************************************************/
void z_spmRndVect( double scale, int m, int n, pastix_complex64_t *A, int lda,
int gM, int m0, int n0, unsigned long long int seed )
{
pastix_complex64_t *tmp = A;
int64_t i, j;
unsigned long long int ran, jump;
jump = (unsigned long long int)m0 + (unsigned long long int)n0 * (unsigned long long int)gM;
for (j=0; j<n; ++j ) {
ran = Rnd64_jump( NBELEM*jump, seed );
for (i = 0; i < m; ++i) {
*tmp = (0.5f - ran * RndF_Mul) * scale;
ran = Rnd64_A * ran + Rnd64_C;
#ifdef COMPLEX
*tmp += (I*(0.5f - ran * RndF_Mul)) * scale;
ran = Rnd64_A * ran + Rnd64_C;
#endif
tmp++;
}
tmp += lda-i;
jump += gM;
}
}
/**
*******************************************************************************
*
* @ingroup pastix_csc
*
* z_spmGenRHS - Generate nrhs right hand side vectors associated to a given
* matrix to test a problem with a solver.
*
*******************************************************************************
*
* @param[in] type
* Defines how to compute the vector b.
* - PastixRhsOne: b is computed such that x = 1 [ + I ]
* - PastixRhsI: b is computed such that x = i [ + i * I ]
* - PastixRhsRndX: b is computed by matrix-vector product, such that
* is a random vector in the range [-0.5, 0.5]
* - PastixRhsRndB: b is computed randomly and x is not computed.
*
* @param[in] nrhs
* Defines the number of right hand side that must be generated.
*
* @param[in] spm
* The sparse matrix uses to generate the right hand side, and the
* solution of the full problem.
*
* @param[out] x
* On exit, if x != NULL, then the x vector(s) generated to compute b
* is returned. Must be of size at least ldx * spm->n.
*
* @param[in] ldx
* Defines the leading dimension of x when multiple right hand sides
* are available. ldx >= spm->n.
*
* @param[in,out] b
* b must be an allocated matrix of size at least ldb * nrhs.
* On exit, b is initialized as defined by the type parameter.
*
* @param[in] ldb
* Defines the leading dimension of b when multiple right hand sides
* are available. ldb >= spm->n.
*
*******************************************************************************
*
* @return
* \retval PASTIX_SUCCESS if the b vector has been computed succesfully,
* \retval PASTIX_ERR_BADPARAMETER otherwise.
*
*******************************************************************************/
int
z_spmGenRHS( int type, int nrhs,
const pastix_csc_t *spm,
void *x, int ldx,
void *b, int ldb )
{
pastix_complex64_t *xptr = (pastix_complex64_t*)x;
pastix_complex64_t *bptr = (pastix_complex64_t*)b;
pastix_int_t i, j;
int rc;
if (( spm == NULL ) ||
( spm->values == NULL )) {
return PASTIX_ERR_BADPARAMETER;
}
/* Other format not supported for now */
if( spm->fmttype != PastixCSC )
return PASTIX_ERR_BADPARAMETER;
if( spm->gN <= 0 )
return PASTIX_ERR_BADPARAMETER;
if( nrhs <= 0 )
return PASTIX_ERR_BADPARAMETER;
if( (nrhs > 1) && (ldx < spm->n) )
return PASTIX_ERR_BADPARAMETER;
if( (nrhs > 1) && (ldb < spm->n) )
return PASTIX_ERR_BADPARAMETER;
if (nrhs == 1) {
ldb = spm->n;
ldx = spm->n;
}
/* We don't handle distributed spm for now */
assert( spm->n == spm->gN );
/* If random b, we do it and exit */
if ( type == PastixRhsRndB ) {
/* Compute the spm norm to scale the b vector */
double norm = z_spmNorm( PastixFrobeniusNorm, spm );
z_spmRndVect( norm, spm->n, nrhs, bptr, ldb,
spm->gN, 0, 0, 24356 );
return PASTIX_SUCCESS;
}
if ( (type == PastixRhsOne ) ||
(type == PastixRhsI ) ||
(type == PastixRhsRndX ) )
{
if ( xptr == NULL ) {
MALLOC_INTERN( xptr, ldx * nrhs, pastix_complex64_t );
}
switch( type ) {
case PastixRhsOne:
for( j=0; j<nrhs; j++ )
{
for( i=0; i<spm->n; i++, xptr++ )
{
#if defined(PRECISION_z) || defined(PRECISION_c)
*xptr = (pastix_complex64_t)(1.+1.*I);
#else
*xptr = (pastix_complex64_t)1.;
#endif
}
xptr += ldx-i;
}
xptr -= nrhs * ldx;
break;
case PastixRhsI:
for( j=0; j<nrhs; j++ )
{
for( i=0; i<spm->n; i++, xptr++ )
{
#if defined(PRECISION_z) || defined(PRECISION_c)
*xptr = (pastix_complex64_t)(i + i * I);
#else
*xptr = (pastix_complex64_t)i;
#endif
}
xptr += ldx-i;
}
xptr -= nrhs * ldx;
break;
case PastixRhsRndX:
default:
z_spmRndVect( 1., spm->n, nrhs, xptr, ldx,
spm->gN, 0, 0, 24356 );
}
switch ( spm->mtxtype ) {
#if defined(PRECISION_z) || defined(PRECISION_c)
case PastixHermitian:
rc = z_spmHeCSCv( 1., spm, xptr, 0., bptr );
break;
#endif
case PastixSymmetric:
rc = z_spmSyCSCv( 1., spm, xptr, 0., bptr );
break;
case PastixGeneral:
default:
rc = z_spmGeCSCv( PastixNoTrans, 1., spm, xptr, 0., bptr );
}
if ( x == NULL ) {
memFree_null(xptr);
}
return rc;
}
fprintf(stderr, "z_spmGenRHS: Generator not implemented yet\n");
return PASTIX_SUCCESS;
}
/**
*******************************************************************************
*
* @ingroup pastix_csc
*
* z_spmCheckAxb - Check the backward error, and the forward error if x0 is
* provided.
*
*******************************************************************************
*
* @param[in] nrhs
* Defines the number of right hand side that must be generated.
*
* @param[in] spm
* The sparse matrix uses to generate the right hand side, and the
* solution of the full problem.
*
* @param[in,out] x0
* If x0 != NULL, the forward error is computed.
* On exit, x0 stores (x0-x)
*
* @param[in] ldx0
* Defines the leading dimension of x0 when multiple right hand sides
* are available. ldx0 >= spm->n.
*
* @param[in,out] b
* b is a matrix of size at least ldb * nrhs.
* On exit, b stores Ax-b.
*
* @param[in] ldb
* Defines the leading dimension of b when multiple right hand sides
* are available. ldb >= spm->n.
*
* @param[in] x
* Contains the solution computed by the solver.
*
* @param[in] ldx
* Defines the leading dimension of x when multiple right hand sides
* are available. ldx >= spm->n.
*
*******************************************************************************
*
* @return
* \retval PASTIX_SUCCESS if the b vector has been computed succesfully,
* \retval PASTIX_ERR_BADPARAMETER otherwise.
*
*******************************************************************************/
int
z_spmCheckAxb( int nrhs,
const pastix_csc_t *spm,
void *x0, int ldx0,
void *b, int ldb,
const void *x, int ldx )
{
static pastix_complex64_t mzone = (pastix_complex64_t)-1.;
static pastix_complex64_t zone = (pastix_complex64_t) 1.;
double normA, normB, normX, normX0, normR;
double backward, forward, eps;
int failure = 0;
eps = LAPACKE_dlamch('e');
/**
* Compute the starting norms
*/
normA = spmNorm( PastixFrobeniusNorm, spm );
normX = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', spm->n, nrhs, x, ldx );
normB = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', spm->n, nrhs, b, ldb );
printf( " || A ||_oo %e\n"
" || b ||_oo %e\n"
" || x ||_oo %e\n",
normA, normB, normX );
/**
* Compute r = A * x - b
*/
spmMatVec( PastixNoTrans, &mzone, spm, x, &zone, b );
normR = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', spm->n, nrhs, b, ldb );
backward = normR / ( normA * normX + normB );
failure = isnan(normX) || isinf(normX) || isnan(backward) || isinf(backward) || ((backward / eps) > 1.e3);
printf( " ||b-Ax||_oo %e\n"
" ||b-Ax||_oo / (||A||_oo ||x||_oo + ||b||_oo) %e (%s)\n",
normR, backward,
failure ? "FAILED" : "SUCCESS" );
/**
* Compute r = x0 - x
*/
if ( x0 != NULL ) {
normX0 = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', spm->n, nrhs, x0, ldx0 );
core_zgeadd( PastixNoTrans, spm->n, nrhs, -1., x, ldx, x0, ldx0 );
normR = LAPACKE_zlange( LAPACK_COL_MAJOR, 'I', spm->n, nrhs, x0, ldx0 );
forward = normR / normX0;
failure = isnan(normX) || isinf(normX) || isnan(forward) || isinf(forward) || ((forward / eps) > 1.e3);
printf( " ||x_0||_oo %e\n"
" ||x_0-x||_oo %e\n"
" ||x_0-x||_oo / ||x_0||_oo %e (%s)\n",
normX0, normR, forward,
failure ? "FAILED" : "SUCCESS" );
}
return PASTIX_SUCCESS;
}