8 #include "util/object_util.hpp"
9 #include "Grid/util.hpp"
10 #include "Vector/vect_isel.hpp"
11 #include "Vector/util.hpp"
12 #include "Vector/map_vector_grow_p.hpp"
13 #include "memory/ExtPreAlloc.hpp"
14 #include "util/util_debug.hpp"
15 #include "util/Pack_stat.hpp"
18 #include <boost/fusion/include/mpl.hpp>
19 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
20 #include <boost/fusion/include/at_c.hpp>
21 #include <boost/fusion/include/for_each.hpp>
22 #include <boost/fusion/container/vector.hpp>
23 #include <boost/fusion/include/vector.hpp>
24 #include <boost/fusion/container/vector/vector_fwd.hpp>
25 #include <boost/fusion/include/vector_fwd.hpp>
26 #include <boost/type_traits.hpp>
27 #include <boost/fusion/include/for_each.hpp>
28 #include <boost/mpl/range_c.hpp>
29 #include <boost/mpl/for_each.hpp>
30 #include "memory_ly/memory_conf.hpp"
31 #include "util/copy_compare/meta_copy.hpp"
33 #include "Memleak_check.hpp"
35 #include "util/for_each_ref.hpp"
39 #include "memory/CudaMemory.cuh"
41 #include "grid_sm.hpp"
43 #include "memory_ly/memory_array.hpp"
44 #include "memory_ly/memory_c.hpp"
46 #include "se_grid.hpp"
47 #include "memory/HeapMemory.hpp"
48 #include "memory/PtrMemory.hpp"
49 #include "grid_common.hpp"
50 #include "util/se_util.hpp"
51 #include "iterators/grid_key_dx_iterator.hpp"
52 #include "iterators/grid_key_dx_iterator_sub.hpp"
53 #include "iterators/grid_key_dx_iterator_sp.hpp"
54 #include "iterators/grid_key_dx_iterator_sub_bc.hpp"
57 typedef HeapMemory CudaMemory;
94 template<typename T, typename Memory=HeapMemory, typename grow_p=grow_policy_double, unsigned int impl=vect_isel<T>::value>
class vector;
97 template<unsigned int dim, typename T, typename S=HeapMemory, typename Mem = typename memory_traits_lin< typename T::type >::type >
102 static constexpr
unsigned int dims = dim;
110 typedef Mem memory_conf;
128 static bool packRequest()
133 static bool calculateMem()
138 template<
int ... prp>
void pack(ExtPreAlloc<S> & mem,
Pack_stat & sts)
142 std::cerr <<
"Error : " << __FILE__ <<
":" << __LINE__ <<
" the reference counter of mem should never be zero when packing \n";
151 size_t alloc_ele = dvect.calculateMem(
size(),0);
180 std::cerr <<
"Error : " << __FILE__ <<
":" << __LINE__ <<
" the reference counter of mem should never be zero when packing \n";
184 typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
192 pack_with_iterator<grid_key_dx_iterator_sub<dims>,dtype,prp...>(sub_it,dest);
206 typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
211 size_t alloc_ele = dvect.calculateMem(
size(),0);
213 v.push_back(alloc_ele);
231 size_t alloc_ele = dvect.template calculateMem<prp...>(sub.
getVolume(),0);
233 v.push_back(alloc_ele);
248 template <
typename it,
typename dtype,
int ... prp>
void pack_with_iterator(it & sub_it, dtype & dest)
251 typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
256 while (sub_it.isNext())
264 object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(
get_o(sub_it.get()),dest.get(
id));
282 typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
285 while (sub_it.isNext())
293 object_s_di<encap_src,encap_dst,OBJ_ENCAP,prp...>(src.get(
id),this->
get_o(sub_it.get()));
311 typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
317 size_t size = svect.calculateMem(this->
size(),0);
320 PtrMemory & ptr = *(
new PtrMemory(mem.getPointerOffset(ps.
getOffset()),size));
325 src.resize(this->
size());
346 typedef object<typename object_creator<typename grid_cpu<dim,T,S,Mem>::value_type::type,prp...>::type> prp_object;
349 size_t size = stype::template calculateMem(sub_it.
getVolume(),0);
352 PtrMemory & ptr = *(
new PtrMemory(mem.getPointerOffset(ps.
getOffset()),size));
359 unpack_with_iterator<grid_key_dx_iterator_sub<dims>,stype,prp...>(mem,sub_it,src,ps);
390 std::vector<size_t> tmp;
392 for (
unsigned int i = 0 ; i < dim ; i++)
406 inline void check_init()
const
410 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" you must call SetMemory before access the grid\n";
411 size_t * err_code_pointer = (
size_t *)&this->
err_code;
412 *err_code_pointer = 1001;
413 ACTION_ON_ERROR(GRID_ERROR);
424 for (
long int i = 0 ; i < dim ; i++)
428 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << v1.
get(i) <<
" >= " <<
getGrid().
size(i) <<
"\n";
429 size_t * err_code_pointer = (
size_t *)&this->
err_code;
430 *err_code_pointer = 1002;
431 ACTION_ON_ERROR(GRID_ERROR);
433 else if (v1.
get(i) < 0)
435 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << v1.
get(i) <<
" is negative " <<
"\n";
436 size_t * err_code_pointer = (
size_t *)&this->
err_code;
437 *err_code_pointer = 1003;
438 ACTION_ON_ERROR(GRID_ERROR);
453 for (
size_t i = 0 ; i < dim ; i++)
455 if (key2.
get(i) >= (
long int)g.
g1.
size(i))
457 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << key2.
get(i) <<
" >= " << g.
g1.
size(i) <<
"\n";
458 size_t * err_code_pointer = (
size_t *)&this->
err_code;
459 *err_code_pointer = 1004;
460 ACTION_ON_ERROR(GRID_ERROR);
462 else if (key2.
get(i) < 0)
464 std::cerr <<
"Error " __FILE__ <<
":" << __LINE__ <<
" grid overflow " <<
"x=[" << i <<
"]=" << key2.
get(i) <<
" is negative " <<
"\n";
465 size_t * err_code_pointer = (
size_t *)&this->
err_code;
466 *err_code_pointer = 1005;
467 ACTION_ON_ERROR(GRID_ERROR);
490 typedef T value_type;
498 check_new(
this,8,GRID_EVENT,1);
522 check_new(
this,8,GRID_EVENT,1);
532 check_new(
this,8,GRID_EVENT,1);
542 check_new(
this,8,GRID_EVENT,1);
564 check_new(
this,8,GRID_EVENT,1);
580 check_new(
this,8,GRID_EVENT,1);
689 data_.setMemory(*mem);
738 if (
data_.mem_r == NULL)
741 return data_.mem_r->get_pointer();
757 if (
data_.mem_r == NULL)
760 return data_.mem_r->get_pointer();
780 if (check_valid(&boost::fusion::at_c<p>(
data_.mem_r->operator[](
g1.
LinId(v1)))) ==
false) {ACTION_ON_ERROR();}
782 return boost::fusion::at_c<p>(
data_.mem_r->operator[](
g1.
LinId(v1)));
802 if (check_valid(&boost::fusion::at_c<p>(
data_.mem_r->operator[](
g1.
LinId(v1)))) ==
false) {ACTION_ON_ERROR()};
804 return boost::fusion::at_c<p>(
data_.mem_r->operator[](
g1.
LinId(v1)));
826 return boost::fusion::at_c<p>(
data_.mem_r->operator[](
g1.
LinId(v1)));
848 return boost::fusion::at_c<p>(
data_.mem_r->operator[](
g1.
LinId(v1)));
868 check_valid(&
data_.mem_r->operator[](
g1.
LinId(v1)),
sizeof(T));
890 if (check_valid(&
data_.mem_r->operator[](
g1.
LinId(v1)),
sizeof(T)) ==
false) {ACTION_ON_ERROR()}
971 this->
swap(grid_new);
986 std::cerr <<
"Error: " << __FILE__ <<
" " << __LINE__ <<
" remove work only on dimension == 1 " <<
"\n";
993 data_.move(&this->
template get<0>());
1009 check_valid(
this,8);
1040 check_valid(
this,8);
1057 check_valid(
this,8);
1068 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop> >(cp);
1083 check_valid(
this,8);
1090 this->
get_o(dx) = obj;
1105 check_valid(
this,8);
1110 check_bound(g,key2);
1125 check_valid(
this,8);
1141 check_valid(
this,8);
1157 check_valid(
this,8);
1171 check_valid(
this,8);
1187 check_valid(
this,8);
1200 check_valid(
this,8);
1217 check_valid(
this,8);
1234 check_valid(
this,8);
1247 return check_whoami(
this,8);
1263 template<
typename S>
1274 template<
typename T>
1278 t.setMemory(*
new S());
1285 #include "grid_gpu.hpp"
size_t size() const
return the size of the grid
size_t getOffset()
Return the actual counter.
bool isExternal
The memory allocator is not internally created.
It copy the properties from one object to another.
void setMemory(S &m)
Get the object that provide memory.
allocate(size_t sz)
constructor it fix the size
Transform the boost::fusion::vector into memory specification (memory_traits)
void set(grid_key_dx< dim > dx, const T &obj)
set an element of the grid
void fill(unsigned char fl)
Fill the memory with the selected byte.
size_t err_code
Error code.
grid_cpu(std::vector< size_t > &&sz) THROW
Constructor allocate memory and give them a representation.
void pack_with_iterator(it &sub_it, dtype &dest)
Pack an N-dimensional grid into a vector like structure B given an iterator of the grid...
grid_key_dx is the key to access any element in the grid
const encapc< dim, T, Mem > get_o(const grid_key_dx< dim > &v1) const
Get the of the selected element as a boost::fusion::vector.
size_t size() const
Return the size of the grid.
void unpack_with_iterator(ExtPreAlloc< S > &mem, it &sub_it, stype &src, Unpack_stat &ps)
unpack the grid given an iterator
void swap(grid_cpu< dim, T, S, Mem > &&grid)
It move the allocated object from one grid to another.
size_t packObject(void *mem)
It fill the message packet.
grid_cpu(const size_t(&sz)[dim]) THROW
Constructor allocate memory and give them a representation.
grid_cpu< dim, T, S, Mem > & operator=(grid_cpu< dim, T, S, Mem > &&g)
It copy an operator.
bool is_mem_init
Is the memory initialized.
grid_cpu< dim, T, S, Mem > & operator=(const grid_cpu< dim, T, S, Mem > &g)
It copy an operator.
bool operator==(const grid_cpu< dim, T, S, Mem > &g)
Compare two grids.
grid_sm< dim, T > g1
This is a structure that store all information related to the grid and how indexes are linearized...
size_t sz
size to allocate
encapc< dim, T, Mem > get_o(const grid_key_dx< dim > &v1)
Get the of the selected element as a boost::fusion::vector.
void resize(const size_t(&sz)[dim])
Resize the space.
This is a container to create a general object.
this class is a functor for "for_each" algorithm
mem_id get(size_t i) const
Get the i index.
const grid_sm< dim, T > & getGrid() const
Return the internal grid information.
size_t packObjectSize()
Return the size of the message needed to pack this object.
memory_traits_lin< typename T::type >::type memory_lin
Definition of the layout.
Grow policy define how the vector should grow every time we exceed the size.
void pack(ExtPreAlloc< S > &mem, grid_key_dx_iterator_sub< dims > &sub_it, Pack_stat &sts)
Pack the object into the memory given an iterator.
void operator()(T &t) const
It call the allocate function for each member.
static bool pack()
Pack the object into the memory given an iterator.
void * getPointer()
Return a plain pointer to the internal data.
grid_cpu(std::vector< size_t > &sz) THROW
Constructor allocate memory and give them a representation.
bool isNext()
Check if there is the next element.
void packRequest(grid_key_dx_iterator_sub< dims > &sub, std::vector< size_t > &v)
Insert an allocation request.
void swap(grid_sm< N, T > &g)
swap the grid_sm informations
void incReq()
Increment the request pointer.
void unpack(ExtPreAlloc< S > &mem, grid_key_dx_iterator_sub< dims > &sub_it, Unpack_stat &ps)
unpack the sub-grid object
~grid_cpu() THROW
Destructor.
const size_t(& getSize() const)[N]
Return the size of the grid as an array.
Mem data_
Memory layout specification + memory chunk pointer.
this class is a functor for "for_each" algorithm
const void * getPointer() const
Return a plain pointer to the internal data.
void set(grid_key_dx< dim > dx, const encapc< 1, T, Memory > &obj)
set an element of the grid
void addOffset(size_t off)
Increment the request pointer.
this structure encapsulate an object of the grid
grid_key_dx< dim > access_key
Access key.
grid_key_dx_iterator_sub< dim > getSubIterator(size_t m)
Return a sub-grid iterator.
void unpack(ExtPreAlloc< S > &mem, Unpack_stat &ps)
unpack the grid object
grid_cpu() THROW
Default constructor.
size_t getLastError()
Return the last error.
grid_cpu< dim, T, S, Mem > duplicate() const THROW
create a duplicated version of the grid
grid_cpu(const grid_cpu &g) THROW
create a grid from another grid
grid_key_dx_iterator_sub< dim > getSubIterator(grid_key_dx< dim > &start, grid_key_dx< dim > &stop) const
Return a sub-grid iterator.
void setMemory()
Create the object that provide memory.
void swap(grid_cpu< dim, T, S, Mem > &grid)
It move the allocated object from one grid to another.
const grid_key_dx< dim > & get()
Get the actual key.
void set(const grid_key_dx< dim > &key1, const grid_cpu< dim, T, S, Mem > &g, const grid_key_dx< dim > &key2)
Set an element of the grid from another element of another grid.
This class is a trick to indicate the compiler a specific specialization pattern. ...
grid_key_dx_iterator_sub< dim > getIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop) const
Return a grid iterator over all the point with the exception of the ghost part.
int yes_i_am_grid
it define that it is a grid
T::type T_type
boost::vector that describe the data type
Mem memory_t
Memory traits.
grid_key_d is the key to access any element in the grid
std::vector< size_t > getV()
Get 1D vector with the.
boost::fusion::result_of::at< vtype, boost::mpl::int_< p > >::type type
return a memory_c<...>
grid_key_dx_iterator_sub< N > getSubIterator(grid_key_dx< N > &start, grid_key_dx< N > &stop) const
Return a sub-grid iterator.
size_t getVolume()
Get the volume spanned by this sub-grid iterator.
mem_id LinId(const grid_key_dx< N > &gk, const char sum_id[N], const size_t(&bc)[N]) const
Linearization of the grid_key_dx with a specified shift.
Implementation of 1-D std::vector like structure.
grid_key_dx_iterator< dim > getIterator() const
Return a grid iterator.
It copy the properties from one object to another.
encapc< dim, T, Mem > container
Object container for T, it is the return type of get_o it return a object type trough.
void packRequest(std::vector< size_t > &v)
Insert an allocation request.