Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save johnwcowan/ef01ad6e375171e0d0a9c8f842f0c340 to your computer and use it in GitHub Desktop.

Select an option

Save johnwcowan/ef01ad6e375171e0d0a9c8f842f0c340 to your computer and use it in GitHub Desktop.
Dag-walking algorithm question
I have a dependency dag where each node is associated with an action.
I need to walk from the root to a chosen node,
executing all the actions (and only the actions)
required by the graph.
If it was a tree, I'd just walk up the tree, collect the actions,
and execute them in reverse order, but having multiple dependencies
at a node is a requirement of the problem.
It's easy to find the nodes to be executed,
but figuring out in which order to execute them baffles me.
@johnwcowan

Copy link
Copy Markdown
Author

The consensus is that determining the ancestors of the distinguished node is straightforward, and then a topological sort will ensure that they are executed in some correct order. Now I need to extend the description to fully solve the problem:

The actions are in fact filters (transformers) used to process a stream of data. It would be useful for performance (not correctness) to know which filters can be executed concurrently, as by a Unix pipeline, and which cannot. Again, in the tree (single dependency) case, the answer is easy: all of them. It will also be correct to run none of them concurrently. But how can I recover what concurrency is in fact possible?

@mcgoron-peter

Copy link
Copy Markdown

I'm a little confused by concurrently. Do you mean that given the DAG

  A -> B -> C
 /           \
R            Z
 \           /
  D -> E -> F

to determine if the A -> B -> C and D -> E -> F as sequences can be executed concurrently, or that A can feed into B can feed into C like a UNIX pipe?

@johnwcowan

Copy link
Copy Markdown
Author

The latter.

@mcgoron-peter

Copy link
Copy Markdown

Here's an example where my pipeline compression wouldn't work (all arrows point to the right):

  A
 / \
R - B

I don't know if this type of relation would happen in this domain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment