Commit e9617064 authored by incardon's avatar incardon
Browse files

Fixing conflicts

parents 8adda2f7 5f0029a6
......@@ -66,6 +66,11 @@ public:
//! no properties
static const unsigned int max_prop = 0;
static inline bool noPointers()
{
return true;
}
};
template<typename V, typename E,
......@@ -101,12 +106,16 @@ public:
{
boost::fusion::at_c<0>(data) = vid_;
}
;
inline void seteid(size_t eid_)
{
boost::fusion::at_c<1>(data) = eid_;
}
;
static inline bool noPointers()
{
return true;
}
};
class edge_key
......
......@@ -294,7 +294,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));
......@@ -307,7 +308,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));
......
This diff is collapsed.
/*
* copy_grid_unit_test.hpp
*
* Created on: Dec 4, 2017
* Author: i-bird
*/
#ifndef OPENFPM_DATA_SRC_GRID_ITERATORS_COPY_GRID_UNIT_TEST_HPP_
#define OPENFPM_DATA_SRC_GRID_ITERATORS_COPY_GRID_UNIT_TEST_HPP_
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "Grid/map_grid.hpp"
#include "data_type/aggregate.hpp"
#include "Vector/map_vector.hpp"
BOOST_AUTO_TEST_SUITE( copy_grid_test )
template<unsigned int dim, typename grid>
void Test_copy_grid(grid & g_src, grid & g_dst,
Box<dim,size_t> & bsrc_1, Box<dim,size_t> & bdst_1)
{
auto gs1 = g_src.getGrid();
auto gd1 = g_dst.getGrid();
auto it = g_src.getIterator();
grid_key_dx<dim> zero[1];
zero[0].zero();
while (it.isNext())
{
auto key = it.get();
g_src.template get<0>(key) = gs1.LinId(key);
++it;
}
copy_grid_fast<false,
dim,
grid_cpu<dim,aggregate<double>>,
grid_sm<dim,aggregate<double>>>::copy(gs1,gd1,
bsrc_1,bdst_1,
g_src,g_dst,
zero);
// Check
bool match = true;
grid_key_dx_iterator_sub<dim, no_stencil> its(gs1,bsrc_1.getKP1(), bsrc_1.getKP2());
grid_key_dx_iterator_sub<dim, no_stencil> itd(gd1,bdst_1.getKP1(), bdst_1.getKP2());
while (its.isNext())
{
auto key_s = its.get();
auto key_d = itd.get();
match &= g_src.template get<0>(key_s) == g_dst.template get<0>(key_d);
++its;
++itd;
}
BOOST_REQUIRE_EQUAL(match,true);
}
template<unsigned int dim, typename grid>
void Test_copy_grid_cmp(grid & g_src, grid & g_dst,
Box<dim,size_t> & bsrc_1, Box<dim,size_t> & bdst_1)
{
auto gs1 = g_src.getGrid();
auto gd1 = g_dst.getGrid();
auto it = g_src.getIterator();
grid_key_dx<dim> zero[1];
zero[0].zero();
while (it.isNext())
{
auto key = it.get();
for (size_t k = 0 ; k < (size_t)gs1.LinId(key) % 4 ; k++)
{
g_src.template get<0>(key).add(gs1.LinId(key) + 1);
}
++it;
}
copy_grid_fast<true,
dim,
grid_cpu<dim,aggregate<openfpm::vector<double>>>,
grid_sm<dim,aggregate<openfpm::vector<double>>>>::copy(gs1,gd1,
bsrc_1,bdst_1,
g_src,g_dst,
zero);
// Check
bool match = true;
grid_key_dx_iterator_sub<dim, no_stencil> its(gs1,bsrc_1.getKP1(), bsrc_1.getKP2());
grid_key_dx_iterator_sub<dim, no_stencil> itd(gd1,bdst_1.getKP1(), bdst_1.getKP2());
while (its.isNext())
{
auto key_s = its.get();
auto key_d = itd.get();
match &= g_src.template get<0>(key_s).size() == g_dst.template get<0>(key_d).size();
for (size_t i = 0 ; i < g_dst.template get<0>(key_d).size() ; i++)
{
match &= g_src.template get<0>(key_s).get(i) == g_dst.template get<0>(key_d).get(i);
}
++its;
++itd;
}
BOOST_REQUIRE_EQUAL(match,true);
}
BOOST_AUTO_TEST_CASE( copy_grid_test_use)
{
{
size_t sz1[1] = {37};
size_t sz2[2] = {37,37};
size_t sz3[3] = {37,37,37};
size_t sz4[4] = {37,37,37,37};
grid_cpu<1,aggregate<double>> g1_src(sz1);
grid_cpu<1,aggregate<double>> g1_dst(sz1);
grid_cpu<2,aggregate<double>> g2_src(sz2);
grid_cpu<2,aggregate<double>> g2_dst(sz2);
grid_cpu<3,aggregate<double>> g3_src(sz3);
grid_cpu<3,aggregate<double>> g3_dst(sz3);
grid_cpu<4,aggregate<double>> g4_src(sz4);
grid_cpu<4,aggregate<double>> g4_dst(sz4);
g1_src.setMemory();
g1_dst.setMemory();
g2_src.setMemory();
g2_dst.setMemory();
g3_src.setMemory();
g3_dst.setMemory();
g4_src.setMemory();
g4_dst.setMemory();
// fill all grids
Box<1,size_t> bsrc_1({4},{11});
Box<1,size_t> bdst_1{{20},{27}};
Test_copy_grid(g1_src,g1_dst,bsrc_1,bdst_1);
Box<2,size_t> bsrc_2({4,7},{11,20});
Box<2,size_t> bdst_2({20,5},{27,18});
Test_copy_grid(g2_src,g2_dst,bsrc_2,bdst_2);
Box<3,size_t> bsrc_3({4,7,1},{11,20,6});
Box<3,size_t> bdst_3({20,5,10},{27,18,15});
Test_copy_grid(g3_src,g3_dst,bsrc_3,bdst_3);
#ifdef SE_CLASS1
Box<4,size_t> bsrc_4({4,7,1,3},{11,20,6,6});
Box<4,size_t> bdst_4({20,5,10,13},{27,18,15,16});
Test_copy_grid(g4_src,g4_dst,bsrc_4,bdst_4);
#else
Box<4,size_t> bsrc_4({4,7,1,3},{11,20,6,6});
Box<4,size_t> bdst_4({20,5,10,13},{27,18,15,16});
Test_copy_grid(g4_src,g4_dst,bsrc_4,bdst_4);
#endif
}
///////////
{
size_t sz1[1] = {37};
size_t sz2[2] = {37,37};
size_t sz3[3] = {37,37,37};
size_t sz4[4] = {37,37,37,37};
grid_cpu<1,aggregate<openfpm::vector<double>>> g1_src(sz1);
grid_cpu<1,aggregate<openfpm::vector<double>>> g1_dst(sz1);
grid_cpu<2,aggregate<openfpm::vector<double>>> g2_src(sz2);
grid_cpu<2,aggregate<openfpm::vector<double>>> g2_dst(sz2);
grid_cpu<3,aggregate<openfpm::vector<double>>> g3_src(sz3);
grid_cpu<3,aggregate<openfpm::vector<double>>> g3_dst(sz3);
grid_cpu<4,aggregate<openfpm::vector<double>>> g4_src(sz4);
grid_cpu<4,aggregate<openfpm::vector<double>>> g4_dst(sz4);
g1_src.setMemory();
g1_dst.setMemory();
g2_src.setMemory();
g2_dst.setMemory();
g3_src.setMemory();
g3_dst.setMemory();
g4_src.setMemory();
g4_dst.setMemory();
// fill all grids
Box<1,size_t> bsrc_1({4},{11});
Box<1,size_t> bdst_1{{20},{27}};
Test_copy_grid_cmp(g1_src,g1_dst,bsrc_1,bdst_1);
Box<2,size_t> bsrc_2({4,7},{11,20});
Box<2,size_t> bdst_2({20,5},{27,18});
Test_copy_grid_cmp(g2_src,g2_dst,bsrc_2,bdst_2);
#ifndef SE_CLASS2
Box<3,size_t> bsrc_3({4,7,1},{11,20,6});
Box<3,size_t> bdst_3({20,5,10},{27,18,15});
Test_copy_grid_cmp(g3_src,g3_dst,bsrc_3,bdst_3);
#ifdef SE_CLASS1
Box<4,size_t> bsrc_4({4,7,1,3},{7,14,6,6});
Box<4,size_t> bdst_4({20,5,10,13},{23,12,15,16});
Test_copy_grid_cmp(g4_src,g4_dst,bsrc_4,bdst_4);
#else
Box<4,size_t> bsrc_4({4,7,1,3},{11,20,6,6});
Box<4,size_t> bdst_4({20,5,10,13},{27,18,15,16});
Test_copy_grid_cmp(g4_src,g4_dst,bsrc_4,bdst_4);
#endif
#endif
}
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* OPENFPM_DATA_SRC_GRID_ITERATORS_COPY_GRID_UNIT_TEST_HPP_ */
......@@ -163,6 +163,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
......@@ -173,6 +178,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);
}
};
......@@ -288,26 +298,26 @@ struct mem_getpointer<data_type,layout,1>
template<typename data_type, typename Mem_type, typename layout, unsigned int sel = 2*is_layout_mlin<layout>::value + is_layout_inte<layout>::value>
struct mem_setmemory
{
template<unsigned int d> static void setMemory(data_type & data_, Mem_type & m, size_t sz)
template<unsigned int d> static void setMemory(data_type & data_, Mem_type & m, size_t sz, bool np)
{
//! Create and set the memory allocator
data_.setMemory(m);
//! Allocate the memory and create the reppresentation
if (sz != 0) data_.allocate(sz);
if (sz != 0) data_.allocate(sz,np);
}
};
template<typename data_type, typename Mem_type, typename layout>
struct mem_setmemory<data_type,Mem_type,layout,1>
{
template<unsigned int p> static void setMemory(data_type & data_, Mem_type & m, size_t sz)
template<unsigned int p> static void setMemory(data_type & data_, Mem_type & m, size_t sz,bool np)
{
//! Create and set the memory allocator
boost::fusion::at_c<p>(data_).setMemory(m);
//! Allocate the memory and create the reppresentation
if (sz != 0) boost::fusion::at_c<p>(data_).allocate(sz);
if (sz != 0) boost::fusion::at_c<p>(data_).allocate(sz,np);
}
};
......
......@@ -52,6 +52,9 @@ struct ite_gpu
};
#endif
#include "copy_grid_fast.hpp"
/*! \brief
*
* Implementation of a N-dimensional grid
......@@ -178,6 +181,23 @@ private:
}
}
/*! \brief Check that the key is inside the grid
*
* check if key2 is inside the g grid boundary
*
* \param g grid
* \param key2
*
*/
template<typename Mem> inline void check_bound(const grid_base_impl<dim,T,Mem,layout,layout_base> & g,const size_t & key2) const
{
if (key2 >= g.getGrid().size())
{
std::cerr << "Error " __FILE__ << ":" << __LINE__ <<" grid overflow " << key2 << " >= " << getGrid().size() << "\n";
ACTION_ON_ERROR(GRID_ERROR_OBJECT);
}
}
#endif
public:
......@@ -501,7 +521,7 @@ public:
//! Allocate the memory and create the reppresentation
// if (g1.size() != 0) data_.allocate(g1.size());
mem_setmemory<decltype(data_),S,layout_base<T>>::template setMemory<p>(data_,m,g1.size());
mem_setmemory<decltype(data_),S,layout_base<T>>::template setMemory<p>(data_,m,g1.size(),T::noPointers);
is_mem_init = true;
}
......@@ -667,6 +687,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
......@@ -882,7 +948,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);
......@@ -981,6 +1073,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
......
......@@ -80,7 +80,7 @@ public:
__device__ __host__ inline grid_key_dx(const long int (&k)[dim])
{
for (size_t i = 0 ; i < dim ; i++)
this->k[i] = k[i];
{this->k[i] = k[i];}
}
/*! \brief Construct a grid key from a list of numbers
......@@ -104,7 +104,7 @@ public:
{
#ifdef SE_CLASS1
if (sizeof...(t) != dim -1)
std::cerr << "Error grid_key: " << __FILE__ << " " << __LINE__ << " creating a key of dimension " << dim << " require " << dim << " numbers " << sizeof...(t) + 1 << " provided" << "\n";
{std::cerr << "Error grid_key: " << __FILE__ << " " << __LINE__ << " creating a key of dimension " << dim << " require " << dim << " numbers " << sizeof...(t) + 1 << " provided" << "\n";}
#endif
k[dim-1] = v;
invert_assign(t...);
......@@ -310,7 +310,8 @@ public:
* \param t list of number
*
*/
template<typename a, typename ...T>void set(a v, T...t)
template<typename a, typename ...T>
inline void set(a v, T...t)
{
#ifdef SE_CLASS1
if (sizeof...(t) != dim -1)
......@@ -320,6 +321,16 @@ public:
invert_assign(t...);
}
/*! \brief Return the internal k structure
*
* \return k
*
*/
const long int(& get_k() const)[dim]
{
return k;
}
/*! \brief Convert to a point the grid_key_dx
*
* \see toPoint
......@@ -376,7 +387,7 @@ public:
* \return the index value
*
*/
mem_id value(size_t i) const
inline mem_id value(size_t i) const
{
return k[i];
}
......@@ -413,11 +424,11 @@ public:
k[i] = id;
}
private:
//! structure that store all the index
index_type k[dim];
private:
/*! \brief Recursively invert the assignment
*
* Recursively invert the assignment at compile-time (hopefully)
......
......@@ -51,7 +51,20 @@ struct pack_simple_cond
auto it = obj.getIterator();
obj.pack_with_iterator<decltype(it),dtype,prp...>(it,dest);
// copy all the object in the send buffer
typedef encapc<dims,value_type,layout > encap_src;
// destination object type
typedef encapc<1,prp_object,typename dtype::layout_type > encap_dst;
pack_with_iterator<!is_contiguos<prp...>::type::value || has_pack_gen<prp_object>::value,
dim,
decltype(obj),
encap_src,
encap_dst,
typename grid_base_impl<dim,T,S,layout,layout_base>::value_type::type,
decltype(it),
dtype,
prp...>::pack(obj,it,dest);
// Update statistic
sts.incReq();
......@@ -140,7 +153,20 @@ struct unpack_simple_cond
auto it = obj.getIterator();
obj.unpack_with_iterator<decltype(it),stype,prp...>(it,src);
// copy all the object in the send buffer
typedef encapc<dim,grid_base_impl<dim,T,S,layout,layout_base>::value_type,layout > encap_dst;
// destination object type
typedef encapc<1,prp_object,typename memory_traits_lin<prp_object>::type > encap_src;
unpack_with_iterator<dim,