Newer
Older

Mathieu Faverge
committed
/**
*

Mathieu Faverge
committed
*

Mathieu Faverge
committed
*
* @copyright 2016-2017 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
* Univ. Bordeaux. All rights reserved.
*
* @version 1.0.0

Mathieu Faverge
committed
* @author Xavier Lacoste
* @author Pierre Ramet
* @author Mathieu Faverge
* @date 2013-06-24
*

Mathieu Faverge
committed
**/
#include "common.h"

Mathieu Faverge
committed
#include "z_spm.h"
#include "c_spm.h"
#include "d_spm.h"
#include "s_spm.h"
#include "p_spm.h"
PICHON Gregoire
committed
#include <cblas.h>
static int (*conversionTable[3][3][6])(pastix_spm_t*) = {

Mathieu Faverge
committed
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
/* From CSC */
{{ NULL, NULL, NULL, NULL, NULL, NULL },
{ p_spmConvertCSC2CSR,
NULL,
s_spmConvertCSC2CSR,
d_spmConvertCSC2CSR,
c_spmConvertCSC2CSR,
z_spmConvertCSC2CSR },
{ p_spmConvertCSC2IJV,
NULL,
s_spmConvertCSC2IJV,
d_spmConvertCSC2IJV,
c_spmConvertCSC2IJV,
z_spmConvertCSC2IJV }},
/* From CSR */
{{ p_spmConvertCSR2CSC,
NULL,
s_spmConvertCSR2CSC,
d_spmConvertCSR2CSC,
c_spmConvertCSR2CSC,
z_spmConvertCSR2CSC },
{ NULL, NULL, NULL, NULL, NULL, NULL },
{ p_spmConvertCSR2IJV,
NULL,
s_spmConvertCSR2IJV,
d_spmConvertCSR2IJV,
c_spmConvertCSR2IJV,
z_spmConvertCSR2IJV }},
/* From IJV */
{{ p_spmConvertIJV2CSC,
NULL,
s_spmConvertIJV2CSC,
d_spmConvertIJV2CSC,
c_spmConvertIJV2CSC,
z_spmConvertIJV2CSC },
{ p_spmConvertIJV2CSR,
NULL,
s_spmConvertIJV2CSR,
d_spmConvertIJV2CSR,
c_spmConvertIJV2CSR,
z_spmConvertIJV2CSR },
{ NULL, NULL, NULL, NULL, NULL, NULL }}
};

