ORB5X 1.0.0
Performance-portable global electromagnetic gyrokinetic PIC code
orb5x::SortingClass Class Reference

Build and apply spatial permutations for marker-data locality. More...

#include "sorting.hpp"

Public Member Functions

void apply_integer8 (const Kokkos::View< int64_t ** > &markers, Kokkos::View< int64_t ** > &sorted_markers, int np, int start_att, int end_att, bool nl_revert)
 Sort or restore signed 64-bit attributes out of place.
 
void apply_integer8_inplace (Kokkos::View< int64_t ** > &markers, int np, int start_att, int end_att, bool nl_revert)
 Sort or restore signed 64-bit attributes in place.
 
void apply_logical (const Kokkos::View< bool ** > &markers, Kokkos::View< bool ** > &sorted_markers, int np, int start_att, int end_att, bool nl_revert)
 Sort or restore logical attributes out of place.
 
void apply_logical_inplace (Kokkos::View< bool ** > &markers, int np, int start_att, int end_att, bool nl_revert)
 Sort or restore logical attributes in place.
 
void apply_real (const Kokkos::View< Real ** > &markers, Kokkos::View< Real ** > &sorted_markers, int np, int start_att, int end_att, bool nl_revert)
 Sort or restore double-precision attributes out of place.
 
void apply_real4 (const Kokkos::View< float ** > &markers, Kokkos::View< float ** > &sorted_markers, int np, int start_att, int end_att, bool nl_revert)
 Sort or restore single-precision attributes out of place.
 
void apply_real4_inplace (Kokkos::View< float ** > &markers, int np, int start_att, int end_att, bool nl_revert)
 Sort or restore single-precision attributes in place.
 
void apply_real_inplace (Kokkos::View< Real ** > &markers, int np, int start_att, int end_att, bool nl_revert)
 Sort or restore double-precision attributes in place.
 
void build_permutation (int np, const Kokkos::View< Real * > &x, const Kokkos::View< Real * > &y=Kokkos::View< Real * >(), const Kokkos::View< Real * > &z=Kokkos::View< Real * >())
 Bin active markers and build forward and inverse permutations.
 
const Kokkos::View< int ** > & get_displs () const
 Access bin/partition starting offsets.
 
const Kokkos::View< int * > & get_inv_permut () const
 Access the sorted-to-original permutation.
 
int get_nbins () const
 Return the number of regular spatial bins.
 
const Kokkos::View< int * > & get_permut () const
 Access the original-to-sorted permutation.
 
void init_device ()
 Device-neutral alias of init_gpu().
 
void init_gpu ()
 Compatibility hook for the former explicit accelerator allocation.
 
 SortingClass (int npalloc, bool nl_inplace, int ndim, Real xmin, Real xmax, int nx, Real ymin=0.0, Real ymax=0.0, int ny=1, Real zmin=0.0, Real zmax=0.0, int nz=1)
 Allocate a fixed-capacity regular-grid sorter.
 
 ~SortingClass ()=default
 Release Kokkos Views through normal reference-counted destruction.
 

Detailed Description

Build and apply spatial permutations for marker-data locality.

The class bins up to npalloc markers in one, two, or three coordinates and constructs mutually inverse mappings between the original order and a bin-contiguous order. The same mapping can then be applied to every typed particle-attribute array, preserving alignment across the complete marker record. Values outside the configured box are grouped in one overflow bin after all regular bins.

Coordinates and bounds use the units of the selected particle variables; the sorter itself performs no normalization. Kernels execute in the active Kokkos execution space and do not communicate between MPI ranks.

Constructor & Destructor Documentation

◆ SortingClass()

orb5x::SortingClass::SortingClass ( int  npalloc,
bool  nl_inplace,
int  ndim,
Real  xmin,
Real  xmax,
int  nx,
Real  ymin = 0.0,
Real  ymax = 0.0,
int  ny = 1,
Real  zmin = 0.0,
Real  zmax = 0.0,
int  nz = 1 
)

Allocate a fixed-capacity regular-grid sorter.

Parameters
[in]npallocMaximum active marker count.
[in]nl_inplaceAllocate work arrays needed by apply_*_inplace.
[in]ndimNumber of coordinates, from 1 through 3.
[in]xminLower bound of coordinate 1 (inclusive).
[in]xmaxUpper bound of coordinate 1 (exclusive).
[in]nxNumber of bins in coordinate 1.
[in]yminLower bound of coordinate 2 when ndim >= 2.
[in]ymaxUpper bound of coordinate 2 when ndim >= 2.
[in]nyNumber of bins in coordinate 2.
[in]zminLower bound of coordinate 3 when ndim == 3.
[in]zmaxUpper bound of coordinate 3 when ndim == 3.
[in]nzNumber of bins in coordinate 3.
Exceptions
std::runtime_errorFor an unsupported dimension, non-positive bin count, or non-increasing bound pair in an active coordinate.

◆ ~SortingClass()

orb5x::SortingClass::~SortingClass ( )
default

Release Kokkos Views through normal reference-counted destruction.

Member Function Documentation

◆ apply_integer8()

void orb5x::SortingClass::apply_integer8 ( const Kokkos::View< int64_t ** > &  markers,
Kokkos::View< int64_t ** > &  sorted_markers,
int  np,
int  start_att,
int  end_att,
bool  nl_revert 
)

Sort or restore signed 64-bit attributes out of place.

Parameters
[in,out]markersOriginal source or restored destination.
[in,out]sorted_markersSorted destination or revert source.
[in]npNumber of markers.
[in]start_attFirst inclusive attribute column.
[in]end_attLast inclusive attribute column.
[in]nl_revertSelect restoration when true.

◆ apply_integer8_inplace()

