@@ -26,19 +26,19 @@ namespace hsolver
2626 // / type 1: directly divide each vector by the precondition vector
2727 // /---------------------------------------------------------------------------------------------
2828 template <typename T, typename Device = base_device::DEVICE_CPU>
29- void div_prevec (T* ptr , const size_t & dim, const size_t & nvec,
29+ void div_prevec (T* const dst, const T* const src , const size_t & dim, const size_t & nvec,
3030 const Real<T>* const pre )
3131 {
3232 Device* ctx = {};
33- for (int m = 0 ; m < nvec; m++)
33+ for (size_t m = 0 ; m < nvec; m++)
3434 {
35- T* const ptr_m = ptr + m * dim;
36- vector_div_vector_op<T, Device>()(ctx, dim, ptr_m, ptr_m , pre );
35+ const size_t offset = m * dim;
36+ vector_div_vector_op<T, Device>()(ctx, dim, dst + offset, src + offset , pre );
3737 }
3838 }
3939 // / Intereface to be called in the eigensolver
4040 template <typename T>
41- using Div = std::function<void (T*, const size_t &, const size_t &)>;
41+ using Div = std::function<void (T* const , const T* const , const size_t &, const size_t &)>;
4242 // Kernel function full of dependence
4343 template <typename T, typename Device = base_device::DEVICE_CPU>
4444 using DivKernel = std::function<decltype (div_prevec<T, Device>)>;
@@ -48,7 +48,7 @@ namespace hsolver
4848 // /$X \to (A-\lambda I)^{-1} X$
4949 // /---------------------------------------------------------------------------------------------
5050 template <typename T, typename Device = base_device::DEVICE_CPU>
51- void div_trans_prevec_minus_eigen (T* ptr , const Real<T>* eig, const size_t & dim, const size_t & nvec,
51+ void div_trans_prevec_minus_eigen (T* const dst, const T* const src , const Real<T>* eig, const size_t & dim, const size_t & nvec,
5252 const Real<T>* const pre , Real<T>* const d_pre = nullptr , const std::function<Real<T>(const Real<T>&)>& transval = fval::none<Real<T>>)
5353 {
5454 using syncmem_var_h2d_op = base_device::memory::synchronize_memory_op<Real<T>, Device, base_device::DEVICE_CPU>;
@@ -57,27 +57,27 @@ namespace hsolver
5757 Device* ctx = {};
5858 base_device::DEVICE_CPU* cpu_ctx = {};
5959
60- for (int m = 0 ; m < nvec; m++)
60+ for (size_t m = 0 ; m < nvec; m++)
6161 {
62- T* const ptr_m = ptr + m * dim;
62+ const size_t offset = m * dim;
6363 for (size_t i = 0 ; i < dim; i++) { pre_trans[i] = transval (pre [i] - eig[m]); }
6464#if defined(__CUDA) || defined(__ROCM)
6565 if (device == base_device::GpuDevice)
6666 {
6767 assert (d_pre);
6868 syncmem_var_h2d_op ()(ctx, cpu_ctx, d_pre, pre_trans.data (), dim);
69- vector_div_vector_op<T, Device>()(ctx, dim, ptr_m, ptr_m , d_pre);
69+ vector_div_vector_op<T, Device>()(ctx, dim, dst + offset, src + offset , d_pre);
7070 }
7171 else
7272#endif
7373 {
74- vector_div_vector_op<T, Device>()(ctx, dim, ptr_m, ptr_m , pre_trans.data ());
74+ vector_div_vector_op<T, Device>()(ctx, dim, dst + offset, src + offset , pre_trans.data ());
7575 }
7676 }
7777 }
7878 // / Intereface to be called in the eigensolver
7979 template <typename T>
80- using DivTransMinusEig = std::function<void (T*, const Real<T>*, const size_t &, const size_t &)>;
80+ using DivTransMinusEig = std::function<void (T* const , const T* const , const Real<T>*, const size_t &, const size_t &)>;
8181 // / Kernel function full of dependence
8282 template <typename T, typename Device = base_device::DEVICE_CPU>
8383 using DivTransMinusEigKernel = std::function<decltype (div_trans_prevec_minus_eigen<T, Device>)>;
@@ -104,7 +104,9 @@ namespace hsolver
104104 dev_ (base_device::get_device_type<Device>({}))
105105 {
106106#if defined(__CUDA) || defined(__ROCM)
107- if (this ->dev_ == base_device::GpuDevice) { resmem_real_op ()({}, this ->d_prevec_ , dim_); }
107+ if (this ->dev_ == base_device::GpuDevice) {
108+ resmem_real_op ()({}, this ->d_prevec_ , dim_);
109+ }
108110#endif
109111 }
110112 PreOP (const PreOP&) = delete;
@@ -119,13 +121,13 @@ namespace hsolver
119121 fvec::Div<T> get () const
120122 {
121123 return std::bind (PreOP<T, Device, Kernel_t>::transvec_,
122- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, this ->prevec_ );
124+ std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, this ->prevec_ );
123125 }
124126 template <typename U = Kernel_t, typename std::enable_if<std::is_same<U, fvec::DivTransMinusEigKernel<T, Device>>::value, bool >::type = 0 >
125127 fvec::DivTransMinusEig<T> get () const
126128 {
127129 return std::bind (PreOP<T, Device, Kernel_t>::transvec_,
128- std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4,
130+ std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5,
129131 this ->prevec_ , this ->d_prevec_ , this ->transval_ );
130132 }
131133
0 commit comments