Mathieu Faverge
committed
/**
*******************************************************************************
*
*
*******************************************************************************
*
* The sparse matrix to init.
*
*******************************************************************************/
void
spmInit( pastix_spm_t *spm )
{
spm->mtxtype = PastixGeneral;
spm->fmttype = PastixCSC;
spm->gN = 0;
spm->n = 0;
spm->gnnz = 0;
spm->nnz = 0;
spm->gNexp = 0;
spm->nexp = 0;
spm->gnnzexp = 0;
spm->nnzexp = 0;
spm->dof = 1;
spm->dofs = NULL;
spm->layout = PastixColMajor;
spm->colptr = NULL;
spm->rowptr = NULL;
spm->loc2glob = NULL;
spm->values = NULL;
}
/**
*******************************************************************************
*
* @brief Update all the computed fields based on the static values stored.
*
*******************************************************************************
*
* @param[inout] spm
* The sparse matrix to update.
*
*******************************************************************************/
void
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
* Compute the local expended field for multi-dofs
*/
if ( spm->dof > 0 ) {
spm->nexp = spm->n * spm->dof;
spm->nnzexp = spm->nnz * spm->dof * spm->dof;
}
else {
pastix_int_t i, j, k, dofi, dofj, baseval;
pastix_int_t *dofptr, *colptr, *rowptr;
baseval = spmFindBase( spm );
colptr = spm->colptr;
rowptr = spm->rowptr;
dofptr = spm->dofs;
spm->nexp = dofptr[ spm->n ] - baseval;
spm->nnzexp = 0;
switch(spm->fmttype)
{
case PastixCSR:
/* Swap pointers to call CSC */
colptr = spm->rowptr;
rowptr = spm->colptr;
case PastixCSC:
for(j=0; j<spm->n; j++, colptr++) {
dofj = dofptr[j+1] - dofptr[j];
for(k=colptr[0]; k<colptr[1]; k++, rowptr++) {
i = *rowptr - baseval;
dofi = dofptr[i+1] - dofptr[i];
spm->nnzexp += dofi * dofj;
}
}
break;
case PastixIJV:
for(k=0; k<spm->nnz; k++, rowptr++, colptr++)
{
i = *rowptr - baseval;
j = *colptr - baseval;
dofi = dofptr[i+1] - dofptr[i];
dofj = dofptr[j+1] - dofptr[j];
spm->nnzexp += dofi * dofj;
}
}
}
/* TODO: add communicator */
spm->gN = spm->n;
spm->gnnz = spm->nnz;
spm->gNexp = spm->nexp;
spm->gnnzexp = spm->nnzexp;
}
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
/**
*******************************************************************************
*
* @brief Init the spm structure.
*
*******************************************************************************
*
* @param[inout] spm
* The sparse matrix to init.
*
*******************************************************************************/
void
spm( pastix_spm_t *spm,
pastix_symmetry_t mtxtype,
pastix_coeftype_t flttype,
pastix_fmttype_t fmttype,
pastix_int_t n,
pastix_int_t nnz,
pastix_int_t *colptr,
pastix_int_t *rowptr,
void *values,
pastix_int_t *loc2glob,
pastix_int_t dof,
pastix_layout_t layout,
pastix_int_t *dofs )
{
spmInit( spm );
if ( ( mtxtype != PastixGeneral ) &&
( mtxtype != PastixGeneral ) &&
( mtxtype != PastixGeneral ) )
{
fprintf(stderr, "spm: The sparse matrix type must be PastixGeneral, PastixSymmetric or PastixHermitian\n");
return;
}
spm->mtxtype = mtxtype;
if ( ( flttype != PastixPattern ) &&
( flttype != PastixFloat ) &&
( flttype != PastixDouble ) &&
( flttype != PastixComplex32 ) &&
( flttype != PastixComplex64 ) )
{
fprintf(stderr, "spm: The sparse matrix coefficient type must be PastixPattern, PastixFloat, PastixDouble, PastixComplex32, or PastixComplex64\n");
return;
}
spm->flttype = flttype;
if ( ( fmttype != PastixCSC ) &&
( fmttype != PastixCSR ) &&
( fmttype != PastixIJV ) )
{
fprintf(stderr, "spm: The sparse matrix format type must be PastixCSC, PastixCSR, or PastixIJV\n");
return;
}
spm->fmttype = fmttype;
if ( n <= 0 )
{
fprintf(stderr, "spm: The local matrix size n, must be strictly positive\n");
return;
}
spm->n = n;
if ( nnz <= 0 )
{
fprintf(stderr, "spm: The number of non zeros in the local matrix must be strictly positive\n");
return;
}
spm->nnz = nnz;
if ( colptr == NULL ) {
fprintf(stderr, "spm: The colptr array must be provided and of size n+1, if PastixCSC, nnz otherwise\n");
return;
}
spm->colptr = colptr;
if ( rowptr == NULL ) {
fprintf(stderr, "spm: The rowptr array must be provided and of size n+1, if PastixCSR, nnz otherwise\n");
return;
}
spm->rowptr = rowptr;
if ( loc2glob != NULL ) {
fprintf(stderr, "spm: The distributed interface is not supported for now\n");
return;
}
spm->loc2glob = NULL;
if ( (flttype != PastixPattern) && (values == NULL) ) {
fprintf(stderr, "spm: The values array of size nnz, and of type flttype must be provided\n");
return;
}
spm->values = values;
spm->dof = dof;
spm->layout = PastixColMajor;
if ( spm->dof != 1 ) {
if ( ( layout != PastixColMajor ) &&
( layout != PastixRowMajor ) )
{
fprintf(stderr, "spm: The sparse matrix layout for multi-dof must be PastixColMajor or PastixRowMajor\n");
return;
}
spm->layout = layout;
if ( dof < 1 ) {
if ( dofs == NULL ) {
fprintf(stderr, "spm: The dofs array must be provided when dof < 1\n");
return;
}
spm->dofs = dofs;
}
else {
spm->dofs = NULL;
}
}
spmUpdateComputedFields( spm );
}

