Commit ec7018d9 authored by Yaroslav's avatar Yaroslav

Packer/Unpacker lastver

parent e858a42b
......@@ -165,13 +165,13 @@ am__define_uniq_tagged_files = \
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = ${SHELL} /home/i-bird/Desktop/MOSAIC/OpenFPM_project/OpenFPM_vcluster/missing aclocal-1.14
ACLOCAL = ${SHELL} /home/yaroslav/openfpm/openfpm_vcluster/missing aclocal-1.14
AMTAR = $${TAR-tar}
AM_DEFAULT_VERBOSITY = 1
AUTOCONF = ${SHELL} /home/i-bird/Desktop/MOSAIC/OpenFPM_project/OpenFPM_vcluster/missing autoconf
AUTOHEADER = ${SHELL} /home/i-bird/Desktop/MOSAIC/OpenFPM_project/OpenFPM_vcluster/missing autoheader
AUTOMAKE = ${SHELL} /home/i-bird/Desktop/MOSAIC/OpenFPM_project/OpenFPM_vcluster/missing automake-1.14
AWK = gawk
AUTOCONF = ${SHELL} /home/yaroslav/openfpm/openfpm_vcluster/missing autoconf
AUTOHEADER = ${SHELL} /home/yaroslav/openfpm/openfpm_vcluster/missing autoheader
AUTOMAKE = ${SHELL} /home/yaroslav/openfpm/openfpm_vcluster/missing automake-1.14
AWK = mawk
BOOST_CPPFLAGS = -pthread -I/usr/include
BOOST_DATE_TIME_LIB = -lboost_date_time
BOOST_FILESYSTEM_LIB = -lboost_filesystem
......@@ -182,17 +182,17 @@ BOOST_REGEX_LIB = -lboost_regex
BOOST_SERIALIZATION_LIB = -lboost_serialization
BOOST_SIGNALS_LIB = -lboost_signals
BOOST_THREAD_LIB = -lboost_thread
BOOST_UNIT_TEST_FRAMEWORK_LIB = -lboost_unit_test_framework
BOOST_UNIT_TEST_FRAMEWORK_LIB =
BOOST_WSERIALIZATION_LIB = -lboost_wserialization
CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2
CPPFLAGS =
CUDA_CFLAGS = -I -I -I/usr/local/cuda/include
CUDA_LIBS = -L -L -L/usr/local/cuda/lib64 -lcuda -lcudart
CUDA_CFLAGS =
CUDA_LIBS =
CXX = mpic++
CXXDEPMODE = depmode=gcc3
CXXFLAGS = --std=c++11 -march=native -mtune=native -Wno-unused-local-typedefs -Wextra -Wno-unused-parameter -g3 -Wall -O0
CXXFLAGS = --std=c++11 -march=native -mtune=native -Wno-unused-local-typedefs -Wextra -Wno-unused-parameter -Wall -O3 -g3 -funroll-loops
CYGPATH_W = echo
DEFAULT_LIB = -lrt
DEFS = -DHAVE_CONFIG_H
......@@ -207,15 +207,15 @@ INSTALL_DATA = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL}
INSTALL_SCRIPT = ${INSTALL}
INSTALL_STRIP_PROGRAM = $(install_sh) -c -s
LDFLAGS =
LDFLAGS =
LIBOBJS =
LIBS =
LTLIBOBJS =
MAKEINFO = ${SHELL} /home/i-bird/Desktop/MOSAIC/OpenFPM_project/OpenFPM_vcluster/missing makeinfo
MKDIR_P = /usr/bin/mkdir -p
NVCC = /usr/local/cuda/bin/nvcc
NVCCFLAGS = -g -O0
NVCC_EXIST = yes
MAKEINFO = ${SHELL} /home/yaroslav/openfpm/openfpm_vcluster/missing makeinfo
MKDIR_P = /bin/mkdir -p
NVCC =
NVCCFLAGS = -O3
NVCC_EXIST = no
OBJEXT = o
PACKAGE = full-package-name
PACKAGE_BUGREPORT = BUG-REPORT-ADDRESS
......@@ -226,13 +226,13 @@ PACKAGE_URL =
PACKAGE_VERSION = VERSION
PATH_SEPARATOR = :
SET_MAKE =
SHELL = /bin/sh
SHELL = /bin/bash
STRIP =
VERSION = VERSION
abs_builddir = /home/i-bird/Desktop/MOSAIC/OpenFPM_project/OpenFPM_vcluster/src
abs_srcdir = /home/i-bird/Desktop/MOSAIC/OpenFPM_project/OpenFPM_vcluster/src
abs_top_builddir = /home/i-bird/Desktop/MOSAIC/OpenFPM_project/OpenFPM_vcluster
abs_top_srcdir = /home/i-bird/Desktop/MOSAIC/OpenFPM_project/OpenFPM_vcluster
abs_builddir = /home/yaroslav/openfpm/openfpm_vcluster/src
abs_srcdir = /home/yaroslav/openfpm/openfpm_vcluster/src
abs_top_builddir = /home/yaroslav/openfpm/openfpm_vcluster
abs_top_srcdir = /home/yaroslav/openfpm/openfpm_vcluster
ac_ct_CC = gcc
ac_ct_CXX =
am__include = include
......@@ -260,7 +260,7 @@ host_vendor = unknown
htmldir = ${docdir}
includedir = ${prefix}/include
infodir = ${datarootdir}/info
install_sh = ${SHELL} /home/i-bird/Desktop/MOSAIC/OpenFPM_project/OpenFPM_vcluster/install-sh
install_sh = ${SHELL} /home/yaroslav/openfpm/openfpm_vcluster/install-sh
libdir = ${exec_prefix}/lib
libexecdir = ${exec_prefix}/libexec
localedir = ${datarootdir}/locale
......
......@@ -15,6 +15,7 @@
#include "util/util_debug.hpp"
#include "Pack_stat.hpp"
#include "Pack_selector.hpp"
#include "Vector/map_vector.hpp"
/*! \brief Packing class
*
......@@ -202,68 +203,16 @@ class Packer<T,Mem,PACKER_VECTOR>
{
public:
/*! \brief pack a vector selecting the properties to pack
*
* \param mem preallocated memory where to pack the vector
* \param obj object to pack
* \param sts pack-stat info
*
*/
template<int ... prp> static void pack(ExtPreAlloc<Mem> & mem, T & obj, Pack_stat & sts)
{
#ifdef DEBUG
if (mem.ref() == 0)
std::cerr << "Error : " << __FILE__ << ":" << __LINE__ << " the reference counter of mem should never be zero when packing \n";
#endif
// if no properties should be packed return
if (sizeof...(prp) == 0)
return;
// Sending property object
typedef object<typename object_creator<typename T::value_type::type,prp...>::type> prp_object;
typedef openfpm::vector<prp_object,ExtPreAlloc<Mem>,openfpm::grow_policy_identity> dtype;
// Create an object over the preallocated memory (No allocation is produced)
dtype dest;
dest.setMemory(mem);
dest.resize(obj.size());
auto obj_it = obj.getIterator();
while (obj_it.isNext())
{
// copy all the object in the send buffer
typedef encapc<1,typename T::value_type,typename T::memory_conf > encap_src;
// destination object type
typedef encapc<1,prp_object,typename dtype::memory_conf > encap_dst;
// Copy only the selected properties
object_si_d<encap_src,encap_dst,ENCAP,prp...>(obj.get(obj_it.get()),dest.get(obj_it.get()));
++obj_it;
}
// Update statistic
sts.incReq();
}
/*! \brief Insert an allocation request into the vector
*
* \param obj vector object to pack
* \param requests vector
*
*/
template<int ... prp> static void packRequest(T & obj, std::vector<size_t> & v)
{
typedef object<typename object_creator<typename T::value_type::type,prp...>::type> prp_object;
obj.packRequest<prp...>(obj, v);
};
// Calculate the required memory for packing
size_t alloc_ele = openfpm::vector<prp_object>::calculateMem(obj.size(),0);
template<int ... prp> static void pack(ExtPreAlloc<Mem> & mem, T & obj, Pack_stat & sts)
{
obj.pack<prp...>(mem, obj, sts);
};
v.push_back(alloc_ele);
}
};
/*! \brief Packer for grids and sub-grids
......@@ -275,157 +224,30 @@ public:
template<typename T, typename Mem>
class Packer<T,Mem,PACKER_GRID>
{
/*! \brief Pack an N-dimensional grid into a vector like structure B given an iterator of the grid
*
* \tparam it type of iterator of the grid-structure
* \tparam dtype type of the structure B
* \tparam dim Dimensionality of the grid
* \tparam properties to pack
*
* \param it Grid iterator
* \param obj object to pack
* \param dest where to pack
*
*/
template <typename it, typename dtype, int ... prp> static void pack_with_iterator(it & sub_it, T & obj, dtype & dest)
{
// Sending property object
typedef object<typename object_creator<typename T::value_type::type,prp...>::type> prp_object;
size_t id = 0;
// Packing the information
while (sub_it.isNext())
{
// copy all the object in the send buffer
typedef encapc<T::dims,typename T::value_type,typename T::memory_conf > encap_src;
// destination object type
typedef encapc<1,prp_object,typename dtype::memory_conf > encap_dst;
// Copy only the selected properties
object_si_d<encap_src,encap_dst,ENCAP,prp...>(obj.get_o(sub_it.get()),dest.get(id));
++id;
++sub_it;
}
}
public:
/*! \brief Pack the object into the memory given an iterator
*
* \tparam dim Dimensionality of the grid
* \tparam prp properties to pack
*
* \param mem preallocated memory where to pack the objects
* \param obj object to pack
* \param sts pack statistic
*
*/
template<int ... prp> static void pack(ExtPreAlloc<Mem> & mem, T & obj, Pack_stat & sts)
template<int ... prp> static void packRequest(T & obj, std::vector<size_t> & v)
{
#ifdef DEBUG
if (mem.ref() == 0)
std::cerr << "Error : " << __FILE__ << ":" << __LINE__ << " the reference counter of mem should never be zero when packing \n";
#endif
// Sending property object and vector
typedef object<typename object_creator<typename T::type,prp...>::type> prp_object;
typedef openfpm::vector<prp_object,ExtPreAlloc<Mem>> dtype;
// Calculate the required memory for packing
size_t alloc_ele = dtype::calculateMem(obj.size(),0);
// Create an object over the preallocated memory (No allocation is produced)
dtype dest;
dest.setMemory(mem);
dest.resize(obj.size());
auto it = obj.getIterator();
pack_with_iterator<decltype(it),dtype,prp...>(mem,it,obj,dest);
obj.packRequest<prp...>(v);
};
// Update statistic
sts.incReq();
}
/*! \brief Pack the object into the memory given an iterator
*
* \tparam prp properties to pack
*
* \param mem preallocated memory where to pack the objects
* \param sub_it sub grid iterator ( or the elements in the grid to pack )
* \param obj object to pack
* \param sts pack statistic
*
*/
template<int ... prp> static void pack(ExtPreAlloc<Mem> & mem, T & obj, grid_key_dx_iterator_sub<T::dims> & sub_it, Pack_stat & sts)
template<int ... prp> static void packRequest(T & obj, grid_key_dx_iterator_sub<T::dims> & sub, std::vector<size_t> & v)
{
#ifdef DEBUG
if (mem.ref() == 0)
std::cerr << "Error : " << __FILE__ << ":" << __LINE__ << " the reference counter of mem should never be zero when packing \n";
#endif
// Sending property object
typedef object<typename object_creator<typename T::value_type::type,prp...>::type> prp_object;
typedef openfpm::vector<prp_object,ExtPreAlloc<Mem>,openfpm::grow_policy_identity> dtype;
// Create an object over the preallocated memory (No allocation is produced)
dtype dest;
dest.setMemory(mem);
dest.resize(sub_it.getVolume());
pack_with_iterator<grid_key_dx_iterator_sub<T::dims>,dtype,prp...>(sub_it,obj,dest);
obj.packRequest<prp...>(sub, v);
};
// Update statistic
sts.incReq();
}
/*! \brief Insert an allocation request
*
* \param vector of requests
*
*/
template<int ... prp> static void packRequest(T & obj, std::vector<size_t> & v)
template<int ... prp> static void pack(ExtPreAlloc<Mem> & mem, T & obj, Pack_stat & sts)
{
// Sending property object
typedef object<typename object_creator<typename T::type::type,prp...>::type> prp_object;
typedef openfpm::vector<prp_object,ExtPreAlloc<Mem>,openfpm::grow_policy_identity> dtype;
// Calculate the required memory for packing
size_t alloc_ele = dtype::calculateMem(obj.size(),0);
v.push_back(alloc_ele);
obj.pack<prp...>(mem, sts);
}
/*! \brief Insert an allocation request
*
* \tparam prp set of properties to pack
*
* \param obj grid to pack
* \param sub sub-grid iterator
* \param vector of requests
*
*/
template<int ... prp> static void packRequest(T & obj, grid_key_dx_iterator_sub<T::dims> & sub, std::vector<size_t> & v)
template<int ... prp> static void pack(ExtPreAlloc<Mem> & mem, T & obj, grid_key_dx_iterator_sub<T::dims> & sub_it, Pack_stat & sts)
{
// Sending property object
typedef object<typename object_creator<typename T::value_type::type,prp...>::type> prp_object;
typedef openfpm::vector<prp_object,ExtPreAlloc<Mem>,openfpm::grow_policy_identity> dtype;
// Calculate the required memory for packing
size_t alloc_ele = dtype::calculateMem(sub.getVolume(),0);
v.push_back(alloc_ele);
obj.pack<prp...>(mem, sub_it, sts);
}
};
/*! \brief Packer class for encapsulated objects
*
* \tparam T object type to pack
* \tparam Mem Memory origin HeapMemory CudaMemory ...
*
*/
template<typename T, typename Mem>
class Packer<T,Mem,PACKER_ENCAP_OBJECTS>
{
......
......@@ -12,6 +12,7 @@
#include "Packer.hpp"
#include "Unpacker.hpp"
#include "Grid/grid_util_test.hpp"
#include <iostream>
BOOST_AUTO_TEST_SUITE( packer_unpacker )
......
......@@ -134,54 +134,10 @@ class Unpacker<T,Mem,PACKER_VECTOR>
{
public:
/*! \brief unpack a vector
*
* \warning the properties should match the packed properties, and the obj must have the same size of the packed vector, consider to pack
* this information if you cannot infer-it
*
* \param ext preallocated memory from where to unpack the vector
* \param obj object where to unpack
*
*/
template<unsigned int ... prp> void static unpack(ExtPreAlloc<Mem> & mem, T & obj, Unpack_stat & ps)
{
// if no properties should be unpacked return
if (sizeof...(prp) == 0)
return;
size_t id = 0;
// Sending property object
typedef object<typename object_creator<typename T::value_type::type,prp...>::type> prp_object;
typedef openfpm::vector<prp_object,PtrMemory,openfpm::grow_policy_identity> stype;
// Calculate the size to pack the object
size_t size = stype::calculateMem(obj.size(),0);
// Create a Pointer object over the preallocated memory (No allocation is produced)
PtrMemory & ptr = *(new PtrMemory(mem.getPointerOffset(ps.getOffset()),size));
stype src;
src.setMemory(ptr);
src.resize(obj.size());
auto obj_it = obj.getIterator();
while (obj_it.isNext())
{
// copy all the object in the send buffer
typedef encapc<1,typename T::value_type,typename T::memory_conf > encap_dst;
// destination object type
typedef encapc<1,prp_object,typename stype::memory_conf > encap_src;
// Copy only the selected properties
object_s_di<encap_src,encap_dst,ENCAP,prp...>(src.get(id),obj.get(obj_it.get()));
++id;
++obj_it;
}
ps.addOffset(size);
}
obj.unpack<prp...>(mem, obj, ps);
};
};
/*! \brief Unpacker for grids
......@@ -193,98 +149,17 @@ public:
template<typename T, typename Mem>
class Unpacker<T,Mem,PACKER_GRID>
{
/*! \brief unpack the grid given an iterator
*
* \tparam it type of iterator
* \tparam prp of the grid object to unpack
*
*/
template <typename it, typename stype, unsigned int ... prp> static void unpack_with_iterator(ExtPreAlloc<Mem> & mem, it & sub_it, T & obj, stype & src, Unpack_stat & ps)
{
size_t id = 0;
// Sending property object
typedef object<typename object_creator<typename T::value_type::type,prp...>::type> prp_object;
// unpacking the information
while (sub_it.isNext())
{
// copy all the object in the send buffer
typedef encapc<T::dims,typename T::value_type,typename T::memory_conf > encap_dst;
// destination object type
typedef encapc<1,prp_object,typename grid_cpu<T::dims,prp_object>::memory_conf > encap_src;
// Copy only the selected properties
object_s_di<encap_src,encap_dst,ENCAP,prp...>(src.get(id),obj.get_o(sub_it.get()));
++id;
++sub_it;
}
}
public:
/*! \brief unpack the grid object
*
* \tparam prp properties to unpack
*
* \param ext preallocated memory from where to unpack the grid
* \param obj object where to unpack
*
*/
template<unsigned int ... prp> static void unpack(ExtPreAlloc<Mem> & mem, T & obj, Unpack_stat & ps)
{
// object that store the information in mem
typedef object<typename object_creator<typename T::type,prp...>::type> prp_object;
typedef openfpm::vector<prp_object,PtrMemory,openfpm::grow_policy_identity> stype;
// Calculate the size to pack the object
size_t size = stype::calculateMem(obj.size(),0);
// Create an Pointer object over the preallocated memory (No allocation is produced)
PtrMemory & ptr = *(new PtrMemory(mem.getPointerOffset(ps.getOffset()),size));
// Create an object over a pointer (No allocation is produced)
stype src;
src.setMemory(mem);
src.resize(obj.size());
auto it = obj.getIterator();
unpack_with_iterator<decltype(it),stype,prp...>(mem,it,obj,src,ps);
ps.addOffset(size);
}
obj.unpack<prp...>(mem, ps);
};
/*! \brief unpack the sub-grid object
*
* \tparam prp properties to unpack
*
* \param mem preallocated memory from where to unpack the object
* \param sub sub-grid iterator
* \param obj object where to unpack
*
*/
template<unsigned int ... prp> static void unpack(ExtPreAlloc<Mem> & mem, grid_key_dx_iterator_sub<T::dims> & sub_it, T & obj, Unpack_stat & ps)
{
// object that store the information in mem
typedef object<typename object_creator<typename T::value_type::type,prp...>::type> prp_object;
typedef openfpm::vector<prp_object,PtrMemory,openfpm::grow_policy_identity> stype;
size_t size = stype::calculateMem(sub_it.getVolume(),0);
// Create an object over the preallocated memory (No allocation is produced)
PtrMemory & ptr = *(new PtrMemory(mem.getPointerOffset(ps.getOffset()),size));
// Create an object of the packed information over a pointer (No allocation is produced)
stype src;
src.setMemory(ptr);
src.resize(sub_it.getVolume());
unpack_with_iterator<grid_key_dx_iterator_sub<T::dims>,stype,prp...>(mem,sub_it,obj,src,ps);
ps.addOffset(size);
}
obj.unpack<prp...>(mem, sub_it, ps);
};
};
/*! \brief Unpacker for encapsulated objects
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment