8#include <dispenso/graph_executor.h>
14 using NodeType =
typename G::NodeType;
15 nodesToExecute_.clear();
16 nodesToExecuteNext_.clear();
18 graph.forEachNode([&](
const NodeType& node) {
20 nodesToExecute_.emplace_back(&node);
24 while (!nodesToExecute_.empty()) {
25 for (
const Node*
n : nodesToExecute_) {
26 const NodeType* node =
static_cast<const NodeType*
>(
n);
28 node->forEachDependent([&](
const Node&
d) {
30 static_cast<const NodeType&
>(
d), std::memory_order_relaxed)) {
31 nodesToExecuteNext_.emplace_back(
static_cast<const NodeType*
>(&
d));
35 nodesToExecute_.swap(nodesToExecuteNext_);
36 nodesToExecuteNext_.clear();
40template <
typename TaskSetT,
typename G>
42 using NodeType =
typename G::NodeType;
43 nodesToExecute_.clear();
44 nodesToExecuteNext_.clear();
46 graph.forEachNode([&](
const NodeType& node) {
48 nodesToExecute_.emplace_back(&node);
51 while (!nodesToExecute_.empty()) {
53 const NodeType* node = static_cast<const NodeType*>(nodesToExecute_[i]);
56 node->forEachDependent([&](const Node& d) {
57 if (decNumIncompletePredecessors(
58 static_cast<const NodeType&>(d), std::memory_order_acq_rel)) {
59 nodesToExecuteNext_.emplace_back(static_cast<const NodeType*>(&d));
64 nodesToExecute_.swap(nodesToExecuteNext_);
65 nodesToExecuteNext_.clear();
70void ConcurrentTaskSetExecutor::operator()(
74 using NodeType =
typename G::NodeType;
77 graph.forEachNode([&](
const NodeType& node) {
79 startNodes_.emplace_back(&node);
83 for (
const Node*
n : startNodes_) {
84 const NodeType* node =
static_cast<const NodeType*
>(
n);
93void setAllNodesIncomplete(
const G&
graph) {
94 using NodeType =
typename G::NodeType;
96 graph.forEachNode([&](
const NodeType& node) {
97 node.numIncompletePredecessors_.store(node.numPredecessors(), std::memory_order_relaxed);
102void ForwardPropagator::operator()(
const G&
graph) {
103 using NodeType =
typename G::NodeType;
105 nodesToVisit_.clear();
106 nodesToVisitNext_.clear();
110 graph.forEachNode([&](
const NodeType& node) {
111 if (!node.isCompleted()) {
112 nodesToVisit_.emplace_back(&node);
113 visited_.insert(&node);
114 appendGroup(static_cast<const NodeType*>(&node), groups_);
118 while (!nodesToVisit_.empty()) {
119 for (
const Node* node : nodesToVisit_) {
120 node->forEachDependent([&](
const Node&
d) {
122 if (visited_.insert(
static_cast<const NodeType*
>(&
d)).second) {
123 nodesToVisitNext_.emplace_back(
static_cast<const NodeType*
>(&
d));
128 nodesToVisit_.swap(nodesToVisitNext_);
129 nodesToVisitNext_.clear();
136void ForwardPropagator::propagateIncompleteStateBidirectionally<Node>() {}
138void ForwardPropagator::propagateIncompleteStateBidirectionally<BiPropNode>() {
139 nodesToVisit_.clear();
141 for (
const std::vector<const BiPropNode*>* group : groups_) {
143 if (gnode->setIncomplete()) {
144 nodesToVisit_.emplace_back(gnode);
149 for (
const Node* node : nodesToVisit_) {
150 const BiPropNode* biPropNode =
static_cast<const BiPropNode*
>(node);
151 biPropNode->forEachDependent([](
const Node& d) { ifIncompleteAddIncompletePredecessor(d); });
155template DISPENSO_DLL_ACCESS
void SingleThreadExecutor::operator()<Graph>(
const Graph&);
156template DISPENSO_DLL_ACCESS
void SingleThreadExecutor::operator()<BiPropGraph>(
const BiPropGraph&);
158template DISPENSO_DLL_ACCESS
void ParallelForExecutor::operator()<TaskSet, Graph>(
161template DISPENSO_DLL_ACCESS
void ParallelForExecutor::operator()<TaskSet, BiPropGraph>(
164template DISPENSO_DLL_ACCESS
void ParallelForExecutor::operator()<ConcurrentTaskSet, Graph>(
165 ConcurrentTaskSet& tasks,
167template DISPENSO_DLL_ACCESS
void ParallelForExecutor::operator()<ConcurrentTaskSet, BiPropGraph>(
168 ConcurrentTaskSet& tasks,
169 const BiPropGraph& graph);
171template DISPENSO_DLL_ACCESS
void ConcurrentTaskSetExecutor::operator()<Graph>(
175template DISPENSO_DLL_ACCESS
void ConcurrentTaskSetExecutor::operator()<BiPropGraph>(
177 const BiPropGraph& graph,
180template DISPENSO_DLL_ACCESS
void setAllNodesIncomplete<Graph>(
const Graph&);
181template DISPENSO_DLL_ACCESS
void setAllNodesIncomplete<BiPropGraph>(
const BiPropGraph&);
182template DISPENSO_DLL_ACCESS
void ForwardPropagator::operator()<Graph>(
const Graph&);
183template DISPENSO_DLL_ACCESS
void ForwardPropagator::operator()<BiPropGraph>(
const BiPropGraph&);
void operator()(TaskSetT &taskSet, const G &graph)
void operator()(const G &graph)
void parallel_for(TaskSetT &taskSet, StateContainer &states, const StateGen &defaultState, const ChunkedRange< IntegerT > &range, F &&f, ParForOptions options={})
detail::OpResult< T > OpResult