Mathieu Faverge
committed
/**
*******************************************************************************
*

Mathieu Faverge
committed
*
*******************************************************************************
*

Mathieu Faverge
committed
*
*******************************************************************************/
void
spmExit( pastix_spm_t *spm )
{
if(spm->colptr != NULL)
memFree_null(spm->colptr);
if(spm->rowptr != NULL)
memFree_null(spm->rowptr);
if(spm->loc2glob != NULL)
memFree_null(spm->loc2glob);
if(spm->values != NULL)
memFree_null(spm->values);
if(spm->dofs != NULL)
memFree_null(spm->dofs);
}
/**
*******************************************************************************

Mathieu Faverge
committed
*
* @brief Rebase the arrays of the spm to the given value.
* If the value is equal to the original base, then nothing is performed.
*
*******************************************************************************
*
* The sparse matrix to rebase.
*
* @param[in] baseval
* The base value to use in the graph (0 or 1).

Mathieu Faverge
committed
*
*******************************************************************************/
void
spmBase( pastix_spm_t *spm,
int baseval )

Mathieu Faverge
committed
{
pastix_int_t baseadj;
pastix_int_t i, n, nnz;
/* Parameter checks */
if ( spm == NULL ) {

Mathieu Faverge
committed
pastix_error_print("spmBase: spm pointer is NULL");

Mathieu Faverge
committed
}
if ( (spm->colptr == NULL) ||
(spm->rowptr == NULL) )
{

Mathieu Faverge
committed
pastix_error_print("spmBase: spm pointer is not correctly initialized");
return;
}
if ( (baseval != 0) &&
(baseval != 1) )
{

Mathieu Faverge
committed
pastix_error_print("spmBase: baseval is incorrect, must be 0 or 1");
return;
}
baseadj = baseval - spmFindBase( spm );
if (baseadj == 0)
return;
n = spm->n;
switch(spm->fmttype)
{
case PastixCSC:
assert( nnz == (spm->colptr[n] - spm->colptr[0]) );
for (i = 0; i <= n; i++) {
spm->colptr[i] += baseadj;
}
for (i = 0; i < nnz; i++) {
spm->rowptr[i] += baseadj;
}
break;
case PastixCSR:
assert( nnz == (spm->rowptr[n] - spm->rowptr[0]) );
for (i = 0; i <= n; i++) {
spm->rowptr[i] += baseadj;
}
for (i = 0; i < nnz; i++) {
spm->colptr[i] += baseadj;
}
break;
case PastixIJV:
for (i = 0; i < nnz; i++) {
spm->rowptr[i] += baseadj;
spm->colptr[i] += baseadj;
}
}
if (spm->loc2glob != NULL) {
for (i = 0; i < n; i++) {
spm->loc2glob[i] += baseadj;
}

Mathieu Faverge
committed
}

Mathieu Faverge
committed
if (spm->dofs != NULL) {

Mathieu Faverge
committed
spm->dofs[i] += baseadj;
}
}

Mathieu Faverge
committed
}
/**
*******************************************************************************
*
* @brief Search the base used in the spm structure.

Mathieu Faverge
committed
*
*******************************************************************************
*
* @param[in] spm
* The sparse matrix structure.
*
********************************************************************************
*
* @return The baseval used in the given sparse matrix structure.
*
*******************************************************************************/
pastix_int_t

