diff --git a/ChangeLog.md b/ChangeLog.md index dd19cf026d6fcb4e7813fdf7a14c254811910b62..1c3ce52d9231721b6a2110e30471426623bc7a84 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -18,6 +18,11 @@ * Fix memory leak in spmSymmetrize (!63) * Fix deadlock issue when loading a matrix in distributed environment (!62) +# spm-1.1.1 + +* spmBase: Fix validity test of the spm when the matrix does not have any nnz, or partial one has no unknowns. +* int32: Fix allocation issue when reaching the limit of the int32 implementation + # spm-1.1.0 * MPI: spmGather/spmScatter are now available in non MPI build for simplicity and return a copy of the matrix diff --git a/src/spm.c b/src/spm.c index 687e4fd1edab3644f0f5117ab82a6eed685c1ec2..7a4cf06c9e3f51e180355b8c7ad730febd001377 100644 --- a/src/spm.c +++ b/src/spm.c @@ -161,8 +161,8 @@ spmInit( spmatrix_t *spm ) void spmAlloc( spmatrix_t *spm ) { - spm_int_t colsize = (spm->fmttype == SpmCSC) ? spm->n + 1 : spm->nnz; - spm_int_t rowsize = (spm->fmttype == SpmCSR) ? spm->n + 1 : spm->nnz; + size_t colsize = (spm->fmttype == SpmCSC) ? spm->n + 1 : spm->nnz; + size_t rowsize = (spm->fmttype == SpmCSR) ? spm->n + 1 : spm->nnz; if ( spm->colptr == NULL ) { spm->colptr = (spm_int_t*)malloc( colsize * sizeof(spm_int_t) ); @@ -174,14 +174,14 @@ spmAlloc( spmatrix_t *spm ) if ( ( spm->dof < 1 ) && ( spm->dofs == NULL ) ) { - spm_int_t dofsize = spm->gN + 1; + size_t dofsize = spm->gN + 1; spm->dofs = (spm_int_t*)malloc( dofsize * sizeof(spm_int_t) ); } if ( (spm->flttype != SpmPattern) && (spm->values == NULL ) ) { - spm_int_t valsize = spm->nnzexp * spm_size_of( spm->flttype ); + size_t valsize = (size_t)(spm->nnzexp) * spm_size_of( spm->flttype ); spm->values = malloc( valsize ); } } @@ -247,17 +247,23 @@ spmBase( spmatrix_t *spm, int baseval ) { spm_int_t baseadj; - spm_int_t i, n, nnz, colsize, rowsize; + size_t i, n, nnz, colsize, rowsize; /* Parameter checks */ if ( spm == NULL ) { fprintf( stderr,"spmBase: spm pointer is NULL"); return; } - if ( (spm->colptr == NULL) || - (spm->rowptr == NULL) ) + + n = spm->n; + nnz = spm->nnz; + colsize = (spm->fmttype == SpmCSC) ? n + 1 : nnz; + rowsize = (spm->fmttype == SpmCSR) ? n + 1 : nnz; + + if ( ((colsize > 0) && (spm->colptr == NULL)) || + ((rowsize > 0) && (spm->rowptr == NULL)) ) { - fprintf( stderr,"spmBase: spm pointer is not correctly initialized"); + fprintf( stderr,"spmBase: spm pointers are not correctly initialized"); return; } if ( (baseval != 0) && @@ -272,11 +278,6 @@ spmBase( spmatrix_t *spm, return; } - n = spm->n; - nnz = spm->nnz; - colsize = (spm->fmttype == SpmCSC) ? n + 1 : nnz; - rowsize = (spm->fmttype == SpmCSR) ? n + 1 : nnz; - for (i = 0; i < colsize; i++) { spm->colptr[i] += baseadj; } @@ -290,7 +291,7 @@ spmBase( spmatrix_t *spm, } } if (spm->dofs != NULL) { - for (i = 0; i <= spm->gN; i++) { + for (i = 0; i <= (size_t)(spm->gN); i++) { spm->dofs[i] += baseadj; } } @@ -346,7 +347,6 @@ spmFindBase( const spmatrix_t *spm ) } } - #if defined(SPM_WITH_MPI) /* Reduce for all cases, just to cover the case with one node without unknowns */ if ( spm->loc2glob != NULL ) { @@ -921,7 +921,7 @@ spmCheckAndCorrect( const spmatrix_t *spm_in, void spmCopy( const spmatrix_t *spm, spmatrix_t *newspm ) { - spm_int_t colsize, rowsize, valsize, dofsize; + size_t colsize, rowsize, valsize, dofsize; memcpy( newspm, spm, sizeof(spmatrix_t)); diff --git a/src/spm_gather.c b/src/spm_gather.c index c38f1991445387f11e3564f916f9b88ed46e9e92..bee099061fb1adefe972700fb1cc0b9c788689ac 100644 --- a/src/spm_gather.c +++ b/src/spm_gather.c @@ -484,7 +484,7 @@ spmGather( const spmatrix_t *oldspm, spmAlloc( newspm ); if ( newspm->dof < 1 ) { - memcpy( newspm->dofs, spmd->dofs, (newspm->gN + 1) * sizeof(spm_int_t) ); + memcpy( newspm->dofs, spmd->dofs, ((size_t)(newspm->gN + 1)) * sizeof(spm_int_t) ); } }