Commit 7283b5d5 authored by incardon's avatar incardon

Fixing swap + intrudicting scan coverty compilation

parent 8c0697ce
......@@ -162,27 +162,6 @@ fi
INCLUDES_PATH+="-I. -Iconfig -I../../openfpm_devices/src"
###### Check for memleak check compilation
AC_MSG_CHECKING(whether to build with memory check)
mem_check=no
AC_ARG_ENABLE(memcheck,
AC_HELP_STRING(
[--enable-memcheck],
[enable memory checking (def=no)]
),
mem_check="$enableval"
)
AC_MSG_RESULT($mem_check)
if test x"$mem_check" = x"yes"; then
AC_DEFINE([MEMLEAK_CHECK],[],[Memory check])
fi
####### Checking for GPU support
AX_CUDA
......
......@@ -250,14 +250,16 @@ public:
*/
template<typename S> inline grid_sm(const grid_sm<N,S> & g)
{
// copy all the members
{
box = g.box;
size_tot = g.size_tot;
for (size_t i = 0 ; i < N ; i++)
{sz[i] = g.sz[i]; sz_s[i] = g.sz_s[i];}
}
{
sz[i] = g.sz[i];
sz_s[i] = g.sz_s[i];
}
}
// Static element to calculate total size
......@@ -667,6 +669,33 @@ public:
return grid_key_dx_iterator_sub<N>(*this,start,stop);
}
/*! \brief swap the grid_sm informations
*
* \param g grid to swap
*
*/
inline void swap(grid_sm<N,T> & g)
{
Box<N,size_t> box_t = box;
box = g.box;
g.box = box_t;
size_t tmp = size_tot;
size_tot = g.size_tot;
g.size_tot = tmp;
for (size_t i = 0 ; i < N ; i++)
{
tmp = sz[i];
sz[i] = g.sz[i];
g.sz[i] = tmp;
tmp = sz_s[i];
sz_s[i] = g.sz_s[i];
g.sz_s[i] = tmp;
}
}
//! It simply mean that all the classes grid are friend of all its specialization
template <unsigned int,typename> friend class grid_sm;
};
......
......@@ -981,6 +981,75 @@ BOOST_AUTO_TEST_CASE(grid_operator_equal)
BOOST_REQUIRE_EQUAL(ret,true);
}
/*! \brief Fill twi grid of boxes with data
*
* \param g1 Grid1
* \param g2 Grid2
*
*/
void fill_2_grid_data(grid_cpu<2,Box<2,float>> & g1, grid_cpu<2,Box<2,float>> & g2)
{
typedef Box<2,float> b;
auto it1 = g1.getIterator();
while (it1.isNext())
{
auto key = it1.get();
g1.template get<b::p1>(key)[0] = key.get(0);
g1.template get<b::p2>(key)[1] = key.get(1);
++it1;
}
auto it2 = g2.getIterator();
while (it2.isNext())
{
auto key = it2.get();
g2.template get<b::p1>(key)[0] = key.get(0);
g2.template get<b::p2>(key)[1] = key.get(1);
++it2;
}
}
BOOST_AUTO_TEST_CASE(grid_operator_swap)
{
size_t sz1[] = {16,16};
size_t sz2[] = {5,5};
typedef Box<2,float> b;
grid_cpu<2,Box<2,float>> g1_old(sz1);
g1_old.setMemory();
grid_cpu<2,Box<2,float>> g2_old(sz2);
g2_old.setMemory();
grid_cpu<2,Box<2,float>> g1(sz1);
g1.setMemory();
grid_cpu<2,Box<2,float>> g2(sz2);
g2.setMemory();
fill_2_grid_data(g1_old,g2_old);
fill_2_grid_data(g1,g2);
//! [swap the memory of two grids]
g2.swap(g1);
//! [swap the memory of two grids]
bool ret = (g2 == g1_old);
BOOST_REQUIRE_EQUAL(ret,true);
ret = (g1 == g2_old);
BOOST_REQUIRE_EQUAL(ret,true);
}
BOOST_AUTO_TEST_SUITE_END()
#endif
......@@ -642,8 +642,8 @@ public:
// move the data
data_.swap(grid.data_);
// move the grid info
g1 = grid.g1;
// exghange the grid info
g1.swap(grid.g1);
// exchange the init status
bool exg = is_mem_init;
......
......@@ -368,4 +368,71 @@ public:
template<typename T> const std::string Point_test_prp<T>::attributes::name[] = {"x","y","z","s","v","t"};
template<typename T> class Point_test_scal
{
public:
typedef boost::fusion::vector<T,T,T,T> type;
type data;
static const unsigned int x = 0;
static const unsigned int y = 1;
static const unsigned int z = 2;
static const unsigned int s = 3;
static const unsigned int max_prop = 4;
// Setter method
inline void setx(T x_) {boost::fusion::at_c<0>(data) = x_;};
inline void sety(T y_) {boost::fusion::at_c<1>(data) = y_;};
inline void setz(T z_) {boost::fusion::at_c<2>(data) = z_;};
inline void sets(T s_) {boost::fusion::at_c<3>(data) = s_;};
//! Attributes name
struct attributes
{
static const std::string name[];
};
// getter method
template<unsigned int i> inline typename boost::fusion::result_of::at<type, boost::mpl::int_<i> >::type get() {return boost::fusion::at_c<i>(data);};
//! Default constructor
Point_test_scal()
{}
//! constructor from encapc
template <typename Mem> inline Point_test_scal(const encapc<1,Point_test_scal<T>,Mem> & p)
{
boost::fusion::at_c<0>(data) = p.template get<0>();
boost::fusion::at_c<1>(data) = p.template get<1>();
boost::fusion::at_c<2>(data) = p.template get<2>();
boost::fusion::at_c<3>(data) = p.template get<3>();
}
//! constructor from another point
inline Point_test_scal(const Point_test_scal<T> & p)
{
boost::fusion::at_c<0>(data) = boost::fusion::at_c<0>(p.data);
boost::fusion::at_c<1>(data) = boost::fusion::at_c<1>(p.data);
boost::fusion::at_c<2>(data) = boost::fusion::at_c<2>(p.data);
boost::fusion::at_c<3>(data) = boost::fusion::at_c<3>(p.data);
}
//! constructor from another point
inline Point_test_scal<T> operator= (const Point_test_scal<T> & p)
{
boost::fusion::at_c<0>(data) = boost::fusion::at_c<0>(p.data);
boost::fusion::at_c<1>(data) = boost::fusion::at_c<1>(p.data);
boost::fusion::at_c<2>(data) = boost::fusion::at_c<2>(p.data);
boost::fusion::at_c<3>(data) = boost::fusion::at_c<3>(p.data);
return *this;
}
};
template<typename T> const std::string Point_test_scal<T>::attributes::name[] = {"x","y","z","s"};
#endif
......@@ -41,8 +41,6 @@ struct generate_array_constexpr_impl<T,0,orig_N, F, args...> {
typedef ArrayHolder_constexpr<T,F<0,orig_N>::value, args...> result;
};
#endif
/*! \brief Main class to generate constexpr compile-time array
*
*
......@@ -68,6 +66,8 @@ struct generate_array_constexpr {
typedef typename generate_array_constexpr_impl<T,N-1, N, F>::result result;
};
#endif
//////////////////////////////////////////////////
//! the array itself
......
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