Mathieu Faverge
committed
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
{
pastix_int_t i, *tmp, baseval;
/*
* Check the baseval, we consider that arrays are sorted by columns or rows
*/
baseval = pastix_imin( *(spm->colptr), *(spm->rowptr) );
/*
* if not:
*/
if ( ( baseval != 0 ) &&
( baseval != 1 ) )
{
baseval = spm->n;
tmp = spm->colptr;
for(i=0; i<spm->nnz; i++, tmp++){
baseval = pastix_imin( *tmp, baseval );
}
}
return baseval;
}
/**
*******************************************************************************
*
*******************************************************************************
* The output format of the sparse matrix. It must be:
* - PastixCSC
* - PastixCSR
* - PastixIJV
* The sparse matrix structure to convert.
*
********************************************************************************
*
* @retval PASTIX_SUCCESS if the conversion happened successfully.
* @retval PASTIX_ERR_BADPARAMETER if one the parameter is incorrect.
* @retval PASTIX_ERR_NOTIMPLEMENTED if the case is not yet implemented.
*
*******************************************************************************/
int
spmConvert( int ofmttype, pastix_spm_t *spm )
{
if ( conversionTable[spm->fmttype][ofmttype][spm->flttype] ) {
//pastix_error_print( "spmConvert: Conversion of non unique dof not yet implemented\n");
return PASTIX_ERR_NOTIMPLEMENTED;
}
return conversionTable[spm->fmttype][ofmttype][spm->flttype]( spm );
}
else {
return PASTIX_SUCCESS;
}
}
/**
*******************************************************************************
*
* @brief Convert the spm matrix into a dense matrix for test purpose.
*
*
*******************************************************************************
*
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
* The sparse matrix structure to convert.
*
********************************************************************************
*
* @return
* The pointer to the allocated array storing the dense version of the
* matrix.
*
*******************************************************************************/
void *
spm2Dense( const pastix_spm_t *spm )
{
switch (spm->flttype) {
case PastixFloat:
return s_spm2dense( spm );
case PastixComplex32:
return c_spm2dense( spm );
case PastixComplex64:
return z_spm2dense( spm );
case PastixDouble:
return d_spm2dense( spm );
default:
return NULL;
}
}
/**
*******************************************************************************
*
* @brief Compute the norm of the spm.
*
* Return the ntype norm of the sparse matrix spm.

Mathieu Faverge
committed
*
* spmNorm = ( max(abs(spm(i,j))), NORM = PastixMaxNorm
* (
* ( norm1(spm), NORM = PastixOneNorm
* (
* ( normI(spm), NORM = PastixInfNorm
* (
* ( normF(spm), NORM = PastixFrobeniusNorm
*
* where norm1 denotes the one norm of a matrix (maximum column sum),
* normI denotes the infinity norm of a matrix (maximum row sum) and
* normF denotes the Frobenius norm of a matrix (square root of sum
* of squares). Note that max(abs(spm(i,j))) is not a consistent matrix
* norm.
*
*******************************************************************************
*
* @param[in] ntype
* - PastixMaxNorm
* - PastixOneNorm
* - PastixInfNorm
* - PastixFrobeniusNorm

Mathieu Faverge
committed
*
* @param[in] spm
* The sparse matrix structure.
*
********************************************************************************
*
* @retval norm The norm described above. Note that for simplicity, even if the
* norm of single real or single complex matrix is computed with
* single precision, the returned norm is stored in double
* precision.
* @retval -1 If the floating point of the sparse matrix is undefined.

Mathieu Faverge
committed
*
*******************************************************************************/
double
spmNorm( pastix_normtype_t ntype,

Mathieu Faverge
committed
{

Mathieu Faverge
committed
if ( spm->dof != 1 ) {
fprintf(stderr, "WARNING: spm expanded due to non implemented norm for non-expanded spm\n");

Mathieu Faverge
committed
case PastixFloat:
norm = (double)s_spmNorm( ntype, spmtmp );
break;

Mathieu Faverge
committed
case PastixDouble:
norm = d_spmNorm( ntype, spmtmp );
break;

Mathieu Faverge
committed
case PastixComplex32:
norm = (double)c_spmNorm( ntype, spmtmp );
break;

Mathieu Faverge
committed
case PastixComplex64:
norm = z_spmNorm( ntype, spmtmp );
break;

Mathieu Faverge
committed

Mathieu Faverge
committed
default:

Mathieu Faverge
committed
}
if ( spmtmp != spm ) {
spmExit( spmtmp );
free(spmtmp);
}

Mathieu Faverge
committed
}
/**
*******************************************************************************
*
* @brief Sort the subarray of edges of each vertex in a CSC or CSR format.

Mathieu Faverge
committed
*
* @warning This function should NOT be called if dof is greater than 1.

Mathieu Faverge
committed
*
*******************************************************************************
*

Mathieu Faverge
committed
* On entry, the pointer to the sparse matrix structure.
* On exit, the same sparse matrix with subarrays of edges sorted by
* ascending order.
*
********************************************************************************
*
* @retval PASTIX_SUCCESS if the sort was called
* @retval PASTIX_ERR_BADPARAMETER if the given spm was incorrect.

Mathieu Faverge
committed
*
*******************************************************************************/
int

Mathieu Faverge
committed
{
if ( spm->dof != 1 ) {
fprintf(stderr, "WARNING: spm expanded due to non implemented sort for non-expanded spm\n");
spm = spmExpand( spm );
}

Mathieu Faverge
committed
case PastixPattern:

Mathieu Faverge
committed
break;
case PastixFloat:

Mathieu Faverge
committed
break;
case PastixDouble:

Mathieu Faverge
committed
break;
case PastixComplex32:

Mathieu Faverge
committed
break;
case PastixComplex64:

Mathieu Faverge
committed
break;
default:
return PASTIX_ERR_BADPARAMETER;
}
return PASTIX_SUCCESS;
}
/**
*******************************************************************************
*
* @brief Merge multiple entries in a spm by summing their values together.
* The sparse matrix needs to be sorted first (see spmSort()).

Mathieu Faverge
committed
*
* @warning Not implemented for CSR and IJV format.

Mathieu Faverge
committed
*
*******************************************************************************
*

Mathieu Faverge
committed
* On entry, the pointer to the sparse matrix structure.
* On exit, the reduced sparse matrix of multiple entries were present
* in it. The multiple values for a same vertex are sum up together.
*
********************************************************************************
*
* @retval >=0 the number of vertices that were merged,
* @retval PASTIX_ERR_BADPARAMETER if the given spm was incorrect.

Mathieu Faverge
committed
*
*******************************************************************************/
pastix_int_t

