XGCa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Enumerations | Functions
shift.cpp File Reference
#include <Cabana_Core.hpp>
#include <Kokkos_Core.hpp>
#include <algorithm>
#include <iostream>
#include <vector>
#include <mpi.h>
#include "timer_macro.hpp"
#include "domain_decomposition.hpp"
#include "sort.hpp"
#include "send_particles.hpp"
#include "shift.hpp"
Include dependency graph for shift.cpp:

Classes

struct  VecParticlesSimple< T >
 
struct  OneParticle< T >
 

Enumerations

enum  PackAction { Pack = 0, Unpack }
 

Functions

void check_new_n_ptl_below_maxnum (int new_n_ptl, int isp)
 
template<PackAction PA>
KOKKOS_INLINE_FUNCTION void reversible_set (double &x, double &y)
 
template<>
KOKKOS_INLINE_FUNCTION void reversible_set< Pack > (double &x, double &y)
 
template<>
KOKKOS_INLINE_FUNCTION void reversible_set< Unpack > (double &x, double &y)
 
template<PackAction PA>
KOKKOS_INLINE_FUNCTION void set_n_trailing_and_n_filled (int ptl_in_bin, int n_leading, int &n_trailing, int &n_ptl_in_whole_vectors)
 
template<>
KOKKOS_INLINE_FUNCTION void set_n_trailing_and_n_filled< Pack > (int ptl_in_bin, int n_leading, int &n_trailing, int &n_ptl_in_whole_vectors)
 
template<>
KOKKOS_INLINE_FUNCTION void set_n_trailing_and_n_filled< Unpack > (int ptl_in_bin, int n_leading, int &n_trailing, int &n_ptl_in_whole_vectors)
 
template<PackAction PA, int PTL_N_DBL, class DataType >
void pack_buffer (Kokkos::View< int *, DeviceType > &cnt, Kokkos::View< int *, DeviceType > &displs, Cabana::AoSoA< DataType, DeviceType, VEC_LEN > &local_particles, int n_staying, Kokkos::View< OneParticle< PTL_N_DBL > *, DeviceType > &buf)
 
template<class DataType >
void pack_and_shift (Kokkos::View< int *, HostType > &sendcnt, Kokkos::View< int *, HostType > &sdispls, Kokkos::View< int *, HostType > &recvcnt, Kokkos::View< int *, HostType > &rdispls, Cabana::AoSoA< DataType, DeviceType, VEC_LEN > &local_particles, int n_staying, int n_leaving, int n_arriving, const MyMPI &mpi)
 
void shift (const Simulation< DeviceType > &sml, Species< DeviceType > &species, const SortViews< DeviceType > &sort_views, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, const DomainDecomposition< DeviceType > &pol_decomp, TmpSpecies< DeviceType > &tmp_species, int isp, bool send_phase0)
 
void shift_all_species (const Simulation< DeviceType > &sml, Plasma &plasma, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, const DomainDecomposition< DeviceType > &pol_decomp, Shift::ShiftPh0 shift_ph0)
 

Enumeration Type Documentation

enum PackAction
Enumerator
Pack 
Unpack 

Function Documentation

void check_new_n_ptl_below_maxnum ( int  new_n_ptl,
int  isp 
)

Here is the caller graph for this function:

template<class DataType >
void pack_and_shift ( Kokkos::View< int *, HostType > &  sendcnt,
Kokkos::View< int *, HostType > &  sdispls,
Kokkos::View< int *, HostType > &  recvcnt,
Kokkos::View< int *, HostType > &  rdispls,
Cabana::AoSoA< DataType, DeviceType, VEC_LEN > &  local_particles,
int  n_staying,
int  n_leaving,
int  n_arriving,
const MyMPI mpi 
)

Packs particles into buffer and shifts them between MPI ranks. If particles are on the device and GPU-aware MPI is off, send the buffer back to host prior to the MPI call, and send the receive buffer back to device for unpacking. The function is templated on the size of the particle (in doubles) and the particle data type. This is done so that phase0 can be sent with the same routine

Parameters
[in]sendcntis the number of particles getting sent to each rank
[in]sdisplsis the displacement in the send buffer of each rank
[in]recvcntis the number of particles getting received from each rank
[in]rdisplsis the displacement in the recv buffer of each rank
[in,out]local_particlesis where the particles are located on device
[in]n_stayingis the number of particles staying on this rank
[in]n_leavingis the number of particles leaving this rank
[in]n_arrivingis the number of particles arriving to this rank
[in]mpicontains MPI and domain decomposition parameters
Returns
void

Here is the call graph for this function:

