Commit 4fecaeb9 authored by incardon's avatar incardon
Browse files

Latest changes

parent 0ab602dd
......@@ -316,7 +316,8 @@ public:
* \return the reference
*
*/
template <unsigned int p, typename r_type=decltype(boost::fusion::at_c<p>(data_c))> inline r_type get()
template <unsigned int p, typename r_type=decltype(boost::fusion::at_c<p>(data_c))>
inline r_type get()
{
#ifdef SE_CLASS2
check_valid(&boost::fusion::at_c<p>(data_c),sizeof(typename boost::mpl::at<type,boost::mpl::int_<p>>::type));
......@@ -329,7 +330,8 @@ public:
* \return the reference
*
*/
template <unsigned int p, typename r_type=decltype(boost::fusion::at_c<p>(data_c))> inline const r_type get() const
template <unsigned int p, typename r_type=decltype(boost::fusion::at_c<p>(data_c))>
inline const r_type get() const
{
#ifdef SE_CLASS2
check_valid(&boost::fusion::at_c<p>(data_c),sizeof(typename boost::mpl::at<type,boost::mpl::int_<p>>::type));
......
......@@ -143,6 +143,11 @@ struct mem_geto
{
return encapc<dim,T,typename layout::type>(data_.mem_r->operator[](g1.LinId(v1)));
}
static inline encapc<dim,T,typename layout::type> get_lin(data_type & data_, const size_t & v1)
{
return encapc<dim,T,typename layout::type>(data_.mem_r->operator[](v1));
}
};
//! Case memory_traits_inte
......@@ -153,6 +158,11 @@ struct mem_geto<dim,T,layout,data_type,g1_type,key_type,1>
{
return encapc<dim,T,typename layout::type>(data_,g1.LinId(v1));
}
static inline encapc<dim,T,typename layout::type> get_lin(data_type & data_, const size_t & v1)
{
return encapc<dim,T,typename layout::type>(data_,v1);
}
};
......
......@@ -547,6 +547,52 @@ public:
return mem_geto<dim,T,layout_base<T>,decltype(this->data_),decltype(this->g1),decltype(v1)>::get(const_cast<decltype(this->data_) &>(data_),g1,v1);
}
/*! \brief Get the of the selected element as a boost::fusion::vector
*
* Get the selected element as a boost::fusion::vector
*
* \param v1 linearized id that identify the element in the grid
*
* \see encap_c
*
* \return an encap_c that is the representation of the object (careful is not the object)
*
*/
inline encapc<dim,T,layout> get_o(size_t v1)
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
#ifdef SE_CLASS1
check_init();
check_bound(v1);
#endif
return mem_geto<dim,T,layout_base<T>,decltype(this->data_),decltype(this->g1),decltype(v1)>::get_lin(data_,v1);
}
/*! \brief Get the of the selected element as a boost::fusion::vector
*
* Get the selected element as a boost::fusion::vector
*
* \param v1 linearized id that identify the element in the grid
*
* \see encap_c
*
* \return an encap_c that is the representation of the object (careful is not the object)
*
*/
inline const encapc<dim,T,layout> get_o(size_t v1) const
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
#ifdef SE_CLASS1
check_init();
check_bound(v1);
#endif
return mem_geto<dim,T,layout_base<T>,decltype(this->data_),decltype(this->g1),decltype(v1)>::get_lin(const_cast<decltype(this->data_) &>(data_),v1);
}
/*! \brief Fill the memory with the selected byte
*
* \warning It is a low level memory operation it ignore any type and semantic safety
......@@ -762,7 +808,33 @@ public:
*
*/
inline void set(const grid_key_dx<dim> & key1,const grid_base_impl<dim,T,S,layout,layout_base> & g, const grid_key_dx<dim> & key2)
inline void set(const grid_key_dx<dim> & key1,
const grid_base_impl<dim,T,S,layout,layout_base> & g,
const grid_key_dx<dim> & key2)
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
#ifdef SE_CLASS1
check_init();
check_bound(key1);
check_bound(g,key2);
#endif
this->get_o(key1) = g.get_o(key2);
}
/*! \brief Set an element of the grid from another element of another grid
*
* \param key1 element of the grid to set
* \param g source grid
* \param key2 element of the source grid to copy
*
*/
inline void set(const size_t key1,
const grid_base_impl<dim,T,S,layout,layout_base> & g,
const size_t key2)
{
#ifdef SE_CLASS2
check_valid(this,8);
......@@ -861,6 +933,23 @@ public:
return grid_key_dx_iterator<dim>(g1);
}
/*! \brief Return a grid iterator
*
* Return a grid iterator, to iterate through the grid with stencil calculation
*
* \return a grid iterator with stencil calculation
*
*/
template<unsigned int Np>
inline grid_key_dx_iterator<dim,stencil_offset_compute<dim,Np>>
getIteratorStencil(const grid_key_dx<dim> (& stencil_pnt)[Np]) const
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
return grid_key_dx_iterator<dim,stencil_offset_compute<dim,Np>>(g1,stencil_pnt);
}
/*! \brief Return a grid iterator over all points included between start and stop point
*
* Return a grid iterator over all the point with the exception of the
......
......@@ -49,7 +49,10 @@ struct pack_simple_cond
dest.setMemory(mem);
dest.resize(obj.size());
auto it = obj.getIterator();
grid_key_dx<dim> cnt[1];
cnt[0].zero();
auto it = obj.getIteratorStencil(cnt);
obj.pack_with_iterator<decltype(it),dtype,prp...>(it,dest);
......@@ -138,7 +141,10 @@ struct unpack_simple_cond
src.setMemory(ptr);
src.resize(obj.size());
auto it = obj.getIterator();
grid_key_dx<dim> cnt[1];
cnt[0].zero();
auto it = obj.getIteratorStencil(cnt);
obj.unpack_with_iterator<decltype(it),stype,prp...>(it,src);
......@@ -321,7 +327,7 @@ struct unpack_simple_cond<true, prp ...>
* \param sts pack statistic
*
*/
template<int ... prp> void pack(ExtPreAlloc<S> & mem, grid_key_dx_iterator_sub<dims> & sub_it, Pack_stat & sts)
template<int ... prp> void pack(ExtPreAlloc<S> & mem, grid_key_dx_iterator_sub<dims,stencil_offset_compute<dims,1>> & sub_it, Pack_stat & sts)
{
#ifdef SE_CLASS1
if (mem.ref() == 0)
......@@ -337,7 +343,7 @@ struct unpack_simple_cond<true, prp ...>
dest.setMemory(mem);
dest.resize(sub_it.getVolume());
pack_with_iterator<grid_key_dx_iterator_sub<dims>,dtype,prp...>(sub_it,dest);
pack_with_iterator<grid_key_dx_iterator_sub<dims,stencil_offset_compute<dims,1>>,dtype,prp...>(sub_it,dest);
// Update statistic
sts.incReq();
......@@ -353,7 +359,7 @@ struct unpack_simple_cond<true, prp ...>
* \param vector of requests
*
*/
template<int ... prp> void packRequest(grid_key_dx_iterator_sub<dims> & sub, size_t & req)
template<int ... prp> void packRequest(grid_key_dx_iterator_sub<dims,stencil_offset_compute<dim,1>> & sub, size_t & req)
{
typedef openfpm::vector<typename grid_base_impl<dim,T,S,layout,layout_base>::value_type,ExtPreAlloc<S>,layout,layout_base,openfpm::grow_policy_identity> dtype;
dtype dvect;
......@@ -374,7 +380,7 @@ struct unpack_simple_cond<true, prp ...>
* \param obj object where to unpack
*
*/
template<unsigned int ... prp> void unpack(ExtPreAlloc<S> & mem, grid_key_dx_iterator_sub<dims> & sub_it, Unpack_stat & ps)
template<unsigned int ... prp> void unpack(ExtPreAlloc<S> & mem, grid_key_dx_iterator_sub<dims,stencil_offset_compute<dims,1>> & sub_it, Unpack_stat & ps)
{
// object that store the information in mem
typedef object<typename object_creator<typename grid_base_impl<dim,T,S,layout,layout_base>::value_type::type,prp...>::type> prp_object;
......@@ -390,7 +396,7 @@ struct unpack_simple_cond<true, prp ...>
src.setMemory(ptr);
src.resize(sub_it.getVolume());
unpack_with_iterator<grid_key_dx_iterator_sub<dims>,stype,prp...>(sub_it,src);
unpack_with_iterator<grid_key_dx_iterator_sub<dims,stencil_offset_compute<dims,1>>,stype,prp...>(sub_it,src);
ps.addOffset(size);
}
......@@ -443,7 +449,7 @@ struct unpack_simple_cond<true, prp ...>
typedef encapc<1,prp_object,typename dtype::layout_type > encap_dst;
// Copy only the selected properties
object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(this->get_o(sub_it.get()),dest.get(id));
object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(this->get_o(sub_it.template getStencil<0>()),dest.get(id));
++id;
++sub_it;
......@@ -472,7 +478,7 @@ struct unpack_simple_cond<true, prp ...>
typedef encapc<1,prp_object,typename memory_traits_lin<prp_object>::type > encap_src;
// Copy only the selected properties
object_s_di<encap_src,encap_dst,OBJ_ENCAP,prp...>(src.get(id),this->get_o(sub_it.get()));
object_s_di<encap_src,encap_dst,OBJ_ENCAP,prp...>(src.get(id),this->get_o(sub_it.template getStencil<0>()));
++id;
++sub_it;
......
......@@ -203,6 +203,37 @@ class grid_key_dx_iterator_sub : public grid_key_dx_iterator<dim,stencil>
#endif
}
/*! \brief After incremented we have to check we did not overflo
* any dimension and in case adjust the dimensions
*
*/
inline void post_increment()
{
//! check the overflow of all the index with exception of the last dimensionality
long int i = 0;
for ( ; i < dim-1 ; i++)
{
/* coverity[dead_error_begin] */
size_t id = this->gk.get(i);
if ((long int)id > gk_stop.get(i))
{
// ! overflow, increment the next index
size_t idr = this->gk.get(i) - gk_start.get(i);
this->gk.set_d(i,gk_start.get(i));
id = this->gk.get(i+1);
this->gk.set_d(i+1,id+1);
this->stl_code.adjust_offset(i,idr,grid_base);
}
else
{
break;
}
}
}
public:
/*! \brief Default constructor
......@@ -254,7 +285,7 @@ public:
*
*/
template<typename T> grid_key_dx_iterator_sub(const grid_sm<dim,T> & g, const grid_key_dx<dim> & start, const grid_key_dx<dim> & stop)
: grid_key_dx_iterator<dim>(g),grid_base(g),gk_start(start), gk_stop(stop)
: grid_key_dx_iterator<dim,stencil>(g),grid_base(g),gk_start(start), gk_stop(stop)
{
#ifdef SE_CLASS1
//! If we are on debug check that the stop grid_key id bigger than the start
......@@ -388,7 +419,6 @@ public:
* \return the next grid_key
*
*/
grid_key_dx_iterator_sub<dim,stencil,warn> & operator++()
{
#ifdef SE_CLASS1
......@@ -403,28 +433,26 @@ public:
this->stl_code.increment();
//! check the overflow of all the index with exception of the last dimensionality
post_increment();
long int i = 0;
for ( ; i < dim-1 ; i++)
{
/* coverity[dead_error_begin] */
size_t id = this->gk.get(i);
if ((long int)id > gk_stop.get(i))
{
// ! overflow, increment the next index
return *this;
}
size_t idr = this->gk.get(i) - gk_start.get(i);
this->gk.set_d(i,gk_start.get(i));
id = this->gk.get(i+1);
this->gk.set_d(i+1,id+1);
/*! \brief increment the operator by more than one
*
* \return the next grid_key
*
*/
grid_key_dx_iterator_sub<dim,stencil,warn> & operator+=(int nsteps)
{
#ifdef SE_CLASS1
if (initialized == false)
{std::cerr << "Error: " << __FILE__ << __LINE__ << " using unitialized iterator" << "\n";}
#endif
this->stl_code.adjust_offset(i,idr,grid_base);
}
else
{
break;
}
for (size_t i = 0 ; i < nsteps ; i++)
{
this->operator ++();
}
return *this;
......@@ -437,7 +465,6 @@ public:
* \return true if there is the next, false otherwise
*
*/
inline bool isNext()
{
#ifdef SE_CLASS1
......
......@@ -169,7 +169,7 @@ struct no_stencil
/*! \brief Set the stencil points
*
* \param stencil points
* \param stencil_pnt stencil points
*
*/
template<unsigned int dim2> void set_stencil(const grid_key_dx<dim2> (& stencil_pnt)[1])
......
......@@ -44,6 +44,11 @@ private:
//! Init SFC
bool init_sfc;
/*! \brief Initialize the space-filling-curve
*
* \param pad padding of the cell-list
*
*/
void initialize_sfc(size_t pad)
{
size_t sz[dim];
......@@ -95,8 +100,9 @@ public:
{};
/*! \brief Set the ghost marker
/*! \brief Get the space filling curve object
*
* \return the SFC object
*
*/
const Prock<dim,CellList_gen<dim,T,Prock,Mem_type,transform,base>> & getCellSFC() const
......@@ -105,8 +111,6 @@ public:
}
/*! \brief Initialize Space-filling-curve (SFC)
*
*
*
*/
inline void init_SFC()
......@@ -140,11 +144,9 @@ public:
* \param slot maximum number of slot
*
*/
void Initialize(const Box<dim,T> & box, const size_t (&div)[dim], size_t g_m_new, const size_t pad = 1, size_t slot=STARTING_NSLOT)
void Initialize(const Box<dim,T> & box, const size_t (&div)[dim], const size_t pad = 1, size_t slot=STARTING_NSLOT)
{
CellList<dim,T,Mem_type,transform,base>::Initialize(box,div,pad,slot);
g_m = g_m_new;
}
......
......@@ -56,7 +56,7 @@ public:
/*! \brief Error, no implementation
*
*/
static size_t packRequest(T & obj, size_t & req)
static size_t packRequest(const T & obj, size_t & req)
{
std::cerr << "Error: " << __FILE__ << ":" << __LINE__ << " packing for the type " << demangle(typeid(T).name()) << " is not implemented\n";
return 0;
......@@ -95,7 +95,7 @@ public:
* \param req requests vector
*
*/
static void packRequest(T & obj, size_t & req)
static void packRequest(const T & obj, size_t & req)
{
req += sizeof(T);
}
......@@ -174,7 +174,7 @@ public:
* \param sts pack-stat info
*
*/
static void pack(ExtPreAlloc<Mem> & ext, T & obj, Pack_stat & sts)
static void pack(ExtPreAlloc<Mem> & ext, const T & obj, Pack_stat & sts)
{
#ifdef SE_CLASS1
if (ext.ref() == 0)
......@@ -195,7 +195,7 @@ public:
* \param req requests vector
*
*/
static void packRequest(T & obj,size_t & req)
static void packRequest(const T & obj,size_t & req)
{
req += sizeof(T);
}
......@@ -229,7 +229,7 @@ public:
* \param sts pack-stat info
*
*/
static void pack(ExtPreAlloc<Mem> & ext, T & obj, Pack_stat & sts)
static void pack(ExtPreAlloc<Mem> & ext, const T & obj, Pack_stat & sts)
{
#ifdef DEBUG
if (ext.ref() == 0)
......@@ -250,7 +250,7 @@ public:
* \param req requests vector
*
*/
static void packRequest(T & obj,size_t & req)
static void packRequest(const T & obj,size_t & req)
{
req += sizeof(T);
}
......@@ -299,22 +299,22 @@ class Packer<T,Mem,PACKER_GRID>
{
public:
template<int ... prp> static void packRequest(T & obj, size_t & req)
template<int ... prp> static void packRequest(const T & obj, size_t & req)
{
obj.template packRequest<prp...>(req);
};
template<int ... prp> static void packRequest(T & obj, grid_key_dx_iterator_sub<T::dims> & sub, size_t & req)
template<int ... prp> static void packRequest(T & obj, grid_key_dx_iterator_sub<T::dims,stencil_offset_compute<T::dims,1>> & sub, size_t & req)
{
obj.template packRequest<prp...>(sub, req);
};
template<int ... prp> static void pack(ExtPreAlloc<Mem> & mem, T & obj, Pack_stat & sts)
template<int ... prp> static void pack(ExtPreAlloc<Mem> & mem, const T & obj, Pack_stat & sts)
{
obj.template pack<prp...>(mem, sts);
}
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 pack(ExtPreAlloc<Mem> & mem, T & obj, grid_key_dx_iterator_sub<T::dims,stencil_offset_compute<T::dims,1>> & sub_it, Pack_stat & sts)
{
obj.template pack<prp...>(mem, sub_it, sts);
}
......
......@@ -94,7 +94,11 @@ BOOST_AUTO_TEST_CASE ( packer_unpacker_test )
grid_cpu<3,Point_test<float>> g(sz);
g.setMemory();
fill_grid<3>(g);
grid_key_dx_iterator_sub<3> sub(g.getGrid(),{1,2,3},{5,6,7});
grid_key_dx<3> cnt[1];
cnt[0].zero();
grid_key_dx_iterator_sub<3,stencil_offset_compute<3,1>> sub(g.getGrid(),{1,2,3},{5,6,7},cnt);
// Here we start to push all the allocations required to pack all the data
......@@ -263,7 +267,8 @@ BOOST_AUTO_TEST_CASE ( packer_unpacker_test )
size_t sz2[] = {16,16,16};
grid_cpu<3,Point_test<float>> g_test(sz2);
g_test.setMemory();
grid_key_dx_iterator_sub<3> sub2(g_test.getGrid(),{1,2,3},{5,6,7});
grid_key_dx_iterator_sub<3,stencil_offset_compute<3,1>> sub2(g_test.getGrid(),{1,2,3},{5,6,7},cnt);
Unpacker<grid_cpu<3,Point_test<float>>,HeapMemory>::unpack<pt::x,pt::v>(mem,sub2,g_test,ps);
......
......@@ -272,7 +272,7 @@ struct call_unpack_agg_functor
ExtPreAlloc<Mem> & mem;
//! object to pack
const obj_type & obj;
obj_type & obj;
//! statistic about packing
Unpack_stat & ps;
......@@ -284,7 +284,7 @@ struct call_unpack_agg_functor
* \param ps packing statistic
*
*/
call_unpack_agg_functor(ExtPreAlloc<Mem> & mem, const obj_type & obj, Unpack_stat & ps)
call_unpack_agg_functor(ExtPreAlloc<Mem> & mem, obj_type & obj, Unpack_stat & ps)
:mem(mem), obj(obj), ps(ps)
{
}
......@@ -311,7 +311,7 @@ struct call_aggregateUnpack
* \param ps packing statistic
*
*/
static inline void call_unpack(const obj_type & obj, ExtPreAlloc<Mem> & mem, Unpack_stat & ps)
static inline void call_unpack(obj_type && obj, ExtPreAlloc<Mem> & mem, Unpack_stat & ps)
{
//Property sequence into boost::mpl::range_c or boost::mpl::vector, depending on sizeof...(prp)
typedef typename prp_all_zero<obj_type,sizeof...(prp) == 0,prp...>::type b_prp;
......
......@@ -186,7 +186,7 @@ public:
obj.template unpack<prp...>(mem, ps);
};
template<unsigned int ... prp> static void unpack(ExtPreAlloc<Mem> & mem, grid_key_dx_iterator_sub<T::dims> & sub_it, T & obj, Unpack_stat & ps)
template<unsigned int ... prp> static void unpack(ExtPreAlloc<Mem> & mem, grid_key_dx_iterator_sub<T::dims,stencil_offset_compute<T::dims,1>> & sub_it, T & obj, Unpack_stat & ps)
{
obj.template unpack<prp...>(mem, sub_it, ps);
};
......
......@@ -500,8 +500,13 @@ namespace openfpm
* \param start index from where to start the merging
*
*/
template <template<typename,typename> class op, typename S, typename M, typename gp, unsigned int ...args>
void merge_prp_v(const vector<S,M,typename layout_base<S>::type,layout_base,gp,OPENFPM_NATIVE> & v,
template <template<typename,typename> class op,
typename S,
typename M,
typename gp,
template <typename> class layout_base2,
unsigned int ...args>
void merge_prp_v(const vector<S,M,typename layout_base2<S>::type,layout_base2,gp,OPENFPM_NATIVE> & v,
size_t start)
{
#ifdef SE_CLASS2
......
......@@ -382,7 +382,13 @@ public:
* \param v source vector
*
*/
template <typename S, typename M, typename gp, unsigned int impl, unsigned int ...args> void add_prp(const T & v)
template <typename S,
typename M,
typename gp,
unsigned int impl,
template <typename> class layout_base,
unsigned int ...args>
void add_prp(const T & v)
{
#ifdef SE_CLASS2
check_valid(this,8);
......
......@@ -9,6 +9,7 @@
#define OPENFPM_DATA_SRC_UTIL_AGGREGATE_HPP_
#include <boost/fusion/container/vector.hpp>
#include <Packer_Unpacker/has_pack_agg.hpp>
#ifdef SE_CLASS3
......@@ -41,6 +42,15 @@ struct aggregate
return boost::fusion::at_c<i>(data);
}
/*! \brief it return false if this aggregate has no pointers
*
*
*/
static bool noPointers()
{
return !has_pack_gen<aggregate<list ...>>::value;
}
/*! \brief get the properties i
*
* \return the property i
......@@ -89,6 +99,15 @@ struct aggregate
return boost::fusion::at_c<i>(data);
}
/*! \brief it return false if this aggregate has no pointers
*
*
*/
static bool noPointers()
{
return