void orb5x::SortingClass::apply_integer8_inplace ( Kokkos::View< int64_t ** > &  markers,
int  np,
int  start_att,
int  end_att,
bool  nl_revert 
)

Sort or restore signed 64-bit attributes in place.

Parameters
[in,out]markersArray to permute.
[in]npNumber of markers.
[in]start_attFirst inclusive attribute column.
[in]end_attLast inclusive attribute column.
[in]nl_revertSelect restoration when true.

◆ apply_logical()

void orb5x::SortingClass::apply_logical ( const Kokkos::View< bool ** > &  markers,
Kokkos::View< bool ** > &  sorted_markers,
int  np,
int  start_att,
int  end_att,
bool  nl_revert 
)

Sort or restore logical attributes out of place.

Parameters
[in,out]markersOriginal source or restored destination.
[in,out]sorted_markersSorted destination or revert source.
[in]npNumber of markers.
[in]start_attFirst inclusive attribute column.
[in]end_attLast inclusive attribute column.
[in]nl_revertSelect restoration when true.

◆ apply_logical_inplace()

void orb5x::SortingClass::apply_logical_inplace ( Kokkos::View< bool ** > &  markers,
int  np,
int  start_att,
int  end_att,
bool  nl_revert 
)

Sort or restore logical attributes in place.

Parameters
[in,out]markersArray to permute.
[in]npNumber of markers.
[in]start_attFirst inclusive attribute column.
[in]end_attLast inclusive attribute column.
[in]nl_revertSelect restoration when true.

◆ apply_real()

void orb5x::SortingClass::apply_real ( const Kokkos::View< Real ** > &  markers,
Kokkos::View< Real ** > &  sorted_markers,
int  np,
int  start_att,
int  end_att,
bool  nl_revert 
)

Sort or restore double-precision attributes out of place.

Parameters
[in,out]markersOriginal-order source when sorting; restored output when nl_revert is true.
[in,out]sorted_markersSorted output when sorting; source when reverting.
[in]npNumber of leading markers to transform.
[in]start_attFirst attribute column, inclusive and zero-based.
[in]end_attLast attribute column, inclusive.
[in]nl_revertFalse for original-to-sorted; true for sorted-to-original.

◆ apply_real4()

void orb5x::SortingClass::apply_real4 ( const Kokkos::View< float ** > &  markers,
Kokkos::View< float ** > &  sorted_markers,
int  np,
int  start_att,
int  end_att,
bool  nl_revert 
)

Sort or restore single-precision attributes out of place.

Parameters
[in,out]markersOriginal source or restored destination.
[in,out]sorted_markersSorted destination or revert source.
[in]npNumber of markers.
[in]start_attFirst inclusive attribute column.
[in]end_attLast inclusive attribute column.
[in]nl_revertSelect restoration when true.

◆ apply_real4_inplace()

void orb5x::SortingClass::apply_real4_inplace ( Kokkos::View< float ** > &  markers,
int  np,
int  start_att,
int  end_att,
bool  nl_revert 
)

Sort or restore single-precision attributes in place.

Parameters
[in,out]markersArray to permute.
[in]npNumber of markers.
[in]start_attFirst inclusive attribute column.
[in]end_attLast inclusive attribute column.
[in]nl_revertSelect restoration when true.

◆ apply_real_inplace()

void orb5x::SortingClass::apply_real_inplace ( Kokkos::View< Real ** > &  markers,
int  np,
int  start_att,
int  end_att,
bool  nl_revert 
)

Sort or restore double-precision attributes in place.

Parameters
[in,out]markersMarker-major attribute array to permute.
[in]npNumber of leading markers to transform.
[in]start_attFirst inclusive zero-based attribute column.
[in]end_attLast inclusive attribute column.
[in]nl_revertFalse to sort; true to restore original order.
Exceptions
std::runtime_errorIf capacity is exceeded or in-place work storage was not requested at construction.

◆ build_permutation()

void orb5x::SortingClass::build_permutation ( int  np,
const Kokkos::View< Real * > &  x,
const Kokkos::View< Real * > &  y = Kokkos::View< Real * >(),
const Kokkos::View< Real * > &  z = Kokkos::View< Real * >() 
)

Bin active markers and build forward and inverse permutations.

Parameters
[in]npNumber of leading markers to include, at most npalloc.
[in]xFirst coordinate, with at least np elements.
[in]ySecond coordinate when configured for two or three dimensions.
[in]zThird coordinate when configured for three dimensions.
Exceptions
std::runtime_errorIf np exceeds capacity or a required coordinate view is absent.

After completion permut[old] gives the sorted index and inv_permut[sorted] gives the original index.

◆ get_displs()

const Kokkos::View< int ** > & orb5x::SortingClass::get_displs ( ) const
inline

Access bin/partition starting offsets.

Returns
Displacements [regular-or-overflow bin][logical partition].

◆ get_inv_permut()

const Kokkos::View< int * > & orb5x::SortingClass::get_inv_permut ( ) const
inline

Access the sorted-to-original permutation.

Returns
View where inv_permut(sorted_index) is the original index.

◆ get_nbins()

int orb5x::SortingClass::get_nbins ( ) const
inline

Return the number of regular spatial bins.

Returns
nx*ny*nz, excluding the additional out-of-bounds bin.

◆ get_permut()

const Kokkos::View< int * > & orb5x::SortingClass::get_permut ( ) const
inline

Access the original-to-sorted permutation.

Returns
View where permut(old_index) is the sorted index.

◆ init_device()

void orb5x::SortingClass::init_device ( )

Device-neutral alias of init_gpu().

◆ init_gpu()

void orb5x::SortingClass::init_gpu ( )

Compatibility hook for the former explicit accelerator allocation.

Note
Construction already allocates all Kokkos Views, so this is a no-op.

The documentation for this class was generated from the following file: