diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 4dbd384aae8f2fc1b82f3700f7da8a629a659ce3..0000000000000000000000000000000000000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,53 +0,0 @@ -include(RulesPrecisions) - -### reset variables -set(generated_sources "") -set(generated_headers "") - -set(HEADERS - z_spm.h -) - -### Generate the headers in all precisions -precisions_rules_py(generated_headers - "${HEADERS}" - PRECISIONS "p;s;d;c;z") - -set(SOURCES - z_spm.c - z_spm_convert_to_csc.c - z_spm_convert_to_csr.c - z_spm_convert_to_ijv.c - z_spm_genrhs.c - z_spm_matrixvector.c - z_spm_norm.c - ) - -set(spm_headers - ${generated_headers} - spm.h - ) - -### Generate the sources in all precisions -precisions_rules_py(generated_sources - "${SOURCES}" - PRECISIONS "p;s;d;c;z") - -set(spm_sources - ${generated_sources} - spm.c - spm_io.c - ) - -add_custom_target(spm_headers_tgt - DEPENDS ${spm_headers} ) - -set_source_files_properties( - spm.c - PROPERTIES DEPENDS spm_headers_tgt - ) - -set(PASTIX_LIB_SRCS - ${PASTIX_LIB_SRCS} - ${spm_sources} - ) diff --git a/spm.c b/spm.c index 112a33a663112571b392aa027fd66d69763616fd..c08db2fd553d1468c401f00eb0fceeef2733ba29 100644 --- a/spm.c +++ b/spm.c @@ -68,40 +68,96 @@ static int (*conversionTable[3][3][6])(pastix_spm_t*) = { }; - /** ******************************************************************************* * * @ingroup pastix_spm * - * spmConvert - Convert the storage format of the given sparse matrix from any - * of the following format: PastixCSC, PastixCSR, or PastixIJV to one of these. + * @brief Free the spm structure * ******************************************************************************* * - * @param[in] ofmttype - * The output format of the sparse matrix. It might be PastixCSC, - * PastixCSR, or PastixIJV. - * * @param[in,out] spm - * The sparse matrix structure to convert. + * The sparse matrix to free. * - ******************************************************************************** + *******************************************************************************/ +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); +} + +/** + ******************************************************************************* * - * @return - * \retval PASTIX_SUCCESS if the conversion happened successfuly - * \retval PASTIX_ERR_BADPARAMETER if one the parameter is incorrect. + * @ingroup pastix_spm + * + * @brief Rebase the spm + * + * Rebase the arrays of the spm to the given value. If the value is equal to the + * original base, then nothing is performed. + * + ******************************************************************************* + * + * @param[in,out] spm + * The sparse matrix to rebase. + * + * @param[in] baseval + * The base value to use in the graph (0 or 1). * *******************************************************************************/ -int -spmConvert( int ofmttype, pastix_spm_t *ospm ) +void +spmBase( pastix_spm_t *spm, + int baseval ) { - if ( conversionTable[ospm->fmttype][ofmttype][ospm->flttype] ) { - return conversionTable[ospm->fmttype][ofmttype][ospm->flttype]( ospm ); + pastix_int_t baseadj; + pastix_int_t i, n, nnz; + + /* Parameter checks */ + if ( spm == NULL ) { + errorPrint("spmBase: spm pointer is NULL"); + return; } - else { - return PASTIX_SUCCESS; + if ( (spm->colptr == NULL) || + (spm->rowptr == NULL) ) + { + errorPrint("spmBase: spm pointer is not correctly initialized"); + return; + } + if ( (baseval != 0) && + (baseval != 1) ) + { + errorPrint("spmBase: baseval is incorrect, must be 0 or 1"); + return; + } + + baseadj = baseval - spmFindBase( spm ); + if (baseadj == 0) + return; + + n = spm->n; + 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; + } + + if (spm->loc2glob != NULL) { + for (i = 0; i < n; i++) { + spm->loc2glob[i] += baseadj; + } } + return; } /** @@ -109,7 +165,7 @@ spmConvert( int ofmttype, pastix_spm_t *ospm ) * * @ingroup pastix_spm * - * spmFindBase - Search the base used in the spm structure given as parameter. + * @brief Search the base used in the spm structure. * ******************************************************************************* * @@ -152,7 +208,46 @@ spmFindBase( const pastix_spm_t *spm ) * * @ingroup pastix_spm * - * spmNorm - Return the ntype norm of the sparse matrix spm. + * @brief Convert the storage format of the spm to ofmttype. + * + * Convert the storage format of the given sparse matrix from any of the + * following format: PastixCSC, PastixCSR, or PastixIJV to one of these. + * + ******************************************************************************* + * + * @param[in] ofmttype + * The output format of the sparse matrix. It might be PastixCSC, + * PastixCSR, or PastixIJV. + * + * @param[in,out] spm + * The sparse matrix structure to convert. + * + ******************************************************************************** + * + * @return + * \retval PASTIX_SUCCESS if the conversion happened successfuly + * \retval PASTIX_ERR_BADPARAMETER if one the parameter is incorrect. + * + *******************************************************************************/ +int +spmConvert( int ofmttype, pastix_spm_t *spm ) +{ + if ( conversionTable[spm->fmttype][ofmttype][spm->flttype] ) { + return conversionTable[spm->fmttype][ofmttype][spm->flttype]( spm ); + } + else { + return PASTIX_SUCCESS; + } +} + +/** + ******************************************************************************* + * + * @ingroup pastix_spm + * + * @brief Compute the norm of the spm. + * + * Return the ntype norm of the sparse matrix spm. * * spmNorm = ( max(abs(spm(i,j))), NORM = PastixMaxNorm * ( @@ -221,7 +316,9 @@ spmNorm( int ntype, * * @ingroup pastix_spm * - * spmSort - This routine sorts the subarray of edges of each vertex in a + * @brief Sort the subarray of edges of each vertex in a CSC or CSR spm + * + * This routine sorts the subarray of edges of each vertex in a * centralized spm stored in CSC or CSR format. Nothing is performed if IJV * format is used. * @@ -271,7 +368,9 @@ spmSort( pastix_spm_t *spm ) * * @ingroup pastix_spm * - * spmMergeDuplicate - This routine merge the multiple entries in a sparse + * @brief Merge mulitple entries in a spm by summing them. + * + * This routine merge the multiple entries in a sparse * matrix by suming their values together. The sparse matrix needs to be sorted * first (see spmSort()). * @@ -320,9 +419,11 @@ spmMergeDuplicate( pastix_spm_t *spm ) * * @ingroup pastix_spm * - * spmSymmetrize - This routine merge the multiple entries in a sparse - * matrix by suming their values together. The sparse matrix needs to be sorted - * first (see spmSort()). + * @brief Symmetrize the pattern of the spm + * + * Symmetrize the pattern of the input spm by edges when A(i,j) exists, but + * A(j,i) does not. When values are associated to the edge, zeroes are added to + * the values array. * * WARNING: Not implemented for CSR and IJV format. * @@ -369,11 +470,13 @@ spmSymmetrize( pastix_spm_t *spm ) * * @ingroup pastix_spm * - * spmCheckAndCorrect - 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 the symmetric matrices. + * @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 the symmetric matrices. * * On exit, if no changes have been made, the initial sparse matrix is returned, * otherwise a copy of the sparse matrix structured fixed to meet the PaStiX @@ -453,33 +556,11 @@ spmCheckAndCorrect( pastix_spm_t *spm ) * * @ingroup pastix_spm * - * spmExit - Free the spm structure given as parameter - * - ******************************************************************************* - * - * @param[in,out] spm - * The sparse matrix to free. - * - *******************************************************************************/ -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); -} - -/** - ******************************************************************************* - * - * @ingroup pastix_spm + * @brief Create a copy of the spm * - * spmCopy - Duplicate the spm data structure given as parameter. + * 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. * ******************************************************************************* * @@ -524,64 +605,47 @@ spmCopy( const pastix_spm_t *spm ) * * @ingroup pastix_spm * - * spmBase - Rebase the spm to the given value. + * @brief Compute a matrix-vector product + * + * Compute the matrix vector product: + * + * y = alpha * op(A) * x + beta * y, where op(A) is one of + * + * op( A ) = A or op( A ) = A' or op( A ) = conjg( A' ) + * + * alpha and beta are scalars, and x and y are vectors. * ******************************************************************************* * - * @param[in,out] spm - * The sparse matrix to rebase. + * @param[in] trans + * Specifies whether the matrix spm is transposed, not transposed or + * conjugate transposed: + * = PastixNoTrans: A is not transposed; + * = PastixTrans: A is transposed; + * = PastixConjTrans: A is conjugate transposed. * - * @param[in] baseval - * The base value to use in the graph (0 or 1). + * @param[in] alpha + * alpha specifies the scalar alpha. + * + * @param[in] spm + * The PastixGeneral spm. + * + * @param[in] x + * The vector x. + * + * @param[in] beta + * beta specifies the scalar beta. + * + * @param[in,out] y + * The vector y. + * + ******************************************************************************* + * + * @return + * \retval PASTIX_SUCCESS if the y vector has been computed succesfully, + * \retval PASTIX_ERR_BADPARAMETER otherwise. * *******************************************************************************/ -void spmBase( pastix_spm_t *spm, - int baseval ) -{ - pastix_int_t baseadj; - pastix_int_t i, n, nnz; - - /* Parameter checks */ - if ( spm == NULL ) { - errorPrint("spmBase: spm pointer is NULL"); - return; - } - if ( (spm->colptr == NULL) || - (spm->rowptr == NULL) ) - { - errorPrint("spmBase: spm pointer is not correctly initialized"); - return; - } - if ( (baseval != 0) && - (baseval != 1) ) - { - errorPrint("spmBase: baseval is incorrect, must be 0 or 1"); - return; - } - - baseadj = baseval - spmFindBase( spm ); - if (baseadj == 0) - return; - - n = spm->n; - 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; - } - - if (spm->loc2glob != NULL) { - for (i = 0; i < n; i++) { - spm->loc2glob[i] += baseadj; - } - } - return; -} - - /** * TODO: Maybe we should move down the cast of the parameters to the lowest * functions, and simplify this one to have identical calls to all subfunction @@ -640,8 +704,11 @@ spmMatVec( int trans, * * @ingroup pastix_spm * - * z_spmGenRHS - Generate nrhs right hand side vectors associated to a given - * matrix to test a problem with a solver. + * @brief Generate right hand sides. + * + * Generate nrhs right hand side vectors associated to a given matrix to test a + * problem with a solver. The vectors can be initialized randomly, or to get a + * specific solution. * ******************************************************************************* * @@ -710,8 +777,9 @@ spmGenRHS( int type, int nrhs, * * @ingroup pastix_spm * - * spmCheckAxb - Check the backward error, and the forward error if x0 is - * provided. + * @brief Check backward and forward errors + * + * Check the backward error, and the forward error if x0 is provided. * ******************************************************************************* * diff --git a/spm.h b/spm.h index 95653c6589c0b9d41f649ad32b5ab32f92b1b863..18fd91d2bccc60f8233e298cf976a90ad6b8c0b1 100644 --- a/spm.h +++ b/spm.h @@ -18,26 +18,36 @@ /** * @ingroup pastix_spm * - * @struct pastix_spm_s - Sparse matrix data structure + * @struct pastix_spm_s + * + * @brief The sparse matrix data structure + * + * This structure describes matrices with different characteristics that can be useful to any solver: + * - the storage format (PastixCSC, PastixCSR or PastixIJV) + * - the properties (PastixGeneral, PastixHermitian, PastixSymmetric) + * - the base value (0 in C, 1 in Fortran for examples) + * + * It is also possible to describe a matrix with constant or varaibel degrees of freedom. + * */ struct pastix_spm_s { - int mtxtype; /*< Matrix structure: PastixGeneral, PastixSymmetric - or PastixHermitian. */ - int flttype; /*< avals datatype: PastixPattern, PastixFloat, PastixDouble, - PastixComplex32 or PastixComplex64 */ - int 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 dof; /*< Number of degrees of freedom per unknown, - if > 0, constant degree of freedom - otherwise, irregular degree of freedom (refer to dofs) */ - pastix_int_t *dofs; /*< Number of degrees of freedom per unknown (NULL, if dof > 0) */ - pastix_int_t *colptr; /*< List of indirections to rows for each vertex */ - pastix_int_t *rowptr; /*< List of edges for each vertex */ - pastix_int_t *loc2glob; /*< Corresponding numbering from local to global */ - void *values; /*< Values stored in the matrix */ + int mtxtype; /**< Matrix structure: PastixGeneral, PastixSymmetric + or PastixHermitian. */ + int flttype; /**< avals datatype: PastixPattern, PastixFloat, PastixDouble, + PastixComplex32 or PastixComplex64 */ + int 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 dof; /**< Number of degrees of freedom per unknown, + if > 0, constant degree of freedom + otherwise, irregular degree of freedom (refer to dofs) */ + pastix_int_t *dofs; /**< Number of degrees of freedom per unknown (NULL, if dof > 0) */ + pastix_int_t *colptr; /**< List of indirections to rows for each vertex */ + pastix_int_t *rowptr; /**< List of edges for each vertex */ + pastix_int_t *loc2glob; /**< Corresponding numbering from local to global */ + void *values; /**< Values stored in the matrix */ }; int diff --git a/z_spm.c b/z_spm.c index d6c0969a3916087055fc16890c9ef154386e5d71..4b740a84508924cf2362c226fe93cd0af13457a0 100644 --- a/z_spm.c +++ b/z_spm.c @@ -19,7 +19,7 @@ /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmSort - This routine sorts the subarray of edges of each vertex in a * centralized spm stored in CSC or CSR format. Nothing is performed if IJV @@ -89,8 +89,7 @@ z_spmSort( pastix_spm_t *spm ) /** ******************************************************************************* * - * @ingroup pastix_spm - * @ingroup pastix_internal + * @ingroup pastix_spm_internal * * z_spmMergeDuplicate - This routine merge the multiple entries in a sparse * matrix by suming their values together. The sparse matrix needs to be sorted @@ -184,8 +183,7 @@ z_spmMergeDuplicate( pastix_spm_t *spm ) /** ******************************************************************************* * - * @ingroup pastix_spm - * @ingroup pastix_internal + * @ingroup pastix_spm_internal * * z_spmSymmetrize - This routine corrects the sparse matrix structure if it's * pattern is not symmetric. It returns the new symmetric pattern with zeores on diff --git a/z_spm_convert_to_csc.c b/z_spm_convert_to_csc.c index 72b96a235f7d7a6f6be8e272ab2e801e4f4b7d3c..bd76019cc490bee69ae093d8693344a48c6ab963 100644 --- a/z_spm_convert_to_csc.c +++ b/z_spm_convert_to_csc.c @@ -20,7 +20,7 @@ /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmConvertIJV2CSC - convert a matrix in IJV format to a matrix in CSC * format. @@ -126,7 +126,7 @@ z_spmConvertIJV2CSC( pastix_spm_t *spm ) /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmConvertCSR2CSC - convert a matrix in CSR format to a matrix in CSC * format. If the matrix is PastixSymmetric or PastixHermitian, then the diff --git a/z_spm_convert_to_csr.c b/z_spm_convert_to_csr.c index ef7b8f35befd14f4e0a99d6bad75bac9588d7f2a..c1d0d4582f0d2edd50c74a231cb6a1419dbfcd50 100644 --- a/z_spm_convert_to_csr.c +++ b/z_spm_convert_to_csr.c @@ -20,7 +20,7 @@ /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmConvertCSC2CSR - convert a matrix in CSC format to a matrix in CSR * format. If the matrix is PastixSymmetric or PastixHermitian, then the @@ -97,7 +97,7 @@ z_spmConvertCSC2CSR( pastix_spm_t *spm ) /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmConvertIJV2CSR - convert a matrix in IJV format to a matrix in CSR * format. diff --git a/z_spm_convert_to_ijv.c b/z_spm_convert_to_ijv.c index 68fa025eb75197aee30fef11230344b36212ced8..6ab25d095da59c6dc59bcf576e9afcc1c5544472 100644 --- a/z_spm_convert_to_ijv.c +++ b/z_spm_convert_to_ijv.c @@ -20,7 +20,7 @@ /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmConvertCSC2IJV - convert a matrix in CSC format to a matrix in IJV * format. @@ -71,7 +71,7 @@ z_spmConvertCSC2IJV( pastix_spm_t *spm ) /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmConvertCSR2IJV - convert a matrix in CSR format to a matrix in IJV * format. diff --git a/z_spm_genrhs.c b/z_spm_genrhs.c index 6fceb4474cafdb70d4cf8edd65306ae0c42bb939..47cf44daafd745c73b87e2263592a7e2c77968db 100644 --- a/z_spm_genrhs.c +++ b/z_spm_genrhs.c @@ -53,7 +53,7 @@ Rnd64_jump(unsigned long long int n, unsigned long long int seed ) { /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmRndVect generates a random vector for testing purpose. * @@ -114,7 +114,7 @@ void z_spmRndVect( double scale, int m, int n, pastix_complex64_t *A, int lda, /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmGenRHS - Generate nrhs right hand side vectors associated to a given * matrix to test a problem with a solver. @@ -284,7 +284,7 @@ z_spmGenRHS( int type, int nrhs, /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmCheckAxb - Check the backward error, and the forward error if x0 is * provided. diff --git a/z_spm_matrixvector.c b/z_spm_matrixvector.c index 7db1de700c9cfb1772956a6e11e6444e20270db2..e5346ebf9c67c735626e2a43394b9f99133dcc5d 100644 --- a/z_spm_matrixvector.c +++ b/z_spm_matrixvector.c @@ -20,10 +20,10 @@ /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmGeCSCv - compute the matrix-vector product: - * y = alpha * op( A ) + beta * y + * y = alpha * op( A ) * x + beta * y * * A is a PastixGeneral csc, where op( X ) is one of * @@ -152,7 +152,7 @@ z_spmGeCSCv( int trans, /** ******************************************************************************* * - * @ingroup pastix_csc + * @ingroup pastix_spm_internal * * z_spmSYCSCv - compute the matrix-vector product: * y = alpha * A + beta * y @@ -241,7 +241,7 @@ z_spmSyCSCv( pastix_complex64_t alpha, /** ******************************************************************************* * - * @ingroup pastix_csc + * @ingroup pastix_spm_internal * * z_spmHeCSCv - compute the matrix-vector product: * y = alpha * A + beta * y diff --git a/z_spm_norm.c b/z_spm_norm.c index afa9ffdb3b356132f11a6c856ef1df17b67e5043..422ace0b4cb31e7eeb46a987f731ebdb3f340622 100644 --- a/z_spm_norm.c +++ b/z_spm_norm.c @@ -23,7 +23,7 @@ /** ******************************************************************************* * - * @ingroup spm_internal + * @ingroup pastix_spm_internal * * z_spmFrobeniusNorm - Compute the Frobenius norm of the non distributed given * spm structure. @@ -114,7 +114,7 @@ z_spmFrobeniusNorm( const pastix_spm_t *spm ) /** ******************************************************************************* * - * @ingroup spm_internal + * @ingroup pastix_spm_internal * * z_spmMaxNorm - Compute the Max norm of the non distributed given spm * structure. @@ -150,7 +150,7 @@ z_spmMaxNorm( const pastix_spm_t *spm ) /** ******************************************************************************* * - * @ingroup spm_internal + * @ingroup pastix_spm_internal * * z_spmInfNorm - Compute the Infinity norm of the non distributed given spm * structure given by the maximum column sum. @@ -265,7 +265,7 @@ z_spmInfNorm( const pastix_spm_t *spm ) /** ******************************************************************************* * - * @ingroup spm_internal + * @ingroup pastix_spm_internal * * z_spmOneNorm - Compute the Oneinity norm of the non distributed given spm * structure fiven by the maximum row sum @@ -380,7 +380,7 @@ z_spmOneNorm( const pastix_spm_t *spm ) /** ******************************************************************************* * - * @ingroup pastix_spm + * @ingroup pastix_spm_internal * * z_spmNorm - Compute the norm of an spm matrix *