Skip to content

Commit

Permalink
Support for Microsoft's non-standard complex types (#334)
Browse files Browse the repository at this point in the history
Replaced _Complex types with a_fcomplex and a_dcomplex in all C/C++ files.
Replaced uses of I and _Complex_I with the CMPLXand CMPLXF constructors.
For MSVC, defined those constructors as macros that call MSVC's functions.
Updated the CHANGES file.
  • Loading branch information
juanjosegarciaripoll authored Jun 18, 2022
1 parent 51249eb commit d3cec6d
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 105 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ arpack-ng - 3.9.0
* CMake: Handle libraries without "lib" prefix.
* CMake: Don't override BLAS/LAPACK/MPI flags. Directly use results from the Find* modules instead.

[ Juan José García-Ripoll ]
* Adapt the C/C++ interface to accept also MSVC's non-standard complex types.

-- Sylvestre Ledru <[email protected]> Mon, 07 Dec 2020 11:37:40 +0100

arpack-ng - 3.8.0
Expand Down
32 changes: 16 additions & 16 deletions EXAMPLES/MATRIX_MARKET/arpackSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,18 +437,18 @@ class arpackSolver {
a_int ldv, a_int * iparam, a_int * ipntr, complex<float> * workd, complex<float> * workl, a_int lworkl, float * & rwork,
a_int * info) {
if (!rwork) rwork = new float[nbCV];
cnaupd_c(ido, bMat, nbDim, which, nbEV, tol, reinterpret_cast<_Complex float*>(resid), nbCV,
reinterpret_cast<_Complex float*>(v), ldv, iparam, ipntr, reinterpret_cast<_Complex float*>(workd),
reinterpret_cast<_Complex float*>(workl), lworkl, rwork, info);
cnaupd_c(ido, bMat, nbDim, which, nbEV, tol, reinterpret_cast<a_fcomplex*>(resid), nbCV,
reinterpret_cast<a_fcomplex*>(v), ldv, iparam, ipntr, reinterpret_cast<a_fcomplex*>(workd),
reinterpret_cast<a_fcomplex*>(workl), lworkl, rwork, info);
};

void aupd(a_int * ido, char const * bMat, a_int nbDim, char const * which, complex<double> * resid, complex<double> * v,
a_int ldv, a_int * iparam, a_int * ipntr, complex<double> * workd, complex<double> * workl, a_int lworkl, double * & rwork,
a_int * info) {
if (!rwork) rwork = new double[nbCV];
znaupd_c(ido, bMat, nbDim, which, nbEV, tol, reinterpret_cast<_Complex double*>(resid), nbCV,
reinterpret_cast<_Complex double*>(v), ldv, iparam, ipntr, reinterpret_cast<_Complex double*>(workd),
reinterpret_cast<_Complex double*>(workl), lworkl, rwork, info);
znaupd_c(ido, bMat, nbDim, which, nbEV, tol, reinterpret_cast<a_dcomplex*>(resid), nbCV,
reinterpret_cast<a_dcomplex*>(v), ldv, iparam, ipntr, reinterpret_cast<a_dcomplex*>(workd),
reinterpret_cast<a_dcomplex*>(workl), lworkl, rwork, info);
};

