Skip to content

Commit

Permalink
Fix CMake and CUDA compiler warnings (#3859)
Browse files Browse the repository at this point in the history
Description of changes:
- fix several issues in the CMake logic
- fix function visibility issues in CUDA code (fixes #3797)
- document the CPU and GPU implementations of `specfunc`
  • Loading branch information
kodiakhq[bot] authored Aug 14, 2020
2 parents 403df2d + e41a54c commit c644d2d
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 41 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ target_compile_options(
-Wno-unused-variable
-Wno-unused-parameter
-Wno-missing-braces
$<$<CXX_COMPILER_ID:GNU>:-Wno-clobbered;-Wno-cast-function-type>
$<$<CXX_COMPILER_ID:GNU>:-Wno-clobbered>
$<$<CXX_COMPILER_ID:Intel>:-wd592>)

# disable more warnings from -Wextra
Expand All @@ -423,6 +423,10 @@ if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_VERSION
# older GCC versions don't support -Wno-pedantic which we need in src/python
target_compile_options(cxx_interface INTERFACE -pedantic)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION
VERSION_GREATER_EQUAL "8.1.0")
target_compile_options(cxx_interface INTERFACE -Wno-cast-function-type)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND CMAKE_CXX_COMPILER_VERSION
VERSION_LESS "16.0")
# workaround for compiler crash related to decltype() and variadic template
Expand Down
9 changes: 9 additions & 0 deletions doc/doxygen/bibliography.bib
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,15 @@ @article{martys99a
doi = {10.1103/PhysRevE.59.3733},
}

@book{moshier89a,
title={{Methods and Programs for Mathematical Functions}},
author={Moshier, Stephen Lloyd Baluk},
isbn={9780470216095},
series={Ellis Horwood Series in Mathematics and Its Applications},
year={1989},
publisher={Ellis Horwood},
}

