Skip to content

Commit

Permalink
Load 'morphology' symbol during registration (#1393)
Browse files Browse the repository at this point in the history
This way if someone define again this symbol (in hoc file for example),
neuron will use the right one during allocation of the module.

This is how it is currently done in neuron.

This behaviour has been spotted with nmodl benchmark.
  • Loading branch information
Nicolas Cornu authored Aug 12, 2024
1 parent a8c5755 commit 86c2c66
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,10 @@ void CodegenNeuronCppVisitor::print_mechanism_global_var_structure(bool print_in
// throw std::runtime_error("Not implemented, global vectorize something else.");
}

if (info.diam_used) {
printer->fmt_line("Symbol* _morphology_sym;");
}

printer->pop_block(";");

print_global_var_struct_assertions();
Expand Down Expand Up @@ -1225,6 +1229,11 @@ void CodegenNeuronCppVisitor::print_mechanism_register() {
printer->add_line("_nrn_thread_reg(mech_type, 0, thread_mem_cleanup);");
}

if (info.diam_used) {
printer->fmt_line("{}._morphology_sym = hoc_lookup(\"morphology\");",
global_struct_instance());
}

printer->pop_block();
}

Expand Down Expand Up @@ -1609,9 +1618,8 @@ void CodegenNeuronCppVisitor::print_nrn_alloc() {
for (size_t i = 0; i < codegen_int_variables.size(); ++i) {
auto var_info = codegen_int_variables[i];
if (var_info.symbol->get_name() == naming::DIAM_VARIABLE) {
printer->add_line("Symbol * morphology_sym = hoc_lookup(\"morphology\");");
printer->fmt_line("Prop * morphology_prop = need_memb(morphology_sym);");

printer->fmt_line("Prop * morphology_prop = need_memb({}._morphology_sym);",
global_struct_instance());
printer->fmt_line(
"_ppvar[{}] = _nrn_mechanism_get_param_handle(morphology_prop, 0);", i);
}
Expand Down

0 comments on commit 86c2c66

Please sign in to comment.