Parallelize sampling external sources and threadsafe rejection counters (#3830)

Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
Ethan Peterson 2026-03-04 15:36:43 -05:00 committed by GitHub
parent 0ab46dfa35
commit 2bd06660c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 114 additions and 37 deletions

View file

@ -4,6 +4,7 @@
#ifndef OPENMC_SOURCE_H
#define OPENMC_SOURCE_H
#include <atomic>
#include <limits>
#include <unordered_set>
@ -25,10 +26,18 @@ namespace openmc {
// source_rejection_fraction
constexpr int EXTSRC_REJECT_THRESHOLD {10000};
// Maximum number of source rejections allowed while sampling a single site
constexpr int64_t MAX_SOURCE_REJECTIONS_PER_SAMPLE {1'000'000};
//==============================================================================
// Global variables
//==============================================================================
// Cumulative counters for source rejection diagnostics. These are atomic to
// allow thread-safe concurrent sampling of external sources.
extern std::atomic<int64_t> source_n_accept;
extern std::atomic<int64_t> source_n_reject;
class Source;
namespace model {
@ -265,6 +274,9 @@ SourceSite sample_external_source(uint64_t* seed);
void free_memory_source();
//! Reset cumulative source rejection counters
void reset_source_rejection_counters();
} // namespace openmc
#endif // OPENMC_SOURCE_H