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 "my_mpi.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 set_spall_num (FortranPtr spall_fptr, int isp, int n_electrons)
 
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, MyMPI &my_mpi)
 
void shift (FortranPtr spall_fptr, const Simulation< DeviceType > &sml, const Species< DeviceType > &species, const GeneratePermutation< DeviceType > &pid_gen_perm, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, const DomainDecomposition< DeviceType > &pol_decomp, TmpSpecies< DeviceType > &tmp_species, int isp)
 
void shift_all_species (FortranPtr spall_fptr, const Simulation< DeviceType > &sml, const std::vector< Species< DeviceType >> &all_species, const GeneratePermutation< DeviceType > &pid_gen_perm, const Grid< DeviceType > &grid, const MagneticField< DeviceType > &magnetic_field, const DomainDecomposition< DeviceType > &pol_decomp, TmpSpecies< DeviceType > &tmp_species)
 

Enumeration Type Documentation

enum PackAction
Enumerator
Pack 
Unpack 

Function Documentation

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,
MyMPI my_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]my_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 set_spall_num ( FortranPtr  spall_fptr,
int  isp,
int  n_electrons 
)
void shift ( FortranPtr  spall_fptr,
const Simulation< DeviceType > &  sml,
const Species< DeviceType > &  species,
const GeneratePermutation< DeviceType > &  pid_gen_perm,
const Grid< DeviceType > &  grid,
const MagneticField< DeviceType > &  magnetic_field,
const DomainDecomposition< DeviceType > &  pol_decomp,
TmpSpecies< DeviceType > &  tmp_species,
int  isp 
)

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]spall_fptris the pointer to the fortran particles
[in]smlis needed for the sort
[in]speciesis needed for the sort
[in]pid_gen_permis needed for the sort
[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
[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 ( FortranPtr  spall_fptr,
const Simulation< DeviceType > &  sml,
const std::vector< Species< DeviceType >> &  all_species,
const GeneratePermutation< DeviceType > &  pid_gen_perm,
const Grid< DeviceType > &  grid,
const MagneticField< DeviceType > &  magnetic_field,
const DomainDecomposition< DeviceType > &  pol_decomp,
TmpSpecies< DeviceType > &  tmp_species 
)

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]spall_fptris the pointer to the fortran particles
[in]smlis needed for the sort
[in]all_speciesis the vector of all species
[in]pid_gen_permis needed for the sort
[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: