diff --git a/src/NativeProviders/Common/lapack_common.h b/src/NativeProviders/Common/lapack_common.h index 5441d599..e3c596b7 100644 --- a/src/NativeProviders/Common/lapack_common.h +++ b/src/NativeProviders/Common/lapack_common.h @@ -1,63 +1,62 @@ -#ifndef LAPACK_COMMON_H -#define LAPACK_COMMON_H +#pragma once -#include +const int INSUFFICIENT_MEMORY = -999999; + +#ifndef LAPACK_MEMORY +#define LAPACK_MEMORY +#include + +template using array_ptr = std::unique_ptr; -void shift_ipiv_down(int m, int ipiv[]); -inline void shift_ipiv_down(int m, int ipiv[]){ - for(int i = 0; i < m; ++i ){ +template +inline array_ptr array_new(const int size) +{ + return array_ptr(new T[size]); +} + +#endif + +template +inline array_ptr array_clone(const int size, const T* array) +{ + auto clone = array_new(size); + memcpy(clone.get(), array, size * sizeof(T)); + return clone; +} + +inline void shift_ipiv_down(int m, int ipiv[]) +{ + for(auto i = 0; i < m; ++i ) + { ipiv[i] -= 1; } } -void shift_ipiv_up(int m, int ipiv[]); -inline void shift_ipiv_up(int m, int ipiv[]){ - for(int i = 0; i < m; ++i ){ +inline void shift_ipiv_up(int m, int ipiv[]) +{ + for(auto i = 0; i < m; ++i ) + { ipiv[i] += 1; } } template -inline T* Clone(const int m, const int n, const T* a){ - T* clone = new T[m*n]; +inline T* Clone(const int m, const int n, const T* a) +{ + auto clone = new T[m*n]; memcpy(clone, a, m*n*sizeof(T)); return clone; } template -inline void copyBtoX (int m, int n, int bn, T b[], T x[]){ - for (int i = 0; i < n; ++i) +inline void copyBtoX (int m, int n, int bn, T b[], T x[]) +{ + for (auto i = 0; i < n; ++i) { - for (int j = 0; j < bn; ++j) + for (auto j = 0; j < bn; ++j) { x[j * n + i] = b[j * m + i]; } } } -#ifndef LAPACK_MEMORY -#define LAPACK_MEMORY - -#include - -const int INSUFFICIENT_MEMORY = -999999; -const int ALIGNMENT = 64; - -template using array_ptr = std::unique_ptr; - -template -inline array_ptr array_new(const int size, int alignment = ALIGNMENT) -{ - return array_ptr(new T[size]); -} - -#endif - -template -inline array_ptr array_clone(const int size, const T* array) { - auto clone = array_new(size); - memcpy(clone.get(), array, size * sizeof(T)); - return clone; -} - -#endif \ No newline at end of file diff --git a/src/NativeProviders/MKL/lapack.h b/src/NativeProviders/MKL/lapack.h index b57ca9ee..bf9e9c45 100644 --- a/src/NativeProviders/MKL/lapack.h +++ b/src/NativeProviders/MKL/lapack.h @@ -1,15 +1,14 @@ #pragma once #include +#include + #define MKL_Complex8 std::complex #define MKL_Complex16 std::complex +#define LAPACK_MEMORY #include "mkl.h" -#define LAPACK_MEMORY -#include - -const int INSUFFICIENT_MEMORY = -999999; const int ALIGNMENT = 64; struct array_free @@ -20,9 +19,9 @@ struct array_free template using array_ptr = std::unique_ptr; template -inline array_ptr array_new(const int size, int alignment = ALIGNMENT) +inline array_ptr array_new(const int size) { - auto ret = static_cast(mkl_malloc(size * sizeof(T), alignment)); + auto ret = static_cast(mkl_malloc(size * sizeof(T), ALIGNMENT)); if (!ret) { @@ -31,4 +30,3 @@ inline array_ptr array_new(const int size, int alignment = ALIGNMENT) return array_ptr(ret); } - diff --git a/src/NativeProviders/OpenBLAS/lapack.h b/src/NativeProviders/OpenBLAS/lapack.h index 30d40bbe..3c9fe4b5 100644 --- a/src/NativeProviders/OpenBLAS/lapack.h +++ b/src/NativeProviders/OpenBLAS/lapack.h @@ -7,3 +7,5 @@ #include "cblas.h" #include "lapacke.h" + +