diff --git a/src/scheduler/Scheduler.cpp b/src/scheduler/Scheduler.cpp index 1613450508ea84a230f36ba6526a1322c6a70559..958b2543208dfdce3eee4e1ba7a22cc8bd0be74b 100644 --- a/src/scheduler/Scheduler.cpp +++ b/src/scheduler/Scheduler.cpp @@ -63,22 +63,15 @@ std::vector<std::shared_ptr<Aidge::Scheduler::StaticSchedulingElement>> Aidge::S std::vector<std::shared_ptr<StaticSchedulingElement>> schedule; - // 1) Initialize consumers list: - // 1.1) List of the GraphView's input nodes - std::set<std::shared_ptr<Node>> consumers = mGraphView->inputNodes(); - - // 1.2) List of nodes inside the GraphView connected to an inner Producer + // 1) Initialize consumers list: start from the output nodes and + // find the required prior producers/consumers at step 2). + // Beware that generateBaseScheduling() can be called multiple time + // with some node having already produced some data. In this case, + // we should always consume available data first. This is ensured + // by setting the consumers list to the output nodes and then recursively + // find the dependencies. + std::set<std::shared_ptr<Node>> consumers = mGraphView->outputNodes(); std::set<std::shared_ptr<Node>> producers; - for (const std::shared_ptr<Node>& nodePtr : mGraphView->getNodes()) { - if (nodePtr->type() == Producer_Op::Type) { - for (const auto& child : nodePtr->getChildren()) { - // Do not schedule childs outside current graph! - if (mGraphView->inView(child)) { - consumers.insert(child); - } - } - } - } do { // 2) From the current consumers list, check if any prior consumer node