Commit d545b749 authored by incardon's avatar incardon
Browse files

Moving files and adding Mem_type tests

parent c0ea1614
......@@ -8,7 +8,7 @@ else
endif
noinst_PROGRAMS = mem_map
mem_map_SOURCES = ../../openfpm_devices/src/Memleak_check.cpp main.cpp Grid/copy_grid_unit_test.cpp $(CUDA_SOURCES) ../../openfpm_devices/src/memory/HeapMemory.cpp ../../openfpm_devices/src/memory/PtrMemory.cpp
mem_map_SOURCES = ../../openfpm_devices/src/Memleak_check.cpp main.cpp Grid/copy_grid_unit_test.cpp NN/Mem_type/Mem_type_unit_tests.cpp $(CUDA_SOURCES) ../../openfpm_devices/src/memory/HeapMemory.cpp ../../openfpm_devices/src/memory/PtrMemory.cpp
mem_map_CXXFLAGS = $(AM_CXXFLAGS) $(LIBHILBERT_INCLUDE) $(CUDA_CFLAGS) $(INCLUDES_PATH) $(BOOST_CPPFLAGS) -I/usr/local/include -I/usr/local/libhilbert/include
mem_map_CFLAGS = $(CUDA_CFLAGS)
mem_map_LDADD = $(LINKLIBS)
......@@ -20,7 +20,7 @@ Grid/iterators/grid_key_dx_iterator_sp.hpp Grid/grid_key_dx_iterator_hilbert.hpp
Point_test.hpp \
Point_orig.hpp \
memory_ly/memory_array.hpp memory_ly/memory_c.hpp memory_ly/memory_conf.hpp memory_ly/t_to_memory_c.hpp \
NN/CellList/MemBalanced.hpp NN/CellList/MemFast.hpp NN/CellList/MemMemoryWise.hpp NN/CellList/CellNNIteratorRuntime.hpp NN/CellList/ParticleItCRS_Cells.hpp NN/CellList/ParticleIt_Cells.hpp NN/CellList/CellDecomposer.hpp NN/VerletList/VerletList.hpp NN/VerletList/VerletListFast.hpp NN/VerletList/VerletNNIterator.hpp NN/CellList/CellListNNIteratorRadius.hpp NN/CellList/CellListIterator.hpp NN/CellList/CellListM.hpp NN/CellList/CellNNIteratorM.hpp NN/CellList/CellList.hpp NN/CellList/CellList_test.hpp NN/CellList/CellListFast_gen.hpp NN/CellList/CellNNIterator.hpp NN/CellList/ProcKeys.hpp \
NN/Mem_type/MemBalanced.hpp NN/Mem_type/MemFast.hpp NN/Mem_type/MemMemoryWise.hpp NN/CellList/CellNNIteratorRuntime.hpp NN/CellList/ParticleItCRS_Cells.hpp NN/CellList/ParticleIt_Cells.hpp NN/CellList/CellDecomposer.hpp NN/VerletList/VerletList.hpp NN/VerletList/VerletListFast.hpp NN/VerletList/VerletNNIterator.hpp NN/CellList/CellListNNIteratorRadius.hpp NN/CellList/CellListIterator.hpp NN/CellList/CellListM.hpp NN/CellList/CellNNIteratorM.hpp NN/CellList/CellList.hpp NN/CellList/CellList_test.hpp NN/CellList/CellListFast_gen.hpp NN/CellList/CellNNIterator.hpp NN/CellList/ProcKeys.hpp \
Space/Ghost.hpp Space/Matrix.hpp Space/SpaceBox.hpp Space/SpaceBox_unit_tests.hpp \
Space/Shape/AdaptiveCylinderCone.hpp Space/Shape/Box.hpp Space/Shape/Box_unit_tests.hpp Space/Shape/HyperCube.hpp Space/Shape/HyperCube_unit_test.hpp Space/Shape/Point.hpp Space/Shape/Point_unit_test.hpp Space/Shape/Point_operators_functions.hpp Space/Shape/Point_operators.hpp Space/Shape/Sphere.hpp \
util/check_no_pointers.hpp util/common.hpp util/convert.hpp util/create_vmpl_sequence.hpp util/ct_array.hpp util/for_each_ref.hpp util/mathutil.hpp util/object_creator.hpp util/object_s_di.hpp util/object_si_d.hpp util/object_util.hpp util/util_debug.hpp util/util_test.hpp util/variadic_to_vmpl.hpp util/variadic_to_vmpl_unit_test.hpp util/Pack_stat.hpp \
......
......@@ -22,9 +22,9 @@
#include "ParticleItCRS_Cells.hpp"
#include "util/common.hpp"
#include "MemFast.hpp"
#include "MemBalanced.hpp"
#include "MemMemoryWise.hpp"
#include "NN/Mem_type/MemFast.hpp"
#include "NN/Mem_type/MemBalanced.hpp"
#include "NN/Mem_type/MemMemoryWise.hpp"
//! Wrapper of the unordered map
template<typename key,typename val>
......
......@@ -10,10 +10,10 @@
#ifndef CELLLISTBAL_HPP_
#define CELLLISTBAL_HPP_
#include "CellList.hpp"
#include "NN/CellList/CellList.hpp"
#include "Space/SpaceBox.hpp"
#include "util/mathutil.hpp"
#include "CellNNIterator.hpp"
#include "NN/CellList/CellNNIterator.hpp"
#include "Space/Shape/HyperCube.hpp"
/*! \brief Class for BALANCED cell list implementation
......@@ -60,6 +60,7 @@ public:
//resize the vector to needed number of cells
cl_base.resize(tot_n_cell);
clear();
}
/*! \brief Copy mem balanced
......
......@@ -11,7 +11,7 @@
#include "Space/SpaceBox.hpp"
#include "util/mathutil.hpp"
#include "Space/Shape/HyperCube.hpp"
#include "CellListIterator.hpp"
#include "NN/CellList/CellListIterator.hpp"
#include <unordered_map>
#include "util/common.hpp"
#include "Vector/map_vector.hpp"
......@@ -66,7 +66,18 @@ class Mem_fast
cl_base.swap(cl_base_);
}
protected:
public:
/*! \brief return the number of elements
*
* \return the number of elements
*
*/
inline size_t size()
{
return cl_n.size();
}
/*! \brief Initialize the data to zero
*
......
......@@ -9,7 +9,7 @@
#ifndef CELLISTMEM_HPP_
#define CELLISTMEM_HPP_
#include "CellList.hpp"
#include "NN/CellList/CellList.hpp"
/*! \brief Class for MEMORY-WISE cell list implementation
*
......
/*
* Mem_type_unit_tests.cpp
*
* Created on: Dec 26, 2017
* Author: Pietro Incardona
*/
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "NN/Mem_type/MemFast.hpp"
#include "NN/Mem_type/MemBalanced.hpp"
BOOST_AUTO_TEST_SUITE( Mem_type_test )
template<typename Mem_type>
void test_mem_type()
{
Mem_type mem(128);
//
mem.init_to_zero(128,10);
mem.add(0,5);
BOOST_REQUIRE_EQUAL(mem.getNelements(0),1ul);
BOOST_REQUIRE_EQUAL(mem.get(0,0),5ul);
mem.init_to_zero(128,5);
BOOST_REQUIRE_EQUAL(mem.getNelements(0),0ul);
}
BOOST_AUTO_TEST_CASE ( Mem_type_check )
{
test_mem_type<Mem_fast<>>();
test_mem_type<Mem_bal>();
}
BOOST_AUTO_TEST_SUITE_END()
......@@ -17,8 +17,9 @@ typedef size_t local_index_;
typedef unsigned int local_index_;
#endif
#define FAST 1
#define VERLETLIST_FAST() VerletList<dim,St,Mem_fast<>,shift<dim,St> >
#define VERLETLIST_BAL VerletList<dim,St,Mem_bal,shift<dim,St> >
#define VERLETLIST_MEM VerletList<dim,St,Mem_mem<>,shift<dim,St> >
/*! \brief Cell list structure
*
......
......@@ -10,9 +10,9 @@
#include "VerletNNIterator.hpp"
#include "NN/CellList/CellList_util.hpp"
#include "NN/CellList/MemFast.hpp"
#include "NN/CellList/MemBalanced.hpp"
#include "NN/CellList/MemMemoryWise.hpp"
#include "NN/Mem_type/MemFast.hpp"
#include "NN/Mem_type/MemBalanced.hpp"
#include "NN/Mem_type/MemMemoryWise.hpp"
#define VERLET_STARTING_NSLOT 128
......@@ -281,7 +281,7 @@ template<unsigned int dim,
typename transform = no_transform<dim,T>,
typename local_index = local_index_,
typename CellListImpl = CellList<dim,T,Mem_fast<>,transform> >
class VerletList/*: private Mem_type*/
class VerletList: public Mem_type
{
protected:
......@@ -289,11 +289,11 @@ protected:
local_index slot;
//! number of neighborhood particles for each particle
openfpm::vector<local_index> cl_n;
/* openfpm::vector<local_index> cl_n;
//! Neighborhood indexes for each particle store (each particle can store a number
//! of elements == slot)
openfpm::vector<local_index> cl_base;
openfpm::vector<local_index> cl_base;*/
//! Domain particles
openfpm::vector<local_index> dp;
......@@ -306,26 +306,6 @@ private:
//! Interlal cell-list
CellListImpl cli;
//! Realloc the vectors
void realloc()
{
// we do not have enough slots reallocate the basic structure with more
// slots
openfpm::vector<local_index> cl_base_(2*slot * cl_n.size());
// copy cl_base
for (size_t i = 0 ; i < cl_n.size() ; i++)
{
for (size_t j = 0 ; j < cl_n.get(i) ; j++)
cl_base_.get(2*i*slot + j) = cl_base.get(slot * i + j);
}
// Double the number of slots
slot *= 2;
// swap the memory
cl_base.swap(cl_base_);
}
/*! \brief Fill the cell-list with data
*
......@@ -391,9 +371,7 @@ private:
auto it = PartItNN<type,dim,openfpm::vector<Point<dim,T>>,CellListImpl>::get(pos,dom,anom,cli,g_m,end);
cl_n.resize(end);
cl_base.resize(end*slot);
cl_n.fill(0);
Mem_type::init_to_zero(slot,end);
dp.clear();
......@@ -439,10 +417,8 @@ private:
*/
inline void createR(openfpm::vector<Point<dim,T>> & pos, T r_cut, size_t g_m, CellListImpl & cl)
{
// resize verlet to store the number of particles
cl_n.resize(g_m);
cl_n.fill(0);
cl_base.resize(g_m*slot);
Mem_type::init_to_zero(slot,g_m);
// square of the cutting radius
T r_cut2 = r_cut * r_cut;
......@@ -487,7 +463,7 @@ public:
*/
size_t size()
{
return cl_n.size();
return Mem_type::size();
}
/*! \brief Add a neighborhood particle to a particle
......@@ -498,17 +474,7 @@ public:
*/
inline void addPart(size_t part_id, size_t ele)
{
// Get the number of element the cell is storing
size_t nl = getNNPart(part_id);
if (nl + 1 >= slot)
realloc();
// we have enough slot to store another neighbor element
cl_base.get(slot * part_id + cl_n.get(part_id)) = ele;
cl_n.get(part_id)++;
Mem_type::addCell(part_id,ele);
}
/*! Initialize the verlet list
......@@ -676,8 +642,8 @@ public:
*/
void Initialize(CellListImpl & cli, T r_cut, const openfpm::vector<Point<dim,T>> & pos, const openfpm::vector<Point<dim,T>> & pos2, size_t g_m, size_t opt = VL_NON_SYMMETRIC)
{
cl_n.resize(g_m);
cl_base.resize(g_m*slot);
// cl_n.resize(g_m);
// cl_base.resize(g_m*slot);
Point<dim,T> spacing = cli.getCellBox().getP2();
......@@ -705,19 +671,19 @@ public:
//! Default Constructor
VerletList()
:slot(VERLET_STARTING_NSLOT),n_dec(0)
:Mem_type(VERLET_STARTING_NSLOT),slot(VERLET_STARTING_NSLOT),n_dec(0)
{};
//! Copy constructor
VerletList(const VerletList<dim,T,Mem_type,transform,local_index,CellListImpl> & cell)
:slot(VERLET_STARTING_NSLOT)
:Mem_type(VERLET_STARTING_NSLOT),slot(VERLET_STARTING_NSLOT)
{
this->operator=(cell);
}
//! Copy constructor
VerletList(VerletList<dim,T,Mem_type,transform,local_index,CellListImpl> && cell)
:slot(VERLET_STARTING_NSLOT),n_dec(0)
:Mem_type(VERLET_STARTING_NSLOT),slot(VERLET_STARTING_NSLOT),n_dec(0)
{
this->operator=(cell);
}
......@@ -798,10 +764,7 @@ public:
{
slot = vl.slot;
cl_n.swap(vl.cl_n);
cl_base.swap(vl.cl_base);
cli.swap(vl.cli);
Mem_type::operator=(vl);
dp.swap(vl.dp);
n_dec = vl.n_dec;
......@@ -820,8 +783,7 @@ public:
{
slot = vl.slot;
cl_n = vl.cl_n;
cl_base = vl.cl_base;
Mem_type::operator=(vl);
cli = vl.cli;
......@@ -840,7 +802,7 @@ public:
*/
inline size_t getNNPart(size_t part_id) const
{
return cl_n.get(part_id);
return Mem_type::getNelements(part_id);
}
/*! \brief Get the neighborhood element j for the particle i
......@@ -853,7 +815,7 @@ public:
*/
inline size_t get(size_t i, size_t j) const
{
return cl_base.get(i * slot + j);
return Mem_type::get(i,j);
}
/*! \brief Swap the memory
......@@ -863,8 +825,7 @@ public:
*/
inline void swap(VerletList<dim,T,Mem_type,transform,local_index,CellListImpl> & vl)
{
cl_n.swap(vl.cl_n);
cl_base.swap(vl.cl_base);
Mem_type::swap(vl);
dp.swap(vl.dp);
size_t vl_slot_tmp = vl.slot;
......@@ -888,7 +849,8 @@ public:
*
*/
template<unsigned int impl=NO_CHECK>
inline VerletNNIterator<dim,VerletList<dim,T,Mem_type,transform,local_index,CellListImpl>> getNNIterator(size_t part_id)
inline VerletNNIterator<dim,VerletList<dim,T,Mem_type,transform,local_index,CellListImpl>>
getNNIterator(size_t part_id)
{
VerletNNIterator<dim,VerletList<dim,T,Mem_type,transform,local_index,CellListImpl>> vln(part_id,*this);
......@@ -900,9 +862,7 @@ public:
*/
void clear()
{
slot = VERLET_STARTING_NSLOT;
for (size_t i = 0 ; i < cl_n.size() ; i++)
cl_n.get(i) = 0;
Mem_type::clear();
}
/*! \brief Return the starting point of the neighborhood for the particle p
......@@ -912,9 +872,9 @@ public:
* \return the index
*
*/
inline size_t getStart(size_t part_id)
inline const size_t & getStart(size_t part_id)
{
return part_id*slot;
return Mem_type::getStartId(part_id);
}
/*! \brief Return the end point of the neighborhood for the particle p
......@@ -924,9 +884,9 @@ public:
* \return the stop index
*
*/
inline size_t getStop(size_t part_id)
inline const size_t & getStop(size_t part_id)
{
return part_id*slot+cl_n.get(part_id);
return Mem_type::getStopId(part_id);
}
/*! \brief Return the neighborhood id
......@@ -936,9 +896,9 @@ public:
* \return the neighborhood id
*
*/
inline size_t get_lin(size_t part_id)
inline const size_t & get_lin(const size_t * part_id)
{
return cl_base.get(part_id);
return Mem_type::get_lin(part_id);
}
/*! \brief Get the internal cell-list used to construct the Verlet-list
......
......@@ -211,9 +211,11 @@ class VerletListM : public VerletBase
auto it = PartItNN<type,dim,openfpm::vector<Point<dim,T>>,CellListImpl>::get(pos,dom,anom,cli,g_m,end);
this->cl_n.resize(end);
/* this->cl_n.resize(end);
this->cl_base.resize(end*this->slot);
this->cl_n.fill(0);
this->cl_n.fill(0);*/
this->init_to_zero(this->slot,end);
// square of the cutting radius
T r_cut2 = r_cut * r_cut;
......@@ -263,8 +265,8 @@ public:
*/
void Initialize(CellListImpl & cli, size_t pp, T r_cut, const openfpm::vector<Point<dim,T>> & pos, const openfpm::vector<struct pos_v<dim,T>> & pos2, size_t g_m, size_t opt = VL_NON_SYMMETRIC)
{
this->cl_n.resize(g_m);
this->cl_base.resize(g_m*this->slot);
// this->cl_n.resize(g_m);
// this->cl_base.resize(g_m*this->slot);
Point<dim,T> spacing = cli.getCellBox().getP2();
......
......@@ -27,13 +27,13 @@
template<unsigned int dim, typename Ver> class VerletNNIterator
{
//! start index for the neighborhood
size_t start;
const size_t * start;
//! stop index for the neighborhood
size_t stop;
const size_t * stop;
//! actual neighborhood
size_t ele_id;
const size_t * ele_id;
//! verlet list
Ver & ver;
......@@ -49,7 +49,7 @@ public:
*
*/
inline VerletNNIterator(size_t part_id, Ver & ver)
:start(ver.getStart(part_id)),stop(ver.getStop(part_id)),ver(ver)
:start(&ver.getStart(part_id)),stop(&ver.getStop(part_id)),ver(ver)
{ele_id = start;}
/*! \brief
......
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