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

Commit a0ce316

Browse files
WeinaJiNicolas Cornupramodk
authored
Clean code: Use bool instead of int (#259)
* clean code: Use bool instead of int wherever possible * Keep old api for fuctions used by Neuron * change use_interleave_permute to interleave_permute_type Co-authored-by: Nicolas Cornu <[email protected]> Co-authored-by: Pramod Kumbhar <[email protected]>
1 parent fd28045 commit a0ce316

23 files changed

+66
-66
lines changed

coreneuron/apps/main1.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ char* prepare_args(int& argc, char**& argv, int use_mpi, const char* arg) {
127127
}
128128

129129
int corenrn_embedded_run(int nthread, int have_gaps, int use_mpi, int use_fast_imem, const char* arg) {
130-
corenrn_embedded = 1;
130+
corenrn_embedded = true;
131131
corenrn_embedded_nthread = nthread;
132-
coreneuron::nrn_have_gaps = have_gaps;
133-
if (use_fast_imem) {
132+
coreneuron::nrn_have_gaps = have_gaps != 0;
133+
if (use_fast_imem != 0) {
134134
coreneuron::nrn_use_fast_imem = true;
135135
}
136136

@@ -143,7 +143,7 @@ int corenrn_embedded_run(int nthread, int have_gaps, int use_mpi, int use_fast_i
143143
free(new_arg);
144144
delete[] argv;
145145

146-
return corenrn_embedded;
146+
return corenrn_embedded ? 1 : 0;
147147
}
148148
}
149149

@@ -249,23 +249,23 @@ void nrn_init_and_load_data(int argc,
249249
report_mem_usage("Before nrn_setup");
250250

251251
// set if need to interleave cells
252-
use_interleave_permute = corenrn_param.cell_interleave_permute;
252+
interleave_permute_type = corenrn_param.cell_interleave_permute;
253253
cellorder_nwarp = corenrn_param.nwarp;
254254
use_solve_interleave = corenrn_param.cell_interleave_permute;
255255

256256
#if LAYOUT == 1
257257
// permuting not allowed for AoS
258-
use_interleave_permute = 0;
259-
use_solve_interleave = 0;
258+
interleave_permute_type = 0;
259+
use_solve_interleave = false;
260260
#endif
261261

262-
if (corenrn_param.gpu && use_interleave_permute == 0) {
262+
if (corenrn_param.gpu && interleave_permute_type == 0) {
263263
if (nrnmpi_myid == 0) {
264264
printf(
265265
" WARNING : GPU execution requires --cell-permute type 1 or 2. Setting it to 1.\n");
266266
}
267-
use_interleave_permute = 1;
268-
use_solve_interleave = 1;
267+
interleave_permute_type = 1;
268+
use_solve_interleave = true;
269269
}
270270

271271
// pass by flag so existing tests do not need a changed nrn_setup prototype.

coreneuron/gpu/nrn_acc_manager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void setup_nrnthreads_on_device(NrnThread* threads, int nthreads) {
329329
}
330330

331331
if (nt->_permute) {
332-
if (use_interleave_permute == 1) {
332+
if (interleave_permute_type == 1) {
333333
/* todo: not necessary to setup pointers, just copy it */
334334
InterleaveInfo* info = interleave_info + i;
335335
InterleaveInfo* d_info = (InterleaveInfo*)acc_copyin(info, sizeof(InterleaveInfo));
@@ -347,7 +347,7 @@ void setup_nrnthreads_on_device(NrnThread* threads, int nthreads) {
347347
d_ptr = (int*)acc_copyin(info->cellsize, sizeof(int) * nt->ncell);
348348
acc_memcpy_to_device(&(d_info->cellsize), &d_ptr, sizeof(int*));
349349

350-
} else if (use_interleave_permute == 2) {
350+
} else if (interleave_permute_type == 2) {
351351
/* todo: not necessary to setup pointers, just copy it */
352352
InterleaveInfo* info = interleave_info + i;
353353
InterleaveInfo* d_info = (InterleaveInfo*)acc_copyin(info, sizeof(InterleaveInfo));

coreneuron/io/mk_mech.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ int nrn_nobanner_;
5151
// NB: this should go away
5252
extern const char* nrn_version(int);
5353

54-
int nrn_need_byteswap;
54+
bool nrn_need_byteswap;
5555
// following copied (except for nrn_need_byteswap line) from NEURON ivocvect.cpp
5656
#define BYTEHEADER \
5757
uint32_t _II__; \
5858
char* _IN__; \
5959
char _OUT__[16]; \
60-
int BYTESWAP_FLAG = 0;
60+
bool BYTESWAP_FLAG = false;
6161
#define BYTESWAP(_X__, _TYPE__) \
6262
BYTESWAP_FLAG = nrn_need_byteswap; \
63-
if (BYTESWAP_FLAG == 1) { \
63+
if (BYTESWAP_FLAG) { \
6464
_IN__ = (char*)&(_X__); \
6565
for (_II__ = 0; _II__ < sizeof(_TYPE__); _II__++) { \
6666
_OUT__[_II__] = _IN__[sizeof(_TYPE__) - _II__ - 1]; \
@@ -111,10 +111,10 @@ void mk_mech(const char* datpath) {
111111
// binary info in files needs to be byteswapped.
112112
int32_t x;
113113
nrn_assert(fread(&x, sizeof(int32_t), 1, f) == 1);
114-
nrn_need_byteswap = 0;
114+
nrn_need_byteswap = false;
115115
if (x != 1) {
116116
BYTEHEADER;
117-
nrn_need_byteswap = 1;
117+
nrn_need_byteswap = true;
118118
BYTESWAP(x, int32_t);
119119
nrn_assert(x == 1);
120120
}
@@ -128,7 +128,7 @@ static void mk_mech() {
128128
if (already_called) {
129129
return;
130130
}
131-
nrn_need_byteswap = 0;
131+
nrn_need_byteswap = false;
132132
std::stringstream ss;
133133
nrn_assert(nrn2core_mkmech_info_);
134134
(*nrn2core_mkmech_info_)(ss);

coreneuron/io/nrn2core_direct.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern "C" {
77
// The callbacks into nrn/src/nrniv/nrnbbcore_write.cpp to get
88
// data directly instead of via files.
99

10-
extern int corenrn_embedded;
10+
extern bool corenrn_embedded;
1111
extern int corenrn_embedded_nthread;
1212

1313
extern void (*nrn2core_group_ids_)(int*);

coreneuron/io/nrn_checkpoint.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
4545

4646
namespace coreneuron {
4747
bool nrn_checkpoint_arg_exists;
48-
int _nrn_skip_initmodel;
48+
bool _nrn_skip_initmodel;
4949
} // namespace coreneuron
5050
#define UseFileHandlerWrap 0
5151

@@ -868,7 +868,7 @@ bool checkpoint_initialize() {
868868

869869
// in case some nrn_init allocate data we need to do that but do not
870870
// want to call initmodel.
871-
_nrn_skip_initmodel = 1;
871+
_nrn_skip_initmodel = true;
872872
for (int i = 0; i < nrn_nthread; ++i) { // should be parallel
873873
NrnThread& nt = nrn_threads[i];
874874
for (NrnThreadMembList* tml = nt.tml; tml; tml = tml->next) {
@@ -879,7 +879,7 @@ bool checkpoint_initialize() {
879879
}
880880
}
881881
}
882-
_nrn_skip_initmodel = 0;
882+
_nrn_skip_initmodel = false;
883883

884884
// if PatternStim exists, needs initialization
885885
for (NrnThreadMembList* tml = nrn_threads[0].tml; tml; tml = tml->next) {

coreneuron/io/nrn_setup.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
5656

5757

5858
/// --> Coreneuron
59-
int corenrn_embedded;
59+
bool corenrn_embedded;
6060
int corenrn_embedded_nthread;
6161

6262
void (*nrn2core_group_ids_)(int*);
@@ -291,14 +291,14 @@ static void store_phase_args(int ngroup,
291291
FileHandler* file_reader,
292292
const char* path,
293293
const char* restore_path,
294-
int byte_swap) {
294+
bool byte_swap) {
295295
ngroup_w = ngroup;
296296
gidgroups_w = gidgroups;
297297
imult_w = imult;
298298
file_reader_w = file_reader;
299299
path_w = path;
300300
restore_path_w = restore_path;
301-
byte_swap_w = (bool)byte_swap;
301+
byte_swap_w = byte_swap;
302302
}
303303

304304
/* read files.dat file and distribute cellgroups to all mpi ranks */
@@ -333,7 +333,7 @@ void nrn_read_filesdat(int& ngrp, int*& grp, int multiple, int*& imult, const ch
333333
// being backward compatible
334334
if (iNumFiles == -1) {
335335
nrn_assert(fscanf(fp, "%d\n", &iNumFiles) == 1);
336-
nrn_have_gaps = 1;
336+
nrn_have_gaps = true;
337337
if (nrnmpi_myid == 0) {
338338
printf("Model uses gap junctions\n");
339339
}
@@ -672,7 +672,7 @@ void nrn_setup_cleanup() {
672672

673673
void nrn_setup(const char* filesdat,
674674
bool is_mapping_needed,
675-
int byte_swap,
675+
bool byte_swap,
676676
bool run_setup_cleanup,
677677
const char* datpath,
678678
const char* restore_path,
@@ -1189,7 +1189,7 @@ void delete_trajectory_requests(NrnThread& nt) {
11891189
}
11901190

11911191
void read_phase2(FileHandler& F, int imult, NrnThread& nt) {
1192-
bool direct = corenrn_embedded ? true : false;
1192+
bool direct = corenrn_embedded;
11931193
if (!direct) {
11941194
assert(!F.fail()); // actually should assert that it is open
11951195
}
@@ -1497,7 +1497,7 @@ void read_phase2(FileHandler& F, int imult, NrnThread& nt) {
14971497
}
14981498
}
14991499

1500-
if (nrn_have_gaps == 1) {
1500+
if (nrn_have_gaps) {
15011501
nrn_partrans::gap_thread_setup(nt);
15021502
}
15031503

@@ -1581,7 +1581,7 @@ void read_phase2(FileHandler& F, int imult, NrnThread& nt) {
15811581
vectors will be read and will need to be permuted as well in subsequent
15821582
sections of this function.
15831583
*/
1584-
if (use_interleave_permute) {
1584+
if (interleave_permute_type) {
15851585
nt._permute = interleave_order(nt.id, nt.ncell, nt.end, nt._v_parent_index);
15861586
}
15871587
if (nt._permute) {
@@ -1628,7 +1628,7 @@ for (int i=0; i < nt.end; ++i) {
16281628
}
16291629
}
16301630

1631-
if (nrn_have_gaps == 1 && use_interleave_permute) {
1631+
if (nrn_have_gaps && interleave_permute_type) {
16321632
nrn_partrans::gap_indices_permute(nt);
16331633
}
16341634

coreneuron/mpi/nrnmpi.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern void nrnmpi_checkbufleak();
6161
static int nrnmpi_under_nrncontrol_;
6262

6363
void nrnmpi_init(int nrnmpi_under_nrncontrol, int* pargc, char*** pargv) {
64-
nrnmpi_use = 1;
64+
nrnmpi_use = true;
6565
nrnmpi_under_nrncontrol_ = nrnmpi_under_nrncontrol;
6666
if (nrnmpi_under_nrncontrol_) {
6767
#if !ALWAYS_CALL_MPI_INIT
@@ -87,7 +87,7 @@ void nrnmpi_init(int nrnmpi_under_nrncontrol, int* pargc, char*** pargv) {
8787
b = true;
8888
}
8989
if (!b) {
90-
nrnmpi_use = 0;
90+
nrnmpi_use = false;
9191
nrnmpi_under_nrncontrol_ = 0;
9292
return;
9393
}
@@ -153,7 +153,7 @@ void nrnmpi_terminate() {
153153
if (nrnmpi_under_nrncontrol_) {
154154
MPI_Finalize();
155155
}
156-
nrnmpi_use = 0;
156+
nrnmpi_use = false;
157157
#if nrnmpidebugleak
158158
nrnmpi_checkbufleak();
159159
#endif

coreneuron/mpi/nrnmpi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ typedef struct {
5656
double spiketime;
5757
} NRNMPI_Spike;
5858

59-
extern int nrnmpi_use; /* NEURON does MPI init and terminate?*/
59+
extern bool nrnmpi_use; /* NEURON does MPI init and terminate?*/
6060

6161
} // namespace coreneuron
6262
#include "coreneuron/mpi/nrnmpidec.h"

coreneuron/mpi/nrnmpi_def_cinc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
2727
*/
2828

2929
namespace coreneuron {
30-
int nrnmpi_use;
30+
bool nrnmpi_use;
3131
int nrnmpi_numprocs = 1; /* size */
3232
int nrnmpi_myid = 0; /* rank */
3333
int nrnmpi_numprocs_world = 1;

coreneuron/network/multisend.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ of spikes sent is equal to the number of spikes sent.
4242
// which has the greatest amount of overlap between computation
4343
// and communication.
4444
namespace coreneuron {
45-
int use_multisend_;
46-
int use_phase2_;
45+
bool use_multisend_;
46+
bool use_phase2_;
4747
int n_multisend_interval = 2;
4848

4949
#if NRN_MULTISEND
@@ -352,7 +352,7 @@ static int multisend_advance() {
352352

353353
#if NRN_MULTISEND
354354
void nrn_multisend_advance() {
355-
if (use_multisend_ == 1) {
355+
if (use_multisend_) {
356356
multisend_advance();
357357
#if ENQUEUE == 2
358358
multisend_receive_buffer[current_rbuf]->enqueue();
@@ -373,7 +373,7 @@ void nrn_multisend_receive(NrnThread* nt) {
373373
#endif
374374
// w1 = nrn_wtime();
375375
#if NRN_MULTISEND & 1
376-
if (use_multisend_ == 1) {
376+
if (use_multisend_) {
377377
nrn_multisend_advance();
378378
#if 0 && ENQUEUE == 2
379379
// want the overlap with computation, not conserve
@@ -437,7 +437,7 @@ void nrn_multisend_cleanup() {
437437

438438
void nrn_multisend_setup() {
439439
nrn_multisend_cleanup();
440-
if (use_multisend_ == 0) {
440+
if (!use_multisend_) {
441441
return;
442442
}
443443
nrnmpi_multisend_comm();

0 commit comments

Comments
 (0)