template<PackAction PA, int PTL_N_DBL, class DataType >
void pack_buffer ( Kokkos::View< int *, DeviceType > &  cnt,
Kokkos::View< int *, DeviceType > &  displs,
Cabana::AoSoA< DataType, DeviceType, VEC_LEN > &  local_particles,
int  n_staying,
Kokkos::View< OneParticle< PTL_N_DBL > *, DeviceType > &  buf 
)

This function does both packing and unpacking. Packing (and unpacking) is done in a three step process. Although the particles were already sorted by destination rank, the first or final particle vector will likely contain particles going to different ranks. These are labeled "leading" and "trailing" particles and are copied to the buffer in AoS format. The rest are copied directly in AoSoA format (but cast as AoS in this function for convenience). On arrival at the receiving buffer, the particles are unpacked accordingly. Since unpacking and packing are almost identical, the same function is used, with the minor differences placed in functions templated on a PackAction.

Parameters
[in]cntis the number of particles getting sent or received in each rank
[in]displsis the displacement in the buffer of each rank
[in,out]local_particlesis where the particles are located on device
[in]n_stayingis the number of particles staying on this rank
[in,out]bufis the buffer where traveling particles are stored for their MPI journey
Returns
void

Here is the call graph for this function:

template<PackAction PA>
KOKKOS_INLINE_FUNCTION void reversible_set ( double &  x,
double &  y 
)

Reversible_set is a templated function that can either set the first arg to the second (for packing), or vice versa (for unpacking).

Parameters
[in,out]xis a double
[in,out]yis another double
Returns
void
template<>
KOKKOS_INLINE_FUNCTION void reversible_set< Pack > ( double &  x,
double &  y 
)
template<>
KOKKOS_INLINE_FUNCTION void reversible_set< Unpack > ( double &  x,
double &  y 
)
template<PackAction PA>
KOKKOS_INLINE_FUNCTION void set_n_trailing_and_n_filled ( int  ptl_in_bin,
int  n_leading,
int &  n_trailing,
int &  n_ptl_in_whole_vectors 
)

set_n_trailing_and_n_filled is a templated function to set n_trailing and n_ptl_in_whole_vectors in the packing and unpacking cases.

Parameters
[in]ptl_in_binis the number of particles in the bin (the count)
[in]n_leadingis the number of particles in the leading partially filled vector (AoS format)
[out]n_trailingis the number of particles in the trailing partially filled vector (AoS format)
[out]n_ptl_in_whole_vectorsis the number of particles (AoSoA format)
Returns
void
template<>
KOKKOS_INLINE_FUNCTION void set_n_trailing_and_n_filled< Pack > ( int  ptl_in_bin,
int  n_leading,
int &  n_trailing,
int &  n_ptl_in_whole_vectors 
)
template<>
KOKKOS_INLINE_FUNCTION void set_n_trailing_and_n_filled< Unpack > ( int  ptl_in_bin,
int  n_leading,
int &  n_trailing,
int &  n_ptl_in_whole_vectors 
)
void shift ( const Simulation< DeviceType > &  sml,
Species< DeviceType > &  species,
const SortViews< DeviceType > &  sort_views,
const Grid< DeviceType > &  grid,
const MagneticField< DeviceType > &  magnetic_field,
const DomainDecomposition< DeviceType > &  pol_decomp,
TmpSpecies< DeviceType > &  tmp_species,
int  isp,
bool  send_phase0 
)

Shifts particles between MPI ranks. First the particles are sorted by destination rank The particles are packed into a buffer and sent with an MPI all-to-all Then they are unpacked from the receiving buffer back into the particle AoSoA The same is done for phase0, needed for ions

Parameters
[in]smlis needed for the sort
[in]speciesis needed for the sort
[in]sort_viewsis needed for the sort
[in]gridis needed for the sort
[in]magnetic_fieldis needed for the sort
[in]pol_decompis needed for the sort and shift
[in,out]tmp_speciesis where the particles are located on device
[in]ispis the species index
Returns
void

Here is the call graph for this function:

Here is the caller graph for this function:

void shift_all_species ( const Simulation< DeviceType > &  sml,
Plasma plasma,
const Grid< DeviceType > &  grid,
const MagneticField< DeviceType > &  magnetic_field,
const DomainDecomposition< DeviceType > &  pol_decomp,
Shift::ShiftPh0  shift_ph0 
)

Shifts particles between MPI ranks. First the particles are sorted by destination rank The particles are packed into a buffer and sent with an MPI all-to-all Then they are unpacked from the receiving buffer back into the particle AoSoA The same is done for phase0, needed for ions

Parameters
[in]smlis needed for the sort
[in]plasmacontains all species info
[in]gridis needed for the sort
[in]magnetic_fieldis needed for the sort
[in]pol_decompis needed for the sort
[in,out]tmp_speciesis where the particles are located on device
Returns
void

Here is the call graph for this function:

Here is the caller graph for this function: