Skip to content

Commit

Permalink
Merge pull request #1027 from NREL-Sienna/rhjddt/fix_cache_long_concat
Browse files Browse the repository at this point in the history
Replace cat with preallocated array to fix stackoverflow issue
  • Loading branch information
jd-lara authored Dec 13, 2023
2 parents 3f6e556 + b11bfd9 commit 6e1e15e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/simulation/optimization_output_cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,22 @@ function get_dirty_data_to_flush!(cache::OptimizationOutputCache)
empty!(cache.dirty_timestamps)
# Uncomment for performance testing of CacheFlush
#TimerOutputs.@timeit RUN_SIMULATION_TIMER "Concatenate arrays for flush" begin
arrays = (cache.data[x] for x in timestamps)
arrays = cat(arrays...; dims = ndims(first(arrays)) + 1)
#end
temp = cache.data[first(timestamps)]
sd = collect(size(temp))
push!(sd, length(timestamps))
arrays = Array{Float64}(undef, sd...)
for (ix, x) in enumerate(timestamps)
temp_data = cache.data[x]
if ndims(temp_data) == 1
arrays[:, ix] = temp_data
elseif ndims(temp_data) == 2
arrays[:, :, ix] = temp_data
elseif ndims(temp_data) == 3
arrays[:, :, :, ix] = temp_data
else
error("Arrays of dimensions $(ndims(temp_data)) are not supported")
end
end

return timestamps, arrays
end
Expand Down

0 comments on commit 6e1e15e

Please sign in to comment.