Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Static Public Member Functions | Static Public Attributes | List of all members
Tpetra::Details::PackTraits< T > Struct Template Reference

Traits class for packing / unpacking data of type T. More...

#include <Tpetra_Details_PackTraits.hpp>

Inheritance diagram for Tpetra::Details::PackTraits< T >:
Inheritance graph
[legend]

Public Types

using value_type = T
 The type of data to pack or unpack. More...
 
using input_buffer_type = Kokkos::View< const char *, Kokkos::AnonymousSpace >
 The type of an input buffer of bytes. More...
 
using output_buffer_type = Kokkos::View< char *, Kokkos::AnonymousSpace >
 The type of an output buffer of bytes. More...
 
using input_array_type = Kokkos::View< const value_type *, Kokkos::AnonymousSpace >
 The type of an input array of value_type. More...
 
using output_array_type = Kokkos::View< value_type *, Kokkos::AnonymousSpace >
 The type of an output array of value_type. More...
 

Static Public Member Functions

static KOKKOS_INLINE_FUNCTION
size_t 
numValuesPerScalar (const value_type &)
 Given an instance of value_type allocated with the right size, return the "number of values" that make up that value_type instance. More...
 
static KOKKOS_INLINE_FUNCTION
Kokkos::pair< int, size_t > 
packArray (char outBuf[], const value_type inBuf[], const size_t numEnt)
 Pack the first numEnt entries of the given input buffer of value_type, into the output buffer of bytes. More...
 
static KOKKOS_INLINE_FUNCTION
Kokkos::pair< int, size_t > 
unpackArray (value_type outBuf[], const char inBuf[], const size_t numEnt)
 Unpack numEnt value_type entries from the given input buffer of bytes, to the given output buffer of value_type. More...
 
static KOKKOS_INLINE_FUNCTION
size_t 
packValueCount (const T &)
 Number of bytes required to pack or unpack the given value of type value_type. More...
 
static KOKKOS_INLINE_FUNCTION
size_t 
packValue (char outBuf[], const T &inVal)
 Pack the given value of type value_type into the given output buffer of bytes (char). More...
 
static KOKKOS_INLINE_FUNCTION
size_t 
packValue (char outBuf[], const size_t outBufIndex, const T &inVal)
 Pack the given value of type value_type into the given output buffer of bytes (char). More...
 
static KOKKOS_INLINE_FUNCTION
size_t 
unpackValue (T &outVal, const char inBuf[])
 Unpack the given value from the given output buffer. More...
 

Static Public Attributes

static const bool compileTimeSize = true
 Whether the number of bytes required to pack one instance of value_type is fixed at compile time. More...
 

Detailed Description

template<class T>
struct Tpetra::Details::PackTraits< T >

Traits class for packing / unpacking data of type T.

Template Parameters
TThe type of the data to pack / unpack.

Definition at line 29 of file Tpetra_Details_PackTraits.hpp.

Member Typedef Documentation

template<class T>
using Tpetra::Details::PackTraits< T >::value_type = T

The type of data to pack or unpack.

Definition at line 31 of file Tpetra_Details_PackTraits.hpp.

template<class T>
using Tpetra::Details::PackTraits< T >::input_buffer_type = Kokkos::View<const char*, Kokkos::AnonymousSpace>

The type of an input buffer of bytes.

Definition at line 49 of file Tpetra_Details_PackTraits.hpp.

template<class T>
using Tpetra::Details::PackTraits< T >::output_buffer_type = Kokkos::View<char*, Kokkos::AnonymousSpace>

The type of an output buffer of bytes.

Definition at line 52 of file Tpetra_Details_PackTraits.hpp.

template<class T>
using Tpetra::Details::PackTraits< T >::input_array_type = Kokkos::View<const value_type*, Kokkos::AnonymousSpace>

The type of an input array of value_type.

Definition at line 55 of file Tpetra_Details_PackTraits.hpp.

template<class T>
using Tpetra::Details::PackTraits< T >::output_array_type = Kokkos::View<value_type*, Kokkos::AnonymousSpace>

The type of an output array of value_type.

Definition at line 58 of file Tpetra_Details_PackTraits.hpp.

Member Function Documentation

template<class T>
static KOKKOS_INLINE_FUNCTION size_t Tpetra::Details::PackTraits< T >::numValuesPerScalar ( const value_type )
inlinestatic

Given an instance of value_type allocated with the right size, return the "number of values" that make up that value_type instance.

This function helps the pack and unpack code that uses PackTraits correctly handle types that have a size specified at run time. PackTraits still assumes that all instances of value_type in an input or output array have the same run-time size.

Parameters
x[in] Instance of value_type with the correct size (possibly determined at run time).
Returns
The "number of values" that make up x.

Definition at line 76 of file Tpetra_Details_PackTraits.hpp.

template<class T>
static KOKKOS_INLINE_FUNCTION Kokkos::pair<int, size_t> Tpetra::Details::PackTraits< T >::packArray ( char  outBuf[],
const value_type  inBuf[],
const size_t  numEnt 
)
inlinestatic

