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

Commit f1a5f61

Browse files
committed
Compilation fixes for NVHPC 22.5.
1 parent 96b8298 commit f1a5f61

File tree

9 files changed

+82
-111
lines changed

9 files changed

+82
-111
lines changed

coreneuron/CMakeLists.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,9 @@ if(CORENRN_ENABLE_GPU)
120120
endif()
121121

122122
# =============================================================================
123-
# eion.cpp depends on CORENRN_USE_LEGACY_UNITS
123+
# CORENEURON_USE_LEGACY_UNITS is used in membfunc.hpp so define it everywhere
124124
# =============================================================================
125-
set(LegacyFR_FILES
126-
${CMAKE_CURRENT_SOURCE_DIR}/mechanism/eion.cpp ${CMAKE_CURRENT_SOURCE_DIR}/apps/main1.cpp
127-
${CMAKE_CURRENT_SOURCE_DIR}/io/global_vars.cpp)
128-
129-
set_property(
130-
SOURCE ${LegacyFR_FILES}
131-
APPEND
132-
PROPERTY COMPILE_DEFINITIONS "CORENRN_USE_LEGACY_UNITS=${CORENRN_USE_LEGACY_UNITS}")
125+
add_compile_definitions(CORENEURON_USE_LEGACY_UNITS=${CORENRN_USE_LEGACY_UNITS})
133126

134127
# =============================================================================
135128
# create libraries

coreneuron/apps/main1.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
# =============================================================================
3-
# Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
3+
# Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
44
#
55
# See top-level LICENSE file for details.
66
# =============================================================================.
@@ -51,9 +51,9 @@ const char* corenrn_version() {
5151
return coreneuron::bbcore_write_version;
5252
}
5353

54-
// the CORENRN_USE_LEGACY_UNITS determined by CORENRN_ENABLE_LEGACY_UNITS
54+
// the CORENEURON_USE_LEGACY_UNITS determined by CORENRN_ENABLE_LEGACY_UNITS
5555
bool corenrn_units_use_legacy() {
56-
return CORENRN_USE_LEGACY_UNITS;
56+
return CORENEURON_USE_LEGACY_UNITS;
5757
}
5858

