CoreNEURON
nrnoc_aux.cpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================.
7 */
8 
9 #include <cstdlib>
10 #include <cstring>
11 
13 #include "coreneuron/mpi/nrnmpi.h"
17 
18 namespace coreneuron {
19 bool stoprun;
22 #define MAXERRCOUNT 5
24 const char* bbcore_write_version = "1.6"; // Allow multiple gid and PreSyn per real cell.
25 
26 char* pnt_name(Point_process* pnt) {
27  return corenrn.get_memb_func(pnt->_type).sym;
28 }
29 
30 void nrn_exit(int err) {
31 #if NRNMPI
34  }
35 #endif
36  exit(err);
37 }
38 
39 void hoc_execerror(const char* s1, const char* s2) {
40  printf("error: %s %s\n", s1, s2 ? s2 : "");
41  abort();
42 }
43 
44 void hoc_warning(const char* s1, const char* s2) {
45  printf("warning: %s %s\n", s1, s2 ? s2 : "");
46 }
47 
48 double* makevector(size_t size) {
49  return (double*) ecalloc(size, sizeof(char));
50 }
51 
52 void freevector(double* p) {
53  if (p) {
54  free(p);
55  }
56 }
57 
58 double** makematrix(size_t nrows, size_t ncols) {
59  double** matrix = (double**) emalloc(nrows * sizeof(double*));
60  *matrix = (double*) emalloc(nrows * ncols * sizeof(double));
61  for (size_t i = 1; i < nrows; i++)
62  matrix[i] = matrix[i - 1] + ncols;
63  return (matrix);
64 }
65 
66 void freematrix(double** matrix) {
67  if (matrix != nullptr) {
68  free(*matrix);
69  free(matrix);
70  }
71 }
72 
73 void* emalloc(size_t size) {
74  void* memptr = malloc(size);
75  assert(memptr);
76  return memptr;
77 }
78 
79 /* some user mod files may use this in VERBATIM */
80 void* hoc_Emalloc(size_t size) {
81  return emalloc(size);
82 }
83 void hoc_malchk(void) {}
84 
85 void* ecalloc(size_t n, size_t size) {
86  if (n == 0) {
87  return nullptr;
88  }
89  void* p = calloc(n, size);
90  assert(p);
91  return p;
92 }
93 
94 void* erealloc(void* ptr, size_t size) {
95  if (!ptr) {
96  return emalloc(size);
97  }
98  void* p = realloc(ptr, size);
99  assert(p);
100  return p;
101 }
102 
103 void* nrn_cacheline_alloc(void** memptr, size_t size) {
104  alloc_memory(*memptr, size, 64);
105  return *memptr;
106 }
107 
108 /* used by nmodl and other c, c++ code */
109 double hoc_Exp(double x) {
110  if (x < -700.) {
111  return 0.;
112  } else if (x > 700) {
113  errno = ERANGE;
114  if (++hoc_errno_count < MAXERRCOUNT) {
115  fprintf(stderr, "exp(%g) out of range, returning exp(700)\n", x);
116  }
117  if (hoc_errno_count == MAXERRCOUNT) {
118  fprintf(stderr, "No more errno warnings during this execution\n");
119  }
120  return exp(700.);
121  }
122  return exp(x);
123 }
124 
125 /* check for version bbcore_write version between NEURON and CoreNEURON
126  * abort in case of missmatch
127  */
129  if (strcmp(version, bbcore_write_version) != 0) {
130  if (nrnmpi_myid == 0)
131  fprintf(stderr,
132  "Error: Incompatible binary input dataset version (expected %s, input %s)\n",
134  version);
135  abort();
136  }
137 }
138 } // namespace coreneuron
coreneuron::ecalloc
void * ecalloc(size_t n, size_t size)
Definition: nrnoc_aux.cpp:85
coreneuron::pnt_name
char * pnt_name(Point_process *pnt)
Definition: nrnoc_aux.cpp:26
coreneuron::nrnmpi_finalize
mpi_function< cnrn_make_integral_constant_t(nrnmpi_finalize_impl)> nrnmpi_finalize
Definition: nrnmpidec.cpp:16
coreneuron::Point_process
Definition: mechanism.hpp:35
nrnoc_aux.hpp
coreneuron::CoreNeuron::get_memb_func
auto & get_memb_func(size_t idx)
Definition: coreneuron.hpp:138
coreneuron::check_bbcore_write_version
void check_bbcore_write_version(const char *)
Definition: nrnoc_aux.cpp:128
coreneuron::hoc_execerror
void hoc_execerror(const char *s1, const char *s2)
Definition: nrnoc_aux.cpp:39
coreneuron::hoc_Emalloc
void * hoc_Emalloc(size_t)
Definition: nrnoc_aux.cpp:80
coreneuron::hoc_errno_count
int hoc_errno_count
Definition: nrnoc_aux.cpp:23
coreneuron::hoc_warning
void hoc_warning(const char *s1, const char *s2)
Definition: nrnoc_aux.cpp:44
coreneuron.hpp
coreneuron::makematrix
double ** makematrix(size_t nrows, size_t ncols)
Definition: nrnoc_aux.cpp:58
coreneuron
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
Definition: corenrn_parameters.cpp:12
corenrn_parameters.hpp
coreneuron::i
int i
Definition: cellorder.cpp:485
coreneuron::makevector
double * makevector(size_t size)
Definition: nrnoc_aux.cpp:48
alloc_memory
void alloc_memory(void *&pointer, size_t num_bytes, size_t alignment)
Definition: memory.h:178
coreneuron::nrn_cacheline_alloc
void * nrn_cacheline_alloc(void **memptr, size_t size)
Definition: nrnoc_aux.cpp:103
coreneuron::diam_changed
int diam_changed
Definition: nrnoc_aux.cpp:21
coreneuron::bbcore_write_version
const char * bbcore_write_version
Definition: nrnoc_aux.cpp:24
coreneuron::nrn_exit
void nrn_exit(int err)
Definition: nrnoc_aux.cpp:30
coreneuron::corenrn_param
corenrn_parameters corenrn_param
Printing method.
Definition: corenrn_parameters.cpp:268
coreneuron::corenrn
CoreNeuron corenrn
Definition: multicore.cpp:53
MAXERRCOUNT
#define MAXERRCOUNT
Definition: nrnoc_aux.cpp:22
coreneuron::v_structure_change
int v_structure_change
Definition: nrnoc_aux.cpp:20
coreneuron::hoc_Exp
double hoc_Exp(double x)
Definition: nrnoc_aux.cpp:109
coreneuron::hoc_malchk
void hoc_malchk(void)
Definition: nrnoc_aux.cpp:83
coreneuron::Point_process::_type
short _type
Definition: mechanism.hpp:37
coreneuron::emalloc
static void * emalloc(size_t size)
Definition: mpispike.cpp:30
multicore.hpp
coreneuron::corenrn_parameters_data::mpi_enable
bool mpi_enable
Initialization seed for random number generator (int)
Definition: corenrn_parameters.hpp:59
coreneuron::erealloc
void * erealloc(void *ptr, size_t size)
Definition: nrnoc_aux.cpp:94
coreneuron::freevector
void freevector(double *p)
Definition: nrnoc_aux.cpp:52
coreneuron::nrnmpi_myid
int nrnmpi_myid
Definition: nrnmpi_def_cinc.cpp:11
coreneuron::version
Project version information.
Definition: config.h:26
nrnmpi.h
coreneuron::freematrix
void freematrix(double **matrix)
Definition: nrnoc_aux.cpp:66
coreneuron::stoprun
bool stoprun
Definition: nrnoc_aux.cpp:19