@@ -337,6 +337,79 @@ void PW_Basis_K::recip_to_real(const base_device::DEVICE_CPU* /*dev*/,
337337 this ->recip2real (in, out, ik, add, factor);
338338 #endif
339339}
340+ template <>
341+ void PW_Basis_K::convolution (const base_device::DEVICE_CPU * ctx,
342+ const int ik,
343+ const int size,
344+ const std::complex <float >* input,
345+ const float * input1,
346+ std::complex <float >* output,
347+ const bool add,
348+ const float factor) const
349+ {
350+ }
351+
352+ template <>
353+ void PW_Basis_K::convolution (const base_device::DEVICE_CPU * ctx,
354+ const int ik,
355+ const int size,
356+ const std::complex <double >* input,
357+ const double * input1,
358+ std::complex <double >* output,
359+ const bool add,
360+ const double factor) const
361+ {
362+ ModuleBase::timer::tick (this ->classname , " convolution" );
363+ assert (this ->gamma_only == false );
364+ // ModuleBase::GlobalFunc::ZEROS(fft_bundle.get_auxg_data<double>(), this->nst * this->nz);
365+ // memset the auxr of 0 in the auxr,here the len of the auxr is nxyz
366+ auto * auxg = this ->fft_bundle .get_auxg_data <double >();
367+ auto * auxr=this ->fft_bundle .get_auxr_data <double >();
368+
369+ memset (auxg, 0 , this ->nst * this ->nz * 2 * 8 );
370+ const int startig = ik * this ->npwk_max ;
371+ const int npwk = this ->npwk [ik];
372+
373+ // copy the mapping form the type of stick to the 3dfft
374+ #ifdef _OPENMP
375+ #pragma omp parallel for schedule(static, 4096 / sizeof(double))
376+ #endif
377+ for (int igl = 0 ; igl < npwk; ++igl)
378+ {
379+ auxg[this ->igl2isz_k [igl + startig]] = input[igl];
380+ }
381+
382+ // use 3d fft backward
383+ this ->fft_bundle .fftzbac (auxg, auxg);
384+
385+ this ->gathers_scatterp (auxg, auxr);
386+
387+ this ->fft_bundle .fftxybac (auxr, auxr);
388+ for (int ir = 0 ; ir < size; ir++)
389+ {
390+ auxr[ir] *= input1[ir];
391+ }
392+
393+ // 3d fft
394+ this ->fft_bundle .fftxyfor (auxr, auxr);
395+
396+ this ->gatherp_scatters (auxr, auxg);
397+
398+ this ->fft_bundle .fftzfor (auxg, auxg);
399+ // copy the result from the auxr to the out ,while consider the add
400+ if (add)
401+ {
402+ double tmpfac = factor / double (this ->nxyz );
403+ #ifdef _OPENMP
404+ #pragma omp parallel for schedule(static, 4096 / sizeof(double))
405+ #endif
406+ for (int igl = 0 ; igl < npwk; ++igl)
407+ {
408+ output[igl] += tmpfac * auxg[this ->igl2isz_k [igl + startig]];
409+ }
410+ }
411+ ModuleBase::timer::tick (this ->classname , " convolution" );
412+ }
340413
341414#if (defined(__CUDA) || defined(__ROCM))
342415template <>
0 commit comments