Skip to content

Commit

Permalink
More clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Cornu committed Dec 13, 2024
1 parent 85dcaaf commit 143017f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 57 deletions.
1 change: 0 additions & 1 deletion src/nrncvode/cvodeobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ extern int hoc_return_type_code;
#include "nrnpy.h"
#include "tqueue.hpp"
#include "mymath.h"
#include "htlist.h"
#include <nrnmutdec.h>

#if NRN_ENABLE_THREADS
Expand Down
3 changes: 1 addition & 2 deletions src/nrncvode/cvodeobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ struct BAMech;
struct NrnThread;
class PlayRecord;
class STEList;
class HTList;
namespace neuron {
struct model_sorted_token;
}
Expand Down Expand Up @@ -72,7 +71,7 @@ class CvodeThreadData {
Node** v_node_;
Node** v_parent_;
PreSynList* psl_th_; // with a threshold
HTList* watch_list_;
std::list<WatchCondition*>* watch_list_;
std::vector<neuron::container::data_handle<double>> pv_, pvdot_;
int nvoffset_; // beginning of this threads states
int nvsize_; // total number of states for this thread
Expand Down
33 changes: 0 additions & 33 deletions src/nrncvode/netcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#undef check

#include "htlist.h"
#include "neuron/container/data_handle.hpp"
#include "nrnmpi.h"
#include "nrnneosm.h"
Expand Down Expand Up @@ -266,38 +265,6 @@ class WatchCondition: public ConditionEvent {
signal<WatchCondition*> del;
};

class HTList {
public:
HTList() = default;
virtual ~HTList() = default;

bool IsEmpty() {
return _list.empty();
}
void Append(WatchCondition* wc) {
_list.push_back(wc);
wc->del.connect([=](WatchCondition* wc) { this->Remove(wc); });
}
void Remove(WatchCondition* wc) {
auto it = std::find(_list.begin(), _list.end(), wc);
if (it != _list.end()) {
_list.erase(it);
}
}
void RemoveAll() {
_list.clear();
}
std::list<WatchCondition*>::iterator First() {
return _list.begin();
}
std::list<WatchCondition*>::iterator End() {
return _list.end();
}

private:
std::list<WatchCondition*> _list;
};

class STECondition: public WatchCondition {
public:
STECondition(Point_process*, double (*)(Point_process*) = NULL);
Expand Down
38 changes: 19 additions & 19 deletions src/nrncvode/netcvode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "vrecitem.h"
#include "oclist.h"
#define PROFILE 0
#include "htlist.h"
#include "ivocvect.h"
#include "netcon.h"
#include "netcvode.h"
Expand Down Expand Up @@ -1265,7 +1264,7 @@ CvodeThreadData::~CvodeThreadData() {
delete[] no_cap_child_;
}
if (watch_list_) {
watch_list_->RemoveAll();
watch_list_->clear();
delete watch_list_;
}
}
Expand Down Expand Up @@ -2425,8 +2424,8 @@ void _nrn_watch_allocate(Datum* d,
void nrn_watch_clear() {
assert(net_cvode_instance->wl_list_.size() == (size_t) nrn_nthread);
for (auto& htlists_of_thread: net_cvode_instance->wl_list_) {
for (HTList* wl: htlists_of_thread) {
wl->RemoveAll();
for (auto* wl: htlists_of_thread) {
wl->clear();
}
}
// not necessary to empty the WatchList in the Point_process dparam array
Expand Down Expand Up @@ -2776,15 +2775,15 @@ void NetCvode::init_events() {
if (gcv_) {
for (int j = 0; j < nrn_nthread; ++j) {
if (gcv_->ctd_[j].watch_list_) {
gcv_->ctd_[j].watch_list_->RemoveAll();
gcv_->ctd_[j].watch_list_->clear();
}
}
} else {
for (int j = 0; j < nrn_nthread; ++j) {
NetCvodeThreadData& d = p[j];
for (i = 0; i < d.nlcv_; ++i) {
if (d.lcv_[i].ctd_[0].watch_list_) {
d.lcv_[i].ctd_[0].watch_list_->RemoveAll();
d.lcv_[i].ctd_[0].watch_list_->clear();
}
}
}
Expand Down Expand Up @@ -5273,13 +5272,14 @@ void WatchCondition::activate(double flag) {
}
assert(cv);
id = (cv->nctd_ > 1) ? thread()->id : 0;
HTList*& wl = cv->ctd_[id].watch_list_;
auto*& wl = cv->ctd_[id].watch_list_;
if (!wl) {
wl = new HTList();
wl = new std::list<WatchCondition*>();
net_cvode_instance->wl_list_[id].push_back(wl);
}
del.send(this);
wl->Append(this);
wl->push_back(this);
del.connect([&](WatchCondition* wc) {auto it = std::find(wl->begin(), wl->end(), wc); if (it != wl->end()) {wl->erase(it);}});
}

void WatchCondition::asf_err() {
Expand Down Expand Up @@ -5452,8 +5452,8 @@ void Cvode::evaluate_conditions(NrnThread* nt) {
}
}
if (z.watch_list_) {
for (auto item = z.watch_list_->First(); item != z.watch_list_->End(); ++item) {
(*item)->condition(this);
for (auto wc: *z.watch_list_) {
wc->condition(this);
}
}
}
Expand All @@ -5480,8 +5480,8 @@ void Cvode::check_deliver(NrnThread* nt) {
}
}
if (z.watch_list_) {
for (auto item = z.watch_list_->First(); item != z.watch_list_->End(); ++item) {
(*item)->check(nt, nt->_t);
for (auto wc: *z.watch_list_) {
wc->check(nt, nt->_t);
}
}
}
Expand Down Expand Up @@ -5893,9 +5893,9 @@ void NetCvode::check_thresh(NrnThread* nt) { // for default method
}
}

for (HTList* wl: wl_list_[nt->id]) {
for (auto item = wl->First(); item != wl->End(); ++item) {
(*item)->check(nt, nt->_t);
for (auto* wl: wl_list_[nt->id]) {
for (auto wc: *wl) {
wc->check(nt, nt->_t);
}
}
}
Expand All @@ -5910,9 +5910,9 @@ void nrn2core_transfer_WATCH(void (*cb)(int, int, int, int, int)) {
// should be revisited for possible simplification since wl_list now
// segregated by threads.
for (auto& htlists_of_thread: net_cvode_instance->wl_list_) {
for (HTList* wl: htlists_of_thread) {
for (auto item = wl->First(); item != wl->End(); ++item) {
nrn2core_transfer_WatchCondition(*item, cb);
for (auto* wl: htlists_of_thread) {
for (auto wc: *wl) {
nrn2core_transfer_WatchCondition(wc, cb);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/nrncvode/netcvode.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ struct hoc_Item;
class PlayRecord;
class IvocVect;
struct BAMechList;
class HTList;
// nrn_nthread vectors of HTList* for fixed step method
// Thread segregated HTList* of all the CVode.CvodeThreadData.HTList*
// Interior vector needed because of the chance of local variable time step.
// Practically it will always have length <= 1.
using HTListList = std::vector<std::vector<HTList*>>;
using HTListList = std::vector<std::vector<std::list<WatchCondition*>*>>;
class NetCvode;
class MaxStateItem;
typedef std::unordered_map<void*, MaxStateItem*> MaxStateTable;
Expand Down

0 comments on commit 143017f

Please sign in to comment.