void spectrum(RC * d, RC * z, a_int nbDim, a_int * iparam) {
Expand Down Expand Up @@ -589,11 +589,11 @@ class arpackSolver {
complex<float> * workev = new complex<float>[2*nbCV];

complex<float> sigma = complex<float>((float) sigmaReal, (float) sigmaImag);
cneupd_c(rvec, howmny, select, reinterpret_cast<_Complex float*>(d), reinterpret_cast<_Complex float*>(z), ldz,
reinterpret_cast<_Complex float &>(sigma), reinterpret_cast<_Complex float*>(workev),
bMat, nbDim, which, nbEV, tol, reinterpret_cast<_Complex float*>(resid), nbCV,
reinterpret_cast<_Complex float*>(v), ldv, iparam, ipntr,
reinterpret_cast<_Complex float*>(workd), reinterpret_cast<_Complex float*>(workl), lworkl, rwork, &info);
cneupd_c(rvec, howmny, select, reinterpret_cast<a_fcomplex*>(d), reinterpret_cast<a_fcomplex*>(z), ldz,
reinterpret_cast<a_fcomplex &>(sigma), reinterpret_cast<a_fcomplex*>(workev),
bMat, nbDim, which, nbEV, tol, reinterpret_cast<a_fcomplex*>(resid), nbCV,
reinterpret_cast<a_fcomplex*>(v), ldv, iparam, ipntr,
reinterpret_cast<a_fcomplex*>(workd), reinterpret_cast<a_fcomplex*>(workl), lworkl, rwork, &info);
if (info == -14) cerr << "Error: zneupd - KO: dsaupd did not find any eigenvalues to sufficient accuracy" << endl;
if (info < 0 && info != -14 /*-14: don't break*/) {cerr << "Error: zneupd - KO with info " << info << endl; return 1;}

Expand All @@ -613,11 +613,11 @@ class arpackSolver {
complex<double> * workev = new complex<double>[2*nbCV];

complex<double> sigma = complex<double>(sigmaReal, sigmaImag);
zneupd_c(rvec, howmny, select, reinterpret_cast<_Complex double*>(d), reinterpret_cast<_Complex double*>(z), ldz,
reinterpret_cast<_Complex double &>(sigma), reinterpret_cast<_Complex double*>(workev),
bMat, nbDim, which, nbEV, tol, reinterpret_cast<_Complex double*>(resid), nbCV,
reinterpret_cast<_Complex double*>(v), ldv, iparam, ipntr,
reinterpret_cast<_Complex double*>(workd), reinterpret_cast<_Complex double*>(workl), lworkl, rwork, &info);
zneupd_c(rvec, howmny, select, reinterpret_cast<a_dcomplex*>(d), reinterpret_cast<a_dcomplex*>(z), ldz,
reinterpret_cast<a_dcomplex &>(sigma), reinterpret_cast<a_dcomplex*>(workev),
bMat, nbDim, which, nbEV, tol, reinterpret_cast<a_dcomplex*>(resid), nbCV,
reinterpret_cast<a_dcomplex*>(v), ldv, iparam, ipntr,
reinterpret_cast<a_dcomplex*>(workd), reinterpret_cast<a_dcomplex*>(workl), lworkl, rwork, &info);
if (info == -14) cerr << "Error: zneupd - KO: dsaupd did not find any eigenvalues to sufficient accuracy" << endl;
if (info < 0 && info != -14 /*-14: don't break*/) {cerr << "Error: zneupd - KO with info " << info << endl; return 1;}

Expand Down
8 changes: 4 additions & 4 deletions ICB/arpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
extern "C" {
#endif

void cnaupd_c(a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, float tol, float _Complex* resid, a_int ncv, float _Complex* v, a_int ldv, a_int* iparam, a_int* ipntr, float _Complex* workd, float _Complex* workl, a_int lworkl, float* rwork, a_int* info);
void cneupd_c(a_int rvec, char const* howmny, a_int const* select, float _Complex* d, float _Complex* z, a_int ldz, float _Complex sigma, float _Complex* workev, char const* bmat, a_int n, char const* which, a_int nev, float tol, float _Complex* resid, a_int ncv, float _Complex* v, a_int ldv, a_int* iparam, a_int* ipntr, float _Complex* workd, float _Complex* workl, a_int lworkl, float* rwork, a_int* info);
void cnaupd_c(a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, float tol, a_fcomplex* resid, a_int ncv, a_fcomplex* v, a_int ldv, a_int* iparam, a_int* ipntr, a_fcomplex* workd, a_fcomplex* workl, a_int lworkl, float* rwork, a_int* info);
void cneupd_c(a_int rvec, char const* howmny, a_int const* select, a_fcomplex* d, a_fcomplex* z, a_int ldz, a_fcomplex sigma, a_fcomplex* workev, char const* bmat, a_int n, char const* which, a_int nev, float tol, a_fcomplex* resid, a_int ncv, a_fcomplex* v, a_int ldv, a_int* iparam, a_int* ipntr, a_fcomplex* workd, a_fcomplex* workl, a_int lworkl, float* rwork, a_int* info);
void dnaupd_c(a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, double tol, double* resid, a_int ncv, double* v, a_int ldv, a_int* iparam, a_int* ipntr, double* workd, double* workl, a_int lworkl, a_int* info);
void dneupd_c(a_int rvec, char const* howmny, a_int const* select, double* dr, double* di, double* z, a_int ldz, double sigmar, double sigmai, double * workev, char const* bmat, a_int n, char const* which, a_int nev, double tol, double* resid, a_int ncv, double* v, a_int ldv, a_int* iparam, a_int* ipntr, double* workd, double* workl, a_int lworkl, a_int* info);
void dsaupd_c(a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, double tol, double* resid, a_int ncv, double* v, a_int ldv, a_int* iparam, a_int* ipntr, double* workd, double* workl, a_int lworkl, a_int* info);
Expand All @@ -17,8 +17,8 @@ void snaupd_c(a_int* ido, char const* bmat, a_int n, char const* which, a_int ne
void sneupd_c(a_int rvec, char const* howmny, a_int const* select, float* dr, float* di, float* z, a_int ldz, float sigmar, float sigmai, float * workev, char const* bmat, a_int n, char const* which, a_int nev, float tol, float* resid, a_int ncv, float* v, a_int ldv, a_int* iparam, a_int* ipntr, float* workd, float* workl, a_int lworkl, a_int* info);
void ssaupd_c(a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, float tol, float* resid, a_int ncv, float* v, a_int ldv, a_int* iparam, a_int* ipntr, float* workd, float* workl, a_int lworkl, a_int* info);
void sseupd_c(a_int rvec, char const* howmny, a_int const* select, float* d, float* z, a_int ldz, float sigma, char const* bmat, a_int n, char const* which, a_int nev, float tol, float* resid, a_int ncv, float* v, a_int ldv, a_int* iparam, a_int* ipntr, float* workd, float* workl, a_int lworkl, a_int* info);
void znaupd_c(a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, double tol, double _Complex* resid, a_int ncv, double _Complex* v, a_int ldv, a_int* iparam, a_int* ipntr, double _Complex* workd, double _Complex* workl, a_int lworkl, double* rwork, a_int* info);
void zneupd_c(a_int rvec, char const* howmny, a_int const* select, double _Complex* d, double _Complex* z, a_int ldz, double _Complex sigma, double _Complex* workev, char const* bmat, a_int n, char const* which, a_int nev, double tol, double _Complex* resid, a_int ncv, double _Complex* v, a_int ldv, a_int* iparam, a_int* ipntr, double _Complex* workd, double _Complex* workl, a_int lworkl, double* rwork, a_int* info);
void znaupd_c(a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, double tol, a_dcomplex* resid, a_int ncv, a_dcomplex* v, a_int ldv, a_int* iparam, a_int* ipntr, a_dcomplex* workd, a_dcomplex* workl, a_int lworkl, double* rwork, a_int* info);
void zneupd_c(a_int rvec, char const* howmny, a_int const* select, a_dcomplex* d, a_dcomplex* z, a_int ldz, a_dcomplex sigma, a_dcomplex* workev, char const* bmat, a_int n, char const* which, a_int nev, double tol, a_dcomplex* resid, a_int ncv, a_dcomplex* v, a_int ldv, a_int* iparam, a_int* ipntr, a_dcomplex* workd, a_dcomplex* workl, a_int lworkl, double* rwork, a_int* info);

#ifdef __cplusplus
}
Expand Down
48 changes: 24 additions & 24 deletions ICB/arpack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ inline void naupd(a_int& ido, bmat const bmat_option, a_int n,
float* rwork, a_int& info) {
internal::cnaupd_c(&ido, internal::convert_to_char(bmat_option), n,
internal::convert_to_char(ritz_option), nev, tol,
reinterpret_cast<_Complex float*>(resid), ncv,
reinterpret_cast<_Complex float*>(v), ldv, iparam, ipntr,
reinterpret_cast<_Complex float*>(workd),
reinterpret_cast<_Complex float*>(workl), lworkl,
reinterpret_cast<a_fcomplex*>(resid), ncv,
reinterpret_cast<a_fcomplex*>(v), ldv, iparam, ipntr,
reinterpret_cast<a_fcomplex*>(workd),
reinterpret_cast<a_fcomplex*>(workl), lworkl,
rwork, &info);
}

Expand All @@ -203,16 +203,16 @@ inline void neupd(a_int rvec, howmny const howmny_option, a_int* select,
a_int lworkl, float* rwork, a_int& info) {
std::complex<float> sigma2 = sigma;
internal::cneupd_c(rvec, internal::convert_to_char(howmny_option), select,
reinterpret_cast<_Complex float*>(d),
reinterpret_cast<_Complex float*>(z), ldz,
*reinterpret_cast<_Complex float*>(&sigma2),
reinterpret_cast<_Complex float*>(workev),
reinterpret_cast<a_fcomplex*>(d),
reinterpret_cast<a_fcomplex*>(z), ldz,
*reinterpret_cast<a_fcomplex*>(&sigma2),
reinterpret_cast<a_fcomplex*>(workev),
internal::convert_to_char(bmat_option), n,
internal::convert_to_char(ritz_option), nev, tol,
reinterpret_cast<_Complex float*>(resid), ncv,
reinterpret_cast<_Complex float*>(v), ldv, iparam, ipntr,
reinterpret_cast<_Complex float*>(workd),
reinterpret_cast<_Complex float*>(workl), lworkl,
reinterpret_cast<a_fcomplex*>(resid), ncv,
reinterpret_cast<a_fcomplex*>(v), ldv, iparam, ipntr,
reinterpret_cast<a_fcomplex*>(workd),
reinterpret_cast<a_fcomplex*>(workl), lworkl,
rwork, &info);
}

Expand All @@ -224,10 +224,10 @@ inline void naupd(a_int& ido, bmat const bmat_option, a_int n,
double* rwork, a_int& info) {
internal::znaupd_c(&ido, internal::convert_to_char(bmat_option), n,
internal::convert_to_char(ritz_option), nev, tol,
reinterpret_cast<_Complex double*>(resid), ncv,
reinterpret_cast<_Complex double*>(v), ldv, iparam, ipntr,
reinterpret_cast<_Complex double*>(workd),
reinterpret_cast<_Complex double*>(workl), lworkl,
reinterpret_cast<a_dcomplex*>(resid), ncv,
reinterpret_cast<a_dcomplex*>(v), ldv, iparam, ipntr,
reinterpret_cast<a_dcomplex*>(workd),
reinterpret_cast<a_dcomplex*>(workl), lworkl,
rwork, &info);
}

Expand All @@ -241,16 +241,16 @@ inline void neupd(a_int rvec, howmny const howmny_option, a_int* select,
a_int lworkl, double* rwork, a_int& info) {
std::complex<double> sigma2 = sigma;
internal::zneupd_c(rvec, internal::convert_to_char(howmny_option), select,
reinterpret_cast<_Complex double*>(d),
reinterpret_cast<_Complex double*>(z), ldz,
*reinterpret_cast<_Complex double*>(&sigma2),
reinterpret_cast<_Complex double*>(workev),
reinterpret_cast<a_dcomplex*>(d),
reinterpret_cast<a_dcomplex*>(z), ldz,
*reinterpret_cast<a_dcomplex*>(&sigma2),
reinterpret_cast<a_dcomplex*>(workev),
internal::convert_to_char(bmat_option), n,
internal::convert_to_char(ritz_option), nev, tol,
reinterpret_cast<_Complex double*>(resid), ncv,
reinterpret_cast<_Complex double*>(v), ldv, iparam, ipntr,
reinterpret_cast<_Complex double*>(workd),
reinterpret_cast<_Complex double*>(workl), lworkl,
reinterpret_cast<a_dcomplex*>(resid), ncv,
reinterpret_cast<a_dcomplex*>(v), ldv, iparam, ipntr,
reinterpret_cast<a_dcomplex*>(workd),
reinterpret_cast<a_dcomplex*>(workl), lworkl,
rwork, &info);
}
} // namespace arpack
Expand Down
8 changes: 4 additions & 4 deletions ICB/parpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
extern "C" {
#endif

void pcnaupd_c(MPI_Fint comm, a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, float tol, float _Complex* resid, a_int ncv, float _Complex* v, a_int ldv, a_int* iparam, a_int* ipntr, float _Complex* workd, float _Complex* workl, a_int lworkl, float _Complex* rwork, a_int* info);
void pcneupd_c(MPI_Fint comm, a_int rvec, char const* howmny, a_int const* select, float _Complex* d, float _Complex* z, a_int ldz, float _Complex sigma, float _Complex* workev, char const* bmat, a_int n, char const* which, a_int nev, float tol, float _Complex* resid, a_int ncv, float _Complex* v, a_int ldv, a_int* iparam, a_int* ipntr, float _Complex* workd, float _Complex* workl, a_int lworkl, float _Complex* rwork, a_int* info);
void pcnaupd_c(MPI_Fint comm, a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, float tol, a_fcomplex* resid, a_int ncv, a_fcomplex* v, a_int ldv, a_int* iparam, a_int* ipntr, a_fcomplex* workd, a_fcomplex* workl, a_int lworkl, a_fcomplex* rwork, a_int* info);
void pcneupd_c(MPI_Fint comm, a_int rvec, char const* howmny, a_int const* select, a_fcomplex* d, a_fcomplex* z, a_int ldz, a_fcomplex sigma, a_fcomplex* workev, char const* bmat, a_int n, char const* which, a_int nev, float tol, a_fcomplex* resid, a_int ncv, a_fcomplex* v, a_int ldv, a_int* iparam, a_int* ipntr, a_fcomplex* workd, a_fcomplex* workl, a_int lworkl, a_fcomplex* rwork, a_int* info);
void pdnaupd_c(MPI_Fint comm, a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, double tol, double* resid, a_int ncv, double* v, a_int ldv, a_int* iparam, a_int* ipntr, double* workd, double* workl, a_int lworkl, a_int* info);
void pdneupd_c(MPI_Fint comm, a_int rvec, char const* howmny, a_int const* select, double* dr, double* di, double* z, a_int ldz, double sigmar, double sigmai, double * workev, char const* bmat, a_int n, char const* which, a_int nev, double tol, double* resid, a_int ncv, double* v, a_int ldv, a_int* iparam, a_int* ipntr, double* workd, double* workl, a_int lworkl, a_int* info);
void pdsaupd_c(MPI_Fint comm, a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, double tol, double* resid, a_int ncv, double* v, a_int ldv, a_int* iparam, a_int* ipntr, double* workd, double* workl, a_int lworkl, a_int* info);
Expand All @@ -24,8 +24,8 @@ void psnaupd_c(MPI_Fint comm, a_int* ido, char const* bmat, a_int n, char const*
void psneupd_c(MPI_Fint comm, a_int rvec, char const* howmny, a_int const* select, float* dr, float* di, float* z, a_int ldz, float sigmar, float sigmai, float * workev, char const* bmat, a_int n, char const* which, a_int nev, float tol, float* resid, a_int ncv, float* v, a_int ldv, a_int* iparam, a_int* ipntr, float* workd, float* workl, a_int lworkl, a_int* info);
void pssaupd_c(MPI_Fint comm, a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, float tol, float* resid, a_int ncv, float* v, a_int ldv, a_int* iparam, a_int* ipntr, float* workd, float* workl, a_int lworkl, a_int* info);
void psseupd_c(MPI_Fint comm, a_int rvec, char const* howmny, a_int const* select, float* d, float* z, a_int ldz, float sigma, char const* bmat, a_int n, char const* which, a_int nev, float tol, float* resid, a_int ncv, float* v, a_int ldv, a_int* iparam, a_int* ipntr, float* workd, float* workl, a_int lworkl, a_int* info);
void pznaupd_c(MPI_Fint comm, a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, double tol, double _Complex* resid, a_int ncv, double _Complex* v, a_int ldv, a_int* iparam, a_int* ipntr, double _Complex* workd, double _Complex* workl, a_int lworkl, double _Complex* rwork, a_int* info);
void pzneupd_c(MPI_Fint comm, a_int rvec, char const* howmny, a_int const* select, double _Complex* d, double _Complex* z, a_int ldz, double _Complex sigma, double _Complex* workev, char const* bmat, a_int n, char const* which, a_int nev, double tol, double _Complex* resid, a_int ncv, double _Complex* v, a_int ldv, a_int* iparam, a_int* ipntr, double _Complex* workd, double _Complex* workl, a_int lworkl, double _Complex* rwork, a_int* info);
void pznaupd_c(MPI_Fint comm, a_int* ido, char const* bmat, a_int n, char const* which, a_int nev, double tol, a_dcomplex* resid, a_int ncv, a_dcomplex* v, a_int ldv, a_int* iparam, a_int* ipntr, a_dcomplex* workd, a_dcomplex* workl, a_int lworkl, a_dcomplex* rwork, a_int* info);
void pzneupd_c(MPI_Fint comm, a_int rvec, char const* howmny, a_int const* select, a_dcomplex* d, a_dcomplex* z, a_int ldz, a_dcomplex sigma, a_dcomplex* workev, char const* bmat, a_int n, char const* which, a_int nev, double tol, a_dcomplex* resid, a_int ncv, a_dcomplex* v, a_int ldv, a_int* iparam, a_int* ipntr, a_dcomplex* workd, a_dcomplex* workl, a_int lworkl, a_dcomplex* rwork, a_int* info);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit d3cec6d

Please sign in to comment.