@@ -15,9 +15,7 @@ namespace atk
1515{
1616
1717/* *
18- * @brief Simplified DAG partitioner using node-centric model with vector-based storage.
19- *
20- * Optimized for performance using only vectors to avoid allocations.
18+ * DAG partitioner for extracting parallelizable subgraphs.
2119 *
2220 * Rules:
2321 * 1) Node exists only once in the graph
@@ -27,27 +25,19 @@ namespace atk
2725 * 5) Every node with NO output connections is an endpoint
2826 * 6) If no other node outputs to this node, it's an input
2927 * 7) If node outputs to >1 nodes, it's a split point (subgraph endpoint)
30- * => Subgraph ends when: numOutputs != 1
3128 * 8) If node receives input from >1 nodes, it's a join point (new subgraph starts)
32- * => New subgraph starts when: numInputs != 1
33- *
34- * In other words: A subgraph is a linear chain where every node has exactly 1 input and 1 output,
35- * except at the boundaries.
3629 *
37- * Template parameter NodeIDType should be copyable and comparable .
30+ * A subgraph is a linear chain where each node has exactly 1 input and 1 output (except boundaries) .
3831 */
3932template <typename NodeIDType>
4033class DagPartitioner
4134{
4235public:
43- /* *
44- * @brief Simple node - tracks what it connects to using vectors.
45- */
4636 struct Node
4737 {
4838 NodeIDType id;
49- std::vector<NodeIDType> outputsTo; // Nodes this one outputs to
50- std::vector<NodeIDType> inputsFrom; // Nodes that output to this one
39+ std::vector<NodeIDType> outputsTo;
40+ std::vector<NodeIDType> inputsFrom;
5141
5242 explicit Node (NodeIDType nodeId = NodeIDType())
5343 : id(nodeId)
@@ -61,15 +51,12 @@ class DagPartitioner
6151 }
6252 };
6353
64- /* *
65- * @brief Partitioned subgraph result.
66- */
6754 struct Subgraph
6855 {
69- std::vector<NodeIDType> nodeIDs; // Nodes in this subgraph
70- std::vector<size_t > dependsOn; // Subgraph indices this depends on
71- std::vector<size_t > dependents; // Subgraph indices that depend on this
72- int topologicalLevel = 0 ; // Topological level for scheduling
56+ std::vector<NodeIDType> nodeIDs;
57+ std::vector<size_t > dependsOn;
58+ std::vector<size_t > dependents;
59+ int topologicalLevel = 0 ;
7360
7461 void clear ()
7562 {
@@ -80,9 +67,6 @@ class DagPartitioner
8067 }
8168 };
8269
83- /* *
84- * @brief Simple thread pool for parallel endpoint tracing.
85- */
8670 class ThreadPool
8771 {
8872 public:
@@ -179,31 +163,11 @@ class DagPartitioner
179163 {
180164 }
181165
182- /* *
183- * @brief Set parallelization threshold.
184- * @param threshold Minimum number of nodes to enable parallel processing (0 = always parallel)
185- */
186166 void setParallelThreshold (size_t threshold)
187167 {
188168 parallelThreshold = threshold;
189169 }
190170
191- /* *
192- * @brief Extract subgraphs from a node graph.
193- *
194- * Uses rules to determine boundaries automatically:
195- * - Rule 5: Node with 0 outputs = output boundary (endpoint)
196- * - Rule 6: Node with 0 inputs = input boundary
197- * - Rule 7: Node with >1 outputs = split point (subgraph endpoint)
198- * - Rule 8: Node with >1 inputs = join point (new subgraph starts)
199- *
200- * Traces from endpoints backwards, creating subgraphs as linear chains.
201- * Each endpoint is traced in parallel as a separate task.
202- *
203- * @param nodes Map of node ID to Node (with connectivity)
204- * @param excludeNodeIDs Optional vector of node IDs to exclude from subgraphs (e.g., I/O nodes)
205- * @return Vector of extracted subgraphs
206- */
207171 std::vector<Subgraph>
208172 extractSubgraphs (const std::map<NodeIDType, Node>& nodes, const std::vector<NodeIDType>& excludeNodeIDs = {})
209173 {
@@ -278,19 +242,6 @@ class DagPartitioner
278242 return subgraphs;
279243 }
280244
281- /* *
282- * @brief Build subgraph dependencies and assign topological levels using ASAP scheduling
283- * with worker-aware load balancing.
284- *
285- * Uses As-Soon-As-Possible (ASAP) scheduling with load balancing:
286- * - Each subgraph is assigned to the earliest possible level (after all dependencies)
287- * - If a level exceeds numWorkers capacity, excess subgraphs with slack are pushed to later levels
288- * - A subgraph has "slack" if its earliest dependent is more than 1 level away
289- *
290- * @param subgraphs Vector of subgraphs (modified in-place)
291- * @param nodes Original node graph
292- * @param numWorkers Number of worker threads (0 or negative = no load balancing)
293- */
294245 void buildSubgraphDependencies (
295246 std::vector<Subgraph>& subgraphs,
296247 const std::map<NodeIDType, Node>& nodes,
0 commit comments