Mathieu Faverge
committed
{
if ( spm->dof != 1 ) {
fprintf(stderr, "WARNING: spm expanded due to non implemented merge for non-expanded spm\n");
spm = spmExpand( spm );
}

Mathieu Faverge
committed
case PastixPattern:

Mathieu Faverge
committed
case PastixFloat:

Mathieu Faverge
committed
case PastixDouble:

Mathieu Faverge
committed
case PastixComplex32:

Mathieu Faverge
committed
case PastixComplex64:

Mathieu Faverge
committed
default:
return PASTIX_ERR_BADPARAMETER;
}
}
/**
*******************************************************************************
*

Mathieu Faverge
committed
*
* This routine corrects the sparse matrix structure if it's pattern is not
* symmetric. It returns the new symmetric pattern with zeroes on the new
* entries.

Mathieu Faverge
committed
*
*******************************************************************************
*

Mathieu Faverge
committed
* On entry, the pointer to the sparse matrix structure.
* On exit, the same sparse matrix with extra entries that makes it
* pattern symmetric.

Mathieu Faverge
committed
*
********************************************************************************
*
* @retval >=0 the number of entries added to the matrix,
* @retval PASTIX_ERR_BADPARAMETER if the given spm was incorrect.

Mathieu Faverge
committed
*
*******************************************************************************/
pastix_int_t

