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

Traits class for packing / unpacking data of type T, using Kokkos data structures that live in the given space D. More...

#include <Tpetra_Details_PackTraits.hpp>

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

Public Types

typedef T value_type
 The type of data to pack or unpack. More...
 
typedef Kokkos::View< const
char *, D,
Kokkos::MemoryUnmanaged > 
input_buffer_type
 The type of an input buffer of bytes. More...
 
typedef Kokkos::View< char
*, D, Kokkos::MemoryUnmanaged > 
output_buffer_type
 The type of an output buffer of bytes. More...
 
typedef Kokkos::View< const
value_type *, D,
Kokkos::MemoryUnmanaged > 
input_array_type
 The type of an input array of value_type. More...
 
typedef Kokkos::View
< value_type *, D,
Kokkos::MemoryUnmanaged > 
output_array_type
 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::View
< value_type *, D > 
allocateArray (const value_type &x, const size_t numEnt, const std::string &label="")
 Given an instance of value_type allocated with the right size, allocate and return a one-dimensional array of value_type. 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, class D>
struct Tpetra::Details::PackTraits< T, D >

Traits class for packing / unpacking data of type T, using Kokkos data structures that live in the given space D.

Template Parameters
TThe type of the data to pack / unpack.
DThe Kokkos "device" type; where the data live.

Definition at line 63 of file Tpetra_Details_PackTraits.hpp.

Member Typedef Documentation

template<class T, class D>
typedef T Tpetra::Details::PackTraits< T, D >::value_type

The type of data to pack or unpack.

Definition at line 65 of file Tpetra_Details_PackTraits.hpp.

template<class T, class D>
typedef Kokkos::View<const char*, D, Kokkos::MemoryUnmanaged> Tpetra::Details::PackTraits< T, D >::input_buffer_type

The type of an input buffer of bytes.

Definition at line 83 of file Tpetra_Details_PackTraits.hpp.

template<class T, class D>
typedef Kokkos::View<char*, D, Kokkos::MemoryUnmanaged> Tpetra::Details::PackTraits< T, D >::output_buffer_type

The type of an output buffer of bytes.

Definition at line 86 of file Tpetra_Details_PackTraits.hpp.

template<class T, class D>
typedef Kokkos::View<const value_type*, D, Kokkos::MemoryUnmanaged> Tpetra::Details::PackTraits< T, D >::input_array_type

The type of an input array of value_type.

Definition at line 89 of file Tpetra_Details_PackTraits.hpp.

template<class T, class D>
typedef Kokkos::View<value_type*, D, Kokkos::MemoryUnmanaged> Tpetra::Details::PackTraits< T, D >::output_array_type

The type of an output array of value_type.

Definition at line 92 of file Tpetra_Details_PackTraits.hpp.

Member Function Documentation

template<class T, class D>
static KOKKOS_INLINE_FUNCTION size_t Tpetra::Details::PackTraits< T, D >::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 110 of file Tpetra_Details_PackTraits.hpp.

template<class T, class D>
static Kokkos::View<value_type*, D> Tpetra::Details::PackTraits< T, D >::allocateArray ( const value_type x,
const size_t  numEnt,
const std::string &  label = "" 
)
inlinestatic

Given an instance of value_type allocated with the right size, allocate and return a one-dimensional array of value_type.

This function lets the pack and unpack code that uses PackTraits correctly handle types that have a size specified at run time. In particular, it's helpful if that code needs to allocate temporary buffers of value_type. 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 (run-time) size.
numEnt[in] Number of entries in the returned array.
label[in] Optional string label of the returned Kokkos::View. (Kokkos::View's constructor takes a string label, which Kokkos uses for debugging output.)
Returns
One-dimensional array of value_type, all instances of which have the same (run-time) size as x.
Note
To implementers of specializations: If the number of bytes to pack or unpack your type may be determined at run time, you might be able just to use this implementation as-is, and just reimplement numValuesPerScalar().

Definition at line 141 of file Tpetra_Details_PackTraits.hpp.

template<class T, class D>
static KOKKOS_INLINE_FUNCTION Kokkos::pair<int, size_t> Tpetra::Details::PackTraits< T, D >::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 181 of file Tpetra_Details_PackTraits.hpp.

template<class T, class D>
static KOKKOS_INLINE_FUNCTION Kokkos::pair<int, size_t> Tpetra::Details::PackTraits< T, D >::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 229 of file Tpetra_Details_PackTraits.hpp.

template<class T, class D>
static KOKKOS_INLINE_FUNCTION size_t Tpetra::Details::PackTraits< T, D >::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 287 of file Tpetra_Details_PackTraits.hpp.

template<class T, class D>
static KOKKOS_INLINE_FUNCTION size_t Tpetra::Details::PackTraits< T, D >::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 303 of file Tpetra_Details_PackTraits.hpp.

template<class T, class D>
static KOKKOS_INLINE_FUNCTION size_t Tpetra::Details::PackTraits< T, D >::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 330 of file Tpetra_Details_PackTraits.hpp.

template<class T, class D>
static KOKKOS_INLINE_FUNCTION size_t Tpetra::Details::PackTraits< T, D >::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 360 of file Tpetra_Details_PackTraits.hpp.

Member Data Documentation

template<class T, class D>
const bool Tpetra::Details::PackTraits< T, D >::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 80 of file Tpetra_Details_PackTraits.hpp.


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