Skip to content

Commit 9ad3c19

Browse files
committed
add the func in test
1 parent d7f50df commit 9ad3c19

File tree

13 files changed

+194
-154
lines changed

13 files changed

+194
-154
lines changed

source/module_base/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ list (APPEND LIBM_SRC
88
endif()
99
if (ENABLE_FLOAT_FFTW)
1010
list (APPEND FFT_SRC
11-
module_fft/fftw_float.cpp
11+
module_fft/fft_cpu_float.cpp
1212
)
1313
endif()
1414
add_library(

source/module_base/module_fft/fft_base.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class FFT_BASE
88
{
99
public:
1010

11-
__attribute__((weak)) FFT_BASE();
12-
virtual __attribute__((weak)) ~FFT_BASE();
11+
FFT_BASE();
12+
virtual ~FFT_BASE();
1313

1414
// init parameters of fft
1515
virtual void initfft(int nx_in, int ny_in, int nz_in, int lixy_in, int rixy_in, int ns_in, int nplane_in,

source/module_base/module_fft/fft_cpu.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ void FFT_CPU<double>::clearfft(fftw_plan& plan)
134134
template <>
135135
void FFT_CPU<double>::cleanFFT()
136136
{
137-
printf("in the double cleanFFT\n");
138137
clearfft(planzfor);
139138
clearfft(planzbac);
140139
clearfft(planxfor1);
@@ -189,6 +188,7 @@ void FFT_CPU<double>::fftxyfor(std::complex<double>* in, std::complex<double>* o
189188
if (this->xprime)
190189
{
191190
fftw_execute_dft(this->planxfor1, (fftw_complex*)in, (fftw_complex*)out);
191+
192192
for (int i = 0; i < this->lixy + 1; ++i)
193193
{
194194
fftw_execute_dft(this->planyfor, (fftw_complex*)&in[i * npy], (fftw_complex*)&out[i * npy]);
@@ -227,13 +227,13 @@ void FFT_CPU<double>::fftxybac(std::complex<double>* in,std::complex<double>* ou
227227
}
228228
else
229229
{
230+
fftw_execute_dft(this->planxbac1, (fftw_complex*)in, (fftw_complex*)out);
231+
fftw_execute_dft(this->planxbac2, (fftw_complex*)&in[rixy * nplane], (fftw_complex*)&out[rixy * nplane]);
232+
230233
for (int i = 0; i < this->nx; ++i)
231234
{
232235
fftw_execute_dft(this->planybac, (fftw_complex*)&in[i * npy], (fftw_complex*)&out[i * npy]);
233236
}
234-
235-
fftw_execute_dft(this->planxbac1, (fftw_complex*)in, (fftw_complex*)out);
236-
fftw_execute_dft(this->planxbac2, (fftw_complex*)&in[rixy * nplane], (fftw_complex*)&out[rixy * nplane]);
237237
}
238238
}
239239
template <>

source/module_base/module_fft/fft_cpu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ template <typename FPTYPE>
1212
class FFT_CPU : public FFT_BASE<FPTYPE>
1313
{
1414
public:
15-
__attribute__((weak)) FFT_CPU();
16-
__attribute__((weak)) ~FFT_CPU();
15+
FFT_CPU();
16+
~FFT_CPU();
1717

1818
__attribute__((weak)) void initfftmode(int fft_mode_in);
1919

source/module_base/module_fft/fft_cpu_float.cpp

Lines changed: 106 additions & 115 deletions
Large diffs are not rendered by default.

source/module_base/module_fft/fft_temp.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,6 @@ FFT_TEMP::FFT_TEMP(std::string device_in,std::string precision_in)
4040

4141
FFT_TEMP::~FFT_TEMP()
4242
{
43-
if (float_flag)
44-
{
45-
delete fft_float;
46-
fft_float=nullptr;
47-
}
48-
if (double_flag)
49-
{
50-
delete fft_double;
51-
fft_double=nullptr;
52-
}
5343
}
5444

5545
void FFT_TEMP::set_device(std::string device_in)
@@ -67,6 +57,11 @@ void FFT_TEMP::setfft(std::string device_in,std::string precision_in)
6757
assert(precision_in=="single" || precision_in=="double" || precision_in=="mixing");
6858
this->device = device_in;
6959
this->precision = precision_in;
60+
61+
}
62+
void FFT_TEMP::initfft(int nx_in, int ny_in, int nz_in, int lixy_in, int rixy_in, int ns_in, int nplane_in,
63+
int nproc_in, bool gamma_only_in, bool xprime_in , bool mpifft_in)
64+
{
7065
if (device=="cpu")
7166
{
7267
fft_float = new FFT_CPU<float>();
@@ -82,22 +77,18 @@ void FFT_TEMP::setfft(std::string device_in,std::string precision_in)
8277
// fft_double = new FFT_CUDA<double>();
8378
// #endif
8479
}
85-
}
86-
void FFT_TEMP::initfft(int nx_in, int ny_in, int nz_in, int lixy_in, int rixy_in, int ns_in, int nplane_in,
87-
int nproc_in, bool gamma_only_in, bool xprime_in , bool mpifft_in)
88-
{
8980
if (this->precision=="single")
9081
{
91-
float_flag = 1;
82+
float_flag = true;
9283
}
9384
else if (this->precision=="double")
9485
{
95-
double_flag = 1;
86+
double_flag = true;
9687
}
9788
else if (this->precision=="mixing")
9889
{
99-
float_flag = 1;
100-
double_flag = 1;
90+
float_flag = true;
91+
double_flag = true;
10192
}
10293
if (float_flag)
10394
{
@@ -149,6 +140,18 @@ void FFT_TEMP::clear()
149140
{
150141
fft_double->clear();
151142
}
143+
if (fft_float!=nullptr)
144+
{
145+
delete fft_float;
146+
fft_float=nullptr;
147+
float_flag = false;
148+
}
149+
if (fft_double!=nullptr)
150+
{
151+
delete fft_double;
152+
fft_double=nullptr;
153+
double_flag = false;
154+
}
152155
}
153156
// access the real space data
154157
template <>

source/module_basis/module_pw/pw_basis.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ PW_Basis::PW_Basis(std::string device_, std::string precision_) : device(std::mo
1717
classname="PW_Basis";
1818
this->ft.set_device(this->device);
1919
this->ft.set_precision(this->precision);
20+
this->ft1.setfft(this->device,this->precision);
2021
}
2122

2223
PW_Basis:: ~PW_Basis()
@@ -57,9 +58,19 @@ void PW_Basis::setuptransform()
5758
this->distribute_g();
5859
this->getstartgr();
5960
this->ft.clear();
60-
if(this->xprime) this->ft.initfft(this->nx,this->ny,this->nz,this->lix,this->rix,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
61-
else this->ft.initfft(this->nx,this->ny,this->nz,this->liy,this->riy,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
61+
this->ft1.clear();
62+
if(this->xprime)
63+
{
64+
this->ft.initfft(this->nx,this->ny,this->nz,this->lix,this->rix,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
65+
this->ft1.initfft(this->nx,this->ny,this->nz,this->lix,this->rix,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
66+
}
67+
else
68+
{
69+
this->ft.initfft(this->nx,this->ny,this->nz,this->liy,this->riy,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
70+
this->ft1.initfft(this->nx,this->ny,this->nz,this->liy,this->riy,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
71+
}
6272
this->ft.setupFFT();
73+
this->ft1.setupFFT();
6374
ModuleBase::timer::tick(this->classname, "setuptransform");
6475
}
6576

source/module_basis/module_pw/pw_basis_k.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,16 @@ void PW_Basis_K::setuptransform()
180180
this->getstartgr();
181181
this->setupIndGk();
182182
this->ft.clear();
183-
if(this->xprime) this->ft.initfft(this->nx,this->ny,this->nz,this->lix,this->rix,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
184-
else this->ft.initfft(this->nx,this->ny,this->nz,this->liy,this->riy,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
183+
this->ft1.clear();
184+
if(this->xprime){
185+
this->ft.initfft(this->nx,this->ny,this->nz,this->lix,this->rix,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
186+
this->ft1.initfft(this->nx,this->ny,this->nz,this->lix,this->rix,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
187+
}else{
188+
this->ft.initfft(this->nx,this->ny,this->nz,this->liy,this->riy,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
189+
this->ft1.initfft(this->nx,this->ny,this->nz,this->liy,this->riy,this->nst,this->nplane,this->poolnproc,this->gamma_only, this->xprime);
190+
}
185191
this->ft.setupFFT();
192+
this->ft1.setupFFT();
186193
ModuleBase::timer::tick(this->classname, "setuptransform");
187194
}
188195

source/module_basis/module_pw/pw_basis_sup.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ void PW_Basis_Sup::setuptransform(const ModulePW::PW_Basis* pw_rho)
2020
this->distribute_g(pw_rho);
2121
this->getstartgr();
2222
this->ft.clear();
23+
this->ft1.clear();
2324
if (this->xprime)
25+
{
2426
this->ft.initfft(this->nx,
2527
this->ny,
2628
this->nz,
@@ -31,7 +33,19 @@ void PW_Basis_Sup::setuptransform(const ModulePW::PW_Basis* pw_rho)
3133
this->poolnproc,
3234
this->gamma_only,
3335
this->xprime);
36+
this->ft1.initfft(this->nx,
37+
this->ny,
38+
this->nz,
39+
this->lix,
40+
this->rix,
41+
this->nst,
42+
this->nplane,
43+
this->poolnproc,
44+
this->gamma_only,
45+
this->xprime);
46+
}
3447
else
48+
{
3549
this->ft.initfft(this->nx,
3650
this->ny,
3751
this->nz,
@@ -42,7 +56,19 @@ void PW_Basis_Sup::setuptransform(const ModulePW::PW_Basis* pw_rho)
4256
this->poolnproc,
4357
this->gamma_only,
4458
this->xprime);
59+
this->ft1.initfft(this->nx,
60+
this->ny,
61+
this->nz,
62+
this->liy,
63+
this->riy,
64+
this->nst,
65+
this->nplane,
66+
this->poolnproc,
67+
this->gamma_only,
68+
this->xprime);
69+
}
4570
this->ft.setupFFT();
71+
this->ft1.setupFFT();
4672
ModuleBase::timer::tick(this->classname, "setuptransform");
4773
}
4874

source/module_basis/module_pw/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ AddTest(
55
SOURCES ../../../module_base/matrix.cpp ../../../module_base/complexmatrix.cpp ../../../module_base/matrix3.cpp ../../../module_base/tool_quit.cpp
66
../../../module_base/mymath.cpp ../../../module_base/timer.cpp ../../../module_base/memory.cpp ../../../module_base/blas_connector.cpp
77
../../../module_base/libm/branred.cpp ../../../module_base/libm/sincos.cpp
8-
../../../module_base/module_fft/fft_base.cpp ../../../module_base/module_fft/fft_temp.cpp
8+
../../../module_base/module_fft/fft_base.cpp ../../../module_base/module_fft/fft_temp.cpp ../../../module_base/module_fft/fft_cpu.cpp
99
# ../../../module_psi/kernels/psi_memory_op.cpp
1010
../../../module_base/module_device/memory_op.cpp
1111
depend_mock.cpp pw_test.cpp test1-1-1.cpp test1-1-2.cpp test1-2.cpp test1-3.cpp test1-4.cpp test1-5.cpp

0 commit comments

Comments
 (0)