5959
void (*nrn2core_part2_clean_)();
@@ -562,8 +562,7 @@ extern "C" int run_solve_core(int argc, char** argv) {
562562
}
563563
#endif
564564
bool compute_gpu = corenrn_param.gpu;
565-
566-
nrn_pragma_acc(update device(celsius, secondorder, pi) if (compute_gpu))
565+
nrn_pragma_acc(data copyin(celsius, secondorder, pi) if (compute_gpu))
567566
nrn_pragma_omp(target update to(celsius, secondorder, pi) if (compute_gpu))
568567
{
569568
double v = corenrn_param.voltage;

coreneuron/io/global_vars.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void set_globals(const char* path, bool cli_global_seed, int cli_global_seed_val
142142
} else if (strcmp(name, "Random123_globalindex") == 0) {
143143
nrnran123_set_globalindex((uint32_t) n);
144144
} else if (strcmp(name, "_nrnunit_use_legacy_") == 0) {
145-
if (n != CORENRN_USE_LEGACY_UNITS) {
145+
if (n != CORENEURON_USE_LEGACY_UNITS) {
146146
hoc_execerror(
147147
"CORENRN_ENABLE_LEGACY_UNITS not"
148148
" consistent with NEURON value of"

coreneuron/mechanism/eion.cpp

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
# =============================================================================
3-
# Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
3+
# Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
44
#
55
# See top-level LICENSE file for details.
66
# =============================================================================.
@@ -154,23 +154,9 @@ the USEION statement of any model using this ion\n",
154154
}
155155
}
156156

157-
#ifndef CORENRN_USE_LEGACY_UNITS
158-
#define CORENRN_USE_LEGACY_UNITS 0
159-
#endif
160-
161-
#if CORENRN_USE_LEGACY_UNITS == 1
162-
#define FARADAY 96485.309
163-
#define gasconstant 8.3134
164-
#else
165-
#include "coreneuron/nrnoc/nrnunits_modern.h"
166-
#define FARADAY _faraday_codata2018
167-
#define gasconstant _gasconstant_codata2018
168-
#endif
169-
170-
#define ktf (1000. * gasconstant * (celsius + 273.15) / FARADAY)
171-
172-
double nrn_nernst(double ci, double co, double z, double celsius) {
173-
/*printf("nrn_nernst %g %g %g\n", ci, co, z);*/
157+
// std::log isn't constexpr, but there are argument values for which nrn_nernst
158+
// is a constant expression
159+
constexpr double nrn_nernst(double ci, double co, double z, double celsius) {
174160
if (z == 0) {
175161
return 0.;
176162
}
@@ -179,7 +165,7 @@ double nrn_nernst(double ci, double co, double z, double celsius) {
179165
} else if (co <= 0.) {
180166
return -1e6;
181167
} else {
182-
return ktf / z * log(co / ci);
168+
return ktf(celsius) / z * std::log(co / ci);
183169
}
184170
}
185171

@@ -200,24 +186,8 @@ void nrn_wrote_conc(int type,
200186
pe[0] = nrn_nernst(pe[1 * _STRIDE], pe[2 * _STRIDE], gimap[type][2], celsius);
201187
}
202188
}
203-
204-
static double efun(double x) {
205-
if (fabs(x) < 1e-4) {
206-
return 1. - x / 2.;
207-
} else {
208-
return x / (exp(x) - 1);
209-
}
210-
}
211-
212189
nrn_pragma_omp(end declare target)
213190

214-
double nrn_ghk(double v, double ci, double co, double z) {
215-
double temp = z * v / ktf;
216-
double eco = co * efun(temp);
217-
double eci = ci * efun(-temp);
218-
return (.001) * z * FARADAY * (eci - eco);
219-
}
220-
221191
#if VECTORIZE
222192
#define erev pd[0 * _STRIDE] /* From Eion */
223193
#define conci pd[1 * _STRIDE]
@@ -257,7 +227,7 @@ ion_style("name_ion", [c_style, e_style, einit, eadvance, cinit])
257227

258228
double nrn_nernst_coef(int type) {
259229
/* for computing jacobian element dconc'/dconc */
260-
return ktf / charge;
230+
return ktf(celsius) / charge;
261231
}
262232

263233
/* Must be called prior to any channels which update the currents */
@@ -271,7 +241,8 @@ void nrn_cur_ion(NrnThread* nt, Memb_list* ml, int type) {
271241
pd = ml->data;
272242
ppd = ml->pdata;
273243
// clang-format off
274-
nrn_pragma_acc(parallel loop present(pd[0:_cntml_padded * 5],
244+
nrn_pragma_acc(parallel loop present(celsius,
245+
pd[0:_cntml_padded * 5],
275246
ppd[0:_cntml_actual],
276247
nrn_ion_global_map[0:nrn_ion_global_map_size]
277248
[0:ion_global_map_member_size])
@@ -311,7 +282,8 @@ void nrn_init_ion(NrnThread* nt, Memb_list* ml, int type) {
311282
// verify if this can be made asynchronous or if there is a strong reason it
312283
// needs to be like this.
313284
// clang-format off
314-
nrn_pragma_acc(parallel loop present(pd[0:_cntml_padded * 5],
285+
nrn_pragma_acc(parallel loop present(celsius,
286+
pd[0:_cntml_padded * 5],
315287
ppd[0:_cntml_actual],
316288
nrn_ion_global_map[0:nrn_ion_global_map_size]
317289
[0:ion_global_map_member_size])

coreneuron/mechanism/membfunc.hpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
/*
22
# =============================================================================
3-
# Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
3+
# Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
44
#
55
# See top-level LICENSE file for details.
66
# =============================================================================.
77
*/
8-
98
#pragma once
109

11-
#include <vector>
12-
1310
#include "coreneuron/mechanism/mechanism.hpp"
1411
#include "coreneuron/utils/offload.hpp"
12+
#include "coreneuron/utils/units.hpp"
13+
14+
#include <cmath>
15+
#include <vector>
16+
1517
namespace coreneuron {
1618

1719
using Pfrpdat = Datum* (*) (void);
@@ -112,12 +114,28 @@ extern void nrn_jacob_capacitance(NrnThread*, Memb_list*, int);
112114
extern void nrn_writes_conc(int, int);
113115
nrn_pragma_omp(declare target)
114116
nrn_pragma_acc(routine seq)
115-
extern void nrn_wrote_conc(int, double*, int, int, double**, double, int);
116-
nrn_pragma_acc(routine seq)
117-
double nrn_nernst(double ci, double co, double z, double celsius);
118-
nrn_pragma_acc(routine seq)
119-
extern double nrn_ghk(double v, double ci, double co, double z);
117+
void nrn_wrote_conc(int, double*, int, int, double**, double, int);
120118
nrn_pragma_omp(end declare target)
119+
constexpr double ktf(double celsius) {
120+
return 1000. * units::gasconstant * (celsius + 273.15) / units::faraday;
121+
}
122+
inline double nrn_ghk(double v, double ci, double co, double z, double celsius) {
123+
auto const efun = [](double x) {
124+
if (std::abs(x) < 1e-4) {
125+
return 1. - x / 2.;
126+
} else {
127+
return x / (std::exp(x) - 1.);
128+
}
129+
};
130+
double const temp{z * v / ktf(celsius)};
131+
double const eco{co * efun(+temp)};
132+
double const eci{ci * efun(-temp)};
133+
return .001 * z * units::faraday * (eci - eco);
134+
}
135+
// Overload using the global celsius variable
136+
inline double nrn_ghk(double v, double ci, double co, double z) {
137+
return nrn_ghk(v, ci, co, z, celsius);
138+
}
121139
extern void hoc_register_prop_size(int, int, int);
122140
extern void hoc_register_dparam_semantics(int type, int, const char* name);
123141
extern void hoc_reg_ba(int, mod_f_t, int);

coreneuron/nrnconf.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,10 @@ using Symbol = char;
3232
#define VEC_AREA(i) (_nt->_actual_area[(i)])
3333
#define VECTORIZE 1
3434

35-
// extern variables require acc declare
35+
// Defined in register_mech.cpp
3636
nrn_pragma_omp(declare target)
37-
extern double celsius;
38-
nrn_pragma_acc(declare create(celsius))
39-
40-
extern double pi;
41-
nrn_pragma_acc(declare create(pi))
42-
37+
extern double celsius, pi;
4338
extern int secondorder;
44-
nrn_pragma_acc(declare create(secondorder))
4539
nrn_pragma_omp(end declare target)
4640

4741
extern double t, dt;

coreneuron/nrnoc/nrnunits_modern.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

coreneuron/utils/nrnoc_aux.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,4 @@ extern void hoc_execerror(const char*, const char*); /* print and abort */
3434
extern void hoc_warning(const char*, const char*);
3535

3636
extern double hoc_Exp(double x);
37-
38-
// defined in eion.cpp and this file included in translated mod files.
39-
extern double nrn_nernst(double ci, double co, double z, double celsius);
40-
extern double nrn_ghk(double v, double ci, double co, double z);
41-
4237
} // namespace coreneuron

coreneuron/utils/units.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
# =============================================================================
3+
# Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
4+
#
5+
# See top-level LICENSE file for details.
6+
# =============================================================================
7+
*/
8+
#pragma once
9+
namespace coreneuron::units {
10+
#if CORENEURON_USE_LEGACY_UNITS == 1
11+
constexpr double faraday{96485.309};
12+
constexpr double gasconstant{8.3134};
13+
#else
14+
/* NMODL translated MOD files get unit constants typically from
15+
* share/lib/nrnunits.lib.in. But there were other source files that hardcode
16+
* some of the constants. Here we gather a few modern units into a single place
17+
* (but, unfortunately, also in nrnunits.lib.in). Legacy units cannot be
18+
* gathered here because they can differ slightly from place to place.
19+
*
20+
* These come from https://physics.nist.gov/cuu/Constants/index.html.
21+
* Termed the "2018 CODATA recommended values", they became available
22+
* on 20 May 2019 and replace the 2014 CODATA set.
23+
*
24+
* See oc/hoc_init.c, nrnoc/eion.c, nrniv/kschan.h
25+
*/
26+
namespace detail {
27+
constexpr double electron_charge{1.602176634e-19}; // coulomb exact
28+
constexpr double avogadro_number{6.02214076e+23}; // exact
29+
constexpr double boltzmann{1.380649e-23}; // joule/K exact
30+
} // namespace detail
31+
constexpr double faraday{detail::electron_charge * detail::avogadro_number}; // 96485.33212...
32+
// coulomb/mol
33+
constexpr double gasconstant{detail::boltzmann * detail::avogadro_number}; // 8.314462618...
34+
// joule/mol-K
35+
#endif
36+
} // namespace coreneuron::units

0 commit comments

Comments
 (0)