@Article{moss96a,
author={Moss, G. P.},
journal={Pure and Applied Chemistry},
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinx/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ each variant having different activated features, and for as many
platforms as you want.
Once you've run ``ccmake``, you can list the configured variables with
``cmake -LAH -N | less`` (uses a pager) or with ``ccmake ..`` and pressing
``cmake -LAH -N .. | less`` (uses a pager) or with ``ccmake ..`` and pressing
key ``t`` to toggle the advanced mode on (uses the curses interface).
**Example:**
Expand Down
2 changes: 1 addition & 1 deletion maintainer/CI/dox_warnings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# This script generates a summary of all Doxygen warnings that require fixing.

DOXYGEN=$(cmake -LA -N | grep "DOXYGEN_EXECUTABLE:FILEPATH" | cut -d'=' -f2-)
DOXYGEN=$(cmake -LA -N . | grep "DOXYGEN_EXECUTABLE:FILEPATH" | cut -d'=' -f2-)
if ! hash "${DOXYGEN}" 2>/dev/null; then
echo "No doxygen found."
exit 2
Expand Down
2 changes: 1 addition & 1 deletion src/core/actor/mmm-common_cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cuda_utils.hpp"
#include "electrostatics_magnetostatics/mmm-common.hpp"
#include "electrostatics_magnetostatics/mmm-modpsi.hpp"
#include "specfunc_cuda.hpp"

// order hardcoded. mmm1d_recalcTables() typically does order less than 30.
Expand Down
42 changes: 40 additions & 2 deletions src/core/actor/specfunc_cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,40 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* Original gsl header
* specfunc/bessel_K0.cpp
*
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Gerard Jungman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

/* Original Author: G. Jungman */

/** \file
* This file contains implementations for the modified Bessel functions of
* first and second kind. The implementations are based on the GSL code (see
* the original GSL header above) and are duplicated from \ref specfunc.cpp.
*/
#include "config.hpp"

const mmm1dgpu_real M_LN2f = M_LN2;

// Adapted from specfunc.c and polynom.h

/** @name Chebyshev expansions based on SLATEC bk0(), bk0e() */
/*@{*/
__constant__ static mmm1dgpu_real bk0_data[11] = {
-.5 - 0.03532739323390276872, 0.3442898999246284869,
0.03597993651536150163, 0.00126461541144692592,
Expand All @@ -47,14 +75,20 @@ __constant__ static mmm1dgpu_real ak02_data[14] = {
-0.00000000000020743, 0.00000000000001925, -0.00000000000000192,
0.00000000000000020, -0.00000000000000002};
__constant__ static int ak02_size = 13;
/*@}*/

/** @name Chebyshev expansions based on SLATEC besi0() */
/*@{*/
__constant__ static mmm1dgpu_real bi0_data[12] = {
5.5 - .07660547252839144951, 1.92733795399380827000, .22826445869203013390,
.01304891466707290428, .00043442709008164874, .00000942265768600193,
.00000014340062895106, .00000000161384906966, .00000000001396650044,
.00000000000009579451, .00000000000000053339, .00000000000000000245};
__constant__ static int bi0_size = 12;
/*@}*/

/** @name Chebyshev expansions based on SLATEC besk1(), besk1e() */
/*@{*/
__constant__ static mmm1dgpu_real bk1_data[11] = {
1.5 + 0.0253002273389477705, -0.3531559607765448760, -0.1226111808226571480,
-0.0069757238596398643, -0.0001730288957513052, -0.0000024334061415659,
Expand All @@ -78,13 +112,17 @@ __constant__ static mmm1dgpu_real ak12_data[14] = {
0.00000000000023720, -0.00000000000002176, 0.00000000000000215,
-0.00000000000000022, 0.00000000000000002};
__constant__ static int ak12_size = 14;
/*@}*/

/** @name Chebyshev expansions based on SLATEC besi1(), besi1e() */
/*@{*/
__constant__ static mmm1dgpu_real bi1_data[11] = {
1.75 - 0.001971713261099859, 0.407348876675464810, 0.034838994299959456,
0.001545394556300123, 0.000041888521098377, 0.000000764902676483,
0.000000010042493924, 0.000000000099322077, 0.000000000000766380,
0.000000000000004741, 0.000000000000000024};
__constant__ static int bi1_size = 11;
/*@}*/

__device__ mmm1dgpu_real evaluateAsChebychevSeriesAt(mmm1dgpu_real const *c,
int n, mmm1dgpu_real x) {
Expand Down
3 changes: 2 additions & 1 deletion src/core/cuda_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ std::vector<EspressoGpuDevice> cuda_gather_gpus() {

/* Truncate to 63 chars to fit struct. */
if (strlen(proc_name) > 63)
proc_name[63] = 0;
proc_name[63] = '\0';

for (int i = 0; i < n_gpus; ++i) {
/* Check if device has at least minimum compute capability */
if (cuda_check_gpu(i) == ES_OK) {
EspressoGpuDevice device;
if (cuda_get_device_props(i, device) == ES_OK) {
strncpy(device.proc_name, proc_name, 64);
device.proc_name[63] = '\0';
device.node = this_node;
devices.push_back(device);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/electrostatics_magnetostatics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/magnetic_non_p3m_methods.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mdlc_correction.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mmm1d.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mmm-common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/mmm-modpsi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/p3m-common.cpp
${CMAKE_CURRENT_SOURCE_DIR}/p3m_send_mesh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/p3m.cpp
Expand Down
15 changes: 2 additions & 13 deletions src/core/electrostatics_magnetostatics/mmm-common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,12 @@
#ifndef MMM_COMMON_H
#define MMM_COMMON_H

#include "mmm-modpsi.hpp"

#include "specfunc.hpp"

#include <vector>

/** \name Math constants */
/*@{*/
#define C_2PI (2 * M_PI)
#define C_GAMMA (0.57721566490153286060651209008)
/*@}*/

/** Table of the Taylor expansions of the modified polygamma functions */
extern std::vector<std::vector<double>> modPsi;
extern int n_modPsi;

/** Modified polygamma for even order 2*n, n >= 0 */
inline double mod_psi_even(int n, double x) {
return evaluateAsTaylorSeriesAt(modPsi[2 * n], x * x);
Expand All @@ -54,7 +46,4 @@ inline double mod_psi_odd(int n, double x) {
return x * evaluateAsTaylorSeriesAt(modPsi[2 * n + 1], x * x);
}

/** Create the both the even and odd polygamma functions up to order 2*n */
void create_mod_psi_up_to(int n);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "config.hpp"

#include "mmm-common.hpp"
#include "mmm-modpsi.hpp"

#include <cmath>

Expand Down
45 changes: 45 additions & 0 deletions src/core/electrostatics_magnetostatics/mmm-modpsi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2010-2019 The ESPResSo project
* Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
* Max-Planck-Institute for Polymer Research, Theory Group
*
* This file is part of ESPResSo.
*
* ESPResSo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ESPResSo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file
* Common parts of the MMM family of methods for the electrostatic
* interaction, MMM1D, MMM2D and ELC. This file contains the code for the
* CPU and GPU implementations.
*/

#ifndef MMM_BASE_H
#define MMM_BASE_H

#include <vector>

/** \name Math constants */
/*@{*/
#define C_2PI (2 * M_PI)
#define C_GAMMA (0.57721566490153286060651209008)
/*@}*/

/** Table of the Taylor expansions of the modified polygamma functions */
extern std::vector<std::vector<double>> modPsi;
extern int n_modPsi;

/** Create both the even and odd polygamma functions up to order 2*n */
void create_mod_psi_up_to(int n);

#endif
8 changes: 4 additions & 4 deletions src/core/electrostatics_magnetostatics/specfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ static double ai12_cs[22] = {
-0.00000000000000003};
/*@}*/

/** Coefficients for Maclaurin summation in hzeta().
* B_{2j}/(2j)!
/** Coefficients for Maclaurin summation in hzeta(). Evaluated as inverse
* numbers, i.e. @f$ \displaystyle\frac{B_{2j}}{(2j)!} @f$.
*/
static double const hzeta_c[15] = {
1.00000000000000000000000000000, 0.083333333333333333333333333333,
Expand All @@ -291,8 +291,8 @@ double hzeta(double s, double q) {
double p3 = pow(q / (2.0 + q), s);
return p1 * (1.0 + p2 + p3);
}
/* Euler-Maclaurin summation formula
* [Moshier, p. 400, with several typo corrections]
/** Euler-Maclaurin summation formula from @cite moshier89a p. 400, with
* several typo corrections.
*/
auto const pmax = pow(kmax + q, -s);
auto scp = s;
Expand Down
11 changes: 6 additions & 5 deletions src/core/electrostatics_magnetostatics/specfunc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
* implementations are based on the GSL code (see \ref specfunc.cpp for the
* original GSL header).
*
* The Hurwitz zeta function is evaluated using the Euler-MacLaurin summation
* The Hurwitz zeta function is evaluated using the Euler-Maclaurin summation
* formula, the Bessel functions are evaluated using several different
* Chebychev expansions. Both achieve a precision of nearly machine precision,
* which is no problem for the Hurwitz zeta function, which is only used when
* determining the coefficients for the modified polygamma functions (see \ref
* mmm-common.hpp "mmm-common.h"). However, the Bessel functions are actually
* mmm-common.hpp). However, the Bessel functions are actually
* used in the near formula of MMM2D, which is therefore slightly slower than
* necessary. On the other hand, the number of terms in the Bessel sum is
* quite small normally, so that a less precise version will probably not
Expand Down Expand Up @@ -84,7 +84,8 @@ double LPK1(double x);
*/
void LPK01(double x, double *K0, double *K1);

/** evaluate the polynomial interpreted as a Taylor series via the Horner scheme
/** Evaluate the polynomial interpreted as a Taylor series via the
* Horner scheme.
*/
inline double evaluateAsTaylorSeriesAt(Utils::Span<const double> series,
double x) {
Expand All @@ -97,8 +98,8 @@ inline double evaluateAsTaylorSeriesAt(Utils::Span<const double> series,
return r;
}

/** evaluate the polynomial interpreted as a Chebychev series. Requires a series
* with at least three coefficients, i.e. no linear approximations!
/** Evaluate the polynomial interpreted as a Chebychev series. Requires a
* series with at least three coefficients, i.e. no linear approximations!
*/
inline double evaluateAsChebychevSeriesAt(Utils::Span<const double> series,
double x) {
Expand Down
11 changes: 0 additions & 11 deletions src/core/grid_based_algorithms/lbgpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ typedef double lbForceFloat;
typedef float lbForceFloat;
#endif

class LB_particle_allocation_state {
bool m_invalid = true;

public:
bool operator()() { return m_invalid; }
void invalidate() { m_invalid = true; }

void validate() { m_invalid = false; }
};

/**-------------------------------------------------------------------------*/
/** Parameters for the lattice Boltzmann system for GPU. */
struct LB_parameters_gpu {
Expand Down Expand Up @@ -160,7 +150,6 @@ typedef struct {
/** Switch indicating momentum exchange between particles and fluid */
extern LB_parameters_gpu lbpar_gpu;
extern std::vector<LB_rho_v_pi_gpu> host_values;
extern LB_particle_allocation_state lb_reinit_particles_gpu;
#ifdef ELECTROKINETICS
extern LB_node_force_density_gpu node_f;
extern bool ek_initialized;
Expand Down

0 comments on commit c644d2d

Please sign in to comment.