Pack the first numEnt entries of the given input buffer of value_type, into the output buffer of bytes.

Precondition
All entries of inBuf must have the same (run-time) size.
Parameters
outBuf[out] Output buffer of bytes (char). Must have enough space to hold the packed version of the first numEnt entries of inBuf.
inBuf[in] Input buffer of value_type. Must have at least numEnt entries.
numEnt[in] Number of entries to pack.
Returns
{The number of bytes used to pack inBuf into outBuf,

Definition at line 98 of file Tpetra_Details_PackTraits.hpp.

template<class T>
static KOKKOS_INLINE_FUNCTION Kokkos::pair<int, size_t> Tpetra::Details::PackTraits< T >::unpackArray ( value_type  outBuf[],
const char  inBuf[],
const size_t  numEnt 
)
inlinestatic

Unpack numEnt value_type entries from the given input buffer of bytes, to the given output buffer of value_type.

Precondition
All entries of outBuf must have the same (run-time) size, and that size must be the same as that of the packed data that live in inBuf.
Parameters
outBuf[in] Output buffer of value_type. Must have at least numEnt entries.
inBuf[out] Input buffer of bytes (char).
numEnt[in] Number of value_type entries to unpack.
Returns
{The number of bytes unpacked (i.e., read from inBuf).

Definition at line 146 of file Tpetra_Details_PackTraits.hpp.

template<class T>
static KOKKOS_INLINE_FUNCTION size_t Tpetra::Details::PackTraits< T >::packValueCount ( const T &  )
inlinestatic

Number of bytes required to pack or unpack the given value of type value_type.

Parameters
inVal[in] The input value (see discussion below).
Returns
The number of bytes required to pack inVal.

Currently, this function returns the exact amount of bytes, not an upper bound. Thus, one can use this function to predict offsets. That assumes packing without padding for (e.g.,) alignment to something bigger than sizeof(char) = 1. At some point, we may need to extend this to be an upper bound, rather than an exact value. Compare to MPI_PACK_SIZE, which only claims to offer an upper bound. In that case, one may not use this function to predict offsets for unpacking; like MPI_UNPACK, one would need to start at the beginning of the packed array and unpack sequentially.

We currently assume that all objects of type value_type require the same number of bytes. Nevertheless, we require an instance of value_type, in case we want to relax this assumption in the future. That's why the brief description of this function says "the given value of type \c value_type."

Definition at line 204 of file Tpetra_Details_PackTraits.hpp.

template<class T>
static KOKKOS_INLINE_FUNCTION size_t Tpetra::Details::PackTraits< T >::packValue ( char  outBuf[],
const T &  inVal 
)
inlinestatic

Pack the given value of type value_type into the given output buffer of bytes (char).

Precondition
outBuf has at least packValueCount(inVal) entries.
Parameters
outBuf[out] Output buffer of bytes.
inVal[in] Input value to pack.
Returns
The number of bytes used to pack inVal.

Definition at line 220 of file Tpetra_Details_PackTraits.hpp.

template<class T>
static KOKKOS_INLINE_FUNCTION size_t Tpetra::Details::PackTraits< T >::packValue ( char  outBuf[],
const size_t  outBufIndex,
const T &  inVal 
)
inlinestatic

Pack the given value of type value_type into the given output buffer of bytes (char).

Precondition
outBuf has at least packValueCount(inVal) entries.
Parameters
outBuf[out] Output buffer of bytes.
outBufIndex[in] Index into output buffer (multiplied by the number of bytes needed to pack inVal).
inVal[in] Input value to pack.
Returns
The number of bytes used to pack inVal.

Definition at line 247 of file Tpetra_Details_PackTraits.hpp.

template<class T>
static KOKKOS_INLINE_FUNCTION size_t Tpetra::Details::PackTraits< T >::unpackValue ( T &  outVal,
const char  inBuf[] 
)
inlinestatic

Unpack the given value from the given output buffer.

Parameters
outVal[in/out] On output: The unpacked value.
inBuf[in] The buffer of packed data from which to unpack the output value.
Returns
The number of bytes unpacked from inBuf.

We assume that the number of bytes required to pack outVal does not depend on the unpacked data. That is, outVal on input requires the same number of packed bytes as it should on output.

Definition at line 277 of file Tpetra_Details_PackTraits.hpp.

Member Data Documentation

template<class T>
const bool Tpetra::Details::PackTraits< T >::compileTimeSize = true
static

Whether the number of bytes required to pack one instance of value_type is fixed at compile time.

This is true for "plain old data" (POD) types like float, double, and int. It is also true of structs or classes of POD, like Kokkos::complex. The Sacado and Stokhos packages may have classes for which this is false. If false, then the size of an instance of value_type may have been determined at run time, for example in its constructor.

Whether or not this is true or false, implementations of PackTraits may assume that all instances of value_type which the implementation encounters have the same size.

Definition at line 46 of file Tpetra_Details_PackTraits.hpp.


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