Mathieu Faverge
committed
{
if ( spm->dof != 1 ) {
fprintf(stderr, "WARNING: spm expanded due to non implemented symmetrize for non-expanded spm\n");
spm = spmExpand( spm );
}

Mathieu Faverge
committed
case PastixPattern:

Mathieu Faverge
committed
case PastixFloat:

Mathieu Faverge
committed
case PastixDouble:

Mathieu Faverge
committed
case PastixComplex32:

Mathieu Faverge
committed
case PastixComplex64:

Mathieu Faverge
committed
default:
return PASTIX_ERR_BADPARAMETER;
}
}
/**
*******************************************************************************
*
* @brief Check the correctness of a spm.
*
* This routine initializes the sparse matrix to fit the PaStiX requirements. If
* needed, the format is changed to CSC, the duplicated vertices are merged
* together by summing their values; the graph is made symmetric for matrices
* with unsymmetric pattern, new values are set to 0. Only the lower part is
* kept for symmetric matrices.

Mathieu Faverge
committed
*
*******************************************************************************

Mathieu Faverge
committed
*

Mathieu Faverge
committed
* The pointer to the sparse matrix structure to check, and correct.
* On exit, the subarrays related to each column might have been sorted
* by ascending order.
*
*******************************************************************************
*
* @return if no changes have been made, the initial sparse matrix is returned,
* otherwise a copy of the sparse matrix, fixed to meet the PaStiX requirements,
* is returned.

Mathieu Faverge
committed
*
*******************************************************************************/
pastix_spm_t *
spmCheckAndCorrect( pastix_spm_t *spm )

