Skip to content

Commit

Permalink
improve const-correctness and improve some arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
RMeli committed Jul 26, 2023
1 parent 7220ac6 commit 15b864c
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 70 deletions.
44 changes: 24 additions & 20 deletions include/dlaf_c/eigensolver/eigensolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
30 changes: 16 additions & 14 deletions include/dlaf_c/factorization/cholesky.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
3 changes: 2 additions & 1 deletion include/dlaf_c/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
39 changes: 23 additions & 16 deletions src/c_api/eigensolver/eigensolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,52 @@
#include <dlaf_c/init.h>
#include <dlaf_c/utils.h>

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<float>(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<double>(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<std::complex<float>>(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<std::complex<double>>(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<float>(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<double>(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<std::complex<float>>(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<std::complex<double>>(uplo, m, a, ia, ja, desca, w, z, iz, jz, descz, *info);
}

Expand Down
8 changes: 4 additions & 4 deletions src/c_api/eigensolver/eigensolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include "../utils.h"

template <typename T>
int eigensolver(int dlaf_context, char uplo, T* a, DLAF_descriptor dlaf_desca, dlaf::BaseType<T>* 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<T>* w, T* z, const DLAF_descriptor dlaf_descz) {
using MatrixHost = dlaf::matrix::Matrix<T, dlaf::Device::CPU>;
using MatrixMirror = dlaf::matrix::MatrixMirror<T, dlaf::Device::Default, dlaf::Device::CPU>;
using MatrixBaseMirror =
Expand Down Expand Up @@ -73,8 +73,8 @@ int eigensolver(int dlaf_context, char uplo, T* a, DLAF_descriptor dlaf_desca, d
#ifdef DLAF_WITH_SCALAPACK

template <typename T>
void pxheevd(char uplo, int m, T* a, int ia, int ja, int* desca, dlaf::BaseType<T>* 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<T>* 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]);
Expand Down
24 changes: 16 additions & 8 deletions src/c_api/factorization/cholesky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,45 @@
#include <dlaf_c/factorization/cholesky.h>
#include <dlaf_c/utils.h>

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<float>(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<double>(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<std::complex<float>>(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<std::complex<double>>(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<float>(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<double>(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<std::complex<float>>(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<std::complex<double>>(uplo, n, a, ia, ja, desca, *info);
}

Expand Down
5 changes: 3 additions & 2 deletions src/c_api/factorization/cholesky.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "../utils.h"

template <typename T>
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<T, dlaf::Device::Default, dlaf::Device::CPU>;

DLAF_ASSERT(dlaf_desca.i == 0, dlaf_desca.i);
Expand Down Expand Up @@ -59,7 +59,8 @@ int cholesky(int dlaf_context, char uplo, T* a, DLAF_descriptor dlaf_desca) {
#ifdef DLAF_WITH_SCALAPACK

template <typename T>
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);
Expand Down
7 changes: 4 additions & 3 deletions src/c_api/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include <dlaf_c/desc.h>
#include <dlaf_c/utils.h>

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);

Expand All @@ -24,7 +25,7 @@ struct DLAF_descriptor make_dlaf_descriptor(int m, int n, int i, int j, int* des
}

std::tuple<dlaf::matrix::Distribution, dlaf::matrix::LayoutInfo> 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);

Expand All @@ -38,7 +39,7 @@ std::tuple<dlaf::matrix::Distribution, dlaf::matrix::LayoutInfo> 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;
}
4 changes: 2 additions & 2 deletions src/c_api/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
#include <dlaf/matrix/layout_info.h>

std::tuple<dlaf::matrix::Distribution, dlaf::matrix::LayoutInfo> 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);

0 comments on commit 15b864c

Please sign in to comment.