From 7714b68215fef1ec2f521987ffda14464c58a479 Mon Sep 17 00:00:00 2001 From: Chichi Lalescu <clalesc1@jhu.edu> Date: Sun, 20 Dec 2015 23:05:20 +0100 Subject: [PATCH] code compiles --- bfps/NavierStokes.py | 20 +++++++++++---- bfps/cpp/fluid_solver.cpp | 47 +++++++++++++++++++++++----------- bfps/cpp/fluid_solver_base.cpp | 13 +++------- bfps/cpp/fluid_solver_base.hpp | 16 ++++++++++++ tests/test_base.py | 2 ++ tox_plain.ini | 5 ++-- 6 files changed, 72 insertions(+), 31 deletions(-) diff --git a/bfps/NavierStokes.py b/bfps/NavierStokes.py index d33274fe..229f1480 100644 --- a/bfps/NavierStokes.py +++ b/bfps/NavierStokes.py @@ -139,17 +139,25 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base): self.stat_src += """ //begincpp double *trS2_Q_R_moments = new double[10*3]; + double *gradu_moments = new double[10*9]; ptrdiff_t *hist_trS2_Q_R = new ptrdiff_t[histogram_bins*3]; + ptrdiff_t *hist_gradu = new ptrdiff_t[histogram_bins*9]; ptrdiff_t *hist_QR2D = new ptrdiff_t[QR2D_histogram_bins*QR2D_histogram_bins]; - max_estimates[0] = max_trS2_estimate; - max_estimates[1] = max_Q_estimate; - max_estimates[2] = max_R_estimate; + double trS2QR_max_estimates[3]; + double gradu_max_estimates[9]; + trS2QR_max_estimates[0] = max_trS2_estimate; + trS2QR_max_estimates[1] = max_Q_estimate; + trS2QR_max_estimates[2] = max_R_estimate; + std::fill_n(gradu_max_estimates, 9, max_trS2_estimate); fs->compute_gradient_statistics( fs->cvelocity, + gradu_moments, trS2_Q_R_moments, + hist_gradu, hist_trS2_Q_R, hist_QR2D, max_estimates, + gradu_max_estimates, histogram_bins, QR2D_histogram_bins); //endcpp @@ -161,7 +169,7 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base): max_estimates[1] = max_estimates[0]; max_estimates[2] = max_estimates[0]; max_estimates[3] = max_velocity_estimate; - fs->compute_rspace_stats(fs->rvelocity, + fs->compute_rspace_stats4(fs->rvelocity, velocity_moments, hist_velocity, max_estimates, @@ -171,7 +179,7 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base): max_estimates[1] = max_estimates[0]; max_estimates[2] = max_estimates[0]; max_estimates[3] = max_vorticity_estimate; - fs->compute_rspace_stats(fs->rvorticity, + fs->compute_rspace_stats4(fs->rvorticity, vorticity_moments, hist_vorticity, max_estimates, @@ -286,7 +294,9 @@ class NavierStokes(bfps.fluid_base.fluid_particle_base): self.stat_src += """ //begincpp delete[] trS2_Q_R_moments; + delete[] gradu_moments; delete[] hist_trS2_Q_R; + delete[] hist_gradu; delete[] hist_QR2D; //endcpp """ diff --git a/bfps/cpp/fluid_solver.cpp b/bfps/cpp/fluid_solver.cpp index fdbadab2..4cb096fa 100644 --- a/bfps/cpp/fluid_solver.cpp +++ b/bfps/cpp/fluid_solver.cpp @@ -554,11 +554,11 @@ template<> \ void fluid_solver<R>::compute_gradient_statistics( \ FFTW(complex) *vec, \ double *gradu_moments, \ - double *trS2_Q_R_moments, \ + double *trS2QR_moments, \ ptrdiff_t *gradu_hist, \ ptrdiff_t *trS2QR_hist, \ ptrdiff_t *QR2D_hist, \ - double trS2_Q_R_max_estimates[], \ + double trS2QR_max_estimates[], \ double gradu_max_estimates[], \ int nbins, \ int QR2D_nbins) \ @@ -588,9 +588,9 @@ void fluid_solver<R>::compute_gradient_statistics( \ dz_u = ra + 4*this->cd->local_size; \ double binsize[2]; \ double tmp_max_estimate[3]; \ - tmp_max_estimate[0] = trS2_Q_R_max_estimates[0]; \ - tmp_max_estimate[1] = trS2_Q_R_max_estimates[1]; \ - tmp_max_estimate[2] = trS2_Q_R_max_estimates[2]; \ + tmp_max_estimate[0] = trS2QR_max_estimates[0]; \ + tmp_max_estimate[1] = trS2QR_max_estimates[1]; \ + tmp_max_estimate[2] = trS2QR_max_estimates[2]; \ binsize[0] = 2*tmp_max_estimate[2] / QR2D_nbins; \ binsize[1] = 2*tmp_max_estimate[1] / QR2D_nbins; \ ptrdiff_t *local_hist = new ptrdiff_t[QR2D_nbins*QR2D_nbins]; \ @@ -636,21 +636,38 @@ void fluid_solver<R>::compute_gradient_statistics( \ QR2D_nbins * QR2D_nbins, \ MPI_INT64_T, MPI_SUM, this->cd->comm); \ delete[] local_hist; \ - this->compute_rspace_stats<3>( \ + this->compute_rspace_stats3( \ this->rv[1], \ trS2QR_moments, \ trS2QR_hist, \ tmp_max_estimate, \ nbins); \ - tmp_max_estimate[0] = gradu_max_estimates[0]; \ - tmp_max_estimate[1] = gradu_max_estimates[1]; \ - tmp_max_estimate[2] = gradu_max_estimates[2]; \ - this->compute_rspace_stats<3>( \ - dx_u, \ - trS2QR_moments, \ - trS2QR_hist, \ - tmp_max_estimate, \ - nbins); \ + double *tmp_moments = new double[10*3]; \ + ptrdiff_t *tmp_hist = new ptrdiff_t[nbins*3]; \ + for (int cc=0; cc<3; cc++) \ + { \ + tmp_max_estimate[0] = gradu_max_estimates[cc*3 + 0]; \ + tmp_max_estimate[1] = gradu_max_estimates[cc*3 + 1]; \ + tmp_max_estimate[2] = gradu_max_estimates[cc*3 + 2]; \ + this->compute_rspace_stats3( \ + dx_u, \ + tmp_moments, \ + tmp_hist, \ + tmp_max_estimate, \ + nbins); \ + for (int n = 0; n < 10; n++) \ + for (int i = 0; i < 3 ; i++) \ + { \ + gradu_moments[(n*3 + cc)*3 + i] = tmp_moments[n*3 + i]; \ + } \ + for (int n = 0; n < nbins; n++) \ + for (int i = 0; i < 3; i++) \ + { \ + gradu_hist[(n*3 + cc)*3 + i] = tmp_hist[n*3 + i]; \ + } \ + } \ + delete[] tmp_moments; \ + delete[] tmp_hist; \ FFTW(free)(ca); \ } \ \ diff --git a/bfps/cpp/fluid_solver_base.cpp b/bfps/cpp/fluid_solver_base.cpp index 23f4155d..5e2d93d7 100644 --- a/bfps/cpp/fluid_solver_base.cpp +++ b/bfps/cpp/fluid_solver_base.cpp @@ -562,7 +562,10 @@ int fluid_solver_base<R>::write_base(const char *fname, FFTW(complex) *data) \ char full_name[512]; \ sprintf(full_name, "%s_%s_i%.5x", this->name, fname, this->iteration); \ return this->cd->write(full_name, (void*)data); \ -} +} \ + \ +/* finally, force generation of code */ \ +template class fluid_solver_base<R>; \ /*****************************************************************************/ @@ -582,11 +585,3 @@ FLUID_SOLVER_BASE_DEFINITIONS( BFPS_MPICXX_DOUBLE_COMPLEX) /*****************************************************************************/ - - -/*****************************************************************************/ -/* finally, force generation of code for single precision */ -template class fluid_solver_base<float>; -template class fluid_solver_base<double>; -/*****************************************************************************/ - diff --git a/bfps/cpp/fluid_solver_base.hpp b/bfps/cpp/fluid_solver_base.hpp index e2a45e07..26ae5ded 100644 --- a/bfps/cpp/fluid_solver_base.hpp +++ b/bfps/cpp/fluid_solver_base.hpp @@ -97,6 +97,22 @@ class fluid_solver_base ptrdiff_t *__restrict__ hist, double max_estimate[nvals], const int nbins = 256); + inline void compute_rspace_stats3(rnumber *__restrict__ a, + double *__restrict__ moments, + ptrdiff_t *__restrict__ hist, + double max_estimate[3], + const int nbins = 256) + { + this->compute_rspace_stats<3>(a, moments, hist, max_estimate, nbins); + } + inline void compute_rspace_stats4(rnumber *__restrict__ a, + double *__restrict__ moments, + ptrdiff_t *__restrict__ hist, + double max_estimate[4], + const int nbins = 256) + { + this->compute_rspace_stats<4>(a, moments, hist, max_estimate, nbins); + } void compute_vector_gradient(rnumber (*__restrict__ A)[2], rnumber(*__restrict__ source)[2]); void write_spectrum(const char *fname, cnumber *a, const double k2exponent = 0.0); void fill_up_filename(const char *base_name, char *full_name); diff --git a/tests/test_base.py b/tests/test_base.py index 7004cb9f..3be7d2f5 100755 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -82,6 +82,8 @@ def launch( fluid_precision = opt.precision, frozen_fields = opt.frozen, use_fftw_wisdom = False) + if code_class == bfps.NavierStokes: + c.QR_stats_on = True c.pars_from_namespace(opt) c.parameters['nx'] = opt.n c.parameters['ny'] = opt.n diff --git a/tox_plain.ini b/tox_plain.ini index ad816b83..0a91d263 100644 --- a/tox_plain.ini +++ b/tox_plain.ini @@ -1,7 +1,8 @@ [tox] -envlist = py34 +envlist = py27 [testenv] -deps = matplotlib +sitepackages = True +#deps = matplotlib whitelist_externals = echo cp -- GitLab