diff --git a/spm.c b/spm.c index e6e3c25daaf7d08f0d75d69d219016a8e4b084a6..78cb2da66a58cb5158a4c27d40d3ef9973ecff00 100644 --- a/spm.c +++ b/spm.c @@ -108,6 +108,82 @@ spmInit( pastix_spm_t *spm ) spm->values = NULL; } +/** + ******************************************************************************* + * + * @ingroup pastix_spm + * + * @brief Update all the computed fields based on the static values stored + * + ******************************************************************************* + * + * @param[in,out] spm + * The sparse matrix to init. + * + *******************************************************************************/ +void +spmUpdateFields( pastix_spm_t *spm ) +{ + + /** + * 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; +} + /** ******************************************************************************* * diff --git a/spm.h b/spm.h index 9e0e0d1ed8ddae235e656e66f11816a0fdce87dd..c4dd0416ab7c4944730dcdb1007ba6b991d9c27b 100644 --- a/spm.h +++ b/spm.h @@ -61,32 +61,32 @@ typedef enum pastix_driver_e { */ struct pastix_spm_s { int mtxtype; /**< Matrix structure: PastixGeneral, PastixSymmetric - or PastixHermitian. */ + or PastixHermitian. */ pastix_coeftype_t flttype; /**< avals datatype: PastixPattern, PastixFloat, PastixDouble, - PastixComplex32 or PastixComplex64 */ - pastix_fmttype_t fmttype; /**< Matrix storage format: PastixCSC, PastixCSR, PastixIJV */ + PastixComplex32 or PastixComplex64 */ + pastix_fmttype_t fmttype; /**< Matrix storage format: PastixCSC, PastixCSR, PastixIJV */ - pastix_int_t gN; /**< Global number of vertices in the compressed graph */ - pastix_int_t n; /**< Local number of vertices in the compressed graph */ - pastix_int_t gnnz; /**< Global number of non zeroes in the compressed graph */ - pastix_int_t nnz; /**< Local number of non zeroes in the compressed graph */ + pastix_int_t gN; /**< Global number of vertices in the compressed graph (Computed) */ + pastix_int_t n; /**< Local number of vertices in the compressed graph */ + pastix_int_t gnnz; /**< Global number of non zeroes in the compressed graph (Computed) */ + pastix_int_t nnz; /**< Local number of non zeroes in the compressed graph */ - pastix_int_t gNexp; /**< Global number of vertices in the compressed graph */ - pastix_int_t nexp; /**< Local number of vertices in the compressed graph */ - pastix_int_t gnnzexp; /**< Global number of non zeroes in the compressed graph */ - pastix_int_t nnzexp; /**< Local number of non zeroes in the compressed graph */ + pastix_int_t gNexp; /**< Global number of vertices in the compressed graph (Computed) */ + pastix_int_t nexp; /**< Local number of vertices in the compressed graph (Computed) */ + pastix_int_t gnnzexp; /**< Global number of non zeroes in the compressed graph (Computed) */ + pastix_int_t nnzexp; /**< Local number of non zeroes in the compressed graph (Computed) */ pastix_int_t dof; /**< Number of degrees of freedom per unknown, if > 0, constant degree of freedom - otherwise, irregular degree of freedom (refer to dofs) */ + otherwise, irregular degree of freedom (refer to dofs) */ pastix_int_t *dofs; /**< Array of the first column of each element in the - expanded matrix [+baseval] */ - pastix_order_t layout; /**< PastixColMajor, or PastixRowMajor */ + expanded matrix [+baseval] */ + pastix_order_t layout; /**< PastixColMajor, or PastixRowMajor */ - pastix_int_t *colptr; /**< List of indirections to rows for each vertex [+baseval] */ - pastix_int_t *rowptr; /**< List of edges for each vertex [+baseval] */ - pastix_int_t *loc2glob;/**< Corresponding numbering from local to global [+baseval] */ - void *values; /**< Values stored in the matrix */ + pastix_int_t *colptr; /**< List of indirections to rows for each vertex [+baseval] */ + pastix_int_t *rowptr; /**< List of edges for each vertex [+baseval] */ + pastix_int_t *loc2glob;/**< Corresponding numbering from local to global [+baseval] */ + void *values; /**< Values stored in the matrix */ }; int @@ -145,6 +145,7 @@ void spmInit( pastix_spm_t *spm ); void spmExit( pastix_spm_t *spm ); pastix_spm_t *spmCopy( const pastix_spm_t *spm ); void spmBase( pastix_spm_t *spm, int baseval ); +void spmUpdateFields( pastix_spm_t *spm ); int spmConvert( int ofmttype, pastix_spm_t *ospm ); void * spm2Dense( const pastix_spm_t *spm ); pastix_int_t spmFindBase( const pastix_spm_t *spm ); diff --git a/spm_dofs.c b/spm_dofs.c index d75f839c5ec3e74d454b83aa555bb47f23c962ba..69b504efb3f257aa49da3913801954011cf8d935 100644 --- a/spm_dofs.c +++ b/spm_dofs.c @@ -44,15 +44,11 @@ spmDofExtend( const int type, * Generate constant dof */ if (type == 0) { - newspm->dof = dof; - newspm->nexp = spm->n * dof; - newspm->gNexp = spm->gN * dof; - newspm->nnzexp = spm->nnz * dof * dof; - newspm->gnnzexp = spm->gnnz * dof * dof; + newspm->dof = dof; } else { - pastix_int_t i, j, k, dofi, dofj, baseval; - pastix_int_t *dofptr, *colptr, *rowptr; + pastix_int_t i, dofi, baseval; + pastix_int_t *dofptr; baseval = spmFindBase( spm ); @@ -69,51 +65,10 @@ spmDofExtend( const int type, dofi = 1 + ( rand() % dof ); dofptr[1] = dofptr[0] + dofi; } - - newspm->nexp = *dofptr - baseval; - newspm->gNexp = newspm->nexp; - - /** - * Count the number of non zeroes - */ - newspm->nnzexp = 0; - colptr = newspm->colptr; - rowptr = newspm->rowptr; - dofptr = newspm->dofs; - - switch(spm->fmttype) - { - case PastixCSR: - /* Swap pointers to call CSC */ - colptr = newspm->rowptr; - rowptr = newspm->colptr; - - case PastixCSC: - for(j=0; j<newspm->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]; - - newspm->nnzexp += dofi * dofj; - } - } - break; - case PastixIJV: - for(k=0; k<newspm->nnz; k++, rowptr++, colptr++) - { - i = *rowptr - baseval; - j = *colptr - baseval; - dofi = dofptr[i+1] - dofptr[i]; - dofj = dofptr[j+1] - dofptr[j]; - - newspm->nnzexp += dofi * dofj; - } - } - newspm->gnnzexp = newspm->nnzexp; } + spmUpdateFields( newspm ); + switch (spm->flttype) { case PastixFloat: s_spmDofExtend( newspm );