Say I have the edges
A -> C
A -> D
A -> E
B -> D
B -> E
To maximise data locality I’d arrange for the DAG to be stored in this order in memory (as an array) to minimise the distance between the node and it’s dependencies.
C, A, D, E, B
so that A has a distance 1 to C, 1 to D, 2 to E.
And that B has a distance of 1 to E, and 2 to D.
Is there name for an algorithm that does this? If not, how would one implement this?
Looks like you want to linearize the DAG. I don’t know whether you are using it for dependancy resolution.
Topological_sortinglooks familiar to your question. also the programtsortdoes very similer thing.However it is dependancy linearization.
Which prints the order in which that tasks have to be performed. and it will possible not work if there is a cycle. its relevant as you mentioned its acyclic.
I dont know if there is any such algorithm for
data locality ordering stringor anything similar however It looks like your data locality string have some problem.What if
Cis close(1) toAand is also close(1) toBandBis too far(4) fromAhow will you represent it with your data locality string ?I don’t now what exactly you want to do. If you want to liniarize dependency to perform tasks in proper order then do a topological sort.