Multithread fft
This commit is contained in:
@@ -14,7 +14,8 @@ int uk(
|
||||
double nu,
|
||||
double delta,
|
||||
_Complex double (*g)(int,int),
|
||||
unsigned int print_freq
|
||||
unsigned int print_freq,
|
||||
unsigned int nthreads
|
||||
){
|
||||
_Complex double* u;
|
||||
_Complex double* tmp1;
|
||||
@@ -26,7 +27,7 @@ int uk(
|
||||
fft_vect ifft;
|
||||
int kx,ky;
|
||||
|
||||
ns_init_tmps(&u, &tmp1, &tmp2, &tmp3, &fft1, &fft2, &ifft, K1, K2, N1, N2);
|
||||
ns_init_tmps(&u, &tmp1, &tmp2, &tmp3, &fft1, &fft2, &ifft, K1, K2, N1, N2, nthreads);
|
||||
ns_init_u(u, K1, K2);
|
||||
|
||||
// iterate
|
||||
@@ -65,7 +66,8 @@ int enstrophy(
|
||||
double nu,
|
||||
double delta,
|
||||
_Complex double (*g)(int,int),
|
||||
unsigned int print_freq
|
||||
unsigned int print_freq,
|
||||
unsigned int nthreads
|
||||
){
|
||||
_Complex double* u;
|
||||
_Complex double* tmp1;
|
||||
@@ -78,7 +80,7 @@ int enstrophy(
|
||||
fft_vect fft2;
|
||||
fft_vect ifft;
|
||||
|
||||
ns_init_tmps(&u, &tmp1, &tmp2, &tmp3, &fft1, &fft2, &ifft, K1, K2, N1, N2);
|
||||
ns_init_tmps(&u, &tmp1, &tmp2, &tmp3, &fft1, &fft2, &ifft, K1, K2, N1, N2, nthreads);
|
||||
ns_init_u(u, K1, K2);
|
||||
|
||||
|
||||
@@ -114,7 +116,8 @@ int quiet(
|
||||
unsigned int nsteps,
|
||||
double nu,
|
||||
double delta,
|
||||
_Complex double (*g)(int,int)
|
||||
_Complex double (*g)(int,int),
|
||||
unsigned int nthreads
|
||||
){
|
||||
_Complex double* u;
|
||||
_Complex double* tmp1;
|
||||
@@ -125,7 +128,7 @@ int quiet(
|
||||
fft_vect fft2;
|
||||
fft_vect ifft;
|
||||
|
||||
ns_init_tmps(&u, &tmp1, &tmp2, &tmp3, &fft1, &fft2, &ifft, K1, K2, N1, N2);
|
||||
ns_init_tmps(&u, &tmp1, &tmp2, &tmp3, &fft1, &fft2, &ifft, K1, K2, N1, N2, nthreads);
|
||||
ns_init_u(u, K1, K2);
|
||||
|
||||
// iterate
|
||||
@@ -150,7 +153,8 @@ int ns_init_tmps(
|
||||
int K1,
|
||||
int K2,
|
||||
int N1,
|
||||
int N2
|
||||
int N2,
|
||||
unsigned int nthreads
|
||||
){
|
||||
// velocity field
|
||||
*u=calloc(sizeof(_Complex double),(2*K1+1)*(2*K2+1));
|
||||
@@ -160,6 +164,10 @@ int ns_init_tmps(
|
||||
*tmp2=calloc(sizeof(_Complex double),(2*K1+1)*(2*K2+1));
|
||||
*tmp3=calloc(sizeof(_Complex double),(2*K1+1)*(2*K2+1));
|
||||
|
||||
// init threads
|
||||
fftw_init_threads();
|
||||
fftw_plan_with_nthreads(nthreads);
|
||||
|
||||
// prepare vectors for fft
|
||||
fft1->fft=fftw_malloc(sizeof(fftw_complex)*N1*N2);
|
||||
fft1->fft_plan=fftw_plan_dft_2d(N1,N2, fft1->fft, fft1->fft, FFTW_FORWARD, FFTW_MEASURE);
|
||||
@@ -189,7 +197,7 @@ int ns_free_tmps(
|
||||
fftw_free(fft2.fft);
|
||||
fftw_free(ifft.fft);
|
||||
|
||||
fftw_cleanup();
|
||||
fftw_cleanup_threads();
|
||||
|
||||
free(tmp3);
|
||||
free(tmp2);
|
||||
|
||||
Reference in New Issue
Block a user