Skip to content

Commit 0eec6a0

Browse files
committed
Only allocate one matching vector in tearing
Before: ```julia julia> @time sysRed, = structural_simplify(sysEx, (inputs=(), outputs=())); 10.891029 seconds (31.88 M allocations: 7.849 GiB, 18.15% gc time) ``` After: ``` julia> @time sysRed, = structural_simplify(sysEx, (inputs=(), outputs=())); 7.814676 seconds (31.85 M allocations: 4.889 GiB, 13.28% gc time) ```
1 parent e15c650 commit 0eec6a0

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/structural_transformation/bipartite_tearing/modia_tearing.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ function tearEquations!(ict::IncrementalCycleTracker, Gsolvable, es::Vector{Int}
4848
return ict
4949
end
5050

51-
function tear_graph_block_modia!(var_eq_matching, graph, solvable_graph, eqs, vars,
51+
function tear_graph_block_modia!(var_eq_matching, vargraph, solvable_graph, eqs, vars,
5252
isder::F) where {F}
53-
ict = IncrementalCycleTracker(DiCMOBiGraph{true}(graph); dir = :in)
53+
ict = IncrementalCycleTracker(vargraph; dir = :in)
5454
tearEquations!(ict, solvable_graph.fadjlist, eqs, vars, isder)
5555
for var in vars
5656
var_eq_matching[var] = ict.graph.matching[var]
@@ -76,6 +76,7 @@ function tear_graph_modia(structure::SystemStructure, isder::F = nothing,
7676
@unpack graph, solvable_graph = structure
7777
var_eq_matching = complete(maximal_matching(graph, eqfilter, varfilter, U))
7878
var_sccs::Vector{Union{Vector{Int}, Int}} = find_var_sccs(graph, var_eq_matching)
79+
vargraph = DiCMOBiGraph{true}(graph)
7980

8081
ieqs = Int[]
8182
filtered_vars = BitSet()
@@ -89,8 +90,15 @@ function tear_graph_modia(structure::SystemStructure, isder::F = nothing,
8990
end
9091
var_eq_matching[var] = unassigned
9192
end
92-
tear_graph_block_modia!(var_eq_matching, graph, solvable_graph, ieqs, filtered_vars,
93+
tear_graph_block_modia!(var_eq_matching, vargraph, solvable_graph, ieqs,
94+
filtered_vars,
9395
isder)
96+
97+
# clear cache
98+
vargraph.ne = 0
99+
for var in vars
100+
vargraph.matching[var] = unassigned
101+
end
94102
empty!(ieqs)
95103
empty!(filtered_vars)
96104
end

0 commit comments

Comments
 (0)