Skip to content

Commit

Permalink
Merge branch 'topic/default/include-chrono' into 'branch/default'
Browse files Browse the repository at this point in the history
C++11 include <chrono> for Windows

Closes #33

See merge request fluiddyn/fluidfft!51
  • Loading branch information
paugier committed Feb 7, 2024
2 parents e329956 + a82babe commit 9f8a752
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 95 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/ci-pixi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ jobs:
- name: Install
run: |
pixi run install-editable
# C++ code is not yet compatible with Windows
# pixi run pip install plugins/fluidfft-fftw -v --no-build-isolation --no-deps
pixi run pip install plugins/fluidfft-fftw -v --no-build-isolation --no-deps
- name: Tests
run: |
pixi run pytest -v tests
# pixi run pytest -v plugins/fluidfft-fftw
pixi run pytest -v -s tests
pixi run pytest -v -s plugins/fluidfft-fftw
26 changes: 10 additions & 16 deletions plugins/fluidfft-builder/fluidfft_builder/src_cpp/base_fft.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

#include <iostream>
#include <chrono>
using namespace std;

#include <stdlib.h>
#include <sys/time.h>

#include <base_fft.h>

Expand All @@ -17,12 +17,6 @@ myreal EPS = 5e-13;

char *dealiasing_coeff_char = getenv("FLUIDFFT_DEALIASING_COEFF");

myreal compute_time_in_second(struct timeval start_time,
struct timeval end_time) {
return (end_time.tv_sec - start_time.tv_sec) +
(end_time.tv_usec - start_time.tv_usec) / 1000000.;
}