Mathieu Faverge
committed
{

Mathieu Faverge
committed
pastix_int_t count;
/* Let's work on a copy */

Mathieu Faverge
committed
/* PaStiX works on CSC matrices */

Mathieu Faverge
committed
if ( newspm->dof != 1 ) {
fprintf(stderr, "WARNING: newspm expanded due to missing check functions implementations\n");
newspm = spmExpand( newspm );
}

Mathieu Faverge
committed
/* Sort the rowptr for each column */

Mathieu Faverge
committed
/* Merge the duplicated entries by summing the values */

Mathieu Faverge
committed
if ( count > 0 ) {
fprintf(stderr, "spmCheckAndCorrect: %ld entries have been merged\n", (long)count );

Mathieu Faverge
committed
}

Mathieu Faverge
committed
* If the matrix is symmetric or hermitian, we keep only the upper or lower
* part, otherwise, we symmetrize the graph to get A+A^t, new values are set
* to 0.
*/
if ( newspm->mtxtype == PastixGeneral ) {
count = spmSymmetrize( newspm );

Mathieu Faverge
committed
if ( count > 0 ) {
fprintf(stderr, "spmCheckAndCorrect: %ld entries have been added for symmetry\n", (long)count );

Mathieu Faverge
committed
}
}
else {

Mathieu Faverge
committed
}

Mathieu Faverge
committed
* Check if we return the new one, or the original one because no changes
* have been made
*/
if (( spm->fmttype != newspm->fmttype ) ||

Mathieu Faverge
committed
{

Mathieu Faverge
committed
}
else {
spmExit( newspm );
free(newspm);
return (pastix_spm_t*)spm;

Mathieu Faverge
committed
}
}
/**
*******************************************************************************
*

Mathieu Faverge
committed
*
* Duplicate the spm data structure given as parameter. All new arrays are
* allocated and copied from the original matrix. Both matrices need to be
* freed.

Mathieu Faverge
committed
*
*******************************************************************************
*
* @param[in] spm
* The sparse matrix to copy.
*
*******************************************************************************
*
* @return
* The copy of the sparse matrix.
*
*******************************************************************************/
pastix_spm_t *
spmCopy( const pastix_spm_t *spm )

Mathieu Faverge
committed
{
pastix_spm_t *newspm = (pastix_spm_t*)malloc(sizeof(pastix_spm_t));
pastix_int_t colsize, rowsize, valsize, dofsize;

Mathieu Faverge
committed
memcpy( newspm, spm, sizeof(pastix_spm_t));

Mathieu Faverge
committed
switch(spm->fmttype){
case PastixCSC:
colsize = spm->n + 1;
rowsize = spm->nnz;
valsize = spm->nnzexp;
dofsize = spm->n + 1;
break;
case PastixCSR:
colsize = spm->nnz;
rowsize = spm->n + 1;
valsize = spm->nnzexp;
dofsize = spm->n + 1;
break;
case PastixIJV:
colsize = spm->nnz;
rowsize = spm->nnz;
valsize = spm->nnzexp;
dofsize = spm->n + 1;
}

Mathieu Faverge
committed
if(spm->colptr != NULL) {
newspm->colptr = (pastix_int_t*)malloc( colsize * sizeof(pastix_int_t));
memcpy( newspm->colptr, spm->colptr, colsize * sizeof(pastix_int_t));

Mathieu Faverge
committed
}
if(spm->rowptr != NULL) {
newspm->rowptr = (pastix_int_t*)malloc(rowsize * sizeof(pastix_int_t));
memcpy( newspm->rowptr, spm->rowptr, rowsize * sizeof(pastix_int_t));

Mathieu Faverge
committed
}
if(spm->loc2glob != NULL) {
newspm->loc2glob = (pastix_int_t*)malloc(dofsize * sizeof(pastix_int_t));
memcpy( newspm->loc2glob, spm->loc2glob, dofsize * sizeof(pastix_int_t));
}
if(spm->dofs != NULL) {
newspm->dofs = (pastix_int_t*)malloc(dofsize * sizeof(pastix_int_t));
memcpy( newspm->dofs, spm->dofs, dofsize * sizeof(pastix_int_t) );

Mathieu Faverge
committed
}
if(spm->values != NULL) {
valsize = valsize * pastix_size_of( spm->flttype );

Mathieu Faverge
committed
newspm->values = malloc(valsize);

Mathieu Faverge
committed
}
return newspm;
}
/**
*******************************************************************************
*
* @brief Print basic informations about the spm matrix into a given stream.
*
*******************************************************************************
*
* @param[in] spm
* The sparse matrix to print.
*
* @param[inout] stream
* Stream to print the spm matrix. stdout is used if stream == NULL.
*
*******************************************************************************/
void
spmPrintInfo( const pastix_spm_t* spm, FILE *stream )
{
char *mtxtypestr[4] = { "General", "Symmetric", "Hermitian", "Incorrect" };
char *flttypestr[7] = { "Pattern", "", "Float", "Double", "Complex32", "Complex64", "Incorrect" };
char *fmttypestr[4] = { "CSC", "CSR", "IJV", "Incorrect" };
int mtxtype = spm->mtxtype - PastixGeneral;
int flttype = spm->flttype - PastixPattern;
int fmttype = spm->fmttype - PastixCSC;
if (stream == NULL) {
stream = stdout;
}
mtxtype = (mtxtype > 2 || mtxtype < 0) ? 3 : mtxtype;
flttype = (flttype > 5 || flttype < 0) ? 6 : flttype;
fmttype = (fmttype > 2 || fmttype < 0) ? 3 : fmttype;
fprintf(stream,
" Matrix type: %s\n"
" Arithmetic: %s\n"
" Format: %s\n"
" N: %ld\n"
" nnz: %ld\n",
mtxtypestr[mtxtype],
flttypestr[flttype],
fmttypestr[fmttype],
if ( spm->dof != 1 ) {
if ( spm->dof > 1 ) {
fprintf(stream,
" Dof: %ld\n",
}
else {
fprintf(stream,
" Dof: Variadic\n" );
}
fprintf(stream,
" N expanded: %ld\n"
" NNZ expanded: %ld\n",
/**
*******************************************************************************
*
* @brief Print an spm matrix into into a given file.
*
*******************************************************************************
*
* @param[in] spm