8 #ifndef OPENFPM_DATA_SRC_GRID_COPY_GRID_FAST_HPP_ 
    9 #define OPENFPM_DATA_SRC_GRID_COPY_GRID_FAST_HPP_ 
   11 #include "Grid/iterators/grid_key_dx_iterator.hpp" 
   17 template<
bool is_complex, 
unsigned int N, 
typename gr
id, 
typename ginfo>
 
   20     static void copy(ginfo & gs_src,
 
   31         while (sub_src.isNext())
 
   34             gd_dst.set(sub_dst.template getStencil<0>(),gd_src,sub_src.template getStencil<0>());
 
   46 template<
typename gr
id, 
typename ginfo>
 
   49     static void copy(ginfo & gs_src,
 
   60         lin_src += bx_src.
getLow(2) * gs_src.size_s(1);
 
   61         lin_dst += bx_dst.
getLow(2) * gs_dst.size_s(1);
 
   62         for (
size_t i = bx_src.
getLow(2) ; i <= bx_src.
getHigh(2) ; i++)
 
   64             lin_src += bx_src.
getLow(1) * gs_src.size_s(0);
 
   65             lin_dst += bx_dst.
getLow(1) * gs_dst.size_s(0);
 
   66             for (
size_t j = bx_src.
getLow(1) ; j <= bx_src.
getHigh(1) ; j++)
 
   68                 lin_src += bx_src.
getLow(0);
 
   69                 lin_dst += bx_dst.
getLow(0);
 
   70                 for (
size_t k = bx_src.
getLow(0) ; k <= bx_src.
getHigh(0) ; k++)
 
   72                     gd_dst.set(lin_dst,gd_src,lin_src);
 
   77                 lin_src -= bx_src.
getHigh(0) + 1;
 
   78                 lin_dst -= bx_dst.
getHigh(0) + 1;
 
   79                 lin_src += gs_src.size_s(0);
 
   80                 lin_dst += gs_dst.size_s(0);
 
   82             lin_src -= (bx_src.
getHigh(1) + 1)*gs_src.size_s(0);
 
   83             lin_dst -= (bx_dst.
getHigh(1) + 1)*gs_dst.size_s(0);
 
   84             lin_src += gs_src.size_s(1);
 
   85             lin_dst += gs_dst.size_s(1);
 
   95 template<
typename gr
id, 
typename ginfo>
 
   98     static void copy(ginfo & gs_src,
 
  110         lin_src += bx_src.
getLow(1) * gs_src.size_s(0);
 
  111         lin_dst += bx_dst.
getLow(1) * gs_dst.size_s(0);
 
  112         for (
size_t j = bx_src.
getLow(1) ; j <= bx_src.
getHigh(1) ; j++)
 
  114             lin_src += bx_src.
getLow(0);
 
  115             lin_dst += bx_dst.
getLow(0);
 
  116             for (
size_t k = bx_src.
getLow(0) ; k <= bx_src.
getHigh(0) ; k++)
 
  118                 gd_dst.set(lin_dst,gd_src,lin_src);
 
  123             lin_src -= bx_src.
getHigh(0) + 1;
 
  124             lin_dst -= bx_dst.
getHigh(0) + 1;
 
  125             lin_src += gs_src.size_s(0);
 
  126             lin_dst += gs_dst.size_s(0);
 
  138 template<
typename gr
id, 
typename ginfo>
 
  141     static void copy(ginfo & gs_src,
 
  152         lin_src += bx_src.
getLow(0);
 
  153         lin_dst += bx_dst.
getLow(0);
 
  154         for (
size_t k = bx_src.
getLow(0) ; k <= bx_src.
getHigh(0) ; k++)
 
  156             gd_dst.set(lin_dst,gd_src,lin_src);
 
  168 template<
typename gr
id>
 
  170                             unsigned char * ptr_dst,
 
  171                             unsigned char * ptr_src,
 
  179     for (
size_t i = bx_src.
getLow(2) ; i <= bx_src.
getHigh(2) ; i++)
 
  181         for (
size_t j = bx_src.
getLow(1) ; j <= bx_src.
getHigh(1) ; j++)
 
  183             memcpy(ptr_dst,ptr_src,n_cpy*
sizeof(
typename grid::value_type));
 
  185             ptr_dst += stride_dst_x;
 
  186             ptr_src += stride_src_x;
 
  188         ptr_dst += stride_dst_y - tot_y*stride_dst_x;
 
  189         ptr_src += stride_src_y - tot_y*stride_src_x;
 
  193 template<
typename gr
id, 
unsigned int n_cpy>
 
  195         unsigned char * ptr_dst,
 
  196         unsigned char * ptr_src,
 
  203     for (
size_t i = bx_src.
getLow(2) ; i <= bx_src.
getHigh(2) ; i++)
 
  205         for (
size_t j = bx_src.
getLow(1) ; j <= bx_src.
getHigh(1) ; j++)
 
  207             __builtin_memcpy(ptr_dst,ptr_src,n_cpy*
sizeof(
typename grid::value_type));
 
  209             ptr_dst += stride_dst_x;
 
  210             ptr_src += stride_src_x;
 
  212         ptr_dst += stride_dst_y - tot_y*stride_dst_x;
 
  213         ptr_src += stride_src_y - tot_y*stride_src_x;
 
  220 template<
typename gr
id>
 
  222                             unsigned char * ptr_dst,
 
  223                             unsigned char * ptr_src,
 
  228     for (
size_t j = bx_src.
getLow(1) ; j <= bx_src.
getHigh(1) ; j++)
 
  230         memcpy(ptr_dst,ptr_src,n_cpy*
sizeof(
typename grid::value_type));
 
  232         ptr_dst += stride_dst_x;
 
  233         ptr_src += stride_src_x;
 
  237 template<
typename gr
id, 
unsigned int n_cpy>
 
  239         unsigned char * ptr_dst,
 
  240         unsigned char * ptr_src,
 
  244     for (
size_t j = bx_src.
getLow(1) ; j <= bx_src.
getHigh(1) ; j++)
 
  246         __builtin_memcpy(ptr_dst,ptr_src,n_cpy*
sizeof(
typename grid::value_type));
 
  248         ptr_dst += stride_dst_x;
 
  249         ptr_src += stride_src_x;
 
  257 template<
typename gr
id, 
typename ginfo>
 
  260     static void copy(ginfo & gs_src,
 
  274         unsigned char * ptr_final_src = (
unsigned char *)&(gd_src.template get<0>(one));
 
  275         unsigned char * ptr_start_src = (
unsigned char *)&(gd_src.template get<0>(zero));
 
  277         unsigned char * ptr_final_dst = (
unsigned char *)&(gd_dst.template get<0>(one));
 
  278         unsigned char * ptr_start_dst = (
unsigned char *)&(gd_dst.template get<0>(zero));
 
  280         unsigned char * ptr_src = (
unsigned char *)&(gd_src.template get<0>(bx_src.
getKP1()));
 
  281         unsigned char * ptr_dst = (
unsigned char *)&(gd_dst.template get<0>(bx_dst.
getKP1()));
 
  287         size_t stride_src_x = ptr_final_src - ptr_start_src;
 
  288         size_t stride_dst_x = ptr_final_dst - ptr_start_dst;
 
  293         ptr_final_src = (
unsigned char *)&(gd_src.template get<0>(one2));
 
  294         ptr_start_src = (
unsigned char *)&(gd_src.template get<0>(zero));
 
  296         ptr_final_dst = (
unsigned char *)&(gd_dst.template get<0>(one2));
 
  297         ptr_start_dst = (
unsigned char *)&(gd_dst.template get<0>(zero));
 
  299         size_t stride_src_y = ptr_final_src - ptr_start_src;
 
  300         size_t stride_dst_y = ptr_final_dst - ptr_start_dst;
 
  305                 copy_grid_fast_shortx_3<grid,1>(bx_src,ptr_dst,ptr_src,
 
  306                                     stride_src_x,stride_dst_x,
 
  307                                     stride_src_y,stride_dst_y,
 
  311                 copy_grid_fast_shortx_3<grid,2>(bx_src,ptr_dst,ptr_src,
 
  312                                     stride_src_x,stride_dst_x,
 
  313                                     stride_src_y,stride_dst_y,
 
  318                 copy_grid_fast_shortx_3<grid,3>(bx_src,ptr_dst,ptr_src,
 
  319                                     stride_src_x,stride_dst_x,
 
  320                                     stride_src_y,stride_dst_y,
 
  325                 copy_grid_fast_shortx_3<grid,4>(bx_src,ptr_dst,ptr_src,
 
  326                                     stride_src_x,stride_dst_x,
 
  327                                     stride_src_y,stride_dst_y,
 
  331                 copy_grid_fast_shortx_3<grid,5>(bx_src,ptr_dst,ptr_src,
 
  332                                     stride_src_x,stride_dst_x,
 
  333                                     stride_src_y,stride_dst_y,
 
  337                 copy_grid_fast_shortx_3<grid,6>(bx_src,ptr_dst,ptr_src,
 
  338                                     stride_src_x,stride_dst_x,
 
  339                                     stride_src_y,stride_dst_y,
 
  344                 copy_grid_fast_shortx_3<grid,7>(bx_src,ptr_dst,ptr_src,
 
  345                                     stride_src_x,stride_dst_x,
 
  346                                     stride_src_y,stride_dst_y,
 
  351                 copy_grid_fast_shortx_3<grid,8>(bx_src,ptr_dst,ptr_src,
 
  352                                     stride_src_x,stride_dst_x,
 
  353                                     stride_src_y,stride_dst_y,
 
  358                 copy_grid_fast_longx_3<grid>(bx_src,ptr_dst,ptr_src,
 
  359                                     stride_src_x,stride_dst_x,
 
  360                                     stride_src_y,stride_dst_y,
 
  370 template<
typename gr
id, 
typename ginfo>
 
  373     static void copy(ginfo & gs_src,
 
  387         unsigned char * ptr_final_src = (
unsigned char *)&(gd_src.template get<0>(one));
 
  388         unsigned char * ptr_start_src = (
unsigned char *)&(gd_src.template get<0>(zero));
 
  390         unsigned char * ptr_final_dst = (
unsigned char *)&(gd_dst.template get<0>(one));
 
  391         unsigned char * ptr_start_dst = (
unsigned char *)&(gd_dst.template get<0>(zero));
 
  393         unsigned char * ptr_src = (
unsigned char *)&(gd_src.template get<0>(bx_src.
getKP1()));
 
  394         unsigned char * ptr_dst = (
unsigned char *)&(gd_dst.template get<0>(bx_dst.
getKP1()));
 
  398         size_t stride_src_x = ptr_final_src - ptr_start_src;
 
  399         size_t stride_dst_x = ptr_final_dst - ptr_start_dst;
 
  404                 copy_grid_fast_shortx_2<grid,1>(bx_src,ptr_dst,ptr_src,
 
  405                                     stride_src_x,stride_dst_x);
 
  408                 copy_grid_fast_shortx_2<grid,2>(bx_src,ptr_dst,ptr_src,
 
  409                                     stride_src_x,stride_dst_x);
 
  413                 copy_grid_fast_shortx_2<grid,3>(bx_src,ptr_dst,ptr_src,
 
  414                                     stride_src_x,stride_dst_x);
 
  418                 copy_grid_fast_shortx_2<grid,4>(bx_src,ptr_dst,ptr_src,
 
  419                                     stride_src_x,stride_dst_x);
 
  422                 copy_grid_fast_shortx_2<grid,5>(bx_src,ptr_dst,ptr_src,
 
  423                                     stride_src_x,stride_dst_x);
 
  426                 copy_grid_fast_shortx_2<grid,6>(bx_src,ptr_dst,ptr_src,
 
  427                                     stride_src_x,stride_dst_x);
 
  431                 copy_grid_fast_shortx_2<grid,7>(bx_src,ptr_dst,ptr_src,
 
  432                                     stride_src_x,stride_dst_x);
 
  436                 copy_grid_fast_shortx_2<grid,8>(bx_src,ptr_dst,ptr_src,
 
  437                                     stride_src_x,stride_dst_x);
 
  441                 copy_grid_fast_longx_2<grid>(bx_src,ptr_dst,ptr_src,
 
  442                                     stride_src_x,stride_dst_x,
 
  459 template <
bool is_complex,
 
  477     static void pack(grid & gr, it & sub_it, dtype & dest)
 
  488         while (sub_it.isNext())
 
  491             object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(gr.get_o(sub_it.get()),dest.get(
id));
 
  510 template <
typename grid,
 
  526     static void pack(grid & gr, it & sub_it, dtype & dest)
 
  538         auto & gs_src = gr.getGrid();
 
  542         lin_src += start.
get(2) * gs_src.size_s(1);
 
  543         for (
long int i = start.
get(2) ; i <= stop.
get(2) ; i++)
 
  545             lin_src += start.
get(1) * gs_src.size_s(0);
 
  546             for (
long int j = start.
get(1) ; j <= stop.
get(1) ; j++)
 
  548                 lin_src += start.
get(0);
 
  549                 for (
long int k = start.
get(0) ; k <= stop.
get(0) ; k++)
 
  552                     object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(gr.get_o(lin_src),dest.get(
id));
 
  557                 lin_src -= stop.
get(0) + 1;
 
  558                 lin_src += gs_src.size_s(0);
 
  560             lin_src -= (stop.
get(1) + 1)*gs_src.size_s(0);
 
  561             lin_src += gs_src.size_s(1);
 
  574 template <
typename grid,
 
  590     static void pack(grid & gr, it & sub_it, dtype & dest)
 
  602         auto & gs_src = gr.getGrid();
 
  606         lin_src += start.
get(1) * gs_src.size_s(0);
 
  607         for (
long int j = start.
get(1) ; j <= stop.
get(1) ; j++)
 
  609             lin_src += start.
get(0);
 
  610             for (
long int k = start.
get(0) ; k <= stop.
get(0) ; k++)
 
  613                 object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(gr.get_o(lin_src),dest.get(
id));
 
  618             lin_src -= stop.
get(0) + 1;
 
  619             lin_src += gs_src.size_s(0);
 
  627 template<
unsigned int dim, 
int obj_byte, 
typename git, 
typename gr
id>
 
  630     static void pack(grid & gr,
 
  632               unsigned char * ptr_dest,
 
  637         std::cout << __FILE__ << 
":" << __LINE__ << 
" critical error, we shoukd never be here" << std::endl;
 
  641 template<
int obj_byte, 
typename git, 
typename gr
id>
 
  644     static void pack(grid & gr,
 
  646               unsigned char * ptr_dest,
 
  651         size_t tot_y = sub_it.getStop().get(1) - sub_it.getStart().get(1) + 1;
 
  653         for (
size_t i = 0 ; i < tot_y ; i++)
 
  655             memcpy(ptr_dest,ptr,n_cpy * obj_byte);
 
  658             ptr_dest += n_cpy * obj_byte;
 
  663 template<
int obj_byte, 
typename git, 
typename gr
id>
 
  666     static void pack(grid & gr,
 
  668               unsigned char * ptr_dest,
 
  673         size_t tot_y = sub_it.getStop().get(1) - sub_it.getStart().get(1) + 1;
 
  674         size_t tot_z = sub_it.getStop().get(2) - sub_it.getStart().get(2) + 1;
 
  681         unsigned char * ptr_final = (
unsigned char *)&(gr.template get<0>(one));
 
  682         unsigned char * ptr_start = (
unsigned char *)&(gr.template get<0>(zero));
 
  684         size_t stride_y = ptr_final - ptr_start;
 
  686         for (
size_t i = 0 ; i < tot_z ; i++)
 
  688             for (
size_t i = 0 ; i < tot_y ; i++)
 
  690                 memcpy(ptr_dest,ptr,n_cpy * obj_byte);
 
  693                 ptr_dest += n_cpy * obj_byte;
 
  695             ptr += stride_y - tot_y*stride_x;
 
  704 template<
unsigned int dim, 
unsigned int n_cpy ,
int obj_byte, 
typename git, 
typename gr
id>
 
  707     static void pack(grid & gr,
 
  709               unsigned char * ptr_dest,
 
  713         std::cout << __FILE__ << 
":" << __LINE__ << 
" critical error, we shoukd never be here" << std::endl;
 
  717 template<
unsigned int n_cpy, 
int obj_byte, 
typename git, 
typename gr
id>
 
  720     static void pack(grid & gr,
 
  722               unsigned char * ptr_dest,
 
  726         size_t tot_y = sub_it.getStop().get(1) - sub_it.getStart().get(1) + 1;
 
  728         for (
size_t i = 0 ; i < tot_y ; i++)
 
  730             __builtin_memcpy(ptr_dest,ptr,n_cpy * obj_byte);
 
  733             ptr_dest += n_cpy * obj_byte;
 
  738 template<
unsigned int n_cpy, 
int obj_byte, 
typename git, 
typename gr
id>
 
  741     static void pack(grid & gr,
 
  743               unsigned char * ptr_dest,
 
  747         size_t tot_y = sub_it.getStop().get(1) - sub_it.getStart().get(1) + 1;
 
  748         size_t tot_z = sub_it.getStop().get(2) - sub_it.getStart().get(2) + 1;
 
  755         unsigned char * ptr_final = (
unsigned char *)&(gr.template get<0>(one));
 
  756         unsigned char * ptr_start = (
unsigned char *)&(gr.template get<0>(zero));
 
  758         size_t stride_y = ptr_final - ptr_start;
 
  760         for (
size_t i = 0 ; i < tot_z ; i++)
 
  762             for (
size_t i = 0 ; i < tot_y ; i++)
 
  764                 __builtin_memcpy(ptr_dest,ptr,n_cpy * obj_byte);
 
  767                 ptr_dest += n_cpy * obj_byte;
 
  769             ptr += stride_y - tot_y*stride_x;
 
  784 template <
unsigned int dim,
 
  801     static void pack(grid & gr, it & sub_it, dtype & dest)
 
  804         if (dim == 1 || dim > 3)
 
  806             pack_with_iterator<true,dim,grid,encap_src,encap_dst,boost_vct,it,dtype,prp...>::pack(gr,sub_it,dest);
 
  824         unsigned char * ptr_final = (
unsigned char *)&(gr.template get<0>(one));
 
  825         unsigned char * ptr_start = (
unsigned char *)&(gr.template get<0>(zero));
 
  827         size_t stride = ptr_final - ptr_start;
 
  830         for (
size_t i = 1 ; i < dim ; i++)
 
  831         {n_tot += sub_it.getStop().get(i) - sub_it.getStart().get(i) + 1;}
 
  833         size_t n_cpy = sub_it.getStop().get(0) - sub_it.getStart().get(0) + 1;
 
  835         unsigned char * ptr_dest = (
unsigned char *)dest.getPointer();
 
  916 template <
typename grid,
 
  932     static void pack(grid & gr, it & sub_it, dtype & dest)
 
  944         auto & gs_src = gr.getGrid();
 
  949         lin_src += start.
get(0);
 
  950         for (
long int k = start.
get(0) ; k <= stop.
get(0) ; k++)
 
  953             object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(gr.get_o(lin_src),dest.get(
id));
 
  958         lin_src -= stop.
get(0) + 1;
 
  959         lin_src += gs_src.size_s(0);
 
  974 template <
unsigned int dim,
 
  991     static void unpack(grid & gr, it & sub_it, stype & src)
 
  996         typedef object<
typename object_creator<boost_vct,prp...>::type> prp_object;
 
  999         while (sub_it.isNext())
 
 1003             object_s_di<encap_src,encap_dst,OBJ_ENCAP,prp...>(src.get(
id),gr.get_o(sub_it.get()));
 
 1020 template <
typename grid,
 
 1042     static void unpack(grid & gr, it & sub_it, stype & src)
 
 1047         typedef object<
typename object_creator<boost_vct,prp...>::type> prp_object;
 
 1051         auto & gs_dst = gr.getGrid();
 
 1057         lin_dst += start.
get(2) * gs_dst.size_s(1);
 
 1058         for (
long int i = start.
get(2) ; i <= stop.
get(2) ; i++)
 
 1060             lin_dst += start.
get(1) * gs_dst.size_s(0);
 
 1061             for (
long int j = start.
get(1) ; j <= stop.
get(1) ; j++)
 
 1063                 lin_dst += start.
get(0);
 
 1064                 for (
long int k = start.
get(0) ; k <= stop.
get(0) ; k++)
 
 1067                     object_s_di<encap_src,encap_dst,OBJ_ENCAP,prp...>(src.get(
id),gr.get_o(lin_dst));
 
 1072                 lin_dst -= stop.
get(0) + 1;
 
 1073                 lin_dst += gs_dst.size_s(0);
 
 1075             lin_dst -= (stop.
get(1) + 1)*gs_dst.size_s(0);
 
 1076             lin_dst += gs_dst.size_s(1);
 
static void pack(grid &gr, it &sub_it, dtype &dest)
Pack an N-dimensional grid into a vector like structure B given an iterator of the grid...
 
It copy the properties from one object to another. 
 
T getLow(int i) const 
get the i-coordinate of the low bound interval of the box 
 
grid_key_dx is the key to access any element in the grid 
 
grid_key_dx< dim > getKP2() const 
Get the point p12 as grid_key_dx. 
 
static void pack(grid &gr, it &sub_it, dtype &dest)
Pack an N-dimensional grid into a vector like structure B given an iterator of the grid...
 
T getHigh(int i) const 
get the high interval of the box 
 
static void unpack(grid &gr, it &sub_it, stype &src)
Pack an N-dimensional grid into a vector like structure B given an iterator of the grid...
 
static void pack(grid &gr, it &sub_it, dtype &dest)
Pack an N-dimensional grid into a vector like structure B given an iterator of the grid...
 
static void pack(grid &gr, it &sub_it, dtype &dest)
Pack an N-dimensional grid into a vector like structure B given an iterator of the grid...
 
Pack an N-dimensional grid into a vector like structure B given an iterator of the grid...
 
This is a way to quickly copy a grid into another grid. 
 
grid_key_dx< dim > getKP1() const 
Get the point p1 as grid_key_dx. 
 
mem_id get(size_t i) const 
Get the i index. 
 
void zero()
Set to zero the key. 
 
static void pack(grid &gr, it &sub_it, dtype &dest)
Pack an N-dimensional grid into a vector like structure B given an iterator of the grid...
 
Declaration grid_key_dx_iterator_sub. 
 
Pack an N-dimensional grid into a vector like structure B given an iterator of the grid...
 
It create a boost::fusion vector with the selected properties. 
 
static void unpack(grid &gr, it &sub_it, stype &src)
Pack an N-dimensional grid into a vector like structure B given an iterator of the grid...
 
void set_d(size_t i, mem_id id)
Set the i index. 
 
It copy the properties from one object to another.