CoreNEURON
test_queueing.cpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================.
7 */
10 
11 #define BOOST_TEST_MODULE QueueingTest
12 #include <boost/test/included/unit_test.hpp>
13 
14 #include <cstdlib>
15 #include <vector>
16 #include <iostream>
17 
18 using namespace coreneuron;
19 // UNIT TESTS
20 BOOST_AUTO_TEST_CASE(priority_queue_nq_dq) {
22  const int num = 8;
23  int cnter = 0;
24  // enqueue 8 items with increasing time
25  for (int i = 0; i < num; ++i)
26  tq.insert(static_cast<double>(i), NULL);
27 
28  BOOST_CHECK(tq.pq_que_.size() == (num - 1));
29 
30  // dequeue items with time <= 5.0. Should be 6 events: from 0. to 5.
31  TQItem* item = NULL;
32  while ((item = tq.atomic_dq(5.0)) != NULL) {
33  ++cnter;
34  delete item;
35  }
36  BOOST_CHECK(cnter == 6);
37  BOOST_CHECK(tq.pq_que_.size() == (num - 6 - 1));
38 
39  // dequeue the rest
40  while ((item = tq.atomic_dq(8.0)) != NULL) {
41  ++cnter;
42  delete item;
43  }
44 
45  BOOST_CHECK(cnter == num);
46  BOOST_CHECK(tq.pq_que_.empty());
47  BOOST_CHECK(tq.least() == NULL);
48 }
49 
50 BOOST_AUTO_TEST_CASE(tqueue_ordered_test) {
52  const int num = 10;
53  int cnter = 0;
54  double time = double();
55 
56  // insert N items with time < N
57  for (int i = 0; i < num; ++i) {
58  time = static_cast<double>(rand() % num);
59  tq.insert(time, NULL);
60  }
61 
62  time = 0.0;
63  TQItem* item = NULL;
64  // dequeue all items and check that previous item time <= current item time
65  while ((item = tq.atomic_dq(10.0)) != NULL) {
66  BOOST_CHECK(time <= item->t_);
67  ++cnter;
68  time = item->t_;
69  delete item;
70  }
71  BOOST_CHECK(cnter == num);
72  BOOST_CHECK(tq.pq_que_.empty());
73  BOOST_CHECK(tq.least() == NULL);
74 }
75 
76 BOOST_AUTO_TEST_CASE(tqueue_move_nolock) {}
77 
78 BOOST_AUTO_TEST_CASE(tqueue_remove) {}
79 
80 BOOST_AUTO_TEST_CASE(threaddata_interthread_send) {
81  NetCvodeThreadData nt{};
82  const size_t num = 6;
83  for (size_t i = 0; i < num; ++i)
84  nt.interthread_send(static_cast<double>(i), NULL, NULL);
85 
86  BOOST_CHECK(nt.inter_thread_events_.size() == num);
87 }
88 /*
89 BOOST_AUTO_TEST_CASE(threaddata_enqueue){
90  NetCvode n = NetCvode();
91  const int num = 6;
92  for(int i = 0; i < num; ++i)
93  n.p[1].interthread_send(static_cast<double>(i), NULL, NULL);
94 
95  BOOST_CHECK(n.p[1].inter_thread_events_.size() == num);
96 
97  //enqueue the inter_thread_events_
98  n.p[1].enqueue(&n, &(n.p[1]));
99  BOOST_CHECK(n.p[1].inter_thread_events_.empty());
100  BOOST_CHECK(n.p[1].tqe_->pq_que_.size() == num);
101 
102  //cleanup priority queue
103  TQItem* item = NULL;
104  while((item = n.p[1].tqe_->atomic_dq(6.0)) != NULL)
105  delete item;
106 }*/
coreneuron::TQueue::atomic_dq
TQItem * atomic_dq(double til)
coreneuron::TQItem
Definition: tqueue.hpp:69
tqueue.hpp
netcvode.hpp
coreneuron::TQItem::t_
double t_
Definition: tqueue.hpp:72
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(priority_queue_nq_dq)
Definition: test_queueing.cpp:20
coreneuron::TQueue::least
TQItem * least()
Definition: tqueue.hpp:128
coreneuron::NetCvodeThreadData::interthread_send
void interthread_send(double, DiscreteEvent *, NrnThread *)
If the PreSyn is on a different thread than the target, we have to lock the buffer.
Definition: netcvode.cpp:133
coreneuron
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
Definition: corenrn_parameters.cpp:12
coreneuron::i
int i
Definition: cellorder.cpp:485
coreneuron::TQueue::insert
TQItem * insert(double t, DiscreteEvent *data)
coreneuron::NetCvodeThreadData
Definition: netcvode.hpp:46
coreneuron::TQueue::pq_que_
std::priority_queue< TQPair, std::vector< TQPair >, less_time > pq_que_
Priority queue of vectors for queuing the events.
Definition: tqueue.hpp:151
coreneuron::TQueue
Definition: tqueue.hpp:123