Commit 6828c5f5 authored by incardon's avatar incardon

Fix for pdata

parent 9711f54c
......@@ -108,6 +108,8 @@ fi
# Set this conditional if cuda is wanted
#
AM_CONDITIONAL(BUILDCUDA, test ! x$NVCC = x"no")
###########################
......
......@@ -69,6 +69,17 @@ public:
}
}
/* \brief Set to invalid the key
*
*
*/
inline void invalid()
{
for (int i = 0 ; i < dim ; i++)
{
k[i] = -1;
}
}
/* \brief sum an a combination to the grid_key
*
......
#include "Memleak_check.hpp"
// 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;*/
......@@ -17,100 +17,100 @@ 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";
}
}
//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
......
/*
* graph_unit_test.hpp
*
* Created on: Nov 22, 2014
* Author: i-bird
*/
#ifndef GRAPH_UNIT_TEST_HPP_
#define GRAPH_UNIT_TEST_HPP_
#include "map_graph.hpp"
#include "Point_test.hpp"
#define GS_SIZE 128
BOOST_AUTO_TEST_SUITE( graph_test )
BOOST_AUTO_TEST_CASE( graph_use)
{
std::cout << "Graph unit test start" << "\n";
typedef Point_test<float> V;
typedef Point_test<float> E;
// Point
Point_test<float> p;
p.setx(1.0);
p.sety(2.0);
p.setz(3.0);
p.sets(4.0);
p.get<V::v>()[0] = 1.0;
p.get<V::v>()[1] = 2.0;
p.get<V::v>()[2] = 7.0;
p.get<V::t>()[0][0] = 10.0;
p.get<V::t>()[0][1] = 13.0;
p.get<V::t>()[0][2] = 8.0;
p.get<V::t>()[1][0] = 19.0;
p.get<V::t>()[1][1] = 23.0;
p.get<V::t>()[1][2] = 5.0;
p.get<V::t>()[2][0] = 4.0;
p.get<V::t>()[2][1] = 3.0;
p.get<V::t>()[2][2] = 11.0;
//! define a test graph where the vertex and edge store several scalar vectorial and tensorial quantities
Graph_CSR<V,E> g;
//! Create a point
//! try to construct a 2D dimensional cartesian graph
// first create the vertex
for (size_t i = 0 ; i < GS_SIZE ; i++)
{
for (size_t j = 0 ; j < GS_SIZE ; j++)
{
// Add vertex
g.addVertex(p);
}
}
// than create the edge
// Create a grid, // NOTE this does not produce any memory grid, it retain only the information
// and give a set of usefull function
std::vector<size_t> gs;
gs.push_back(GS_SIZE);
gs.push_back(GS_SIZE);
grid<2,void> g2(gs);
// Create the edge 4 for each vertex
for (size_t i = 0 ; i < GS_SIZE ; i++)
{
for (size_t j = 0 ; j < GS_SIZE ; j++)
{
// Add 4 edge
g.addEdge<CheckExistence>(g2.LinId(i,j),g2.LinId(i+1,j),p);
g.addEdge<CheckExistence>(g2.LinId(i,j),g2.LinId(i,j+1),p);
g.addEdge<CheckExistence>(g2.LinId(i,j),g2.LinId(i-1,j),p);
g.addEdge<CheckExistence>(g2.LinId(i,j),g2.LinId(i,j-1),p);
}
}
// Test if duplicate work
Graph_CSR<V,E> g_dup = g.duplicate();
// check if the two graph matches
for (size_t i = 0 ; i < g.getNVertex() ; i++)
{
BOOST_REQUIRE_EQUAL(g.vertex(i).template get<V::x>(),g_dup.vertex(i).template get<V::x>());
BOOST_REQUIRE_EQUAL(g.vertex(i).template get<V::y>(),g_dup.vertex(i).template get<V::y>());
BOOST_REQUIRE_EQUAL(g.vertex(i).template get<V::z>(),g_dup.vertex(i).template get<V::z>());
BOOST_REQUIRE_EQUAL(g.vertex(i).template get<V::s>(),g_dup.vertex(i).template get<V::s>());
for (int j = 0 ; j < 3 ; j++)
{
BOOST_REQUIRE_EQUAL(g.vertex(i).template get<V::v>()[j],g_dup.vertex(i).template get<V::v>()[j]);
}
for (int j = 0 ; j < 3 ; j++)
{
for (int k = 0 ; k < 3 ; k++)
{
BOOST_REQUIRE_EQUAL(g.vertex(i).template get<V::t>()[j][k],g_dup.vertex(i).template get<V::t>()[j][k]);
}
}
}
std::cout << "Graph unit test end" << "\n";
}
BOOST_AUTO_TEST_SUITE_END()
#endif /* GRAPH_UNIT_TEST_HPP_ */
......@@ -12,14 +12,14 @@
#include "memory/HeapMemory.hpp"
#include "memory_conf.hpp"
#include "Grid/map_grid.hpp"
#include "map_vector.hpp"
#include "map_graph.hpp"
#include "Vector/map_vector.hpp"
#include "Graph/map_graph.hpp"
// Include tests
#include "hypercube_unit_test.hpp"
#include "graph_unit_tests.hpp"
#include "vector_unit_tests.hpp"
#include "Graph/graph_unit_tests.hpp"
#include "Vector/vector_unit_tests.hpp"
#include "Grid/grid_unit_tests.hpp"
//int main()
......
This diff is collapsed.
This diff is collapsed.
#ifndef VECTOR_UNIT_TESTS_HPP
#define VECTOR_UNIT_TESTS_HPP
#include "map_vector.hpp"
#include "Point_test.hpp"
BOOST_AUTO_TEST_SUITE( vector_test )
// Test the openfpm vector
BOOST_AUTO_TEST_CASE( vector_use)
{
std::cout << "Vector unit test start" << "\n";
openfpm::vector<Point_test<float>> ofv;
typedef Point_test<float> P;
// Point
Point_test<float> p;
p.setx(1.0);
p.sety(2.0);
p.setz(3.0);
p.sets(4.0);
p.get<P::v>()[0] = 1.0;
p.get<P::v>()[1] = 2.0;
p.get<P::v>()[2] = 7.0;
p.get<P::t>()[0][0] = 10.0;
p.get<P::t>()[0][1] = 13.0;
p.get<P::t>()[0][2] = 8.0;
p.get<P::t>()[1][0] = 19.0;
p.get<P::t>()[1][1] = 23.0;
p.get<P::t>()[1][2] = 5.0;
p.get<P::t>()[2][0] = 4.0;
p.get<P::t>()[2][1] = 3.0;
p.get<P::t>()[2][2] = 11.0;
ofv.add(p);
// try to push 1000 object
for (size_t i = 0 ; i < 1000 ; i++)
{
// Modify p
p.get<P::v>()[0] = 1.0 + i;
p.get<P::v>()[1] = 2.0 + i;
p.get<P::v>()[2] = 7.0 + i;
p.get<P::t>()[0][0] = 10.0 + i;
p.get<P::t>()[0][1] = 13.0 + i;
p.get<P::t>()[0][2] = 8.0 + i;
p.get<P::t>()[1][0] = 19.0 + i;
p.get<P::t>()[1][1] = 23.0 + i;
p.get<P::t>()[1][2] = 5.0 + i;
p.get<P::t>()[2][0] = 4.0 + i;
p.get<P::t>()[2][1] = 3.0 + i;
p.get<P::t>()[2][2] = 11.0 + i;
ofv.add(p);
}
// try to push 2000 object
for (size_t i = 0 ; i < 2000 ; i++)
{
p.get<P::v>()[0] = 1.0 + i + 1359.0;
p.get<P::v>()[1] = 2.0 + i + 1700.0;
p.get<P::v>()[2] = 7.0 + i + 1511.0;
p.get<P::t>()[0][0] = 10.0 + i + 2333.0;
p.get<P::t>()[0][1] = 13.0 + i + 2345.0;
p.get<P::t>()[0][2] = 8.0 + i + 1234.0;
p.get<P::t>()[1][0] = 19.0 + i + 333.0;
p.get<P::t>()[1][1] = 23.0 + i + 4560.0;
p.get<P::t>()[1][2] = 5.0 + i + 5672.0;
p.get<P::t>()[2][0] = 4.0 + i + 1111.0;
p.get<P::t>()[2][1] = 3.0 + i + 3423.0;
p.get<P::t>()[2][2] = 11.0 + i + 7321.0;
ofv.add(p);
}
// try to push 3000 object
for (size_t i = 0 ; i < 3000 ; i++)
{
p.get<P::v>()[0] = 1.0 + i + 1569.0;
p.get<P::v>()[1] = 2.0 + i + 1720.0;
p.get<P::v>()[2] = 7.0 + i + 1211.0;
p.get<P::t>()[0][0] = 10.0 + i + 1333.0;
p.get<P::t>()[0][1] = 13.0 + i + 1345.0;
p.get<P::t>()[0][2] = 8.0 + i + 3234.0;
p.get<P::t>()[1][0] = 19.0 + i + 4333.0;
p.get<P::t>()[1][1] = 23.0 + i + 7560.0;
p.get<P::t>()[1][2] = 5.0 + i + 5872.0;
p.get<P::t>()[2][0] = 4.0 + i + 1311.0;
p.get<P::t>()[2][1] = 3.0 + i + 3123.0;
p.get<P::t>()[2][2] = 11.0 + i + 7821.0;
ofv.add(p);
}
// try to push 10000 object
for (size_t i = 0 ; i < 10000 ; i++)
{
p.get<P::v>()[0] = 1.0 + i + 8569.0;
p.get<P::v>()[1] = 2.0 + i + 2720.0;
p.get<P::v>()[2] = 7.0 + i + 5211.0;
p.get<P::t>()[0][0] = 10.0 + i + 2333.0;
p.get<P::t>()[0][1] = 13.0 + i + 4345.0;
p.get<P::t>()[0][2] = 8.0 + i + 1234.0;
p.get<P::t>()[1][0] = 19.0 + i + 2333.0;
p.get<P::t>()[1][1] = 23.0 + i + 5560.0;
p.get<P::t>()[1][2] = 5.0 + i + 4872.0;
p.get<P::t>()[2][0] = 4.0 + i + 2311.0;
p.get<P::t>()[2][1] = 3.0 + i + 1123.0;
p.get<P::t>()[2][2] = 11.0 + i + 5821.0;
ofv.add(p);
}
// try to push 20000 object
for (size_t i = 0 ; i < 20000 ; i++)
{
p.get<P::v>()[0] = 1.0 + i + 1569.0;
p.get<P::v>()[1] = 2.0 + i + 3720.0;
p.get<P::v>()[2] = 7.0 + i + 2211.0;
p.get<P::t>()[0][0] = 10.0 + i + 1333.0;
p.get<P::t>()[0][1] = 13.0 + i + 2345.0;
p.get<P::t>()[0][2] = 8.0 + i + 2234.0;
p.get<P::t>()[1][0] = 19.0 + i + 4333.0;
p.get<P::t>()[1][1] = 23.0 + i + 1560.0;
p.get<P::t>()[1][2] = 5.0 + i + 2872.0;
p.get<P::t>()[2][0] = 4.0 + i + 1311.0;
p.get<P::t>()[2][1] = 3.0 + i + 5123.0;
p.get<P::t>()[2][2] = 11.0 + i + 1821.0;
ofv.add(p);
}
//
// Now check the vector
BOOST_REQUIRE_EQUAL(ofv.template get<P::x>(0),1.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::y>(0),2.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::z>(0),3.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::s>(0),4.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(0)[0],1.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(0)[1],2.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(0)[2],7.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(0)[0][0],10.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(0)[0][1],13.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(0)[0][2],8.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(0)[1][0],19.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(0)[1][1],23.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(0)[1][2],5.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(0)[2][0],4.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(0)[2][1],3.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(0)[2][2],11.0);
// Check next 1000 object
for (size_t i = 0 ; i < 1000 ; i++)
{
// Modify p
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(i+1)[0],1.0 + i);
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(i+1)[1],2.0 + i);
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(i+1)[2],7.0 + i);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1)[0][0],10.0 + i);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1)[0][1],13.0 + i);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1)[0][2],8.0 + i);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1)[1][0],19.0 + i);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1)[1][1],23.0 + i);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1)[1][2],5.0 + i);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1)[2][0],4.0 + i);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1)[2][1],3.0 + i);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1)[2][2],11.0 + i);
}
// try to push 2000 object
for (size_t i = 0 ; i < 2000 ; i++)
{
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(i+1001)[0], 1.0 + i + 1359.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(i+1001)[1], 2.0 + i + 1700.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(i+1001)[2], 7.0 + i + 1511.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1001)[0][0], 10.0 + i + 2333.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1001)[0][1], 13.0 + i + 2345.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1001)[0][2], 8.0 + i + 1234.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1001)[1][0], 19.0 + i + 333.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1001)[1][1], 23.0 + i + 4560.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1001)[1][2], 5.0 + i + 5672.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1001)[2][0], 4.0 + i + 1111.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1001)[2][1], 3.0 + i + 3423.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+1001)[2][2], 11.0 + i + 7321.0);
}
// try to push 3000 object
for (size_t i = 0 ; i < 3000 ; i++)
{
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(i+3001)[0], 1.0 + i + 1569.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(i+3001)[1], 2.0 + i + 1720.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(i+3001)[2], 7.0 + i + 1211.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+3001)[0][0], 10.0 + i + 1333.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+3001)[0][1], 13.0 + i + 1345.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+3001)[0][2], 8.0 + i + 3234.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+3001)[1][0], 19.0 + i + 4333.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+3001)[1][1], 23.0 + i + 7560.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+3001)[1][2], 5.0 + i + 5872.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+3001)[2][0], 4.0 + i + 1311.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+3001)[2][1], 3.0 + i + 3123.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::t>(i+3001)[2][2], 11.0 + i + 7821.0);
}
// try to push 10000 object
for (size_t i = 0 ; i < 10000 ; i++)
{
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(i+6001)[0], 1.0 + i + 8569.0);
BOOST_REQUIRE_EQUAL(ofv.template get<P::v>(i+6001)[