21 template<
typename X,
typename... Args>
65 to_yield.
push(x, thr);
84 std::vector<std::thread> threads(ctl.
nthreads);
86 assert(__nrunning==0);
99 for(
unsigned long thr=0;thr<ctl.
nthreads;thr++) {
105 while(__nrunning > 0 and !
CTRL_C) {
110 if(not to_yield.
empty()) {
111 auto val = to_yield.
pop();
112 if(val.has_value()) co_yield val.value();
120 while(not to_yield.
empty()) {
121 auto val = to_yield.
pop();
122 if(val.has_value()) co_yield val.value();
127 for(
auto& t : threads)
137 std::cerr <<
"*** Warning running unthreaded_run (intended for debugging)" << std::endl;
142 auto val = to_yield.
pop();
143 if(val.has_value()) co_yield val.value();
void push(const T &item, size_t thr)
Definition: ConcurrentQueue.h:116
virtual generator< X & > run_thread(Control &ctl, Args... args)=0
bool empty()
Definition: ConcurrentQueue.h:137
size_t nthreads()
How many threads are currently run in this interface?
Definition: ThreadedInferenceInterface.h:51
A concurrent queue class that allows multiple threads to push and consume. Note that this has a fixed...
volatile sig_atomic_t CTRL_C
void start()
Definition: Control.h:54
bool yieldOnlyChainOne
Definition: FleetArgs.h:56
std::atomic< size_t > __nrunning
Definition: ThreadedInferenceInterface.h:35
ThreadedInferenceInterface()
Definition: ThreadedInferenceInterface.h:39
Definition: generator.hpp:21
unsigned long next_index()
Return the next index to operate on (in a thread-safe way).
Definition: ThreadedInferenceInterface.h:45
void run_thread_generator_wrapper(size_t thr, Control &ctl, Args... args)
We have to wrap run_thread in something that manages the sync with main. This really just synchronize...
Definition: ThreadedInferenceInterface.h:60
ConcurrentQueueRing< X > to_yield
Definition: ThreadedInferenceInterface.h:37
Primitive< typename Grammar_t::input_t > X(Op::X, BUILTIN_LAMBDA { assert(!vms->xstack.empty());vms->template push< typename Grammar_t::input_t >(vms->xstack.top());})
size_t nthreads
Definition: Control.h:26
std::atomic< size_t > index
Definition: ThreadedInferenceInterface.h:31
size_t __nthreads
Definition: ThreadedInferenceInterface.h:34
Definition: ThreadedInferenceInterface.h:22
generator< X & > unthreaded_run(Control ctl, Args... args)
Definition: ThreadedInferenceInterface.h:132
generator< X & > run(Control ctl, Args... args)
Set up the multiple threads and actually run, calling run_thread_generator_wrapper.
Definition: ThreadedInferenceInterface.h:82
This class has all the information for running MCMC or MCTS in a little package. It defaultly constru...
Definition: FleetArgs.h:10
std::optional< T > pop()
Definition: ConcurrentQueue.h:121