From 15b864c6ac8150e8323d07c5aaa480942f66d194 Mon Sep 17 00:00:00 2001 From: Rocco Meli Date: Wed, 26 Jul 2023 11:15:13 +0200 Subject: [PATCH] improve const-correctness and improve some arguments --- include/dlaf_c/eigensolver/eigensolver.h | 44 +++++++++++++----------- include/dlaf_c/factorization/cholesky.h | 30 ++++++++-------- include/dlaf_c/utils.h | 3 +- src/c_api/eigensolver/eigensolver.cpp | 39 ++++++++++++--------- src/c_api/eigensolver/eigensolver.h | 8 ++--- src/c_api/factorization/cholesky.cpp | 24 ++++++++----- src/c_api/factorization/cholesky.h | 5 +-- src/c_api/utils.cpp | 7 ++-- src/c_api/utils.h | 4 +-- 9 files changed, 94 insertions(+), 70 deletions(-) diff --git a/include/dlaf_c/eigensolver/eigensolver.h b/include/dlaf_c/eigensolver/eigensolver.h index be514b53e6..2cf645653a 100644 --- a/include/dlaf_c/eigensolver/eigensolver.h +++ b/include/dlaf_c/eigensolver/eigensolver.h @@ -33,24 +33,24 @@ /// @param z Local part of the global matrix \f$\mathbf{Z}\f$ /// @param dlaf_descz DLA-Future descriptor of the global matrix \f$\mathbf{Z}\f$ /// @return 0 if the eigensolver completed normally -DLAF_EXTERN_C int dlaf_eigensolver_s(int dlaf_context, char uplo, float* a, - struct DLAF_descriptor dlaf_desca, float* w, float* z, - struct DLAF_descriptor dlaf_descz); +DLAF_EXTERN_C int dlaf_eigensolver_s(const int dlaf_context, const char uplo, float* a, + const struct DLAF_descriptor dlaf_desca, float* w, float* z, + const struct DLAF_descriptor dlaf_descz); /// @copydoc dlaf_eigensolver_s -DLAF_EXTERN_C int dlaf_eigensolver_d(int dlaf_context, char uplo, double* a, - struct DLAF_descriptor dlaf_desca, double* w, double* z, - struct DLAF_descriptor dlaf_descz); +DLAF_EXTERN_C int dlaf_eigensolver_d(const int dlaf_context, const char uplo, double* a, + const struct DLAF_descriptor dlaf_desca, double* w, double* z, + const struct DLAF_descriptor dlaf_descz); /// @copydoc dlaf_eigensolver_s -DLAF_EXTERN_C int dlaf_eigensolver_c(int dlaf_context, char uplo, dlaf_complex_c* a, - struct DLAF_descriptor dlaf_desca, float* w, dlaf_complex_c* z, - struct DLAF_descriptor dlaf_descz); +DLAF_EXTERN_C int dlaf_eigensolver_c(const int dlaf_context, const char uplo, dlaf_complex_c* a, + const struct DLAF_descriptor dlaf_desca, float* w, + dlaf_complex_c* z, const struct DLAF_descriptor dlaf_descz); /// @copydoc dlaf_eigensolver_s -DLAF_EXTERN_C int dlaf_eigensolver_z(int dlaf_context, char uplo, dlaf_complex_z* a, - struct DLAF_descriptor dlaf_desca, double* w, dlaf_complex_z* z, - struct DLAF_descriptor dlaf_descz); +DLAF_EXTERN_C int dlaf_eigensolver_z(const int dlaf_context, const char uplo, dlaf_complex_z* a, + const struct DLAF_descriptor dlaf_desca, double* w, + dlaf_complex_z* z, const struct DLAF_descriptor dlaf_descz); #ifdef DLAF_WITH_SCALAPACK @@ -85,19 +85,23 @@ DLAF_EXTERN_C int dlaf_eigensolver_z(int dlaf_context, char uplo, dlaf_complex_z /// submatrix \f$\mathbf{A}\f$, has to be 1 /// @param descz ScaLAPACK array descriptor of the global matrix \f$\mathbf{Z}\f$ /// @param[out] info 0 if the eigensolver completed normally -DLAF_EXTERN_C void dlaf_pssyevd(char uplo, int n, float* a, int ia, int ja, int* desca, float* w, - float* z, int iz, int jz, int* descz, int* info); +DLAF_EXTERN_C void dlaf_pssyevd(const char uplo, const int n, float* a, const int ia, const int ja, + const int desca[9], float* w, float* z, const int iz, const int jz, + const int descz[9], int* info); /// @copydoc dlaf_pssyevd -DLAF_EXTERN_C void dlaf_pdsyevd(char uplo, int n, double* a, int ia, int ja, int* desca, double* w, - double* z, int iz, int jz, int* descz, int* info); +DLAF_EXTERN_C void dlaf_pdsyevd(const char uplo, const int n, double* a, const int ia, const int ja, + const int desca[9], double* w, double* z, const int iz, const int jz, + const int descz[9], int* info); /// @copydoc dlaf_pssyevd -DLAF_EXTERN_C void dlaf_pcheevd(char uplo, int n, dlaf_complex_c* a, int ia, int ja, int* desca, - float* w, dlaf_complex_c* z, int iz, int jz, int* descz, int* info); +DLAF_EXTERN_C void dlaf_pcheevd(const char uplo, const int n, dlaf_complex_c* a, const int ia, + const int ja, const int desca[9], float* w, dlaf_complex_c* z, + const int iz, const int jz, const int descz[9], int* info); /// @copydoc dlaf_pssyevd -DLAF_EXTERN_C void dlaf_pzheevd(char uplo, int n, dlaf_complex_z* a, int ia, int ja, int* desca, - double* w, dlaf_complex_z* z, int iz, int jz, int* descz, int* info); +DLAF_EXTERN_C void dlaf_pzheevd(const char uplo, const int n, dlaf_complex_z* a, const int ia, + const int ja, const int desca[9], double* w, dlaf_complex_z* z, + const int iz, const int jz, const int descz[9], int* info); #endif diff --git a/include/dlaf_c/factorization/cholesky.h b/include/dlaf_c/factorization/cholesky.h index 3287b054f3..5a01ef6767 100644 --- a/include/dlaf_c/factorization/cholesky.h +++ b/include/dlaf_c/factorization/cholesky.h @@ -29,20 +29,20 @@ /// @param a Local part of the global matrix \f$\mathbf{A}\f$ /// @param dlaf_desca DLA-Future descriptor of the global matrix \f$\mathbf{A}\f$ /// @return 0 if the factorization completed normally -DLAF_EXTERN_C int dlaf_cholesky_s(int dlaf_context, char uplo, float* a, - struct DLAF_descriptor dlaf_desca); +DLAF_EXTERN_C int dlaf_cholesky_s(const int dlaf_context, const char uplo, float* a, + const struct DLAF_descriptor dlaf_desca); /// @copydoc dlaf_cholesky_s -DLAF_EXTERN_C int dlaf_cholesky_d(int dlaf_context, char uplo, double* a, - struct DLAF_descriptor dlaf_desca); +DLAF_EXTERN_C int dlaf_cholesky_d(const int dlaf_context, const char uplo, double* a, + const struct DLAF_descriptor dlaf_desca); /// @copydoc dlaf_cholesky_s -DLAF_EXTERN_C int dlaf_cholesky_c(int dlaf_context, char uplo, dlaf_complex_c* a, - struct DLAF_descriptor dlaf_desca); +DLAF_EXTERN_C int dlaf_cholesky_c(const int dlaf_context, const char uplo, dlaf_complex_c* a, + const struct DLAF_descriptor dlaf_desca); /// @copydoc dlaf_cholesky_s -DLAF_EXTERN_C int dlaf_cholesky_z(int dlaf_context, char uplo, dlaf_complex_z* a, - struct DLAF_descriptor dlaf_desca); +DLAF_EXTERN_C int dlaf_cholesky_z(const int dlaf_context, const char uplo, dlaf_complex_z* a, + const struct DLAF_descriptor dlaf_desca); #ifdef DLAF_WITH_SCALAPACK @@ -69,17 +69,19 @@ DLAF_EXTERN_C int dlaf_cholesky_z(int dlaf_context, char uplo, dlaf_complex_z* a /// submatrix \f$\mathbf{A}\f$, has to be 1 /// @param desca ScaLAPACK array descriptor of the global matrix \f$\mathbf{A}\f$ /// @param[out] info 0 if the factorization completed normally -DLAF_EXTERN_C void dlaf_pspotrf(char uplo, int n, float* a, int ia, int ja, int* desca, int* info); +DLAF_EXTERN_C void dlaf_pspotrf(const char uplo, const int n, float* a, const int ia, const int ja, + const int desca[9], int* info); /// @copydoc dlaf_pspotrf -DLAF_EXTERN_C void dlaf_pdpotrf(char uplo, int n, double* a, int ia, int ja, int* desca, int* info); +DLAF_EXTERN_C void dlaf_pdpotrf(const char uplo, const int n, double* a, const int ia, const int ja, + const int desca[9], int* info); /// @copydoc dlaf_pspotrf -DLAF_EXTERN_C void dlaf_pcpotrf(char uplo, int n, dlaf_complex_c* a, int ia, int ja, int* desca, - int* info); +DLAF_EXTERN_C void dlaf_pcpotrf(const char uplo, const int n, dlaf_complex_c* a, const int ia, + const int ja, const int desca[9], int* info); /// @copydoc dlaf_pspotrf -DLAF_EXTERN_C void dlaf_pzpotrf(char uplo, int n, dlaf_complex_z* a, int ia, int ja, int* desca, - int* info); +DLAF_EXTERN_C void dlaf_pzpotrf(const char uplo, const int n, dlaf_complex_z* a, const int ia, + const int ja, const int desca[9], int* info); #endif diff --git a/include/dlaf_c/utils.h b/include/dlaf_c/utils.h index 43cbd18897..b66ccd4ea3 100644 --- a/include/dlaf_c/utils.h +++ b/include/dlaf_c/utils.h @@ -38,4 +38,5 @@ typedef double complex dlaf_complex_z; ///< Double precision complex number /// @param j Column index in the global matrix indicating the first colum index of the submatrix /// @param desc ScaLAPACK descriptor /// @return DLA-Future descriptor -DLAF_EXTERN_C struct DLAF_descriptor make_dlaf_descriptor(int m, int n, int i, int j, int* desc); +DLAF_EXTERN_C struct DLAF_descriptor make_dlaf_descriptor(const int m, const int n, const int i, + const int j, const int desc[9]); diff --git a/src/c_api/eigensolver/eigensolver.cpp b/src/c_api/eigensolver/eigensolver.cpp index 9a0dc45237..cf8aa02ab6 100644 --- a/src/c_api/eigensolver/eigensolver.cpp +++ b/src/c_api/eigensolver/eigensolver.cpp @@ -16,45 +16,52 @@ #include #include -int dlaf_eigensolver_s(int dlaf_context, char uplo, float* a, struct DLAF_descriptor dlaf_desca, - float* w, float* z, struct DLAF_descriptor dlaf_descz) { +int dlaf_eigensolver_s(const int dlaf_context, const char uplo, float* a, + const struct DLAF_descriptor dlaf_desca, float* w, float* z, + const struct DLAF_descriptor dlaf_descz) { return eigensolver(dlaf_context, uplo, a, dlaf_desca, w, z, dlaf_descz); } -int dlaf_eigensolver_d(int dlaf_context, char uplo, double* a, struct DLAF_descriptor dlaf_desca, - double* w, double* z, struct DLAF_descriptor dlaf_descz) { +int dlaf_eigensolver_d(const int dlaf_context, const char uplo, double* a, + const struct DLAF_descriptor dlaf_desca, double* w, double* z, + const struct DLAF_descriptor dlaf_descz) { return eigensolver(dlaf_context, uplo, a, dlaf_desca, w, z, dlaf_descz); } -int dlaf_eigensolver_c(int dlaf_context, char uplo, dlaf_complex_c* a, struct DLAF_descriptor dlaf_desca, - float* w, dlaf_complex_c* z, struct DLAF_descriptor dlaf_descz) { +int dlaf_eigensolver_c(const int dlaf_context, const char uplo, dlaf_complex_c* a, + const struct DLAF_descriptor dlaf_desca, float* w, dlaf_complex_c* z, + const struct DLAF_descriptor dlaf_descz) { return eigensolver>(dlaf_context, uplo, a, dlaf_desca, w, z, dlaf_descz); } -int dlaf_eigensolver_z(int dlaf_context, char uplo, dlaf_complex_z* a, struct DLAF_descriptor dlaf_desca, - double* w, dlaf_complex_z* z, struct DLAF_descriptor dlaf_descz) { +int dlaf_eigensolver_z(const int dlaf_context, const char uplo, dlaf_complex_z* a, + const struct DLAF_descriptor dlaf_desca, double* w, dlaf_complex_z* z, + const struct DLAF_descriptor dlaf_descz) { return eigensolver>(dlaf_context, uplo, a, dlaf_desca, w, z, dlaf_descz); } #ifdef DLAF_WITH_SCALAPACK -void dlaf_pssyevd(char uplo, int m, float* a, int ia, int ja, int* desca, float* w, float* z, int iz, - int jz, int* descz, int* info) { +void dlaf_pssyevd(const char uplo, const int m, float* a, const int ia, const int ja, const int desca[9], + float* w, float* z, const int iz, const int jz, const int descz[9], int* info) { pxheevd(uplo, m, a, ia, ja, desca, w, z, iz, jz, descz, *info); } -void dlaf_pdsyevd(char uplo, int m, double* a, int ia, int ja, int* desca, double* w, double* z, int iz, - int jz, int* descz, int* info) { +void dlaf_pdsyevd(const char uplo, const int m, double* a, const int ia, const int ja, + const int desca[9], double* w, double* z, const int iz, const int jz, + const int descz[9], int* info) { pxheevd(uplo, m, a, ia, ja, desca, w, z, iz, jz, descz, *info); } -void dlaf_pcheevd(char uplo, int m, dlaf_complex_c* a, int ia, int ja, int* desca, float* w, - dlaf_complex_c* z, int iz, int jz, int* descz, int* info) { +void dlaf_pcheevd(const char uplo, const int m, dlaf_complex_c* a, const int ia, const int ja, + const int desca[9], float* w, dlaf_complex_c* z, const int iz, const int jz, + const int descz[9], int* info) { pxheevd>(uplo, m, a, ia, ja, desca, w, z, iz, jz, descz, *info); } -void dlaf_pzheevd(char uplo, int m, dlaf_complex_z* a, int ia, int ja, int* desca, double* w, - dlaf_complex_z* z, int iz, int jz, int* descz, int* info) { +void dlaf_pzheevd(const char uplo, const int m, dlaf_complex_z* a, const int ia, const int ja, + const int desca[9], double* w, dlaf_complex_z* z, const int iz, const int jz, + const int descz[9], int* info) { pxheevd>(uplo, m, a, ia, ja, desca, w, z, iz, jz, descz, *info); } diff --git a/src/c_api/eigensolver/eigensolver.h b/src/c_api/eigensolver/eigensolver.h index 8117273e46..9e8ceb3c38 100644 --- a/src/c_api/eigensolver/eigensolver.h +++ b/src/c_api/eigensolver/eigensolver.h @@ -28,8 +28,8 @@ #include "../utils.h" template -int eigensolver(int dlaf_context, char uplo, T* a, DLAF_descriptor dlaf_desca, dlaf::BaseType* w, - T* z, DLAF_descriptor dlaf_descz) { +int eigensolver(const int dlaf_context, const char uplo, T* a, const DLAF_descriptor dlaf_desca, + dlaf::BaseType* w, T* z, const DLAF_descriptor dlaf_descz) { using MatrixHost = dlaf::matrix::Matrix; using MatrixMirror = dlaf::matrix::MatrixMirror; using MatrixBaseMirror = @@ -73,8 +73,8 @@ int eigensolver(int dlaf_context, char uplo, T* a, DLAF_descriptor dlaf_desca, d #ifdef DLAF_WITH_SCALAPACK template -void pxheevd(char uplo, int m, T* a, int ia, int ja, int* desca, dlaf::BaseType* w, T* z, int iz, - int jz, int* descz, int& info) { +void pxheevd(const char uplo, const int m, T* a, const int ia, const int ja, const int desca[9], + dlaf::BaseType* w, T* z, const int iz, int jz, const int descz[9], int& info) { DLAF_ASSERT(desca[0] == 1, desca[0]); DLAF_ASSERT(descz[0] == 1, descz[0]); DLAF_ASSERT(desca[1] == descz[1], desca[1], descz[1]); diff --git a/src/c_api/factorization/cholesky.cpp b/src/c_api/factorization/cholesky.cpp index 842422512e..a556750243 100644 --- a/src/c_api/factorization/cholesky.cpp +++ b/src/c_api/factorization/cholesky.cpp @@ -13,37 +13,45 @@ #include #include -int dlaf_cholesky_s(int dlaf_context, char uplo, float* a, DLAF_descriptor dlaf_desca) { +int dlaf_cholesky_s(const int dlaf_context, const char uplo, float* a, + const DLAF_descriptor dlaf_desca) { return cholesky(dlaf_context, uplo, a, dlaf_desca); } -int dlaf_cholesky_d(int dlaf_context, char uplo, double* a, DLAF_descriptor dlaf_desca) { +int dlaf_cholesky_d(const int dlaf_context, const char uplo, double* a, + const DLAF_descriptor dlaf_desca) { return cholesky(dlaf_context, uplo, a, dlaf_desca); } -int dlaf_cholesky_c(int dlaf_context, char uplo, dlaf_complex_c* a, DLAF_descriptor dlaf_desca) { +int dlaf_cholesky_c(const int dlaf_context, const char uplo, dlaf_complex_c* a, + const DLAF_descriptor dlaf_desca) { return cholesky>(dlaf_context, uplo, a, dlaf_desca); } -int dlaf_cholesky_z(int dlaf_context, char uplo, dlaf_complex_z* a, DLAF_descriptor dlaf_desca) { +int dlaf_cholesky_z(const int dlaf_context, const char uplo, dlaf_complex_z* a, + const DLAF_descriptor dlaf_desca) { return cholesky>(dlaf_context, uplo, a, dlaf_desca); } #ifdef DLAF_WITH_SCALAPACK -void dlaf_pspotrf(char uplo, int n, float* a, int ia, int ja, int* desca, int* info) { +void dlaf_pspotrf(const char uplo, const int n, float* a, const int ia, const int ja, const int desca[9], + int* info) { pxpotrf(uplo, n, a, ia, ja, desca, *info); } -void dlaf_pdpotrf(char uplo, int n, double* a, int ia, int ja, int* desca, int* info) { +void dlaf_pdpotrf(const char uplo, const int n, double* a, const int ia, const int ja, + const int desca[9], int* info) { pxpotrf(uplo, n, a, ia, ja, desca, *info); } -void dlaf_pcpotrf(char uplo, int n, dlaf_complex_c* a, int ia, int ja, int* desca, int* info) { +void dlaf_pcpotrf(const char uplo, const int n, dlaf_complex_c* a, const int ia, const int ja, + const int desca[9], int* info) { pxpotrf>(uplo, n, a, ia, ja, desca, *info); } -void dlaf_pzpotrf(char uplo, int n, dlaf_complex_z* a, int ia, int ja, int* desca, int* info) { +void dlaf_pzpotrf(const char uplo, const int n, dlaf_complex_z* a, const int ia, const int ja, + const int desca[9], int* info) { pxpotrf>(uplo, n, a, ia, ja, desca, *info); } diff --git a/src/c_api/factorization/cholesky.h b/src/c_api/factorization/cholesky.h index d6d9f3dfe4..4d3a42662e 100644 --- a/src/c_api/factorization/cholesky.h +++ b/src/c_api/factorization/cholesky.h @@ -28,7 +28,7 @@ #include "../utils.h" template -int cholesky(int dlaf_context, char uplo, T* a, DLAF_descriptor dlaf_desca) { +int cholesky(const int dlaf_context, const char uplo, T* a, const DLAF_descriptor dlaf_desca) { using MatrixMirror = dlaf::matrix::MatrixMirror; DLAF_ASSERT(dlaf_desca.i == 0, dlaf_desca.i); @@ -59,7 +59,8 @@ int cholesky(int dlaf_context, char uplo, T* a, DLAF_descriptor dlaf_desca) { #ifdef DLAF_WITH_SCALAPACK template -void pxpotrf(char uplo, int n, T* a, int ia, int ja, int* desca, int& info) { +void pxpotrf(const char uplo, const int n, T* a, const int ia, const int ja, const int desca[9], + int& info) { DLAF_ASSERT(desca[0] == 1, desca[0]); DLAF_ASSERT(ia == 1, ia); DLAF_ASSERT(ja == 1, ja); diff --git a/src/c_api/utils.cpp b/src/c_api/utils.cpp index 7b7c1e69b7..7319d2fe19 100644 --- a/src/c_api/utils.cpp +++ b/src/c_api/utils.cpp @@ -14,7 +14,8 @@ #include #include -struct DLAF_descriptor make_dlaf_descriptor(int m, int n, int i, int j, int* desc) { +struct DLAF_descriptor make_dlaf_descriptor(const int m, const int n, const int i, const int j, + const int desc[9]) { DLAF_ASSERT(i == 1, i); DLAF_ASSERT(j == 1, j); @@ -24,7 +25,7 @@ struct DLAF_descriptor make_dlaf_descriptor(int m, int n, int i, int j, int* des } std::tuple distribution_and_layout( - struct DLAF_descriptor dlaf_desc, dlaf::comm::CommunicatorGrid& grid) { + const struct DLAF_descriptor dlaf_desc, dlaf::comm::CommunicatorGrid& grid) { dlaf::GlobalElementSize matrix_size(dlaf_desc.m, dlaf_desc.n); dlaf::TileElementSize block_size(dlaf_desc.mb, dlaf_desc.nb); @@ -38,7 +39,7 @@ std::tuple distribution_an return std::make_tuple(distribution, layout); } -dlaf::common::Ordering char2order(char order) { +dlaf::common::Ordering char2order(const char order) { return order == 'C' or order == 'c' ? dlaf::common::Ordering::ColumnMajor : dlaf::common::Ordering::RowMajor; } diff --git a/src/c_api/utils.h b/src/c_api/utils.h index 700c0696e0..4a834fce41 100644 --- a/src/c_api/utils.h +++ b/src/c_api/utils.h @@ -13,6 +13,6 @@ #include std::tuple distribution_and_layout( - struct DLAF_descriptor dlaf_desc, dlaf::comm::CommunicatorGrid& grid); + const struct DLAF_descriptor dlaf_desc, dlaf::comm::CommunicatorGrid& grid); -dlaf::common::Ordering char2order(char order); +dlaf::common::Ordering char2order(const char order);