Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Averaging slight adjustement for ensured thread safety #810

Merged

Conversation

nbollis
Copy link
Member

@nbollis nbollis commented Nov 26, 2024

In theory, the previous code was thread safe. However, additional steps were taken to ensure thread safety.

  • Import System.Collections.Concurrent for concurrent collections.
  • Change averagedPeaks from List to ConcurrentBag for thread safety.
  • Move binIncidences array creation outside parallel loop to avoid redundancy.
  • Modify Parallel.ForEach loop to use array length instead of list count.
  • Remove lock around averagedPeaks.Add as ConcurrentBag is thread-safe.
  • Reduced test project folders by moving the averaging test data into the averaging test folder

Benchmarked on a single top-down file
Old Time: 255s
New Time: 197 s

- Import `System.Collections.Concurrent` for concurrent collections.
- Change `averagedPeaks` from `List` to `ConcurrentBag` for thread safety.
- Move `binIncidences` array creation outside parallel loop to avoid redundancy.
- Modify `Parallel.ForEach` loop to use array length instead of list count.
- Remove `lock` around `averagedPeaks.Add` as `ConcurrentBag` is thread-safe.
@nbollis nbollis added the Maintenance The user isn't impacted by it, it's purely behind the scenes label Nov 26, 2024
Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.21%. Comparing base (6411360) to head (3bfed73).
Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #810      +/-   ##
==========================================
- Coverage   77.21%   77.21%   -0.01%     
==========================================
  Files         218      218              
  Lines       32966    32964       -2     
  Branches     3413     3413              
==========================================
- Hits        25455    25453       -2     
  Misses       6944     6944              
  Partials      567      567              
Files with missing lines Coverage Δ
...b/SpectralAveraging/Algorithms/SpectraAveraging.cs 98.59% <100.00%> (-0.04%) ⬇️
...ctralAveraging/Util/SpectralAveragingParameters.cs 100.00% <100.00%> (ø)

@nbollis nbollis marked this pull request as ready for review November 26, 2024 22:44
trishorts
trishorts previously approved these changes Dec 2, 2024
RayMSMS
RayMSMS previously approved these changes Dec 3, 2024
@nbollis nbollis dismissed stale reviews from RayMSMS and trishorts via a283aee December 4, 2024 05:03
@trishorts trishorts merged commit fed869f into smith-chem-wisc:master Dec 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Maintenance The user isn't impacted by it, it's purely behind the scenes ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants