OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
Packer< T, Mem, pack_type > Class Template Reference

Packing class. More...

Detailed Description

template<typename T, typename Mem, int pack_type = Pack_selector<T>::value>
class Packer< T, Mem, pack_type >

Packing class.

This class pack objects primitives vectors and grids, the general usage is to create a vector of packing request (std::vector<size_t>) that contain the size of the required space needed to pack the information. Calculate the total size, allocating it on HeapMemory (for example), Create an ExtPreAlloc memory object giving the preallocated memory to it and finally Pack all the objects subsequently

In order to unpack the information the Unpacker class can be used

See Also
Unpacker
typedef Point_test<float> pt;
// Create all the objects we want to pack
unsigned char uc = 1;
char c = 2;
short s = 3;
unsigned short us = 4;
int i = 5;
unsigned int ui = 6;
long int li = 7;
unsigned long int uli = 8;
float f = 9;
double d = 10;
openfpm::vector<Point_test<float>> v = allocate_openfpm(1024);
p.fill();
size_t sz[] = {16,16,16};
g.setMemory();
fill_grid<3>(g);
grid_key_dx_iterator_sub<3> sub(g.getGrid(),{1,2,3},{5,6,7});
// Here we start to push all the allocations required to pack all the data
std::vector<size_t> pap_prp;
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],sizeof(unsigned char));
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],sizeof(char));
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],sizeof(short));
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],sizeof(unsigned short));
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],sizeof(int));
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],sizeof(unsigned int));
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],sizeof(long int));
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],sizeof(long unsigned int));
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],sizeof(float));
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],sizeof(double));
Packer<openfpm::vector<Point_test<float>>,HeapMemory>::packRequest<pt::x,pt::v>(v,pap_prp);
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],(sizeof(float) + sizeof(float[3])) * v.size());
Packer<grid_cpu<3,Point_test<float>>,HeapMemory>::packRequest<pt::x,pt::v>(g,sub,pap_prp);
BOOST_REQUIRE_EQUAL(pap_prp[pap_prp.size()-1],(sizeof(float) + sizeof(float[3])) * sub.getVolume());
// Calculate how much preallocated memory we need to pack all the objects
size_t req = ExtPreAlloc<HeapMemory>::calculateMem(pap_prp);
// allocate the memory
HeapMemory pmem;
pmem.allocate(req);
ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(pap_prp,pmem));
mem.incRef();
Pack_stat sts;
// try to pack
Packer<Point_test<float>,HeapMemory>::pack(mem,p,sts);
Packer<openfpm::vector<Point_test<float>>,HeapMemory>::pack<pt::x,pt::v>(mem,v,sts);
Packer<grid_cpu<3,Point_test<float>>,HeapMemory>::pack<pt::x,pt::v>(mem,g,sub,sts);
Template Parameters
Tobject type to pack
MemMemory origin HeapMemory CudaMemory ...
Implementationof the packer (the Pack_selector choose the correct one)

Definition at line 46 of file Packer.hpp.

#include <Packer.hpp>

Static Public Member Functions

static void pack (ExtPreAlloc< Mem >, const T &obj)
 Error, no implementation. More...
 
static size_t packRequest (std::vector< size_t > &req)
 Error, no implementation. More...
 

Member Function Documentation

template<typename T, typename Mem, int pack_type = Pack_selector<T>::value>
static void Packer< T, Mem, pack_type >::pack ( ExtPreAlloc< Mem >  ,
const T &  obj 
)
inlinestatic

Error, no implementation.

Definition at line 53 of file Packer.hpp.

template<typename T, typename Mem, int pack_type = Pack_selector<T>::value>
static size_t Packer< T, Mem, pack_type >::packRequest ( std::vector< size_t > &  req)
inlinestatic

Error, no implementation.

Definition at line 61 of file Packer.hpp.


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