Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 8e804989 authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

Modify spmExpand API to uniformize the behavior

parent 2bb844a4
No related branches found
No related tags found
1 merge request!20Fix warnings and issues raised by coverity
......@@ -185,7 +185,7 @@ int spmParseLaplacianInfo( const char * filename,
void * spm2Dense( const spmatrix_t *spm );
void spmPrint( const spmatrix_t *spm, FILE *f );
void spmPrintInfo( const spmatrix_t *spm, FILE *f );
spmatrix_t *spmExpand( const spmatrix_t *spm );
void spmExpand( const spmatrix_t *spm_in, spmatrix_t *spm_out );
spmatrix_t *spmDofExtend( const spmatrix_t *spm, const int type, const int dof );
/**
......
......@@ -537,7 +537,8 @@ spmNorm( spm_normtype_t ntype,
if ( spm->dof != 1 ) {
fprintf(stderr, "WARNING: spm expanded due to non implemented norm for non-expanded spm\n");
spmtmp = spmExpand( spm );
spmtmp = malloc( sizeof(spmatrix_t) );
spmExpand( spm, spmtmp );
}
switch (spm->flttype) {
case SpmFloat:
......@@ -563,7 +564,7 @@ spmNorm( spm_normtype_t ntype,
if ( spmtmp != spm ) {
spmExit( spmtmp );
free(spmtmp);
free( spmtmp );
}
return norm;
}
......@@ -752,12 +753,17 @@ spmCheckAndCorrect( const spmatrix_t *spm_in,
spmatrix_t *newspm = NULL;
spm_int_t count;
/* Let's work on a copy */
newspm = spmCopy( spm_in );
if ( (newspm->dof != 1) && (newspm->flttype != SpmPattern) ) {
/*
* Let's work on a copy
* If multi-dof with variables, we need to expand the spm
*/
if ( (spm_in->dof != 1) && (spm_in->flttype != SpmPattern) ) {
fprintf(stderr, "spmCheckAndCorrect: spm is expanded due to multiple degrees of freedom\n");
newspm = spmExpand( newspm );
newspm = malloc( sizeof(spmatrix_t) );
spmExpand( spm_in, newspm );
}
else {
newspm = spmCopy( spm_in );
}
/* PaStiX works on CSC matrices */
......@@ -1007,26 +1013,26 @@ spmPrint( const spmatrix_t *spm,
* The copy of the sparse matrix.
*
*******************************************************************************/
spmatrix_t *
spmExpand( const spmatrix_t* spm )
void
spmExpand( const spmatrix_t* spm_in, spmatrix_t* spm_out )
{
switch(spm->flttype)
switch(spm_in->flttype)
{
case SpmPattern:
return p_spmExpand(spm);
p_spmExpand(spm_in, spm_out);
break;
case SpmFloat:
return s_spmExpand(spm);
s_spmExpand(spm_in, spm_out);
break;
case SpmComplex32:
return c_spmExpand(spm);
c_spmExpand(spm_in, spm_out);
break;
case SpmComplex64:
return z_spmExpand(spm);
z_spmExpand(spm_in, spm_out);
break;
case SpmDouble:
default:
return d_spmExpand(spm);
d_spmExpand(spm_in, spm_out);
}
}
......@@ -1089,7 +1095,8 @@ spmMatVec( spm_trans_t trans,
}
if ( spm->dof != 1 ) {
espm = spmExpand( spm );
espm = malloc( sizeof(spmatrix_t) );
spmExpand( spm, espm );
}
switch (spm->flttype) {
case SpmFloat:
......@@ -1179,7 +1186,8 @@ spmMatMat( spm_trans_t trans,
int rc = SPM_SUCCESS;
if ( A->dof != 1 ) {
espm = spmExpand( A );
espm = malloc( sizeof(spmatrix_t) );
spmExpand( A, espm );
}
switch (A->flttype) {
case SpmFloat:
......
......@@ -82,9 +82,8 @@ int z_spmCheckAxb( spm_fixdbl_t eps, int nrhs, const spmatrix_t *spm, void *x0,
void z_spmDensePrint( FILE *f, spm_int_t m, spm_int_t n, const spm_complex64_t *A, spm_int_t lda );
void z_spmPrint( FILE *f, const spmatrix_t *spm );
spmatrix_t *z_spmExpand(const spmatrix_t *spm);
void z_spmDofExtend(spmatrix_t *spm);
void z_spmScal( const double alpha, spmatrix_t *spm );
void z_spmExpand( const spmatrix_t *spm_in, spmatrix_t *spm_out );
void z_spmDofExtend( spmatrix_t *spm );
void z_spmScal( const double alpha, spmatrix_t *spm );
#endif /* _z_spm_h_ */
This diff is collapsed.
......@@ -47,7 +47,8 @@ p_spm_print_check( char *filename, const spmatrix_t *spm )
free(file);
if ( spm->dof != 1 ) {
spmatrix_t *espm = p_spmExpand( spm );
spmatrix_t *espm = malloc( sizeof(spmatrix_t) );
p_spmExpand( spm, espm );
rc = asprintf( &file, "expand_%s_sparse_ucp.dat", filename );
if ( (f = fopen( file, "w" )) == NULL ) {
......
......@@ -75,7 +75,8 @@ z_spm_print_check( char *filename, const spmatrix_t *spm )
free(A);
if ( spm->dof != 1 ) {
spmatrix_t *espm = z_spmExpand( spm );
spmatrix_t *espm = malloc( sizeof(spmatrix_t) );
z_spmExpand( spm, espm );
rc = asprintf( &file, "expand_%s_sparse_ucp.dat", filename );
if ( (f = fopen( file, "w" )) == NULL ) {
......@@ -98,7 +99,7 @@ z_spm_print_check( char *filename, const spmatrix_t *spm )
free(A);
spmExit( espm );
free(espm);
free( espm );
}
(void)rc; (void)A;
......
......@@ -394,14 +394,14 @@ module spmf
end interface
interface
function spmExpand_c(spm) &
subroutine spmExpand_c(spm_in, spm_out) &
bind(c, name='spmExpand')
use iso_c_binding
import spmatrix_t
implicit none
type(c_ptr) :: spmExpand_c
type(c_ptr), value :: spm
end function spmExpand_c
type(c_ptr), value :: spm_in
type(c_ptr), value :: spm_out
end subroutine spmExpand_c
end interface
interface
......@@ -710,13 +710,13 @@ contains
call spmPrintInfo_c(c_loc(spm), c_null_ptr)
end subroutine spmPrintInfo
subroutine spmExpand(spm, spmo)
subroutine spmExpand(spm_in, spm_out)
use iso_c_binding
implicit none
type(spmatrix_t), intent(in), target :: spm
type(spmatrix_t), intent(out), pointer :: spmo
type(spmatrix_t), intent(in), target :: spm_in
type(spmatrix_t), intent(inout), target :: spm_out
call c_f_pointer(spmExpand_c(c_loc(spm)), spmo)
call spmExpand_c(c_loc(spm_in), c_loc(spm_out))
end subroutine spmExpand
subroutine spmDofExtend(spm, type, dof, spmo)
......
......@@ -189,10 +189,10 @@ def pyspm_spmPrintInfo( spm ):
libspm.spmPrintInfo.argtypes = [ POINTER(pyspm_spmatrix_t), c_void_p ]
libspm.spmPrintInfo( spm, None )
def pyspm_spmExpand( spm ):
libspm.spmExpand.argtypes = [ POINTER(pyspm_spmatrix_t) ]
libspm.spmExpand.restype = POINTER(pyspm_spmatrix_t)
return libspm.spmExpand( spm )
def pyspm_spmExpand( spm_in, spm_out ):
libspm.spmExpand.argtypes = [ POINTER(pyspm_spmatrix_t),
POINTER(pyspm_spmatrix_t) ]
libspm.spmExpand( spm_in, spm_out )
def pyspm_spmDofExtend( spm, type, dof ):
libspm.spmDofExtend.argtypes = [ POINTER(pyspm_spmatrix_t), c_int, c_int ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment