CoreNEURON
vrecord.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 <cstdio>
10 
11 #include "coreneuron/nrnconf.h"
16 namespace coreneuron {
17 extern NetCvode* net_cvode_instance;
18 
20  plr_->deliver(tt, ns);
21 }
22 
24  return nrn_threads + plr_->ith_;
25 }
26 
27 void PlayRecordEvent::pr(const char* s, double tt, NetCvode*) {
28  printf("%s PlayRecordEvent %.15g ", s, tt);
29  plr_->pr();
30 }
31 
32 PlayRecord::PlayRecord(double* pd, int ith)
33  : pd_(pd)
34  , ith_(ith) {}
35 
37  printf("PlayRecord\n");
38 }
39 
41  IvocVect&& yvec,
42  IvocVect&& tvec,
43  IvocVect* discon,
44  int ith)
45  : PlayRecord(pd, ith)
46  , y_(std::move(yvec))
47  , t_(std::move(tvec))
48  , discon_indices_(discon)
49  , e_(new PlayRecordEvent{}) {
50  e_->plr_ = this;
51 }
52 
54  delete e_;
55 }
56 
58  NrnThread* nt = nrn_threads + ith_;
59  last_index_ = 0;
60  discon_index_ = 0;
61  if (discon_indices_) {
62  if (discon_indices_->size() > 0) {
64  // printf("play_init %d %g\n", ubound_index_, t_->elem(ubound_index_));
66  } else {
67  ubound_index_ = t_.size() - 1;
68  }
69  } else {
70  ubound_index_ = 0;
72  }
73 }
74 
75 void VecPlayContinuous::deliver(double tt, NetCvode* ns) {
76  NrnThread* nt = nrn_threads + ith_;
77  // printf("deliver %g\n", tt);
79  // clang-format off
80 
82  nrn_pragma_omp(target update to(last_index_) if (nt->compute_gpu))
83  // clang-format on
84  if (discon_indices_) {
85  if (discon_index_ < discon_indices_->size()) {
87  // printf("after deliver:send %d %g\n", ubound_index_, t_->elem(ubound_index_));
88  e_->send(t_[ubound_index_], ns, nt);
89  } else {
90  ubound_index_ = t_.size() - 1;
91  }
92  } else {
93  if (ubound_index_ < t_.size() - 1) {
94  ubound_index_++;
95  e_->send(t_[ubound_index_], ns, nt);
96  }
97  }
98  // clang-format off
99 
101  nrn_pragma_omp(target update to(ubound_index_) if (nt->compute_gpu))
102  // clang-format on
103  continuous(tt);
104 }
105 
107 #ifdef CORENEURON_ENABLE_GPU
108  NrnThread* nt = nrn_threads + ith_;
109 #endif
110  // clang-format off
111 
112  nrn_pragma_acc(kernels present(this) if(nt->compute_gpu))
113  nrn_pragma_omp(target if(nt->compute_gpu))
114  {
115  *pd_ = interpolate(tt);
116  }
117  // clang-format on
118 }
119 
121  if (tt >= t_[ubound_index_]) {
123  if (last_index_ == 0) {
124  // printf("return last tt=%g ubound=%g y=%g\n", tt, t_->elem(ubound_index_),
125  // y_->elem(last_index_));
126  return y_[last_index_];
127  }
128  } else if (tt <= t_[0]) {
129  last_index_ = 0;
130  // printf("return elem(0) tt=%g t0=%g y=%g\n", tt, t_->elem(0), y_->elem(0));
131  return y_[0];
132  } else {
133  search(tt);
134  }
135  double x0 = y_[last_index_ - 1];
136  double x1 = y_[last_index_];
137  double t0 = t_[last_index_ - 1];
138  double t1 = t_[last_index_];
139  // printf("IvocVectRecorder::continuous tt=%g t0=%g t1=%g theta=%g x0=%g x1=%g\n", tt, t0, t1,
140  // (tt - t0)/(t1 - t0), x0, x1);
141  if (t0 == t1) {
142  return (x0 + x1) / 2.;
143  }
144  return interp((tt - t0) / (t1 - t0), x0, x1);
145 }
146 
147 void VecPlayContinuous::search(double tt) {
148  // assert (tt > t_->elem(0) && tt < t_->elem(t_->size() - 1))
149  while (tt < t_[last_index_]) {
150  --last_index_;
151  }
152  while (tt >= t_[last_index_]) {
153  ++last_index_;
154  }
155 }
156 
158  printf("VecPlayContinuous ");
159  // printf("%s.x[%d]\n", hoc_object_name(y_->obj_), last_index_);
160 }
161 } // namespace coreneuron
coreneuron::VecPlayContinuous::t_
IvocVect t_
Definition: vrecitem.h:80
coreneuron::VecPlayContinuous::continuous
void continuous(double tt) override
Definition: vrecord.cpp:106
coreneuron::VecPlayContinuous::VecPlayContinuous
VecPlayContinuous(double *, IvocVect &&yvec, IvocVect &&tvec, IvocVect *discon, int ith)
Definition: vrecord.cpp:40
coreneuron::VecPlayContinuous::deliver
virtual void deliver(double tt, NetCvode *) override
Definition: vrecord.cpp:75
coreneuron::PlayRecord::ith_
int ith_
Definition: vrecitem.h:54
nrn_pragma_omp
nrn_pragma_acc(routine seq) nrn_pragma_omp(declare target) philox4x32_ctr_t coreneuron_random123_philox4x32_helper(coreneuron nrn_pragma_omp(end declare target) namespace coreneuron
Provide a helper function in global namespace that is declared target for OpenMP offloading to functi...
Definition: nrnran123.h:69
netcvode.hpp
coreneuron::NrnThread::compute_gpu
int compute_gpu
Definition: multicore.hpp:136
coreneuron::VecPlayContinuous::ubound_index_
std::size_t ubound_index_
Definition: vrecitem.h:84
coreneuron
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
Definition: corenrn_parameters.cpp:12
coreneuron::VecPlayContinuous::discon_index_
std::size_t discon_index_
Definition: vrecitem.h:83
coreneuron::VecPlayContinuous::~VecPlayContinuous
virtual ~VecPlayContinuous()
Definition: vrecord.cpp:53
ivocvect.hpp
coreneuron::update
void update(NrnThread *_nt)
Definition: fadvance_core.cpp:201
coreneuron::VecPlayContinuous::play_init
virtual void play_init() override
Definition: vrecord.cpp:57
coreneuron::PlayRecordEvent::pr
virtual void pr(const char *, double t, NetCvode *) override
Definition: vrecord.cpp:27
coreneuron::PlayRecordEvent::plr_
PlayRecord * plr_
Definition: vrecitem.h:28
coreneuron::NrnThread
Definition: multicore.hpp:75
coreneuron::VecPlayContinuous::pr
virtual void pr() override
Definition: vrecord.cpp:157
coreneuron::PlayRecordEvent
Definition: vrecitem.h:21
coreneuron::VecPlayContinuous::e_
PlayRecordEvent * e_
Definition: vrecitem.h:86
coreneuron::fixed_vector< double >
coreneuron::VecPlayContinuous::y_
IvocVect y_
Definition: vrecitem.h:79
coreneuron::PlayRecord::PlayRecord
PlayRecord(double *pd, int ith)
Definition: vrecord.cpp:32
coreneuron::nrn_threads
NrnThread * nrn_threads
Definition: multicore.cpp:56
coreneuron::DiscreteEvent::send
virtual void send(double deliverytime, NetCvode *, NrnThread *)
Definition: netcvode.cpp:362
nrnconf.h
coreneuron::VecPlayContinuous::last_index_
std::size_t last_index_
Definition: vrecitem.h:82
coreneuron::PlayRecordEvent::thread
virtual NrnThread * thread()
Definition: vrecord.cpp:23
coreneuron::PlayRecord::deliver
virtual void deliver(double, NetCvode *)
Definition: vrecitem.h:44
coreneuron::net_cvode_instance
NetCvode * net_cvode_instance
Definition: netcvode.cpp:35
coreneuron::PlayRecord
Definition: vrecitem.h:37
vrecitem.h
multicore.hpp
coreneuron::PlayRecordEvent::deliver
virtual void deliver(double, NetCvode *, NrnThread *) override
Definition: vrecord.cpp:19
coreneuron::VecPlayContinuous::search
void search(double tt)
Definition: vrecord.cpp:147
coreneuron::VecPlayContinuous::interpolate
double interpolate(double tt)
Definition: vrecord.cpp:120
coreneuron::VecPlayContinuous::discon_indices_
IvocVect * discon_indices_
Definition: vrecitem.h:81
coreneuron::VecPlayContinuous::interp
double interp(double th, double x0, double x1)
Definition: vrecitem.h:70
coreneuron::PlayRecord::pr
virtual void pr()
Definition: vrecord.cpp:36
coreneuron::nrn_pragma_acc
nrn_pragma_acc(routine vector) static void triang_interleaved2(NrnThread *nt
Definition: ivocvect.cpp:30
coreneuron::NetCvode
Definition: netcvode.hpp:59
coreneuron::PlayRecord::pd_
double * pd_
Definition: vrecitem.h:53