OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
Packer< T, Mem, pack_type > Class Template Reference

Packing class. More...

Detailed Description

template<typename T, typename Mem, int pack_type>
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<openfpm::vector<Point_test<float>>>(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;
size_t size_total = 0;
size_t size_total_old = 0;
BOOST_REQUIRE_EQUAL(size_total,sizeof(unsigned char));
size_total_old = size_total;
BOOST_REQUIRE_EQUAL(size_total - size_total_old,sizeof(char));
size_total_old = size_total;
BOOST_REQUIRE_EQUAL(size_total - size_total_old,sizeof(short));
size_total_old = size_total;
BOOST_REQUIRE_EQUAL(size_total - size_total_old,sizeof(unsigned short));
size_total_old = size_total;
BOOST_REQUIRE_EQUAL(size_total - size_total_old,sizeof(int));
size_total_old = size_total;
BOOST_REQUIRE_EQUAL(size_total - size_total_old,sizeof(unsigned int));
size_total_old = size_total;
BOOST_REQUIRE_EQUAL(size_total - size_total_old,sizeof(long int));
size_total_old = size_total;
BOOST_REQUIRE_EQUAL(size_total - size_total_old,sizeof(long unsigned int));
size_total_old = size_total;
BOOST_REQUIRE_EQUAL(size_total - size_total_old,sizeof(float));
size_total_old = size_total;
BOOST_REQUIRE_EQUAL(size_total - size_total_old,sizeof(double));
size_total_old = size_total;
#ifndef SE_CLASS3
BOOST_REQUIRE_EQUAL(size_total - size_total_old,(sizeof(float)*4 + sizeof(float[3]) + sizeof(float[3][3])));
#endif
size_total_old = size_total;
Packer<openfpm::vector<Point_test<float>>,HeapMemory>::packRequest<pt::x,pt::v>(v,size_total);
#ifndef SE_CLASS3
BOOST_REQUIRE_EQUAL(size_total - size_total_old,(sizeof(float) + sizeof(float[3])) * v.size() + sizeof(v.size()));
#endif
size_total_old = size_total;
Packer<grid_cpu<3,Point_test<float>>,HeapMemory>::packRequest<decltype(sub),pt::x,pt::v>(g,sub,size_total);
#ifndef SE_CLASS3
BOOST_REQUIRE_EQUAL(size_total - size_total_old,(sizeof(float) + sizeof(float[3])) * sub.getVolume());
#endif
// 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(size_total);
ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(size_total,pmem));
mem.incRef();
Pack_stat sts;
// try to pack
Packer<openfpm::vector<Point_test<float>>,HeapMemory>::pack<pt::x,pt::v>(mem,v,sts);
Packer<grid_cpu<3,Point_test<float>>,HeapMemory>::pack<decltype(sub),pt::x,pt::v>(mem,g,sub,sts);
virtual void incRef()
Increment the reference counter.
This class allocate, and destroy CPU memory.
virtual bool allocate(size_t sz)
allocate memory
Packing status object.
Definition Pack_stat.hpp:61
Packing class.
Definition Packer.hpp:50
static void pack(ExtPreAlloc< Mem >, const T &obj)
Error, no implementation.
Definition Packer.hpp:56
static size_t packRequest(const T &obj, size_t &req)
Error, no implementation.
Definition Packer.hpp:66
Test structure used for several test.
void fill()
fill
Declaration grid_key_dx_iterator_sub.
Implementation of 1-D std::vector like structure.
Template Parameters
Tobject type to pack
MemMemory origin HeapMemory CudaMemory ...
Implementationof the packer (the Pack_selector choose the correct one)

Definition at line 49 of file Packer.hpp.

#include <Packer.hpp>

Static Public Member Functions

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

Member Function Documentation

◆ pack()

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

Error, no implementation.

Definition at line 56 of file Packer.hpp.

◆ packRequest()

template<typename T , typename Mem , int pack_type>
static size_t Packer< T, Mem, pack_type >::packRequest ( const T &  obj,
size_t &  req 
)
inlinestatic

Error, no implementation.

Definition at line 66 of file Packer.hpp.


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