Commit ce09322b authored by incardon's avatar incardon

Fixing bug and removed warnings

parent 178d18b2
......@@ -7,7 +7,7 @@ AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
AC_CANONICAL_SYSTEM
AC_CONFIG_SRCDIR([src/main.cpp])
AM_INIT_AUTOMAKE
AC_CONFIG_HEADER([src/config.h])
AC_CONFIG_HEADER([src/config/config.h])
m4_ifdef([MYSQL_FOUND],,[m4_include([m4/ax_lib_mysql.m4])])
m4_ifdef([AX_CHECK_COMPILER_FLAGS],,[m4_include([m4/ax_check_compiler_flags.m4])])
m4_ifdef([ACX_PTHREAD],,[m4_include([m4/acx_pthread.m4])])
......@@ -65,9 +65,9 @@ fi
AC_MSG_CHECKING(whether to build with memory check)
mem_check=no
AC_ARG_ENABLE(memorycheck,
AC_ARG_ENABLE(memcheck,
AC_HELP_STRING(
[--enable-memorycheck],
[--enable-memcheck],
[enable memory checking (def=no)]
),
mem_check="$enableval"
......@@ -82,7 +82,7 @@ fi
####### include OpenFPM_devices include path
INCLUDES_PATH+="-I. -I../../OpenFPM_devices/src"
INCLUDES_PATH+="-I. -Iconfig -I../../OpenFPM_devices/src"
####### Checking for GPU support
......
......@@ -166,8 +166,6 @@ BOOST_AUTO_TEST_CASE( graph_use)
// Check that each vertex has 2 child
size_t start = 0;
for (size_t i = 0 ; i < g_no_edge.getNVertex() ; i++)
{
if (g_no_edge.getNChilds(i) == 0)
......
......@@ -486,9 +486,7 @@ public:
return v.template get<i>(id);
}
/*! \brief operator to access the vertex
*
* operator to access the vertex
/*! \brief Function to access the vertexes
*
*
* \param i property to access
......@@ -500,9 +498,7 @@ public:
return v.template get<i>(id);
}
/*! \brief operator to access the vertex
*
* operator to access the vertex
/*! \brief Function to access the vertexes
*
* \param id of the vertex to access
*
......
......@@ -77,25 +77,22 @@ public:
:data(data)
{}
/*! \brief access the data
/*! \brief Return the address of the base
*
* \return the reference
* \return the address of the data encapsulated
*
*/
template <unsigned int p> typename type_cpu_prop<p,T>::type get()
type * operator&()
{
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data),sizeof(typename type_cpu_prop<p,T>::type));
#endif
return boost::fusion::at_c<p>(data);
return &data;
}
/*! \brief access the data but return a constant reference
/*! \brief access the data
*
* \return the reference
*
*/
template <unsigned int p> const typename type_cpu_prop<p,T>::type get() const
template <unsigned int p> typename type_cpu_prop<p,T>::type get()
{
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data),sizeof(typename type_cpu_prop<p,T>::type));
......@@ -103,12 +100,12 @@ public:
return boost::fusion::at_c<p>(data);
}
/*! \brief Get the data
/*! \brief access the data but return a constant reference
*
* \return the data
* \return the reference
*
*/
template <unsigned int p> typename boost::remove_reference<typename type_cpu_prop<p,T>::type>::type get() const
template <unsigned int p> const typename type_cpu_prop<p,T>::type get() const
{
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data),sizeof(typename type_cpu_prop<p,T>::type));
......@@ -182,9 +179,6 @@ public:
// access the data
template <unsigned int p> typename type_gpu_prop<p,T>::type::reference get()
{
#ifdef MEMLEAK_CHECK
check_valid(&boost::fusion::at_c<p>(data.mem_r->operator[](g1.LinId(k))));
#endif
return boost::fusion::at_c<p>(data).mem_r->operator[](g1.LinId(k));
}
};
......
This diff is collapsed.
......@@ -29,6 +29,64 @@
#include "memory_c.hpp"
#include <vector>
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
* element of the boost::vector the operator() is called.
* Is mainly used to copy one object into one target
* grid element in a generic way for a
* generic object T with variable number of property
*
* \tparam dim Dimensionality
* \tparam S type of grid
* \tparam Memory type of memory needed for encap
*
*/
template<unsigned int dim, typename S, typename Memory>
struct copy_cpu_encap
{
//! size to allocate
grid_key_dx<dim> & key;
//! grid where we have to store the data
S & grid_dst;
//! type of the object we have to set
typedef typename S::type obj_type;
//! type of the object boost::sequence
typedef typename S::type::type ov_seq;
//! object we have to store
const encapc<1,obj_type,Memory> & obj;
/*! \brief constructor
*
* It define the copy parameters.
*
* \param key which element we are modifying
* \param grid_src grid we are updating
* \param obj object we have to set in grid_src
*
*/
copy_cpu_encap(grid_key_dx<dim> & key, S & grid_dst, const encapc<1,obj_type,Memory> & obj)
:key(key),grid_dst(grid_dst),obj(obj){};
//! It call the copy function for each property
template<typename T>
void operator()(T& t) const
{
// This is the type of the object we have to copy
typedef typename boost::fusion::result_of::at_c<ov_seq,T::value>::type copy_type;
// Remove the reference from the type to copy
typedef typename boost::remove_reference<copy_type>::type copy_rtype;
meta_copy<copy_rtype> cp(obj.template get<T::value>(),grid_dst.template get<T::value>(key));
}
};
/*! \brief this class is a functor for "for_each" algorithm
*
* This class is a functor for "for_each" algorithm. For each
......@@ -221,8 +279,7 @@ class grid_cpu
//! This is an header that store all information related to the grid
grid_sm<dim,T> g1;
//! This is the interface to allocate an resize memory
//! and give also a representation to the allocated memory
//! Memory layout specification + memory chunk pointer
Mem data;
/*! \brief Get 1D vector with the
......@@ -361,7 +418,7 @@ class grid_cpu
*
* Create the object that provide memory
*
* \param T memory
* \tparam S memory type to allocate
*
*/
......@@ -374,6 +431,25 @@ class grid_cpu
data.allocate(g1.size());
}
/*! \brief Get the object that provide memory
*
* Create the object that provide memory
*
* \tparam S memory type
*
* \param m external memory allocator
*
*/
template<typename S> void setMemory(S & m)
{
//! Create and set the memory allocator
data.setMemory(m);
//! Allocate the memory and create the reppresentation
data.allocate(g1.size());
}
/*! \brief Return a plain pointer to the internal data
*
* Return a plain pointer to the internal data
......@@ -489,7 +565,7 @@ class grid_cpu
inline encapc<dim,T,Mem> get_o(const grid_key_dx<dim> & v1)
{
#ifdef MEMLEAK_CHECK
check_valid(&data.mem_r->operator[](g1.LinId(v1)),sizeof(typename type_cpu_prop<p,T>::type));
check_valid(&data.mem_r->operator[](g1.LinId(v1)),sizeof(T));
#endif
return encapc<dim,T,Mem>(data.mem_r->operator[](g1.LinId(v1)));
}
......@@ -602,6 +678,36 @@ class grid_cpu
swap(grid);
}
/*! \brief set an element of the grid
*
* set an element of the grid
*
* \param dx is the grid key or the position to set
* \param obj value to set
*
*/
template<typename Memory> inline void set(grid_key_dx<dim> dx, const encapc<1,T,Memory> & obj)
{
#ifdef DEBUG
// Check that the element exist
for (int i = 0 ; i < dim ; i++)
{
if (dx.get(i) >= g1.size(i))
{
std::cerr << "Error: " << __FILE__ << " " << __LINE__ << " out of bound" << "\n";
}
}
#endif
// create the object to copy the properties
copy_cpu_encap<dim,grid_cpu<dim,T,Mem>,Mem> cp(dx,*this,obj);
// copy each property
boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(cp);
}
/*! \brief set an element of the grid
*
* set an element of the grid
......@@ -620,7 +726,7 @@ class grid_cpu
{
if (dx.get(i) >= g1.size(i))
{
std::cerr << "Error map_grid.hpp: out of bound" << "\n";
std::cerr << "Error: " << __FILE__ << " " << __LINE__ << " out of bound" << "\n";
}
}
#endif
......
#include "config.h"
#include "Memleak_check.hpp"
#ifdef MEMLEAK_CHECK
// counter for allocation of new memory
/*size_t new_data;
size_t new_data;
// counter to delete memory
size_t delete_data;
// structure that store all the active pointer
std::map<byte_ptr, size_t> active_ptr;*/
std::map<byte_ptr, size_t> active_ptr;
#endif
#include "config.h"
#include <iostream>
#include <map>
......@@ -17,121 +18,103 @@ extern std::map<byte_ptr,size_t> active_ptr;
* \param pointer to check and remove
*
*/
//static void remove_ptr(void * ptr)
//{
// // Check if the pointer exist
// std::map<byte_ptr, size_t>::iterator it = active_ptr.find((byte_ptr)ptr);
//
// // if the element does not exist, print that something wrong happened and return
// if ( it == active_ptr.end() )
// {
// std::cout << "ERROR POINTER NOT FOUND " << ptr << "\n";
// return;
// }
//
// // erase the pointer
// active_ptr.erase((byte_ptr)ptr);
//}
//
///*! \brief Print all active pointer
// *
// * Print all active pointer
// *
// */
//static void print_unalloc()
//{
// for (std::map<byte_ptr,size_t>::iterator it = active_ptr.begin(); it != active_ptr.end(); ++it)
// {
// std::cout << "Unallocated memory " << it->first << " size " << it->second << "\n";
// }
//}
//
//
///*! \brief Add the new allocated active pointer
// *
// * Add the new allocated active pointer
// *
// * \param new data active pointer
// * \param sz size of the new allocated memory
// *
// */
//static void check_new(void * data, size_t sz)
//{
// // Add a new pointer
// new_data++;
// active_ptr[(byte_ptr)data] = sz;
// std::cout << "New data: " << new_data << " " << data << "\n";
//}
//
///*! \brief check and delete a pointer
// *
// * check and delete a pointer from the list of active pointers
// *
// * \param pointer data
// *
// */
//static void check_delete(void * data)
//{
// // Delete the pointer
// delete_data++;
// remove_ptr(data);
// std::cout << "Delete data: " << delete_data << " " << data << "\n";
//}
//
///*! \brief check if the access is valid
// *
// * check if the access is valid
// *
// * \param ptr pointer we are going to access
// * \param size_access is the size in byte of the data we are fetching
// *
// */
//static void check_valid(void * ptr, size_t size_access)
//{
// // get the lower bound
//
// std::map<byte_ptr, size_t>::iterator l_b = active_ptr.upper_bound((byte_ptr)ptr);
//
// //! subtract one
// l_b--;
//
// // if where is not memory that satisfy the request
// if (l_b == active_ptr.end())
// {
// std::cout << "Error invalid pointer: " << ptr << "\n";
// return;
// }
//
// // check if ptr is in the range
//
// size_t sz = l_b->second;
//
// if (((unsigned char *)l_b->first) + sz < ((unsigned char *)ptr) + size_access)
// {
// std::cout << "Error invalid pointer: " << ptr << "\n";
// }
//}
#else
static void remove_ptr(void * ptr)
{
// Check if the pointer exist
std::map<byte_ptr, size_t>::iterator it = active_ptr.find((byte_ptr)ptr);
// if the element does not exist, print that something wrong happened and return
if ( it == active_ptr.end() )
{
std::cout << "ERROR POINTER NOT FOUND " << ptr << "\n";
return;
}
// erase the pointer
active_ptr.erase((byte_ptr)ptr);
}
/*! \brief Print all active pointer
*
* Print all active pointer
*
*/
static void print_unalloc()
{
for (std::map<byte_ptr,size_t>::iterator it = active_ptr.begin(); it != active_ptr.end(); ++it)
{
std::cout << "Unallocated memory " << it->first << " size " << it->second << "\n";
}
}
static void check_new(void * ptr)
/*! \brief Add the new allocated active pointer
*
* Add the new allocated active pointer
*
* \param new data active pointer
* \param sz size of the new allocated memory
*
*/
static void check_new(void * data, size_t sz)
{
// Add a new pointer
new_data++;
active_ptr[(byte_ptr)data] = sz;
std::cout << "New data: " << new_data << " " << data << "\n";
}
static void check_delete(void * ptr)
/*! \brief check and delete a pointer
*
* check and delete a pointer from the list of active pointers
*
* \param pointer data
*
*/
static void check_delete(void * data)
{
// Delete the pointer
delete_data++;
remove_ptr(data);
std::cout << "Delete data: " << delete_data << " " << data << "\n";
}
static void check_valid(void * ptr)
/*! \brief check if the access is valid
*
* check if the access is valid
*
* \param ptr pointer we are going to access
* \param size_access is the size in byte of the data we are fetching
*
*/
static void check_valid(void * ptr, size_t size_access)
{
// get the lower bound
std::map<byte_ptr, size_t>::iterator l_b = active_ptr.upper_bound((byte_ptr)ptr);
//! subtract one
l_b--;
// if there is no memory that satisfy the request
if (l_b == active_ptr.end())
{
std::cout << "Error invalid pointer: " << __FILE__ << " " << __LINE__ << " " << ptr << "\n";
return;
}
// check if ptr is in the range
size_t sz = l_b->second;
if (((unsigned char *)l_b->first) + sz < ((unsigned char *)ptr) + size_access)
{
std::cout << "Error invalid pointer: " << __FILE__ << " " << __LINE__ << " " << ptr << "\n";
}
}
#else
#endif
......@@ -8,6 +8,7 @@
#ifndef CELLLISTSTANDARD_HPP_
#define CELLLISTSTANDARD_HPP_
#include "CellDecomposer.hpp"
#include "Space/SpaceBox.hpp"
#include "mathutil.hpp"
#include "CellNNIterator.hpp"
......@@ -51,7 +52,7 @@
*
*/
template<unsigned int dim, typename T, typename base>
class CellList<dim,T,FAST,base>
class CellList<dim,T,FAST,base> : public CellDecomposer_sm<dim,T>
{
// The array contain the neighborhood of the cell-id in case of asymmetric interaction
//
......@@ -75,9 +76,6 @@ class CellList<dim,T,FAST,base>
//
long int NNc_cr[openfpm::math::pow(2,dim)];
// Total number of cell
size_t tot_n_cell;
// Number of slot for each cell
size_t slot;
......@@ -88,15 +86,6 @@ class CellList<dim,T,FAST,base>
// of elements == slot )
base cl_base;
// Domain of the cell list
SpaceBox<dim,T> box;
// Unit box of the Cell list
SpaceBox<dim,T> box_unit;
// Grid structure of the Cell list
grid_sm<dim,void> gr_cell;
//Origin point
Point<dim,T> orig;
......@@ -107,7 +96,7 @@ class CellList<dim,T,FAST,base>
// Create a cell-list with double of the slots
CellList cl_tmp(box,gr_cell.getSize(),orig,slot*2);
CellList cl_tmp(this->box,this->gr_cell.getSize(),orig,slot*2);
// copy cl_base
......@@ -134,26 +123,16 @@ public:
*
*/
CellList(SpaceBox<dim,T> & box, size_t (&div)[dim], Point<dim,T> & orig, size_t slot=16)
:slot(slot),box(box),gr_cell(div),orig(orig)
:CellDecomposer_sm<dim,T>(box,div),slot(slot),orig(orig)
{
tot_n_cell = 1;
// Total number of cells and calculate the unt cell size
for (size_t i = 0 ; i < dim ; i++)
{
tot_n_cell *= div[i];
box_unit.setHigh(i,box.getHigh(i) / div[i]);
}
// create the array that store the number of particle on each cell and se it to 0
cl_n.resize(tot_n_cell);
cl_n.resize(this->tot_n_cell);
cl_n.fill(0);
// create the array that store the cell id
cl_base.resize(tot_n_cell * slot);
cl_base.resize(this->tot_n_cell * slot);
// Calculate the NNc_full array, it is a structure to get the neighborhood array
......@@ -165,15 +144,15 @@ public:
// Generate the sub-grid iterator
grid_key_dx_iterator_sub<dim> gr_sub3(gr_cell,NNzero::data,NNtwo::data);
grid_key_dx_iterator_sub<dim> gr_sub3(this->gr_cell,NNzero::data,NNtwo::data);
// Calculate the NNc array
size_t middle = gr_cell.LinId(NNone::data);
size_t middle = this->gr_cell.LinId(NNone::data);
size_t i = 0;
while (gr_sub3.isNext())
{
NNc_full[i] = (long int)gr_cell.LinId(gr_sub3.get()) - middle;
NNc_full[i] = (long int)this->gr_cell.LinId(gr_sub3.get()) - middle;
++gr_sub3;
i++;
......@@ -187,7 +166,7 @@ public:
{
auto key = gr_sub3.get();
size_t lin = gr_cell.LinId(key);
size_t lin = this->gr_cell.LinId(key);
// Only the first half is considered
if (lin < middle)
......@@ -205,13 +184,13 @@ public:
// Calculate the NNc_cross array
i = 0;
grid_key_dx_iterator_sub<dim> gr_sub2(gr_cell,NNzero::data,NNone::data);
grid_key_dx_iterator_sub<dim> gr_sub2(this->gr_cell,NNzero::data,NNone::data);
while (gr_sub2.isNext())
{
auto key = gr_sub2.get();
NNc_cr[i] = (long int)gr_cell.LinId(key);
NNc_cr[i] = (long int)this->gr_cell.LinId(key);
++gr_sub2;
i++;
......@@ -228,7 +207,7 @@ public:
{
// calculate the Cell id
size_t cell_id = getCell(pos);
size_t cell_id = this->getCell(pos);
// Get the number of element the cell is storing
......@@ -255,7 +234,7 @@ public:
{
// calculate the Cell id
size_t cell_id = getCell(pos);
size_t cell_id = this->getCell(pos);
// Get the number of element the cell is storing
......@@ -283,52 +262,6 @@ public:
cl_n.get(cell)--;
}
/*! \brief Get the cell-id
*
* Convert the point coordinates into the cell id
*
* \param pos Point position
*