We study parallel DAG traversal — visiting every vertex of a directed acyclic graph in dependency order, processing each vertex as soon as all of its predecessors have finished. Graph traversal is a fundamental building block of large-scale graph analytics, build systems, circuit simulation, and workflow engines.
Given a directed acyclic graph (DAG), we want to visit each vertex exactly once, respecting the partial order defined by the edges. The following figure shows the six-vertex, seven-edge DAG used as a running example:
The graph has a single source (Task1) and a single sink (Task6). When Task1 completes, Task2, Task3, and Task4 can all run simultaneously — giving a maximum parallelism of three at that point. The challenge is to exploit this available parallelism automatically, without writing explicit thread management or synchronisation code.
We represent the graph as an array of Node structures. Each node stores its index, a visited flag, an atomic in-degree counter (dependents), and a list of outgoing edge pointers (successors):
We generate random DAGs with ordered edges, which guarantees acyclicity since all edges point from lower- to higher-indexed nodes:
We build a Taskflow that mirrors the graph structure exactly: one task per node, with task dependencies mirroring graph edges. Each task marks its node visited, decrements the dependents counter of each successor, and completes. In practice, the task body would contain the actual computation for that node — the visited and dependents updates are used here only to verify correctness after traversal.
The implementation has two clearly separated phases. First, it creates a traversal task for each node. Second, it wires task dependencies to exactly mirror the graph edges. The resulting taskflow is topologically equivalent to the input DAG. The executor distributes tasks across all available cores, respecting all dependencies and maximising parallelism wherever the graph structure allows it. No manual thread management, mutexes, or barrier synchronisation is required.