From 7f6fc147bb2c1a0e2bb5b4d4574c0174caf3ad42 Mon Sep 17 00:00:00 2001 From: Cristian C Lalescu <Cristian.Lalescu@mpcdf.mpg.de> Date: Sat, 30 Jul 2022 17:13:19 +0200 Subject: [PATCH 1/6] mark intel-only pragma as such --- cpp/kspace.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cpp/kspace.cpp b/cpp/kspace.cpp index b1f40ae4..3628893d 100644 --- a/cpp/kspace.cpp +++ b/cpp/kspace.cpp @@ -172,7 +172,9 @@ kspace<be, dt>::kspace( // I chose the last option because there's no reason to optimize this // loop. Furthermore, it seems like the solution that's most readable, // and with the least amount of side effects. - # pragma novector + #if defined(__INTEL_COMPILER) + #pragma novector + #endif for (int n=0; n<this->nshells; n++){ if (this->nshell[n] > 0) this->kshell[n] /= this->nshell[n]; -- GitLab From 1c46242f7742d3378f182aee3f3363fad6c7e815 Mon Sep 17 00:00:00 2001 From: Cristian C Lalescu <Cristian.Lalescu@mpcdf.mpg.de> Date: Sat, 30 Jul 2022 18:27:16 +0200 Subject: [PATCH 2/6] gets rid of GCC warnings --- cpp/field.cpp | 8 ++++++++ cpp/full_code/NSVE.cpp | 5 ++--- cpp/full_code/NSVE.hpp | 7 ++++--- cpp/full_code/postprocess.cpp | 5 ++--- cpp/full_code/postprocess.hpp | 9 +++++---- cpp/vorticity_equation.cpp | 28 ++++++++++++++-------------- cpp/vorticity_equation.hpp | 6 ++++-- 7 files changed, 39 insertions(+), 29 deletions(-) diff --git a/cpp/field.cpp b/cpp/field.cpp index 16091a6b..2f7a7a90 100644 --- a/cpp/field.cpp +++ b/cpp/field.cpp @@ -1017,6 +1017,13 @@ void field<rnumber, be, fc>::compute_rspace_stats( // dset_name.c_str()); assert(ndims == int(ndim(fc))-1); assert(dims[1] == nmoments); + // gcc complains about the following code, when ndim(fc)-1 is too small + // since I already assert what the value of ndims is, I know the code + // is safe, so I just tell GCC to ignore the apparent problem with this + // pragma. See link below for more info: + // https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html +#pragma GCC diagnostic ignored "-Warray-bounds" +#pragma GCC diagnostic push switch(ndims) { case 2: @@ -1029,6 +1036,7 @@ void field<rnumber, be, fc>::compute_rspace_stats( nvals = dims[2]*dims[3]; break; } +#pragma GCC diagnostic pop H5Sclose(wspace); H5Dclose(dset); dset = H5Dopen(group, ("histograms/" + dset_name).c_str(), H5P_DEFAULT); diff --git a/cpp/full_code/NSVE.cpp b/cpp/full_code/NSVE.cpp index 5c0d360c..20591057 100644 --- a/cpp/full_code/NSVE.cpp +++ b/cpp/full_code/NSVE.cpp @@ -84,7 +84,7 @@ int NSVE<rnumber>::initialize(void) this->fs->fk0 = fk0; this->fs->fk1 = fk1; this->fs->dt = dt; - strncpy(this->fs->forcing_type, forcing_type, 128); + this->fs->forcing_type = forcing_type; this->fs->iteration = this->iteration; this->fs->checkpoint = this->checkpoint; @@ -193,8 +193,7 @@ int NSVE<rnumber>::read_parameters(void) this->histogram_bins = hdf5_tools::read_value<int>(parameter_file, "parameters/histogram_bins"); this->max_velocity_estimate = hdf5_tools::read_value<double>(parameter_file, "parameters/max_velocity_estimate"); this->max_vorticity_estimate = hdf5_tools::read_value<double>(parameter_file, "parameters/max_vorticity_estimate"); - std::string tmp = hdf5_tools::read_string(parameter_file, "parameters/forcing_type"); - snprintf(this->forcing_type, 511, "%s", tmp.c_str()); + this->forcing_type = hdf5_tools::read_string(parameter_file, "parameters/forcing_type"); this->fftw_plan_rigor = hdf5_tools::read_string(parameter_file, "parameters/fftw_plan_rigor"); H5Fclose(parameter_file); // the following ensures the file is free after exiting this method diff --git a/cpp/full_code/NSVE.hpp b/cpp/full_code/NSVE.hpp index 15a388dc..60809a88 100644 --- a/cpp/full_code/NSVE.hpp +++ b/cpp/full_code/NSVE.hpp @@ -28,12 +28,13 @@ #define NSVE_HPP - -#include <cstdlib> #include "base.hpp" #include "vorticity_equation.hpp" #include "full_code/direct_numerical_simulation.hpp" +#include <cstdlib> +#include <string> + /** \brief Navier-Stokes solver. * * Solves the vorticity equation for a Navier-Stokes fluid. @@ -58,7 +59,7 @@ class NSVE: public direct_numerical_simulation double energy; double injection_rate; int fmode; - char forcing_type[512]; + std::string forcing_type; int histogram_bins; double max_velocity_estimate; double max_vorticity_estimate; diff --git a/cpp/full_code/postprocess.cpp b/cpp/full_code/postprocess.cpp index 2fe20c34..2c136a7b 100644 --- a/cpp/full_code/postprocess.cpp +++ b/cpp/full_code/postprocess.cpp @@ -73,8 +73,7 @@ int postprocess::read_parameters() this->variation_time_scale = hdf5_tools::read_value<double>(parameter_file, "parameters/variation_time_scale"); this->energy = hdf5_tools::read_value<double>(parameter_file, "parameters/energy"); this->injection_rate = hdf5_tools::read_value<double>(parameter_file, "parameters/injection_rate"); - std::string tmp = hdf5_tools::read_string(parameter_file, "parameters/forcing_type"); - snprintf(this->forcing_type, 511, "%s", tmp.c_str()); + this->forcing_type = hdf5_tools::read_string(parameter_file, "parameters/forcing_type"); H5Fclose(parameter_file); MPI_Barrier(this->comm); return EXIT_SUCCESS; @@ -96,7 +95,7 @@ int postprocess::copy_parameters_into( dst->friction_coefficient = this->friction_coefficient; dst->variation_strength = this->variation_strength; dst->variation_time_scale = this->variation_time_scale; - strncpy(dst->forcing_type, this->forcing_type, 128); + dst->forcing_type = this->forcing_type; return EXIT_SUCCESS; } diff --git a/cpp/full_code/postprocess.hpp b/cpp/full_code/postprocess.hpp index 4a8fab39..52826cf7 100644 --- a/cpp/full_code/postprocess.hpp +++ b/cpp/full_code/postprocess.hpp @@ -27,13 +27,14 @@ #ifndef POSTPROCESS_HPP #define POSTPROCESS_HPP +#include "full_code/code_base.hpp" +#include "vorticity_equation.hpp" +#include "base.hpp" + #include <cstdlib> #include <sys/types.h> #include <sys/stat.h> #include <vector> -#include "base.hpp" -#include "vorticity_equation.hpp" -#include "full_code/code_base.hpp" class postprocess: public code_base { @@ -56,7 +57,7 @@ class postprocess: public code_base double variation_strength; double variation_time_scale; int fmode; - char forcing_type[512]; + std::string forcing_type; double nu; postprocess( diff --git a/cpp/vorticity_equation.cpp b/cpp/vorticity_equation.cpp index c32c0331..7ce50a76 100644 --- a/cpp/vorticity_equation.cpp +++ b/cpp/vorticity_equation.cpp @@ -289,12 +289,12 @@ void vorticity_equation<rnumber, be>::add_forcing( double t) { TIMEZONE("vorticity_equation::add_forcing"); - if (strcmp(this->forcing_type, "Kolmogorov") == 0) + if (this->forcing_type == std::string("Kolmogorov")) { this->add_Kolmogorov_forcing(dst, this->fmode, this->famplitude); return; } - if (strcmp(this->forcing_type, "2Kolmogorov") == 0) + if (this->forcing_type == std::string("2Kolmogorov")) { // 2 Kolmogorov forces // first one wavenumber fk0, amplitude 1 - A @@ -307,7 +307,7 @@ void vorticity_equation<rnumber, be>::add_forcing( this->add_Kolmogorov_forcing(dst, fmode, amplitude); return; } - if (strcmp(this->forcing_type, "Kolmogorov_and_drag") == 0) + if (this->forcing_type == std::string("Kolmogorov_and_drag")) { this->add_Kolmogorov_forcing(dst, this->fmode, this->famplitude); this->add_field_band( @@ -316,7 +316,7 @@ void vorticity_equation<rnumber, be>::add_forcing( -this->friction_coefficient); return; } - if (strcmp(this->forcing_type, "Kolmogorov_and_compensated_drag") == 0) + if (this->forcing_type == std::string("Kolmogorov_and_compensated_drag")) { double amplitude = this->famplitude * ( 1 + this->friction_coefficient / sqrt(this->fmode * this->famplitude)); @@ -327,7 +327,7 @@ void vorticity_equation<rnumber, be>::add_forcing( -this->friction_coefficient); return; } - if (strcmp(this->forcing_type, "linear") == 0) + if (this->forcing_type == std::string("linear")) { this->add_field_band( dst, vort_field, @@ -335,9 +335,9 @@ void vorticity_equation<rnumber, be>::add_forcing( this->famplitude); return; } - if ((strcmp(this->forcing_type, "fixed_energy_injection_rate") == 0) || - (strcmp(this->forcing_type, "fixed_energy_injection_rate_and_drag") == 0) || - (strcmp(this->forcing_type, "sinusoidal_energy_injection_rate") == 0)) + if (this->forcing_type == std::string("fixed_energy_injection_rate") || + this->forcing_type == std::string("fixed_energy_injection_rate_and_drag") || + this->forcing_type == std::string("sinusoidal_energy_injection_rate")) { // first, compute energy in shell shared_array<double> local_energy_in_shell(1); @@ -377,7 +377,7 @@ void vorticity_equation<rnumber, be>::add_forcing( if (energy_in_shell < 10*std::numeric_limits<rnumber>::epsilon()) energy_in_shell = 1; double temp_famplitude = 0; - if (strcmp(this->forcing_type, "sinusoidal_energy_injection_rate") == 0){ + if (this->forcing_type == std::string("sinusoidal_energy_injection_rate")){ temp_famplitude = (this->injection_rate + this->variation_strength *sin(t/this->variation_time_scale)) / energy_in_shell; @@ -389,18 +389,18 @@ void vorticity_equation<rnumber, be>::add_forcing( this->fk0, this->fk1, temp_famplitude); // and add drag if desired - if (strcmp(this->forcing_type, "fixed_energy_injection_rate_and_drag") == 0) + if (this->forcing_type == std::string("fixed_energy_injection_rate_and_drag")) this->add_field_band( dst, vort_field, this->fmode, this->fmode + (this->fk1 - this->fk0), -this->friction_coefficient); return; } - if (strcmp(this->forcing_type, "fixed_energy") == 0) + if (this->forcing_type == std::string("fixed_energy")) return; else { - DEBUG_MSG("unknown forcing type printed on next line\n%s", this->forcing_type); + DEBUG_MSG("unknown forcing type printed on next line\n%s", this->forcing_type.c_str()); throw std::invalid_argument("unknown forcing type"); } } @@ -412,7 +412,7 @@ void vorticity_equation<rnumber, be>::impose_forcing( field<rnumber, be, THREE> *oold) { TIMEZONE("vorticity_equation::impose_forcing"); - if (strcmp(this->forcing_type, "fixed_energy") == 0) + if (this->forcing_type == std::string("fixed_energy")) { // first, compute energy in shell shared_array<double> local_energy_in_shell(1); @@ -802,7 +802,7 @@ void vorticity_equation<rnumber, be>::compute_Eulerian_acceleration( for (int i=0; i<2; i++) acceleration->get_cdata()[tindex+cc][i] = \ - this->nu*k2*this->cvelocity->get_cdata()[tindex+cc][i]; - if (strcmp(this->forcing_type, "linear") == 0) + if (this->forcing_type == std::string("linear")) { double knorm = sqrt(k2); if ((this->fk0 <= knorm) && diff --git a/cpp/vorticity_equation.hpp b/cpp/vorticity_equation.hpp index 90803b4b..e48196f3 100644 --- a/cpp/vorticity_equation.hpp +++ b/cpp/vorticity_equation.hpp @@ -27,12 +27,14 @@ #ifndef VORTICITY_EQUATION #define VORTICITY_EQUATION +#include "field.hpp" + #include <sys/stat.h> #include <stdio.h> #include <stdlib.h> #include <iostream> +#include <string> -#include "field.hpp" extern int myrank, nprocs; @@ -79,7 +81,7 @@ class vorticity_equation double friction_coefficient; // for Kolmogorov_and_drag double variation_strength; // for time-varying forcing double variation_time_scale; // for time-varying forcing - char forcing_type[128]; + std::string forcing_type; /* constructor, destructor */ vorticity_equation( -- GitLab From 3edd6a0dd5835c28830b58202441bd3e29e17567 Mon Sep 17 00:00:00 2001 From: Cristian C Lalescu <Cristian.Lalescu@mpcdf.mpg.de> Date: Sat, 30 Jul 2022 20:50:07 +0200 Subject: [PATCH 3/6] gets rid of intel warnings --- cpp/hdf5_tools.cpp | 9 +++------ cpp/particles/abstract_particle_rhs.hpp | 2 +- cpp/particles/rhs/deformation_tensor_rhs.hpp | 2 +- cpp/particles/rhs/tracer_rhs.hpp | 2 +- cpp/particles/rhs/tracer_with_collision_counter_rhs.hpp | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cpp/hdf5_tools.cpp b/cpp/hdf5_tools.cpp index 9a92c459..2db76f3a 100644 --- a/cpp/hdf5_tools.cpp +++ b/cpp/hdf5_tools.cpp @@ -1,7 +1,9 @@ #include "hdf5_tools.hpp" #include "scope_timer.hpp" + #include <cfloat> #include <climits> +#include <limits> template <> hid_t hdf5_tools::hdf5_type_id<char>() { @@ -258,12 +260,7 @@ number hdf5_tools::read_value( { DEBUG_MSG("attempted to read dataset %s which does not exist.\n", dset_name.c_str()); - if (typeid(number) == typeid(int)) - result = INT_MAX; - else if (typeid(number) == typeid(long long int)) - result = -1; - else if (typeid(number) == typeid(double)) - result = number(DBL_MAX); + result = std::numeric_limits<number>::max(); } H5Tclose(mem_dtype); return result; diff --git a/cpp/particles/abstract_particle_rhs.hpp b/cpp/particles/abstract_particle_rhs.hpp index 947e1524..a0c68816 100644 --- a/cpp/particles/abstract_particle_rhs.hpp +++ b/cpp/particles/abstract_particle_rhs.hpp @@ -49,7 +49,7 @@ class abstract_particle_rhs /** Probe the dimension of the ODE */ - virtual const int getStateSize() const = 0; + virtual int getStateSize() const = 0; /** Compute right-hand-side of the ODE diff --git a/cpp/particles/rhs/deformation_tensor_rhs.hpp b/cpp/particles/rhs/deformation_tensor_rhs.hpp index 0835f986..43b75cb9 100644 --- a/cpp/particles/rhs/deformation_tensor_rhs.hpp +++ b/cpp/particles/rhs/deformation_tensor_rhs.hpp @@ -48,7 +48,7 @@ class deformation_tensor_rhs: public abstract_particle_rhs deformation_tensor_rhs(){} ~deformation_tensor_rhs() noexcept(false){} - const int getStateSize() const + int getStateSize() const { // 3 numbers for position // 9 numbers for components of deformation tensor diff --git a/cpp/particles/rhs/tracer_rhs.hpp b/cpp/particles/rhs/tracer_rhs.hpp index 680b46fd..eca90024 100644 --- a/cpp/particles/rhs/tracer_rhs.hpp +++ b/cpp/particles/rhs/tracer_rhs.hpp @@ -43,7 +43,7 @@ class tracer_rhs: public abstract_particle_rhs tracer_rhs(){} ~tracer_rhs() noexcept(false){} - const int getStateSize() const + int getStateSize() const { return 3; } diff --git a/cpp/particles/rhs/tracer_with_collision_counter_rhs.hpp b/cpp/particles/rhs/tracer_with_collision_counter_rhs.hpp index 5aa15213..4fdc0686 100644 --- a/cpp/particles/rhs/tracer_with_collision_counter_rhs.hpp +++ b/cpp/particles/rhs/tracer_with_collision_counter_rhs.hpp @@ -44,7 +44,7 @@ class tracer_with_collision_counter_rhs: public tracer_rhs<rnumber, be, tt> tracer_with_collision_counter_rhs(){} ~tracer_with_collision_counter_rhs() noexcept(false){} - virtual const int getStateSize() const + virtual int getStateSize() const { return 3; } -- GitLab From 1ae9d5baba9c637a401c7742bbf69c61a701c618 Mon Sep 17 00:00:00 2001 From: Cristian C Lalescu <Cristian.Lalescu@mpcdf.mpg.de> Date: Sat, 30 Jul 2022 20:50:42 +0200 Subject: [PATCH 4/6] removes unused headers --- cpp/hdf5_tools.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/cpp/hdf5_tools.cpp b/cpp/hdf5_tools.cpp index 2db76f3a..aadd0c74 100644 --- a/cpp/hdf5_tools.cpp +++ b/cpp/hdf5_tools.cpp @@ -1,8 +1,6 @@ #include "hdf5_tools.hpp" #include "scope_timer.hpp" -#include <cfloat> -#include <climits> #include <limits> template <> hid_t hdf5_tools::hdf5_type_id<char>() -- GitLab From 302b8e472cbf59f1f38f1a5663151ec1c74c0daf Mon Sep 17 00:00:00 2001 From: Cristian C Lalescu <Cristian.Lalescu@mpcdf.mpg.de> Date: Sat, 30 Jul 2022 20:57:02 +0200 Subject: [PATCH 5/6] use hdf5_tools::hdf5_type_id to simplify code --- cpp/hdf5_tools.cpp | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/cpp/hdf5_tools.cpp b/cpp/hdf5_tools.cpp index aadd0c74..e75070b4 100644 --- a/cpp/hdf5_tools.cpp +++ b/cpp/hdf5_tools.cpp @@ -208,13 +208,7 @@ std::vector<number> hdf5_tools::read_vector( hsize_t vector_length; // first, read size of array hid_t dset, dspace; - hid_t mem_dtype; - if (typeid(number) == typeid(int)) - mem_dtype = H5Tcopy(H5T_NATIVE_INT); - else if (typeid(number) == typeid(double)) - mem_dtype = H5Tcopy(H5T_NATIVE_DOUBLE); - else - return result; + hid_t mem_dtype = H5Tcopy(hdf5_tools::hdf5_type_id<number>()); dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT); dspace = H5Dget_space(dset); assert(H5Sget_simple_extent_ndims(dspace) == 1); @@ -235,15 +229,7 @@ number hdf5_tools::read_value( TIMEZONE("hdf5_tools::read_value"); number result; hid_t dset; - hid_t mem_dtype; - if (typeid(number) == typeid(int)) - mem_dtype = H5Tcopy(H5T_NATIVE_INT); - else if (typeid(number) == typeid(long long int)) - mem_dtype = H5Tcopy(H5T_NATIVE_LLONG); - else if (typeid(number) == typeid(double)) - mem_dtype = H5Tcopy(H5T_NATIVE_DOUBLE); - else - return result; + hid_t mem_dtype = H5Tcopy(hdf5_tools::hdf5_type_id<number>()); if (H5Lexists(group, dset_name.c_str(), H5P_DEFAULT)) { dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT); @@ -270,13 +256,10 @@ int hdf5_tools::write_value_with_single_rank( const std::string dset_name, const number value) { + assert(typeid(number) == typeid(int) || + typeid(number) == typeid(double)); hid_t dset, mem_dtype; - if (typeid(number) == typeid(int)) - mem_dtype = H5Tcopy(H5T_NATIVE_INT); - else if (typeid(number) == typeid(double)) - mem_dtype = H5Tcopy(H5T_NATIVE_DOUBLE); - else - return EXIT_FAILURE; + mem_dtype = H5Tcopy(hdf5_tools::hdf5_type_id<number>()); if (H5Lexists(group, dset_name.c_str(), H5P_DEFAULT)) { dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT); -- GitLab From 1381dbea08cfb35c98a1de89e872b91dbcf68dde Mon Sep 17 00:00:00 2001 From: Cristian C Lalescu <Cristian.Lalescu@mpcdf.mpg.de> Date: Sat, 30 Jul 2022 21:19:08 +0200 Subject: [PATCH 6/6] fixes leftover conflict --- TurTLE/test/collisions/stokes_rhs.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TurTLE/test/collisions/stokes_rhs.hpp b/TurTLE/test/collisions/stokes_rhs.hpp index 582f7089..41268149 100644 --- a/TurTLE/test/collisions/stokes_rhs.hpp +++ b/TurTLE/test/collisions/stokes_rhs.hpp @@ -43,7 +43,7 @@ class stokes_rhs: public abstract_particle_rhs public: stokes_rhs(){} ~stokes_rhs(){} - const int getStateSize() const + int getStateSize() const { // 3 numbers for position // // 9 numbers for components of deformation tensor // 3 numbers to store logarithmic factors -- GitLab