// template <typename T, typename U>
// inline std::complex<T> operator*(std::complex<T> lhs, const U& rhs)
// {
Expand Down Expand Up @@ -151,7 +145,7 @@ int BaseFFT::test() {

void BaseFFT::bench(int nb_time_execute, myreal *times) {
int i;
struct timeval start_time, end_time;
chrono::duration<double> duration_in_sec;
myreal time_in_sec;
myreal *fieldX;
mycomplex *fieldK;
Expand All @@ -163,32 +157,32 @@ void BaseFFT::bench(int nb_time_execute, myreal *times) {
this->alloc_array_X(fieldX);
this->alloc_array_K(fieldK);

gettimeofday(&start_time, NULL);
auto start_time = chrono::high_resolution_clock::now();
for (i = 0; i < nb_time_execute; i++) {
fieldX[0] = i;
fft(fieldX, fieldK);
}
gettimeofday(&end_time, NULL);
auto end_time = chrono::high_resolution_clock::now();

if (rank == 0) {
time_in_sec =
compute_time_in_second(start_time, end_time) / nb_time_execute;
duration_in_sec = end_time - start_time;
time_in_sec = duration_in_sec.count() / nb_time_execute;
times[0] = time_in_sec;
snprintf(tmp_char, sizeof(tmp_char), "time fft (%s): %f s\n",
this->get_classname(), time_in_sec);
cout << tmp_char;
}

gettimeofday(&start_time, NULL);
start_time = chrono::high_resolution_clock::now();
for (i = 0; i < nb_time_execute; i++) {
fieldK[0] = i;
ifft(fieldK, fieldX);
}
gettimeofday(&end_time, NULL);
end_time = chrono::high_resolution_clock::now();

if (rank == 0) {
time_in_sec =
compute_time_in_second(start_time, end_time) / nb_time_execute;
duration_in_sec = end_time - start_time;
time_in_sec = duration_in_sec.count() / nb_time_execute;
snprintf(tmp_char, sizeof(tmp_char), "time ifft (%s): %f s\n",
this->get_classname(), time_in_sec);
cout << tmp_char;
Expand Down
3 changes: 1 addition & 2 deletions plugins/fluidfft-builder/fluidfft_builder/src_cpp/base_fft.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#include <cstring>
#include <iostream>
#include <stdexcept>

#include <sys/time.h>
#include <chrono>

#include <complex>
using std::complex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@


#include <iostream>
#include <chrono>
using namespace std;

#include <stdlib.h>
#include <string.h>

#include <sys/time.h>

#include <fft2d_with_fftw1d.h>

FFT2DWithFFTW1D::FFT2DWithFFTW1D(int argN0, int argN1)
: BaseFFT2D::BaseFFT2D(argN0, argN1) {
struct timeval start_time, end_time;
myreal total_usecs;
chrono::duration<double> clocktime_in_sec;
// int iX0;
int istride = 1, ostride = 1;
int howmany, sign;
Expand Down Expand Up @@ -48,7 +46,7 @@ FFT2DWithFFTW1D::FFT2DWithFFTW1D(int argN0, int argN1)
arrayK_pR = (mycomplex *)fftwf_malloc(sizeof(mycomplex) * nX0loc * nKx);
arrayK_pC = (mycomplex *)fftwf_malloc(sizeof(mycomplex) * nKxloc * N0);

gettimeofday(&start_time, NULL);
auto start_time = chrono::high_resolution_clock::now();

howmany = nX0loc;

Expand All @@ -73,7 +71,7 @@ FFT2DWithFFTW1D::FFT2DWithFFTW1D(int argN0, int argN1)
arrayK_pR = (mycomplex *)fftw_malloc(sizeof(mycomplex) * nX0loc * nKx);
arrayK_pC = (mycomplex *)fftw_malloc(sizeof(mycomplex) * nKxloc * N0);

gettimeofday(&start_time, NULL);
auto start_time = chrono::high_resolution_clock::now();

howmany = nX0loc;

Expand All @@ -98,14 +96,13 @@ FFT2DWithFFTW1D::FFT2DWithFFTW1D(int argN0, int argN1)
istride, N0, reinterpret_cast<mycomplex_fftw *>(arrayK_pC), &N0, ostride,
N0, sign, flags);
#endif
gettimeofday(&end_time, NULL);
auto end_time = chrono::high_resolution_clock::now();

total_usecs = (end_time.tv_sec - start_time.tv_sec) +
(end_time.tv_usec - start_time.tv_usec) / 1000000.;
clocktime_in_sec = end_time - start_time;

if (rank == 0)
printf("Initialization (%s) done in %f s\n", this->get_classname(),
total_usecs);
clocktime_in_sec.count());
}

void FFT2DWithFFTW1D::destroy(void) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

FFT2DWithFFTW2D::FFT2DWithFFTW2D(int argN0, int argN1)
: BaseFFT2D::BaseFFT2D(argN0, argN1) {
struct timeval start_time, end_time;
myreal total_usecs;
chrono::duration<double> clocktime_in_sec;

this->_init();

Expand Down Expand Up @@ -33,28 +32,28 @@ FFT2DWithFFTW2D::FFT2DWithFFTW2D(int argN0, int argN1)
#ifdef SINGLE_PREC
arrayX = fftwf_alloc_real(nX0 * nX1);
arrayK = fftwf_alloc_complex(nK0 * nK1);
gettimeofday(&start_time, NULL);
auto start_time = chrono::high_resolution_clock::now();
plan_r2c = fftwf_plan_dft_r2c_2d(N0, N1, arrayX, arrayK, flags);
plan_c2r = fftwf_plan_dft_c2r_2d(N0, N1, arrayK, arrayX, flags);
#else
arrayX = (myreal *)fftw_malloc(sizeof(myreal) * nX0 * nX1);
arrayK = reinterpret_cast<mycomplex *>(fftw_malloc(sizeof(mycomplex) * nK0 * nK1));
gettimeofday(&start_time, NULL);
auto start_time = chrono::high_resolution_clock::now();
plan_r2c = fftw_plan_dft_r2c_2d(
N0, N1, arrayX, reinterpret_cast<mycomplex_fftw *>(arrayK), flags);

plan_c2r = fftw_plan_dft_c2r_2d(
N0, N1, reinterpret_cast<mycomplex_fftw *>(arrayK), arrayX, flags);
#endif

gettimeofday(&end_time, NULL);
auto end_time = chrono::high_resolution_clock::now();

total_usecs = (end_time.tv_sec - start_time.tv_sec) +
(end_time.tv_usec - start_time.tv_usec) / 1000000.;
clocktime_in_sec = end_time - start_time;

if (rank == 0)
printf("Initialization (%s) done in %f s\n", this->get_classname(),
total_usecs);
printf("Initialization (%s) done in %f s\n",
this->get_classname(),
clocktime_in_sec.count());
}

void FFT2DWithFFTW2D::destroy(void) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

FFT3DWithFFTW3D::FFT3DWithFFTW3D(int argN0, int argN1, int argN2)
: BaseFFT3D::BaseFFT3D(argN0, argN1, argN2) {
struct timeval start_time, end_time;
myreal total_usecs;
chrono::duration<double> clocktime_in_sec;

this->_init();
#ifdef OMP
Expand Down Expand Up @@ -52,7 +51,7 @@ FFT3DWithFFTW3D::FFT3DWithFFTW3D(int argN0, int argN1, int argN2)
arrayK = reinterpret_cast<mycomplex *>(fftw_malloc(sizeof(mycomplex) * nK0 * nK1 * nK2));
#endif

gettimeofday(&start_time, NULL);
auto start_time = chrono::high_resolution_clock::now();
#ifdef OMP
#ifdef SINGLE_PREC
fftwf_plan_with_nthreads(omp_get_max_threads());
Expand All @@ -75,14 +74,13 @@ FFT3DWithFFTW3D::FFT3DWithFFTW3D(int argN0, int argN1, int argN2)
N0, N1, N2, reinterpret_cast<mycomplex_fftw *>(arrayK), arrayX, flags);
#endif

gettimeofday(&end_time, NULL);
auto end_time = chrono::high_resolution_clock::now();

total_usecs = (end_time.tv_sec - start_time.tv_sec) +
(end_time.tv_usec - start_time.tv_usec) / 1000000.;
clocktime_in_sec = end_time - start_time;

if (rank == 0)
printf("Initialization (%s) done in %f s\n", this->get_classname(),
total_usecs);
clocktime_in_sec.count());
}

