Reduce memory usage of sample-level result accumulators - #109
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #109 +/- ##
==========================================
- Coverage 84.14% 83.28% -0.86%
==========================================
Files 45 45
Lines 2491 2537 +46
==========================================
+ Hits 2096 2113 +17
- Misses 395 424 +29 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
f6313c9 to
b4b5ba3
Compare
b113d5e to
8adce48
Compare
|
|
||
| abstract type ResultAccumulator{R<:ResultSpec} end | ||
|
|
||
| issamplebased(::ResultSpec) = false |
There was a problem hiding this comment.
Is it worth it to just do this the other way round, so you don't have to define this for all the non sample ResultSpec s?
| ) where {A<:ResultAccumulator} | ||
|
|
||
| field = fieldnames(A)[1] | ||
| xarr = getfield(x, field) |
There was a problem hiding this comment.
I think this leads to some performance issues. Have you tested this on very high sample results?
There was a problem hiding this comment.
If only grabbing the 1st filed is correct (I don't thnk it is), repalcing with this could work:
`function copy_sample_partition!(
x::A,
y::A,
sampleids::UnitRange{Int},
) where {A<:ResultAccumulator}
# Using a literal integer makes this completely type-stable
xarr = getfield(x, 1)
yarr = getfield(y, 1)
@views xarr[:, :, sampleids] .= yarr
return nothing
end`
This explicitly tells the complier the field and the type of the field you want to grab.
Previously, threaded execution created worker-local sample accumulators sized for the full Monte Carlo sample count. For sample-based result specs like
ShortfallSamplesthis caused memory usage to scale asO(regions x timesteps x samples x threads).This PR changes sample-based result accumulation so each threaded worker's recorder stores only that worker's assigned sample range. The partitions are then combined during finalization to produce the same full sample result.
Example for 3 threaded workers:
Before, each worker accumulator allocated the whole sample matrix:
Now, samples are split into ranges:
Benchmarks
System: Guam 2028, 13 regions, 8760 timestamps, hourly resolution
Simulation: Run on HPC, using
standardnodes (104 cores, 250 GB)Result:
ShortfallSamples()1000 MC Samples
10000 MC Samples