Skip to content

Commit 29d9e87

Browse files
fix for out-of-place plans
JuliaApproximation/FastTransforms.jl#162 can't use an aliased pointer when the two arrays are genuinely different in the execution
1 parent 4f0beb3 commit 29d9e87

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/fftw.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,16 @@ ft_sphere_fftw_plan * ft_plan_sph_with_kind(const int N, const int M, const fftw
9999
idist = odist = 1;
100100
istride = ostride = N;
101101
howmany = N;
102-
if (kind[2][0] == FFTW_HC2R)
103-
P->planphi = fftw_plan_many_dft_c2r(rank, n, howmany, (fftw_complex *) P->Y, inembed, istride, idist, P->Y, onembed, ostride, odist, FT_FFTW_FLAGS);
104-
else if (kind[2][0] == FFTW_R2HC)
105-
P->planphi = fftw_plan_many_dft_r2c(rank, n, howmany, P->Y, inembed, istride, idist, (fftw_complex *) P->Y, onembed, ostride, odist, FT_FFTW_FLAGS);
102+
if (kind[2][0] == FFTW_HC2R) {
103+
double * Z = fftw_malloc(N*M*sizeof(double));
104+
P->planphi = fftw_plan_many_dft_c2r(rank, n, howmany, (fftw_complex *) P->Y, inembed, istride, idist, Z, onembed, ostride, odist, FT_FFTW_FLAGS);
105+
fftw_free(Z);
106+
}
107+
else if (kind[2][0] == FFTW_R2HC) {
108+
double * Z = fftw_malloc(N*M*sizeof(double));
109+
P->planphi = fftw_plan_many_dft_r2c(rank, n, howmany, Z, inembed, istride, idist, (fftw_complex *) P->Y, onembed, ostride, odist, FT_FFTW_FLAGS);
110+
fftw_free(Z);
111+
}
106112
return P;
107113
}
108114

@@ -436,10 +442,16 @@ ft_disk_fftw_plan * ft_plan_disk_with_kind(const int N, const int M, const fftw_
436442
idist = odist = 1;
437443
istride = ostride = N;
438444
howmany = N;
439-
if (kind[2][0] == FFTW_HC2R)
440-
P->plantheta = fftw_plan_many_dft_c2r(rank, n, howmany, (fftw_complex *) P->Y, inembed, istride, idist, P->Y, onembed, ostride, odist, FT_FFTW_FLAGS);
441-
else if (kind[2][0] == FFTW_R2HC)
442-
P->plantheta = fftw_plan_many_dft_r2c(rank, n, howmany, P->Y, inembed, istride, idist, (fftw_complex *) P->Y, onembed, ostride, odist, FT_FFTW_FLAGS);
445+
if (kind[2][0] == FFTW_HC2R) {
446+
double * Z = fftw_malloc(N*M*sizeof(double));
447+
P->plantheta = fftw_plan_many_dft_c2r(rank, n, howmany, (fftw_complex *) P->Y, inembed, istride, idist, Z, onembed, ostride, odist, FT_FFTW_FLAGS);
448+
fftw_free(Z);
449+
}
450+
else if (kind[2][0] == FFTW_R2HC) {
451+
double * Z = fftw_malloc(N*M*sizeof(double));
452+
P->plantheta = fftw_plan_many_dft_r2c(rank, n, howmany, Z, inembed, istride, idist, (fftw_complex *) P->Y, onembed, ostride, odist, FT_FFTW_FLAGS);
453+
fftw_free(Z);
454+
}
443455
return P;
444456
}
445457

@@ -646,7 +658,9 @@ ft_spinsphere_fftw_plan * ft_plan_spinsph_with_kind(const int N, const int M, co
646658
idist = odist = 1;
647659
istride = ostride = N;
648660
howmany = N;
649-
P->planphi = fftw_plan_many_dft(rank, n, howmany, (fftw_complex *) P->Y, inembed, istride, idist, (fftw_complex *) P->Y, onembed, ostride, odist, sign, FT_FFTW_FLAGS);
661+
fftw_complex * Z = fftw_malloc(N*M*sizeof(fftw_complex));
662+
P->planphi = fftw_plan_many_dft(rank, n, howmany, (fftw_complex *) P->Y, inembed, istride, idist, Z, onembed, ostride, odist, sign, FT_FFTW_FLAGS);
663+
fftw_free(Z);
650664
P->S = S;
651665
return P;
652666
}

0 commit comments

Comments
 (0)