void FFT3DWithFFTW3D::destroy(void) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ FFT2DMPIWithFFTWMPI2D::FFT2DMPIWithFFTWMPI2D(int argN0, int argN1)
: BaseFFT2DMPI::BaseFFT2DMPI(argN0, argN1) {
int nK0_loc_iszero = 0;
int count_nK0loc_zero = 0;
struct timeval start_time, end_time;
myreal total_usecs;
chrono::duration<double> clocktime_in_sec;
ptrdiff_t local_nX0;
ptrdiff_t local_nK0;

Expand Down Expand Up @@ -65,7 +64,7 @@ FFT2DMPIWithFFTWMPI2D::FFT2DMPIWithFFTWMPI2D(int argN0, int argN1)
arrayX = fftwf_alloc_real(2 * alloc_local);
arrayK = fftwf_alloc_complex(alloc_local);

gettimeofday(&start_time, NULL);
auto start_time = chrono::high_resolution_clock::now();

plan_r2c = fftwf_mpi_plan_dft_r2c_2d(N0, N1, arrayX, arrayK, MPI_COMM_WORLD,
flags | FFTW_MPI_TRANSPOSED_OUT);
Expand All @@ -76,7 +75,7 @@ FFT2DMPIWithFFTWMPI2D::FFT2DMPIWithFFTWMPI2D(int argN0, int argN1)
arrayX = (myreal *)fftw_malloc(sizeof(myreal) * 2 * alloc_local);
arrayK = reinterpret_cast<mycomplex *>(fftw_malloc(sizeof(mycomplex) * alloc_local));

gettimeofday(&start_time, NULL);
auto start_time = chrono::high_resolution_clock::now();

plan_r2c = fftw_mpi_plan_dft_r2c_2d(
N0, N1, arrayX, reinterpret_cast<mycomplex_fftw *>(arrayK),
Expand All @@ -86,14 +85,13 @@ FFT2DMPIWithFFTWMPI2D::FFT2DMPIWithFFTWMPI2D(int argN0, int argN1)
N0, N1, reinterpret_cast<mycomplex_fftw *>(arrayK), arrayX,
MPI_COMM_WORLD, flags | FFTW_MPI_TRANSPOSED_IN);
#endif
gettimeofday(&end_time, NULL);
auto end_time = chrono::high_resolution_clock::now();

total_usecs = (end_time.tv_sec - start_time.tv_sec) +
(end_time.tv_usec - start_time.tv_usec) / 1000000.;
clocktime_in_sec = end_time - start_time;

if (rank == 0)
printf("Initialization (%s) done in %f s\n", this->get_classname(),
total_usecs);
clocktime_in_sec.count());
}

void FFT2DMPIWithFFTWMPI2D::destroy(void) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@


#include <iostream>
#include <chrono>
using namespace std;

#include <stdlib.h>

#include <sys/time.h>

#ifdef OMP
#include <omp.h>
#endif
Expand All @@ -15,8 +14,7 @@ using namespace std;

