15#include <Kokkos_DualView.hpp>
35 template <
typename BunchType,
typename BinningSelector>
44 using bin_type =
typename ippl::ParticleAttrib<bin_index_type>;
46 using hash_type = ippl::detail::hash_type<Kokkos::DefaultExecutionSpace::memory_space>;
88 Inform msg(
"AdaptBins");
89 msg <<
"AdaptBins initialized with maxBins = " <<
maxBins_m
172 KOKKOS_INLINE_FUNCTION
268 template<
typename ReducerType>
417 Inform msg(
"KOKKOS DEBUG");
419 int rank = ippl::Comm->rank();
420 msg <<
"=====================================" << endl;
421 msg <<
" Kokkos Debug Information (Rank " << rank <<
")" << endl;
422 msg <<
"=====================================" << endl;
425 #ifdef KOKKOS_ENABLE_OPENMP
426 int num_threads = Kokkos::OpenMP::concurrency();
427 msg <<
"CPU Threads (OpenMP): " << num_threads << endl;
428 #elif defined(KOKKOS_ENABLE_THREADS)
429 int num_threads = Kokkos::Threads::concurrency();
430 msg <<
"CPU Threads (Kokkos::Threads): " << num_threads << endl;
432 msg <<
"CPU Threads: No multi-threaded CPU execution space enabled." << endl;
436 #ifdef KOKKOS_ENABLE_CUDA
437 int num_gpus = Kokkos::Cuda::detect_device_count();
438 msg <<
"CUDA Enabled: Rank " << rank <<
" sees " << num_gpus <<
" GPU(s) available." << endl;
439 Kokkos::Cuda cuda_instance;
440 std::stringstream ss;
441 cuda_instance.print_configuration(ss);
444 msg <<
"CUDA: GPU support disabled.\n";
448 int default_concurrency = Kokkos::DefaultExecutionSpace::concurrency();
449 msg <<
"Default Execution Space Concurrency: " << default_concurrency << endl;
452 msg <<
"=====================================" << endl;
483 template <
typename T,
unsigned Dim>
ippl::Field< ippl::Vector< T, Dim >, Dim, ViewArgs... > VField_t
IpplTimings::TimerRef bInitLimitsT
void assignBinsToParticles()
Assigns each particle in the bunch to a bin based on its position.
IpplTimings::TimerRef bVerifySortingT
typename d_histo_type::hview_type hview_type
AdaptBins(std::shared_ptr< BunchType > bunch, BinningSelector var_selector, bin_index_type maxBins, value_type binningAlpha, value_type binningBeta, value_type desiredWidth)
Constructs an AdaptBins object with a specified maximum number of bins and a selector.
typename d_histo_type::hindex_transform_type hindex_transform_type
typename BunchType::bin_index_type bin_index_type
Histogram< size_type, bin_index_type, value_type, true > d_histo_type
typename particle_position_type::view_type position_view_type
Histogram< size_type, bin_index_type, value_type, false, Kokkos::HostSpace > h_histo_type_g
size_type getNPartInBin(bin_index_type binIndex, bool global=false)
Retrieves the number of particles in a specified bin.
std::shared_ptr< BunchType > bunch_m
Shared pointer to the particle container.
void initGlobalHistogram()
Retrieves the global histogram across all processes.
value_type binningAlpha_m
Alpha parameter for binning cost function.
value_type binningBeta_m
Beta parameter for binning cost function.
typename h_histo_type_g::hview_type hview_type_g
value_type desiredWidth_m
Desired bin width for binning cost function.
VField_t< T, Dim > & LTrans(VField_t< T, Dim > &field, const bin_index_type ¤tBin)
Applies a Lorentz transformation to a given vector field based on particle velocities.
void initLocalHisto(HistoReductionMode modePreference=HistoReductionMode::Standard)
Initializes a local histogram for particle binning.
void initTimers()
Initializes timers for various operations in the binning process.
bin_index_type getCurrentBinCount() const
Returns the current number of bins.
value_type getBinWidth() const
Returns the average binwidth.
Kokkos::RangePolicy getBinIterationPolicy(const bin_index_type &binIndex)
Returns the bin iteration policy for a given bin index.
value_type binWidth_m
Width of each bin (assumes a uniform histogram).
ippl::detail::hash_type< Kokkos::DefaultExecutionSpace::memory_space > hash_type
IpplTimings::TimerRef bAllReduceLimitsT
void initHistogram(HistoReductionMode modePreference=HistoReductionMode::Standard)
Initializes the local/global histogram based on the Bin attribute.
hash_type getHashArray()
Returns the index map that sorts the particle container by bin number.
void instantiateHistogram(bool setToZero=false)
Initializes the histogram view for binning and optionally sets it to zero.
static KOKKOS_INLINE_FUNCTION bin_index_type getBin(value_type x, value_type xMin, value_type xMax, value_type binWidthInv, bin_index_type numBins)
Calculates the bin index for a given position value in a uniform histogram.
void debug()
Outputs debug information related to Kokkos and MPI configurations.
typename BunchType::particle_position_type particle_position_type
value_type xMax_m
Maximum value of bin attribute.
void print()
Prints the current global histogram to the Inform output stream.
typename ippl::ParticleAttrib< bin_index_type > bin_type
void initLimits()
Initializes the limits for binning based on the particle data.
typename h_histo_type_g::hindex_transform_type hindex_transform_type_g
void setCurrentBinCount(bin_index_type nBins)
Sets the current number of bins and adjusts the bin width.
h_histo_type_g globalBinHisto_m
Global histogram view (over ranks reduced local histograms).
d_histo_type localBinHisto_m
Local histogram view for bin counts.
BinningSelector var_selector_m
Variable selector for binning.
hash_type sortedIndexArr_m
Particle index map that sorts the bunch by bin index.
typename bin_type::view_type bin_view_type
void executeInitLocalHistoReduction(ReducerType &to_reduce)
Executes a parallel reduction to initialize the local histogram for particle bins.
bin_index_type getMaxBinCount() const
Gets the maximum number of bins. Will be used for the fine uniform histogram before merging.
void executeInitLocalHistoReductionTeamFor()
Initializes and performs a team-based histogram reduction for particle bins.
typename BinningSelector::value_type value_type
void genAdaptiveHistogram()
Generates an adaptive histogram based on a fine global histogram.
IpplTimings::TimerRef bSortContainerByBinT
bin_index_type currentBins_m
Current number of bins in use.
typename d_histo_type::dview_type dview_type
IpplTimings::TimerRef bAssignUniformBinsT
value_type xMin_m
Minimum value of bin attribute.
typename d_histo_type::dindex_transform_type dindex_transform_type
typename BunchType::size_type size_type
IpplTimings::TimerRef bAllReduceGlobalHistoT
typename d_histo_type::dwidth_view_type dwidth_view_type
bin_view_type getBinView()
Returns a view to the particle bin array.
void doFullRebin(bin_index_type nBins, bool recalculateLimits=true, HistoReductionMode modePreference=HistoReductionMode::Standard)
Performs a full rebinning operation on the bunch.
void sortContainerByBin()
Sorts the container of particles by their bin indices.
const bin_index_type maxBins_m
Maximum number of bins.
IpplTimings::TimerRef bExecuteHistoReductionT
Template class providing adaptive particle histogram binning with support for Kokkos Views and DualVi...
typename DeviceViewTraits< UseDualView, view_type >::h_type hview_type
typename DeviceViewTraits< UseDualView, view_type >::d_type dview_type
index_transform_type< Kokkos::DefaultExecutionSpace > dindex_transform_type
index_transform_type< Kokkos::HostSpace > hindex_transform_type
typename DeviceViewTraits< UseDualView, width_view_type >::d_type dwidth_view_type