Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Require C++17 #834

Merged
merged 9 commits into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CMake/MakefileBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ endforeach()
# =============================================================================
# compile flags : common to all backend
# =============================================================================
# PGI compiler adds --c++14;-A option for C++14, remove ";"
string(REPLACE ";" " " CXX14_STD_FLAGS "${CMAKE_CXX14_STANDARD_COMPILE_OPTION}")
string(JOIN " " CMAKE_CXX17_STANDARD_COMPILE_OPTION_STRING ${CMAKE_CXX17_STANDARD_COMPILE_OPTION})
string(TOUPPER "${CMAKE_BUILD_TYPE}" _BUILD_TYPE)
list(TRANSFORM CORENRN_COMPILE_DEFS PREPEND -D OUTPUT_VARIABLE CORENRN_COMPILE_DEF_FLAGS)
string(
Expand All @@ -85,7 +84,7 @@ string(
CORENRN_CXX_FLAGS
${CMAKE_CXX_FLAGS}
${CMAKE_CXX_FLAGS_${_BUILD_TYPE}}
${CXX14_STD_FLAGS}
${CMAKE_CXX17_STANDARD_COMPILE_OPTION_STRING}
${NVHPC_ACC_COMP_FLAGS}
${NVHPC_CXX_INLINE_FLAGS}
${CORENRN_COMPILE_DEF_FLAGS}
Expand Down
2 changes: 0 additions & 2 deletions CMake/OpenAccHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ if(CORENRN_ENABLE_GPU)
else()
message(FATAL_ERROR "${CORENRN_ACCELERATOR_OFFLOAD} not supported with NVHPC compilers")
endif()
# avoid PGI adding standard compliant "-A" flags
set(CMAKE_CXX14_STANDARD_COMPILE_OPTION --c++14)
string(APPEND CMAKE_EXE_LINKER_FLAGS " ${NVHPC_ACC_COMP_FLAGS}")
# Use `-Mautoinline` option to compile .cpp files generated from .mod files only. This is
# especially needed when we compile with -O0 or -O1 optimisation level where we get link errors.
Expand Down
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ math(EXPR CORENEURON_VERSION_COMBINED
# =============================================================================
# CMake common project settings
# =============================================================================
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_BUILD_TYPE
RelWithDebInfo
CACHE STRING "Empty or one of Debug, Release, RelWithDebInfo")

if(NOT "cxx_std_14" IN_LIST CMAKE_CXX_COMPILE_FEATURES OR NOT "cxx_digit_separators" IN_LIST
CMAKE_CXX_COMPILE_FEATURES)
if(NOT "cxx_std_17" IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(
FATAL_ERROR
"This compiler does not fully support C++14, choose an higher version or an other compiler.")
"This compiler does not fully support C++17, choose a higher version or another compiler.")
endif()

# =============================================================================
Expand Down Expand Up @@ -297,6 +296,11 @@ if(CORENRN_HAVE_NVHPC_COMPILER)
# problem. If GPU support is disabled, we define R123_USE_INTRIN_H=0 to avoid the problem.
list(APPEND CORENRN_COMPILE_DEFS R123_USE_INTRIN_H=0)
endif()
# CMake versions <3.19 used to add -A when using NVHPC/PGI, which makes the compiler excessively
# pedantic. See https://gitlab.kitware.com/cmake/cmake/-/issues/20997.
if(CMAKE_VERSION VERSION_LESS 3.19)
list(REMOVE_ITEM CMAKE_CXX17_STANDARD_COMPILE_OPTION -A)
endif()
endif()

# ~~~
Expand Down
6 changes: 4 additions & 2 deletions coreneuron/mechanism/mech/mod2c_core_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "coreneuron/mechanism/mechanism.hpp"
#include "coreneuron/utils/offload.hpp"

#include <functional>

namespace coreneuron {

#define _STRIDE _cntml_padded + _iml
Expand Down Expand Up @@ -74,7 +76,7 @@ template <typename F>
int euler_thread(int neqn, int* var, int* der, F fun, _threadargsproto_) {
double const dt{_nt->_dt};
/* calculate the derivatives */
fun(_threadargs_); // std::invoke in C++17
std::invoke(fun, _threadargs_);
/* update dependent variables */
for (int i = 0; i < neqn; i++) {
_p[var[i] * _STRIDE] += dt * (_p[der[i] * _STRIDE]);
Expand All @@ -84,7 +86,7 @@ int euler_thread(int neqn, int* var, int* der, F fun, _threadargsproto_) {

template <typename F>
int derivimplicit_thread(int n, int* slist, int* dlist, F fun, _threadargsproto_) {
fun(_threadargs_); // std::invoke in C++17
std::invoke(fun, _threadargs_);
return 0;
}

Expand Down
9 changes: 5 additions & 4 deletions coreneuron/sim/scopmath/newton_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <algorithm>
#include <cmath>
#include <functional>

namespace coreneuron {
#if defined(scopmath_newton_ix) || defined(scopmath_newton_s) || defined(scopmath_newton_x)
Expand Down Expand Up @@ -57,11 +58,11 @@ void nrn_buildjacobian_thread(NewtonSpace* ns,
for (int j = 0; j < n; j++) {
double increment = std::max(std::fabs(0.02 * (scopmath_newton_x(index[j]))), STEP);
scopmath_newton_x(index[j]) += increment;
func(_threadargs_); // std::invoke in C++17
std::invoke(func, _threadargs_);
for (int i = 0; i < n; i++)
high_value[scopmath_newton_ix(i)] = value[scopmath_newton_ix(i)];
scopmath_newton_x(index[j]) -= 2.0 * increment;
func(_threadargs_); // std::invoke in C++17
std::invoke(func, _threadargs_);
for (int i = 0; i < n; i++) {
low_value[scopmath_newton_ix(i)] = value[scopmath_newton_ix(i)];

Expand All @@ -75,7 +76,7 @@ void nrn_buildjacobian_thread(NewtonSpace* ns,
/* Restore original variable and function values. */

scopmath_newton_x(index[j]) += increment;
func(_threadargs_); // std::invoke in C++17
std::invoke(func, _threadargs_);
}
}
#undef scopmath_newton_x
Expand Down Expand Up @@ -160,7 +161,7 @@ inline int nrn_newton_thread(NewtonSpace* ns,
}
}
// Evaulate function values with new solution.
func(_threadargs_); // std::invoke in C++17
std::invoke(func, _threadargs_);
max_dev = 0.0;
for (int i = 0; i < n; i++) {
value[scopmath_newton_ix(i)] = -value[scopmath_newton_ix(i)]; /* Required correction
Expand Down
14 changes: 8 additions & 6 deletions coreneuron/sim/scopmath/sparse_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "coreneuron/mechanism/mech/mod2c_core_thread.hpp"
#include "coreneuron/sim/scopmath/errcodes.h"

#include <functional>

namespace coreneuron {
namespace scopmath {
namespace sparse {
Expand Down Expand Up @@ -479,7 +481,7 @@ void create_coef_list(SparseObj* so, int n, SPFUN fun, _threadargsproto_) {
initeqn(so, (unsigned) n);
so->phase = 1;
so->ngetcall[0] = 0;
fun(so, so->rhs, _threadargs_); // std::invoke in C++17
std::invoke(fun, so, so->rhs, _threadargs_);
if (so->coef_list) {
free(so->coef_list);
}
Expand All @@ -488,7 +490,7 @@ void create_coef_list(SparseObj* so, int n, SPFUN fun, _threadargsproto_) {
spar_minorder(so);
so->phase = 2;
so->ngetcall[0] = 0;
fun(so, so->rhs, _threadargs_); // std::invoke in C++17
std::invoke(fun, so, so->rhs, _threadargs_);
so->phase = 0;
}
} // namespace sparse
Expand Down Expand Up @@ -565,7 +567,7 @@ int sparse_thread(SparseObj* so,
}
for (err = 1, j = 0; err > CONVERGE; j++) {
scopmath::sparse::init_coef_list(so, _iml);
fun(so, so->rhs, _threadargs_); // std::invoke in C++17
std::invoke(fun, so, so->rhs, _threadargs_);
if ((ierr = scopmath::sparse::matsol(so, _iml))) {
return ierr;
}
Expand All @@ -583,8 +585,8 @@ int sparse_thread(SparseObj* so,
break;
}
scopmath::sparse::init_coef_list(so, _iml);
fun(so, so->rhs, _threadargs_); // std::invoke in C++17
for (i = 0; i < n; i++) { /*restore Dstate at t+dt*/
std::invoke(fun, so, so->rhs, _threadargs_);
for (i = 0; i < n; i++) { /*restore Dstate at t+dt*/
scopmath_sparse_d(i) = (scopmath_sparse_s(i) - scopmath_sparse_d(i)) / dt;
}
return SUCCESS;
Expand All @@ -603,7 +605,7 @@ int _cvode_sparse_thread(void** vpr, int n, int* x, SPFUN fun, _threadargsproto_
}
scopmath::sparse::create_coef_list(so, n, fun, _threadargs_); /* calls fun twice */
scopmath::sparse::init_coef_list(so, _iml);
fun(so, so->rhs, _threadargs_); // std::invoke in C++17
std::invoke(fun, so, so->rhs, _threadargs_);
int ierr;
if ((ierr = scopmath::sparse::matsol(so, _iml))) {
return ierr;
Expand Down