Commit 869dc55b authored by Cyrille Bonamy's avatar Cyrille Bonamy
Browse files

clean src_cpp

parent e6e689b2ab27
......@@ -276,13 +276,3 @@ void FFT2DWithCUFFT::ifft(mycomplex *fieldK, myreal *fieldX)
}
void FFT2DWithCUFFT::init_array_X_random(myreal* &fieldX)
{
int ii;
this->alloc_array_X(fieldX);
for (ii = 0; ii < nX0*nX1; ++ii)
fieldX[ii] = (myreal)rand() / RAND_MAX;
}
......@@ -30,8 +30,6 @@ class FFT2DWithCUFFT: public BaseFFT2D
myreal compute_energy_from_X(myreal* fieldX);
myreal compute_mean_from_X(myreal* fieldX);
void init_array_X_random(myreal* &fieldX);
private:
int nX1loc, nK1loc, nXxloc, nXyloc, nXx, nXy, nKyloc;
myreal coef_norm;
......
......@@ -301,11 +301,3 @@ void FFT2DWithFFTW1D::ifft(mycomplex *fieldK, myreal *fieldX)
memcpy(fieldX,arrayX, nX0loc*nX1*sizeof(myreal));
}
void FFT2DWithFFTW1D::init_array_X_random(myreal* &fieldX)
{
int ii;
this->alloc_array_X(fieldX);
for (ii = 0; ii < nX0*nX1; ++ii)
fieldX[ii] = (myreal)rand() / RAND_MAX;
}
......@@ -18,8 +18,6 @@ class FFT2DWithFFTW1D: public BaseFFT2D
myreal compute_energy_from_X(myreal* fieldX);
myreal compute_mean_from_X(myreal* fieldX);
void init_array_X_random(myreal* &fieldX);
private:
myreal coef_norm;
myreal *arrayX;
......
......@@ -218,12 +218,3 @@ void FFT2DWithFFTW2D::ifft(mycomplex *fieldK, myreal *fieldX)
memcpy(fieldX, arrayX, nX0*nX1*sizeof(myreal));
}
void FFT2DWithFFTW2D::init_array_X_random(myreal* &fieldX)
{
int ii;
this->alloc_array_X(fieldX);
for (ii = 0; ii < nX0*nX1; ++ii)
fieldX[ii] = (myreal)rand() / RAND_MAX;
}
......@@ -19,8 +19,6 @@ class FFT2DWithFFTW2D: public BaseFFT2D
myreal compute_mean_from_X(myreal* fieldX);
myreal compute_mean_from_K(mycomplex* fieldK);
void init_array_X_random(myreal* &fieldX);
private:
myreal coef_norm;
myfftw_plan plan_r2c, plan_c2r;
......
......@@ -300,13 +300,3 @@ void FFT2DMPIWithFFTW1D::ifft(mycomplex *fieldK, myreal *fieldX)
memcpy(fieldX,arrayX, nX0loc*nX1*sizeof(myreal));
}
void FFT2DMPIWithFFTW1D::init_array_X_random(myreal* &fieldX)
{
int ii;
this->alloc_array_X(fieldX);
for (ii = 0; ii < nX0loc*nX1; ++ii)
fieldX[ii] = (myreal)rand() / RAND_MAX;
}
......@@ -21,8 +21,6 @@ class FFT2DMPIWithFFTW1D: public BaseFFT2DMPI
myreal compute_mean_from_X(myreal* fieldX);
myreal compute_mean_from_K(mycomplex* fieldK);
void init_array_X_random(myreal* &fieldX);
private:
myreal coef_norm;
fftw_plan plan_r2c, plan_c2c_fwd, plan_c2r, plan_c2c_bwd;
......
......@@ -291,23 +291,3 @@ void FFT2DMPIWithFFTWMPI2D::ifft(mycomplex *fieldK, myreal *fieldX)
fieldX[i1 + i0*nX1] = arrayX[i1 + i0*nX1_pad];
}
void FFT2DMPIWithFFTWMPI2D::init_array_X_random(myreal* &fieldX)
{
int ii;
this->alloc_array_X(fieldX);
// for (i0=0; i0<nX0loc; i0++)
// for (i1=0; i1<nX1; i1++)
// fieldX[i1 + i0*nX1] = 1.3425243;
// if (local_X0_start==0)
// {
// for (i0=0; i0<nX0loc; i0++)
// for (i1=0; i1<nX1; i1++)
// fieldX[i1 + i0*nX1] = 1111.3425243;
// }
for (ii = 0; ii < nX0loc*nX1; ++ii)
fieldX[ii] = (myreal)rand() / RAND_MAX;
}
......@@ -25,8 +25,6 @@ class FFT2DMPIWithFFTWMPI2D: public BaseFFT2DMPI
myreal compute_mean_from_X(myreal* fieldX);
myreal compute_mean_from_K(mycomplex* fieldK);
void init_array_X_random(myreal* &fieldX);
private:
int nX1_pad;
myreal coef_norm;
......
......@@ -18,36 +18,37 @@ void BaseFFT3D::_init()
BaseFFT::_init();
if (rank == 0)
cout << "N0 = " << N0 << " ; N1 = " << N1 << " ; N2 = " << N2 << endl;
coef_norm = N0 * N1 * N2;
}
int BaseFFT3D::get_local_size_X()
{
return nX0loc * nX1loc * nX2;
return nX0loc * nX1loc * nX2loc;
}
int BaseFFT3D::get_local_size_K()
{
return nK0loc * nK1loc * nK2;
return nK0loc * nK1loc * nK2loc;
}
void BaseFFT3D::get_local_shape_X(int *ptr_nX0loc, int *ptr_nX1loc,
int *ptr_nX2)
int *ptr_nX2loc)
{
*ptr_nX0loc = nX0loc;
*ptr_nX1loc = nX1loc;
*ptr_nX2 = nX2;
*ptr_nX2loc = nX2loc;
}
void BaseFFT3D::get_local_shape_K(int *ptr_nK0loc, int *ptr_nK1loc,
int *ptr_nK2)
int *ptr_nK2loc)
{
*ptr_nK0loc = nK0loc;
*ptr_nK1loc = nK1loc;
*ptr_nK2 = nK2;
*ptr_nK2loc = nK2loc;
}
......@@ -79,3 +80,26 @@ void BaseFFT3D::get_seq_indices_first_K(int *i0, int *i1)
*i0 = 0;
*i1 = 0;
}
myreal BaseFFT3D::compute_mean_from_X(myreal* fieldX)
{
myreal mean,mean1,mean2;
int ii,jj,kk;
mean=0.;
for (ii=0; ii<nX0; ii++)
{
mean1=0.;
for (jj=0; jj<nX1; jj++)
{
mean2=0.;
for (kk=0; kk<nX2; kk++)
mean2 += fieldX[(ii*nX1+jj)*nX2+kk];
mean1 += mean2/nX2;
}
mean += mean1 / nX1;
}
return mean / nX0;
}
......@@ -23,9 +23,16 @@ class BaseFFT3D: virtual public BaseFFT
virtual void get_dimX_K(int*, int*, int*);
virtual void get_seq_indices_first_K(int*, int*);
virtual myreal compute_mean_from_X(myreal* fieldX);
protected:
int N2, nz, nX2, nK2, nK1loc, nKz, nXz, nX1loc;
int N2, nz, nX2, nK2, nKz;
int nK1loc, nK2loc, nK3loc;
int nXx, nXy, nXz;
int nXxloc, nXyloc, nXzloc;
int nX1loc, nX2loc, nX3loc;
myreal coef_norm;
};
......
......@@ -48,3 +48,45 @@ void calcul_nprocmesh(int rank, int nb_proc, int* nprocmesh)
nprocmesh[1] = np1;
}
myreal BaseFFT3DMPI::compute_mean_from_X(myreal* fieldX)
{
myreal mean, local_mean;
int ii;
local_mean=0.;
for (ii=0; ii<nX0loc*nX1loc*nX2loc; ii++)
local_mean += fieldX[ii];
MPI_Allreduce(&local_mean, &mean, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
return mean / coef_norm;
}
myreal BaseFFT3DMPI::compute_mean_from_K(mycomplex* fieldK)
{
myreal mean;
if (rank == 0)
mean = real(fieldK[0]);
MPI_Bcast(&mean, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
return mean;
}
myreal BaseFFT3DMPI::compute_energy_from_X(myreal* fieldX)
{
int ii;
double energy_loc = 0;
double energy;
for (ii=0; ii<nX0loc*nX1loc*nX2loc; ii++)
energy_loc += (double) pow(fieldX[ii], 2);
MPI_Allreduce(&energy_loc, &energy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
return (myreal) energy / 2 /coef_norm;
}
......@@ -12,8 +12,13 @@ class BaseFFT3DMPI: public BaseFFT3D, public BaseFFTMPI
public:
BaseFFT3DMPI(int N0, int N1, int N2);
virtual myreal compute_mean_from_K(mycomplex* fieldK);
virtual myreal compute_mean_from_X(myreal* fieldX);
virtual myreal compute_energy_from_X(myreal* fieldX);
protected:
int nX2_pad, nKyloc, nXzloc;
int nX2_pad, nXzloc;
int nKxloc, nKyloc, nKzloc;
};
void calcul_nprocmesh(int rank, int nb_proc, int* nprocmesh);
......
......@@ -51,9 +51,9 @@ FFT3DWithCUFFT::FFT3DWithCUFFT(int argN0, int argN1, int argN2):
nX1 = N1;
nX1loc = nX1;
nX2 = N2;
nX2loc = N2;
nKx = nx/2+1;
nKxloc = nKx;
nKy = ny;
nKz = nz;
......@@ -63,6 +63,7 @@ FFT3DWithCUFFT::FFT3DWithCUFFT(int argN0, int argN1, int argN2):
nK1 = nKy;
nK1loc = nK1;
nK2 = nKx;
nK2loc = nK2;
coef_norm = N0*N1*N2;
......@@ -134,7 +135,7 @@ myreal FFT3DWithCUFFT::compute_energy_from_X(myreal* fieldX)
}
//cout << "energyX=" << energy / nX0 / 2 << endl;
return energy / nX0 / 2;
return (myreal) (energy / nX0 / 2);
}
......@@ -241,28 +242,6 @@ void FFT3DWithCUFFT::sum_wavenumbers_complex(mycomplex* fieldK, mycomplex* resul
}
myreal FFT3DWithCUFFT::compute_mean_from_X(myreal* fieldX)
{
myreal mean,mean1,mean2;
int ii,jj,kk;
mean=0.;
for (ii=0; ii<nX0; ii++)
{
mean1=0.;
for (jj=0; jj<nX1; jj++)
{
mean2=0.;
for (kk=0; kk<nX2; kk++)
mean2 += fieldX[(ii*nX1+jj)*nX2+kk];
mean1 += mean2/nX2;
}
mean += mean1 / nX1;
}
return mean / nX0;
}
myreal FFT3DWithCUFFT::compute_mean_from_K(mycomplex* fieldK)
{
myreal mean;
......@@ -327,12 +306,3 @@ void FFT3DWithCUFFT::ifft(mycomplex *fieldK, myreal *fieldX)
}
void FFT3DWithCUFFT::init_array_X_random(myreal* &fieldX)
{
int ii;
this->alloc_array_X(fieldX);
for (ii = 0; ii < nX0*nX1*nX2; ++ii)
fieldX[ii] = (myreal)rand() / RAND_MAX;
}
......@@ -31,13 +31,9 @@ class FFT3DWithCUFFT: public BaseFFT3D
void sum_wavenumbers_complex(mycomplex* fieldK, mycomplex* result);
myreal compute_energy_from_X(myreal* fieldX);
myreal compute_mean_from_X(myreal* fieldX);
myreal sum_wavenumbers_double(myreal* fieldK);
void init_array_X_random(myreal* &fieldX);
private:
int nX2loc, nK2loc, nXxloc, nXyloc, nXzloc, nKzloc, nXx, nXy, nXz, nKyloc;
myreal coef_norm;
int mem_size;//equivalent à la taille de arrayK?
......
......@@ -27,9 +27,9 @@ FFT3DWithFFTW3D::FFT3DWithFFTW3D(int argN0, int argN1, int argN2):
nX2 = N2;
nX0loc = nX0;
nX1loc = nX1;
nX2loc = nX2;
nKx = nx/2+1;
nKxloc = nKx;
nKy = ny;
nKz = nz;
......@@ -39,6 +39,7 @@ FFT3DWithFFTW3D::FFT3DWithFFTW3D(int argN0, int argN1, int argN2):
nK1 = nKy;
nK1loc = nK1;
nK2 = nKx;
nK2loc = nK2;
coef_norm = N0*N1*N2;
......@@ -169,7 +170,7 @@ myreal FFT3DWithFFTW3D::compute_energy_from_K(mycomplex* fieldK)
energy += energy_tmp;
// other modes
for (i0=0; i0<nK0loc; i0++)
for (i0=0; i0<nK0; i0++)
for (i1=0; i1<nK1; i1++)
for (i2=1; i2<nK2-1; i2++)
energy += (double) pow(abs(fieldK[i2 + (i1 + i0 * nK1) * nK2]), 2);
......@@ -205,7 +206,7 @@ myreal FFT3DWithFFTW3D::sum_wavenumbers_double(myreal* fieldK)
sum += sum_tmp;
// other modes
for (i0=0; i0<nK0loc; i0++)
for (i0=0; i0<nK0; i0++)
for (i1=0; i1<nK1; i1++)
for (i2=1; i2<nK2-1; i2++)
sum += fieldK[i2 + (i1 + i0 * nK1) * nK2];
......@@ -240,7 +241,7 @@ void FFT3DWithFFTW3D::sum_wavenumbers_complex(mycomplex* fieldK, mycomplex* resu
sum += sum_tmp;
// other modes
for (i0=0; i0<nK0loc; i0++)
for (i0=0; i0<nK0; i0++)
for (i1=0; i1<nK1; i1++)
for (i2=1; i2<nK2-1; i2++)
sum += fieldK[i2 + (i1 + i0 * nK1) * nK2];
......@@ -248,27 +249,6 @@ void FFT3DWithFFTW3D::sum_wavenumbers_complex(mycomplex* fieldK, mycomplex* resu
*result = sum;
}
myreal FFT3DWithFFTW3D::compute_mean_from_X(myreal* fieldX)
{
myreal mean,mean1,mean2;
int ii,jj,kk;
mean=0.;
for (ii=0; ii<nX0; ii++)
{
mean1=0.;
for (jj=0; jj<nX1; jj++)
{
mean2=0.;
for (kk=0; kk<nX2; kk++)
mean2 += fieldX[(ii*nX1+jj)*nX2+kk];
mean1 += mean2/nX2;
}
mean += mean1 / nX1;
}
return mean / nX0;
}
myreal FFT3DWithFFTW3D::compute_mean_from_K(mycomplex* fieldK)
{
......@@ -291,7 +271,7 @@ void FFT3DWithFFTW3D::fft(myreal *fieldX, mycomplex *fieldK)
fftw_execute(plan_r2c);
#endif
for (ii=0; ii<nK0loc*nK1loc*nK2; ii++)
for (ii=0; ii<nK0*nK1*nK2; ii++)
fieldK[ii] = arrayK[ii]/coef_norm;
}
......@@ -307,13 +287,3 @@ void FFT3DWithFFTW3D::ifft(mycomplex *fieldK, myreal *fieldX)
#endif
memcpy(fieldX, arrayX, nX0*nX1*nX2*sizeof(myreal));
}
void FFT3DWithFFTW3D::init_array_X_random(myreal* &fieldX)
{
int ii;
this->alloc_array_X(fieldX);
for (ii = 0; ii < nX0*nX1*nX2; ++ii)
fieldX[ii] = (myreal)rand() / RAND_MAX;
}
......@@ -18,11 +18,8 @@ class FFT3DWithFFTW3D: public BaseFFT3D
void sum_wavenumbers_complex(mycomplex* fieldK, mycomplex* result);
myreal compute_energy_from_X(myreal* fieldX);
myreal compute_mean_from_X(myreal* fieldX);
myreal sum_wavenumbers_double(myreal* fieldK);
void init_array_X_random(myreal* &fieldX);
private:
myreal coef_norm;
myreal *arrayX;
......
......@@ -27,7 +27,7 @@ FFT3DMPIWithFFTW1D::FFT3DMPIWithFFTW1D(int argN0, int argN1, int argN2):
nX2 = N2;
nX0loc = N0/nb_proc;
nX1loc = N1;
nXzloc = nX0loc;
nX2loc = N2;
nKx = nx/2;
nKxloc = (nKx)/nb_proc;
......@@ -47,7 +47,8 @@ FFT3DMPIWithFFTW1D::FFT3DMPIWithFFTW1D(int argN0, int argN1, int argN2):
nK1 = N1;
nK1loc = N1;
nK2 = N0;
coef_norm = N0*N1*N2;
nK2loc = N0;
// coef_norm = N0*N1*N2;
local_X0_start = rank * nX0loc;
local_K0_start = rank * nK0loc;
......@@ -179,24 +180,6 @@ char const* FFT3DMPIWithFFTW1D::get_classname()
{ return "FFT3DMPIWithFFTW1D";}
myreal FFT3DMPIWithFFTW1D::compute_energy_from_X(myreal* fieldX)
{
int i0, i1, i2;
myreal energy_loc = 0;
myreal energy;
for (i0=0; i0<nX0loc; i0++)
for (i1=0; i1<nX1; i1++)
for (i2=0; i2<nX2; i2++)
energy_loc += pow(fieldX[i2 + i1*nX2 + i0*nX1*nX2], 2);
MPI_Allreduce(&energy_loc, &energy, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
// cout << "energyX" << energy / 2 /coef_norm << endl;
return energy / 2 /coef_norm;
}
myreal FFT3DMPIWithFFTW1D::compute_energy_from_K(mycomplex* fieldK)
{
int i0, i1, i2;
......@@ -291,35 +274,6 @@ void FFT3DMPIWithFFTW1D::sum_wavenumbers_complex(
}
myreal FFT3DMPIWithFFTW1D::compute_mean_from_X(myreal* fieldX)
{
myreal mean, local_mean;
int ii;
local_mean=0.;
for (ii=0; ii<nX0loc*nX1*nX2; ii++)
local_mean += fieldX[ii];
MPI_Allreduce(&local_mean, &mean, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
// cout << "mean="<<mean / coef_norm<<endl;
return mean / coef_norm;
}
myreal FFT3DMPIWithFFTW1D::compute_mean_from_K(mycomplex* fieldK)
{
myreal mean;
if (rank == 0)
mean = real(fieldK[0]);
MPI_Bcast(&mean, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
// cout << "meanK="<<mean<<endl;
return mean;
}
void FFT3DMPIWithFFTW1D::fft(myreal *fieldX, mycomplex *fieldK)
{
int ii;
......@@ -362,33 +316,22 @@ void FFT3DMPIWithFFTW1D::ifft(mycomplex *fieldK, myreal *fieldX)
}
void FFT3DMPIWithFFTW1D::init_array_X_random(myreal* &fieldX)
{
int ii;
this->alloc_array_X(fieldX);
// cout << "init fieldX" << endl;
for (ii = 0; ii < nX0loc*nX1*nX2; ++ii)
fieldX[ii] = (myreal)rand() / RAND_MAX;
}
int FFT3DMPIWithFFTW1D::get_local_size_K()
void FFT3DMPIWithFFTW1D::get_dimX_K(int *d0, int *d1, int *d2)
{
// cout << "FFT3DMPIWithFFTW1D::get_local_size_K" << endl;
return nKxloc * nKy * nKz;
*d0 = 2;
*d1 = 1;
*d2 = 0;
}
int FFT3DMPIWithFFTW1D::get_local_size_X()
bool FFT3DMPIWithFFTW1D::are_parameters_bad()
{
// cout << "FFT3DMPIWithFFTW1D::get_local_size_X" << endl;
return nX0loc * nX1 * nX2;
if ((N0/nb_proc == 0) || (N2/2/nb_proc == 0))
{
if (rank == 0)
cout << "bad parameters N0 or N2" << endl;
return 1;
}
return 0;
}
void FFT3DMPIWithFFTW1D::get_dimX_K(int *d0, int *d1, int *d2)
{
*d0 = 2;
*d1 = 1;
*d2 = 0;
}
......@@ -6,33 +6,26 @@ class FFT3DMPIWithFFTW1D: public BaseFFT3DMPI
public:
FFT3DMPIWithFFTW1D(int N0, int N1, int N2);
void destroy();
bool are_parameters_bad();
virtual const char* get_classname();
void fft(myreal *fieldX, mycomplex *fieldK);
void ifft(mycomplex *fieldK, myreal *fieldX);
myreal compute_energy_from_X(myreal* fieldX);