Skip to content

Commit

Permalink
add includes for concurrent writer
Browse files Browse the repository at this point in the history
SteveBronder committed Jan 10, 2025
1 parent e48467b commit be3cf7e
Showing 2 changed files with 11 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/stan/callbacks/concurrent_writer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#ifndef STAN_CALLBACKS_CONCURRENT_WRITER_HPP
#define STAN_CALLBACKS_CONCURRENT_WRITER_HPP

#include <stan/math/prim/fun/Eigen.hpp>
#include <stan/math/prim/meta.hpp>
#include <tbb/concurrent_queue.h>
#include <functional>
#include <string>
#include <thread>
#include <vector>

#ifdef STAN_THREADS
/**
* Takes a writer and makes it thread safe via multiple queues.
@@ -33,19 +41,16 @@ struct concurrent_writer {
std::string str;
std::vector<std::string> vec_str;
Eigen::RowVectorXd eigen;
std::size_t max_size = 0;
while (continue_writing_
|| !(str_messages_.empty() && vec_str_messages_.empty()
&& eigen_messages_.empty())) {
if (str_messages_.try_pop(str)) {
while (str_messages_.try_pop(str)) {
writer(str);
}
if (vec_str_messages_.try_pop(vec_str)) {
while (vec_str_messages_.try_pop(vec_str)) {
writer(vec_str);
}
max_size = std::max(max_size,
static_cast<std::size_t>(eigen_messages_.size()));
if (eigen_messages_.try_pop(eigen)) {
while (eigen_messages_.try_pop(eigen)) {
writer(eigen);
}
}
1 change: 0 additions & 1 deletion src/stan/services/pathfinder/multi.hpp
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
#include <tbb/parallel_for.h>
#include <tbb/concurrent_vector.h>
#include <tbb/concurrent_queue.h>
#include <tbb/task_group.h>
#include <boost/random/discrete_distribution.hpp>
#include <string>
#include <vector>

0 comments on commit be3cf7e

Please sign in to comment.