36#ifndef MADNESS_WORLD_DQUEUE_H__INCLUDED
37#define MADNESS_WORLD_DQUEUE_H__INCLUDED
43#define MADNESS_DQ_STATS
48#include <madness/config.h>
93#ifdef MADNESS_DQ_USE_PREBUF
94 static const size_t NPREBUF=MADNESS_DQ_PREBUF_SIZE;
95 inline static thread_local T prebuf[NPREBUF] = {
T{}};
96 inline static thread_local T prebufhi[NPREBUF] = {
T{}};
97 inline static thread_local size_t ninprebuf = 0, ninprebufhi = 0;
102#ifdef MADNESS_DQ_STATS
109 else if (
sz <= 1048576)
115 int lo =
sz/2 - oldsz/2;
116 for (
int i=
_front; i<int(oldsz); ++i,++
lo) {
120 for (
int i=0; i<=
_back; ++i,++
lo) {
134 if (num < 0) num +=
sz;
135 if (num==
int(
sz) && n==0) num=0;
136 if (num==0 && n==
sz) num=
sz;
149#ifdef MADNESS_DQ_STATS
155 if (
b >=
int(ss))
b = 0;
158#ifdef MADNESS_DQ_STATS
175#ifdef MADNESS_DQ_STATS
181 if (
f < 0)
f = ss - 1;
184#ifdef MADNESS_DQ_STATS
194#ifdef MADNESS_DQ_USE_PREBUF
216 ,
sz(hint>2 ? hint : 2)
233 template <
typename opT>
240 std::cout <<
"IN Q " << nn << std::endl;
243 T*
p =
const_cast<T*
>(
buf +
f);
269#ifdef MADNESS_DQ_STATS
276 nmax = std::min(nmax,std::max(
int(nn>>6),1));
293 if (
f >=
int(thesize))
f = 0;
303 if (
f >=
int(thesize))
f = 0;
323 return std::pair<T,bool>(r,ngot==1);
337 template <
typename T>
339#ifdef MADNESS_DQ_USE_PREBUF
340 if (ninprebuf+ninprebufhi) {
347 template <
typename T>
349#ifdef MADNESS_DQ_USE_PREBUF
351 prebufhi[ninprebufhi++] = value;
357 push_front_with_lock(value);
361 template <
typename T>
363#ifdef MADNESS_DQ_USE_PREBUF
365 prebuf[ninprebuf++] = value;
374 push_back_with_lock(value);
380 template <
typename T>
382#ifdef MADNESS_DQ_USE_PREBUF
383 return (ninprebuf+ninprebufhi+n)==0;
void set_wait_policy(WaitPolicy p, int us=0)
Definition worldmutex.h:504
A thread safe, fast but simple doubled-ended queue.
Definition dqueue.h:80
int pop_front(int nmax, T *r, bool wait)
Pop multiple values off the front of queue ... returns number popped ... might be zero.
Definition dqueue.h:256
void flush_prebuf()
Definition dqueue.h:193
const DQStats & get_stats() const
Definition dqueue.h:332
void push_front(const T &value)
Insert value at front of queue.
Definition dqueue.h:348
virtual ~DQueue()
Definition dqueue.h:221
size_t sz
Current capacity.
Definition dqueue.h:86
std::pair< T, bool > pop_front(bool wait)
Pop value off the front of queue.
Definition dqueue.h:320
DQStats stats
Definition dqueue.h:91
size_t size() const
Definition dqueue.h:326
void push_back(const T &value, int ncopy=1)
Insert element at back of queue (default is just one copy)
Definition dqueue.h:362
void scan(opT &op)
Definition dqueue.h:234
int _front
Index of element at front of buffer.
Definition dqueue.h:88
T * buf
Actual buffer.
Definition dqueue.h:87
size_t n __attribute__((aligned(64)))
Number of elements in the buffer.
bool empty() const
Definition dqueue.h:381
void push_back_with_lock(const T &value)
Definition dqueue.h:141
DQueue(size_t hint=200000)
Definition dqueue.h:214
void push_front_with_lock(const T &value)
Definition dqueue.h:165
int _back
Index of element at back of buffer.
Definition dqueue.h:89
void grow()
Definition dqueue.h:100
void sanity_check() const
Definition dqueue.h:131
char pad[64]
To put the lock and the data in separate cache lines.
Definition dqueue.h:81
void lock_and_flush_prebuf()
Definition dqueue.h:338
void set_wait_policy(WaitPolicy p, int us=0)
Definition dqueue.h:208
Simple wrapper for Pthread condition variable with its own mutex.
Definition worldmutex.h:635
void signal() const
Definition worldmutex.h:673
void wait() const
You should have acquired the mutex before entering here.
Definition worldmutex.h:669
Mutex that is applied/released at start/end of a scope.
Definition worldmutex.h:239
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
static double lo
Definition dirac-hatom.cc:23
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:34
Tensor< double > op(const Tensor< double > &x)
Definition kain.cc:508
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
WaitPolicy
wait policies supported by ConditionVariable/DQueue/ThreadPool
Definition worldmutex.h:492
bool is_madness_thread()
Definition thread_info.h:70
NDIM & f
Definition mra.h:2416
static const double b
Definition nonlinschro.cc:119
uint64_t ngrow
#calls to grow
Definition dqueue.h:63
uint64_t npush_front
#calls to push_front
Definition dqueue.h:61
uint64_t npush_back
#calls to push_back
Definition dqueue.h:60
DQStats()
Definition dqueue.h:66
uint64_t nmax
Lifetime max. entries in the queue.
Definition dqueue.h:64
uint64_t npop_front
#calls to pop_front
Definition dqueue.h:62
Implements thread introspection.
Implements Mutex, MutexFair, Spinlock, ConditionVariable.