Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Jauslin <ian@jauslin.org>2022-05-18 23:52:01 +0200
committerIan Jauslin <ian@jauslin.org>2022-05-18 23:52:01 +0200
commit8bce8632c520acea86b4a6b2b7cf3eafe7964124 (patch)
tree583cb335ce38e2c520c3d84483c4e9b7a23be05a /src/navier-stokes.c
parent199b8f0df5adeaaac4ca2afc2eff5237dfee36c3 (diff)
Multithread fft
Diffstat (limited to 'src/navier-stokes.c')
-rw-r--r--src/navier-stokes.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/navier-stokes.c b/src/navier-stokes.c
index 87f5aba..7f22c31 100644
--- a/src/navier-stokes.c
+++ b/src/navier-stokes.c
@@ -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);