FFT3DMPIWithFFTWMPI3D::FFT3DMPIWithFFTWMPI3D(int argN0, int argN1, int argN2)
: BaseFFT3DMPI::BaseFFT3DMPI(argN0, argN1, argN2) {
struct timeval start_time, end_time;
myreal total_usecs;
chrono::duration<double> clocktime_in_sec;
ptrdiff_t local_nX0; //, local_X0_start;
ptrdiff_t local_nK0;

Expand Down Expand Up @@ -85,7 +83,7 @@ FFT3DMPIWithFFTWMPI3D::FFT3DMPIWithFFTWMPI3D(int argN0, int argN1, int argN2)
arrayX = fftwf_alloc_real(2 * alloc_local);
arrayK = reinterpret_cast<mycomplex *>(fftwf_alloc_complex(alloc_local));

gettimeofday(&start_time, NULL);
auto start_time = chrono::high_resolution_clock::now();
#ifdef OMP
fftwf_plan_with_nthreads(omp_get_max_threads());
#endif
Expand All @@ -100,7 +98,7 @@ FFT3DMPIWithFFTWMPI3D::FFT3DMPIWithFFTWMPI3D(int argN0, int argN1, int argN2)
arrayX = (myreal *)fftw_malloc(sizeof(myreal) * 2 * alloc_local);
arrayK = reinterpret_cast<mycomplex *>(fftw_malloc(sizeof(mycomplex) * alloc_local));

gettimeofday(&start_time, NULL);
auto start_time = chrono::high_resolution_clock::now();
#ifdef OMP
fftw_plan_with_nthreads(omp_get_max_threads());
#endif
Expand All @@ -112,14 +110,13 @@ FFT3DMPIWithFFTWMPI3D::FFT3DMPIWithFFTWMPI3D(int argN0, int argN1, int argN2)
N0, N1, N2, reinterpret_cast<mycomplex_fftw *>(arrayK), arrayX,
MPI_COMM_WORLD, flags | FFTW_MPI_TRANSPOSED_IN);
#endif
gettimeofday(&end_time, NULL);
auto end_time = chrono::high_resolution_clock::now();

total_usecs = (end_time.tv_sec - start_time.tv_sec) +
(end_time.tv_usec - start_time.tv_usec) / 1000000.;
clocktime_in_sec = end_time - start_time;

if (rank == 0)
printf("Initialization (%s) done in %f s\n", this->get_classname(),
total_usecs);
clocktime_in_sec.count());
}

void FFT3DMPIWithFFTWMPI3D::destroy(void) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

FFT2DMPIWithFFTW1D::FFT2DMPIWithFFTW1D(int argN0, int argN1)
: BaseFFT2DMPI::BaseFFT2DMPI(argN0, argN1) {
struct timeval start_time, end_time;
myreal total_usecs;
chrono::duration<double> clocktime_in_sec;
int iX0;
int istride = 1, ostride = 1;
int howmany, sign;
Expand Down Expand Up @@ -44,7 +43,7 @@ FFT2DMPIWithFFTW1D::FFT2DMPIWithFFTW1D(int argN0, int argN1)
arrayK_pR = (mycomplex *)fftw_malloc(sizeof(mycomplex) * nX0loc * (nKx + 1));
arrayK_pC = (mycomplex *)fftw_malloc(sizeof(mycomplex) * nKxloc * N0);

gettimeofday(&start_time, NULL);
auto start_time = chrono::high_resolution_clock::now();

howmany = nX0loc;
plan_r2c =
Expand All @@ -69,14 +68,13 @@ FFT2DMPIWithFFTW1D::FFT2DMPIWithFFTW1D(int argN0, int argN1)
istride, N0, reinterpret_cast<mycomplex_fftw *>(arrayK_pC), &N0, ostride,
N0, sign, flags);

gettimeofday(&end_time, NULL);
auto end_time = chrono::high_resolution_clock::now();

total_usecs = (end_time.tv_sec - start_time.tv_sec) +
(end_time.tv_usec - start_time.tv_usec) / 1000000.;
clocktime_in_sec = end_time - start_time;

if (rank == 0)
printf("Initialization (%s) done in %f s\n", this->get_classname(),
total_usecs);
clocktime_in_sec.count());

for (iX0 = 0; iX0 < nX0loc; iX0++)
arrayK_pR[iX0 * (nKx + 1) + nKx] = 0.;
Expand Down
Loading

0 comments on commit 9f8a752

Please sign in to comment.