Add GraphProperties and property caching
This commit is contained in:
@@ -58,12 +58,12 @@ function show(io::IO, graph::DAG)
|
||||
end
|
||||
println(io)
|
||||
println(io, " Edges: ", noEdges)
|
||||
properties = graph_properties(graph)
|
||||
println(io, " Total Compute Effort: ", properties.compute_effort)
|
||||
properties = get_properties(graph)
|
||||
println(io, " Total Compute Effort: ", properties.computeEffort)
|
||||
println(io, " Total Data Transfer: ", properties.data)
|
||||
return println(
|
||||
io,
|
||||
" Total Compute Intensity: ",
|
||||
properties.compute_intensity,
|
||||
properties.computeIntensity,
|
||||
)
|
||||
end
|
||||
|
@@ -1,31 +1,17 @@
|
||||
"""
|
||||
graph_properties(graph::DAG)
|
||||
get_properties(graph::DAG)
|
||||
|
||||
Return the graph's properties, a named tuple with fields `.data`, `.compute_effort`, `.compute_intensity`, `.nodes` (number of nodes) and `.edges` (number of edges).
|
||||
Return the graph's [`GraphProperties`](@ref).
|
||||
"""
|
||||
function graph_properties(graph::DAG)
|
||||
function get_properties(graph::DAG)
|
||||
# make sure the graph is fully generated
|
||||
apply_all!(graph)
|
||||
|
||||
d = 0
|
||||
ce = 0
|
||||
ed = 0
|
||||
for node in graph.nodes
|
||||
d += data(node.task) * length(node.parents)
|
||||
ce += compute_effort(node.task)
|
||||
ed += length(node.parents)
|
||||
if (graph.properties.computeEffort == 0.0)
|
||||
graph.properties = GraphProperties(graph)
|
||||
end
|
||||
|
||||
ci = ce / d
|
||||
|
||||
result = (
|
||||
data = d,
|
||||
compute_effort = ce,
|
||||
compute_intensity = ci,
|
||||
nodes = length(graph.nodes),
|
||||
edges = ed,
|
||||
)
|
||||
return result
|
||||
return graph.properties
|
||||
end
|
||||
|
||||
"""
|
||||
|
@@ -41,6 +41,9 @@ mutable struct DAG
|
||||
# "snapshot" system: keep track of added/removed nodes/edges since last snapshot
|
||||
# these are muted in insert_node! etc.
|
||||
diff::Diff
|
||||
|
||||
# the cached properties of the DAG
|
||||
properties::GraphProperties
|
||||
end
|
||||
|
||||
"""
|
||||
@@ -69,5 +72,6 @@ function DAG()
|
||||
PossibleOperations(),
|
||||
Set{Node}(),
|
||||
Diff(),
|
||||
GraphProperties(),
|
||||
)
|
||||
end
|
||||
|
Reference in New Issue
Block a user