5#ifndef LINE_SOLVERS_AG_AG_EXEC_H
6#define LINE_SOLVERS_AG_AG_EXEC_H
63template <
class T,
class Gen,
class Sol>
65 std::vector<
Matrix<T>>& Q, std::vector<std::vector<T>>& pi) {
66 for (std::size_t k = 0; k < n; ++k) {
77template <
class T,
class Gen,
class Sol>
79 std::vector<
Matrix<T>>& Q, std::vector<std::vector<T>>& pi) {
80 unsigned hw = nworkers > 0 ? nworkers : std::thread::hardware_concurrency();
82 const std::size_t nthreads = std::min<std::size_t>(hw, n == 0 ? 1 : n);
88 std::vector<std::thread> pool;
89 pool.reserve(nthreads);
94 for (std::size_t t = 0; t < nthreads; ++t) {
95 pool.emplace_back([&, t]() {
96 for (std::size_t k = t; k < n; k += nthreads) {
102 for (std::size_t t = 0; t < pool.size(); ++t) pool[t].join();
113template <
class T,
class Gen,
class Sol,
class Payload>
115 Gen
gen, Sol sol, Payload payload,
116 std::vector<
Matrix<T>>& Q, std::vector<std::vector<T>>& pi) {
117 if constexpr (!std::is_same<T, double>::value) {
118 (void)workers; (void)x; (void)payload;
120 "ag: the 'cluster' execution backend is double only, because the ag-worker "
121 "protocol is JSON and an exact or high-precision value would have to be rounded "
122 "to send it; rerun with --arith double, or use exec 'serial' or 'parallel'");
126 for (std::size_t k = 0; k < n; ++k) Q[k] =
gen(k);
128 std::vector<bool> pending(n,
true);
129 std::vector<double> xd(x.size());
130 for (std::size_t c = 0; c < x.size(); ++c) xd[c] = x[c];
132 workers.
sweep(xd, pi, pending);
134 for (std::size_t k = 0; k < n; ++k) {
135 if (pending[k]) pi[k] = sol(Q[k], k);
Options of the agent-based (RCAT) solver.
Coordinator-side connections to the ag-worker processes.
UnsupportedError(const std::string &what)
The connections to every configured worker, plus the agent partition.
void ensure_assigned(std::size_t num_agents, Payload payload)
Connect and ship the static half of each owned agent, once.
void sweep(const std::vector< double > &x, std::vector< std::vector< double > > &pi, std::vector< bool > &pending)
One sweep.
The exception types the port throws.
Dense matrix and non-owning view.
void ag_sweep_cluster(std::size_t n, AgWorkerPool &workers, const std::vector< T > &x, Gen gen, Sol sol, Payload payload, std::vector< Matrix< T > > &Q, std::vector< std::vector< T > > &pi)
The same sweep with the agents partitioned over remote ag-worker processes.
void ag_sweep_serial(std::size_t n, Gen gen, Sol sol, std::vector< Matrix< T > > &Q, std::vector< std::vector< T > > &pi)
Evaluate every agent of one sweep.
void ag_sweep_parallel(std::size_t n, unsigned nworkers, Gen gen, Sol sol, std::vector< Matrix< T > > &Q, std::vector< std::vector< T > > &pi)
The same sweep over a thread pool.
Conservation laws of a layered queueing network, enumerated from its structure.
Number-type abstraction for the templated API port.