Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
283ee1b
* move coreneuron toward full c++
fouriaux Mar 26, 2018
a18f77e
Update mod2c to new commit
pramodk Mar 27, 2018
d129dbb
fix ivocvect vector compatibility and declarations
fouriaux Mar 28, 2018
32c4b1b
fixing core_read and core_write to be out of coreneuron namespace
fouriaux Mar 29, 2018
e80852c
add missing prototype
fouriaux Mar 29, 2018
9a9aa18
update mod2c
fouriaux Mar 29, 2018
7afb97d
update mod2c link
fouriaux Apr 3, 2018
f6a80aa
update submodule
fouriaux Apr 3, 2018
a812e74
fix public API of coreneuron to explose core_psolve
fouriaux Apr 12, 2018
aabed5d
add pulbic header
fouriaux Apr 12, 2018
a7d0c9b
kinderiv.h has prototype declaration for euler methods
pramodk Apr 12, 2018
859a6a9
public header accessible from C, clean up unused arguments
fouriaux Apr 12, 2018
0e17acd
Changes to integrate with neurodamus: psolve_core renamed and added -…
pramodk Apr 12, 2018
ba4105a
Merge branch 'master' into full_cpp_interface
pramodk Apr 19, 2018
95798d8
mod2c updated
pramodk Apr 19, 2018
a7d827b
W.I.P for fixup openACC version
fouriaux Apr 20, 2018
ca893d6
OpenACC pragma annotation was missing for kernels using euler
pramodk Apr 21, 2018
992000f
cudaMemset wrong pointer fix
pramodk Apr 21, 2018
9a572b7
User provided flags should take precedence
pramodk Apr 21, 2018
f639ed7
Merge remote-tracking branch 'origin/euler_acc' into full_cpp_interface
pramodk Apr 21, 2018
18692d9
Removed unnecessary acc declare annotations: actual errors are coming…
pramodk Apr 21, 2018
503ff8d
Fix issue while compiling with -DENABLE_MPI=OFF
pramodk Apr 28, 2018
f9facdc
Merge branch 'master' into full_cpp_interface
pramodk Apr 30, 2018
66f0a4f
fix mpi build
fouriaux May 8, 2018
fb26434
Direct transfer of model from NEURON to CoreNeuron without using files.
nrnhines Apr 18, 2018
7c5b70a
Direct transfer of globals.dat info in place.
nrnhines Apr 18, 2018
a6d0339
Gap junction direct transfer. Change callback prefix to nrn2core_ .
nrnhines Apr 19, 2018
9f97ead
Phase1 direct transfer.
nrnhines Apr 20, 2018
642e6f9
Seems to work with direct transfer of data (but phase2 dat files
nrnhines Apr 24, 2018
fe0cde6
Direct transfer of dat2 to coreneuron almost works but
nrnhines May 7, 2018
4bb4cc8
Direct transfer works for ringtest.
nrnhines May 8, 2018
2867348
Merge branch 'master' into nrn2coredirect
nrnhines May 18, 2018
a372469
Update funding notice with latest HBP and NI grants
pramodk Sep 7, 2018
ca57775
Merge branch 'master' into nrn2coredirect
pramodk Sep 7, 2018
6747aba
Update test dataset
pramodk Sep 7, 2018
c969af1
coreneuron_embedded_run does not read any files but needs info about
nrnhines Sep 8, 2018
7f769a4
Fix coreneuron gap junction direct transfer bugs.
nrnhines Sep 8, 2018
f53a269
coreneuron_embedded_run takes tstop as an argument.
nrnhines Sep 9, 2018
89d47ed
Changed the last arg of coreneuron_embedded_run to const char* arg
nrnhines Sep 9, 2018
99d422e
For direct transfer, if OMP_NUM_THREADS is not set then
nrnhines Sep 10, 2018
34ff7ee
Allow CoreNEURON to send data version to NEURON
nrnhines Sep 11, 2018
92d8101
Update Michael's branch with clang-format
pramodk Sep 11, 2018
a459e3a
Refactor argument parsing logic with strtok
pramodk Oct 1, 2018
885d035
Fix memory leaks :
pramodk Oct 1, 2018
450409d
Merge branch 'master' into nrn2coredirect_master
pramodk Oct 2, 2018
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
137 changes: 86 additions & 51 deletions coreneuron/nrniv/global_vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "coreneuron/nrniv/nrniv_decl.h"
#include "coreneuron/nrnoc/membfunc.h"
#include "coreneuron/nrniv/nrn_assert.h"
#include "coreneuron/nrniv/nrn2core_direct.h"

void* (*nrn2core_get_global_dbl_item_)(void*, const char*& name, int& size, double*& val);
int (*nrn2core_get_global_int_item_)(const char* name);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we transfer these to single header? (nrn2core_direct.h)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought they needed a separare declaration in the header (extern) and then a definition in
some file (memory to hold the function pointer)


using namespace std;
namespace coreneuron {
Expand Down Expand Up @@ -37,69 +41,99 @@ void set_globals(const char* path, bool cli_global_seed, int cli_global_seed_val
(*n2v)["dt"] = PSD(0, &dt);
(*n2v)["t"] = PSD(0, &t);

string fname = string(path) + string("/globals.dat");
FILE* f = fopen(fname.c_str(), "r");
if (!f) {
printf("ignore: could not open %s\n", fname.c_str());
delete n2v;
n2v = NULL;
return;
}

char line[256];
char name[256];
double val;
int n;

fscanf(f, "%s\n", line);
check_bbcore_write_version(line);
if (corenrn_embedded) { // CoreNEURON embedded, get info direct from NEURON

for (;;) {
nrn_assert(fgets(line, 256, f) != NULL);
N2V::iterator it;
if (sscanf(line, "%s %lf", name, &val) == 2) {
if (strcmp(name, "0") == 0) {
break;
}
const char* name;
int size;
double* val = NULL;
for (void* p = NULL; (p = (*nrn2core_get_global_dbl_item_)(p, name, size, val)) != NULL;) {
N2V::iterator it;
it = n2v->find(name);
if (it != n2v->end()) {
nrn_assert(it->second.first == 0);
*(it->second.second) = val;
}
} else if (sscanf(line, "%[^[][%d]\n", name, &n) == 2) {
if (strcmp(name, "0") == 0) {
break;
if (size == 0) {
nrn_assert(it->second.first == 0);
*(it->second.second) = val[0];
} else {
nrn_assert(it->second.first == (size_t)size);
double* pval = it->second.second;
for (int i = 0; i < size; ++i) {
pval[i] = val[i];
}
}
}
it = n2v->find(name);
if (it != n2v->end()) {
nrn_assert(it->second.first == (size_t)n);
double* pval = it->second.second;
for (int i = 0; i < n; ++i) {
nrn_assert(fgets(line, 256, f) != NULL);
nrn_assert(sscanf(line, "%lf\n", &val) == 1);
pval[i] = val;
delete[] val;
}
secondorder = (*nrn2core_get_global_int_item_)("secondorder");
nrnran123_set_globalindex((*nrn2core_get_global_int_item_)("Random123_global_index"));

} else { // get the info from the globals.dat file

string fname = string(path) + string("/globals.dat");
FILE* f = fopen(fname.c_str(), "r");
if (!f) {
printf("ignore: could not open %s\n", fname.c_str());
delete n2v;
n2v = NULL;
return;
}

char line[256];
char name[256];
double val;
int n;

fscanf(f, "%s\n", line);
check_bbcore_write_version(line);

for (;;) {
nrn_assert(fgets(line, 256, f) != NULL);
N2V::iterator it;
if (sscanf(line, "%s %lf", name, &val) == 2) {
if (strcmp(name, "0") == 0) {
break;
}
it = n2v->find(name);
if (it != n2v->end()) {
nrn_assert(it->second.first == 0);
*(it->second.second) = val;
}
} else if (sscanf(line, "%[^[][%d]\n", name, &n) == 2) {
if (strcmp(name, "0") == 0) {
break;
}
it = n2v->find(name);
if (it != n2v->end()) {
nrn_assert(it->second.first == (size_t)n);
double* pval = it->second.second;
for (int i = 0; i < n; ++i) {
nrn_assert(fgets(line, 256, f) != NULL);
nrn_assert(sscanf(line, "%lf\n", &val) == 1);
pval[i] = val;
}
}
} else {
nrn_assert(0);
}
} else {
nrn_assert(0);
}
}

while (fgets(line, 256, f)) {
if (sscanf(line, "%s %d", name, &n) == 2) {
if (strcmp(name, "secondorder") == 0) {
secondorder = n;
} else if ( strcmp(name, "Random123_globalindex") == 0) {
nrnran123_set_globalindex((uint32_t)n);
while (fgets(line, 256, f)) {
if (sscanf(line, "%s %d", name, &n) == 2) {
if (strcmp(name, "secondorder") == 0) {
secondorder = n;
} else if (strcmp(name, "Random123_globalindex") == 0) {
nrnran123_set_globalindex((uint32_t)n);
}
}
}
}

fclose(f);
// overwrite global.dat config if seed is specified on Command line
if (cli_global_seed) {
nrnran123_set_globalindex((uint32_t)cli_global_seed_value);
fclose(f);

// overwrite global.dat config if seed is specified on Command line
if (cli_global_seed) {
nrnran123_set_globalindex((uint32_t)cli_global_seed_value);
}
}

#if 0
for (N2V::iterator i = n2v->begin(); i != n2v->end(); ++i) {
printf("%s %ld %p\n", i->first.c_str(), i->second.first, i->second.second);
Expand All @@ -109,4 +143,5 @@ void set_globals(const char* path, bool cli_global_seed, int cli_global_seed_val
delete n2v;
n2v = NULL;
}

} // namespace coreneuron
84 changes: 81 additions & 3 deletions coreneuron/nrniv/main1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ THE POSSIBILITY OF SUCH DAMAGE.
#include "coreneuron/nrnoc/nrnoc_decl.h"
#include "coreneuron/nrnmpi/nrnmpi.h"
#include "coreneuron/nrniv/nrniv_decl.h"
#include "coreneuron/nrniv/nrnmutdec.h"
#include "coreneuron/nrniv/output_spikes.h"
#include "coreneuron/nrniv/nrn_checkpoint.h"
#include "coreneuron/utils/endianness.h"
Expand All @@ -54,9 +55,86 @@ THE POSSIBILITY OF SUCH DAMAGE.
#include "coreneuron/nrniv/partrans.h"
#include "coreneuron/nrniv/multisend.h"
#include "coreneuron/utils/file_utils.h"
#include "coreneuron/nrniv/nrn2core_direct.h"
#include <string.h>
#include <climits>

extern "C" {
const char* corenrn_version() {
return coreneuron::bbcore_write_version;
}

/**
* If "export OMP_NUM_THREADS=n" is not set then omp by default sets
* the number of threads equal to the number of cores on this node.
* If there are a number of mpi processes on this node as well, things
* can go very slowly as there are so many more threads than cores.
* Assume the NEURON users pc.nthread() is well chosen if
* OMP_NUM_THREADS is not set.
*/
void set_openmp_threads(int nthread) {
#if defined(_OPENMP)
if (!getenv("OMP_NUM_THREADS")) {
omp_set_num_threads(nthread);
}
#endif
}

/**
* Convert char* containing arguments from neuron to char* argv[] for
* coreneuron command line argument parser.
*/
char* prepare_args(int& argc, char**& argv, int use_mpi, const char* arg) {
// first construct all arguments as string
std::string args(arg);
args.insert(0, " coreneuron ");
if (use_mpi) {
args.append(" -mpi ");
}

// we can't modify string with strtok, make copy
char* first = strdup(args.c_str());
const char* sep = " ";

// first count the no of argument
char* token = strtok(first, sep);
argc = 0;
while (token) {
token = strtok(NULL, sep);
argc++;
}
free(first);

// now build char*argv
argv = new char*[argc];
first = strdup(args.c_str());
token = strtok(first, sep);
for (int i = 0; token; i++) {
argv[i] = token;
token = strtok(NULL, sep);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only rank 0 should print?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. unfortunately, coreneuron has not started mpi yet and nrniv did not pass its version of
nrnmpi_myid to nrncore_run

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were for debugging and can be removed


// return actual data to be freed
return first;
}

int corenrn_embedded_run(int nthread, int have_gaps, int use_mpi, const char* arg) {
corenrn_embedded = 1;
corenrn_embedded_nthread = nthread;
coreneuron::nrn_have_gaps = have_gaps;

set_openmp_threads(nthread);
int argc = 0;
char** argv;
char* new_arg = prepare_args(argc, argv, use_mpi, arg);
solve_core(argc, argv);
free(new_arg);
delete[] argv;

return corenrn_embedded;
}
}

#if 0
#include <fenv.h>
#define NRN_FEEXCEPT (FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW)
Expand Down Expand Up @@ -120,7 +198,8 @@ void nrn_init_and_load_data(int argc,
mk_mech(nrnopt_get_str("--datpath").c_str());

// read the global variable names and set their values from globals.dat
set_globals(nrnopt_get_str("--datpath").c_str(), nrnopt_get_flag("--seed"), nrnopt_get_int("--seed"));
set_globals(nrnopt_get_str("--datpath").c_str(), nrnopt_get_flag("--seed"),
nrnopt_get_int("--seed"));

report_mem_usage("After mk_mech");

Expand Down Expand Up @@ -285,7 +364,6 @@ extern "C" int solve_core(int argc, char** argv) {
reports_needs_finalize = configs.size();
}
}

// initializationa and loading functions moved to separate
nrn_init_and_load_data(argc, argv, configs.size() > 0);
std::string checkpoint_path = nrnopt_get_str("--checkpoint");
Expand Down Expand Up @@ -329,7 +407,7 @@ extern "C" int solve_core(int argc, char** argv) {

// register all reports into reportinglib
double min_report_dt = INT_MAX;
for (int i = 0; i < configs.size(); i++) {
for (size_t i = 0; i < configs.size(); i++) {
register_report(dt, tstop, delay, configs[i]);
if (configs[i].report_dt < min_report_dt) {
min_report_dt = configs[i].report_dt;
Expand Down
Loading