OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
copy_grid_fast.hpp
1 /*
2  * copy_grid_fast.hpp
3  *
4  * Created on: Nov 29, 2017
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_DATA_SRC_GRID_COPY_GRID_FAST_HPP_
9 #define OPENFPM_DATA_SRC_GRID_COPY_GRID_FAST_HPP_
10 
11 #include "Grid/iterators/grid_key_dx_iterator.hpp"
12 
17 template<bool is_complex, unsigned int N, typename grid, typename ginfo>
19 {
20  static void copy(ginfo & gs_src,
21  ginfo & gs_dst,
22  Box<N,size_t> & bx_src,
23  Box<N,size_t> & bx_dst,
24  const grid & gd_src,
25  grid & gd_dst,
26  grid_key_dx<N> (& cnt)[1] )
27  {
28  grid_key_dx_iterator_sub<N,stencil_offset_compute<N,1>> sub_src(gs_src,bx_src.getKP1(),bx_src.getKP2(),cnt);
29  grid_key_dx_iterator_sub<N,stencil_offset_compute<N,1>> sub_dst(gs_dst,bx_dst.getKP1(),bx_dst.getKP2(),cnt);
30 
31  while (sub_src.isNext())
32  {
33  // Option 1
34  gd_dst.set(sub_dst.template getStencil<0>(),gd_src,sub_src.template getStencil<0>());
35 
36  ++sub_src;
37  ++sub_dst;
38  }
39  }
40 };
41 
46 template<typename grid, typename ginfo>
47 struct copy_grid_fast<true,3,grid,ginfo>
48 {
49  static void copy(ginfo & gs_src,
50  ginfo & gs_dst,
51  Box<3,size_t> & bx_src,
52  Box<3,size_t> & bx_dst,
53  const grid & gd_src,
54  grid & gd_dst,
55  grid_key_dx<3> (& cnt)[1] )
56  {
57  size_t lin_src = 0;
58  size_t lin_dst = 0;
59 
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++)
63  {
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++)
67  {
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++)
71  {
72  gd_dst.set(lin_dst,gd_src,lin_src);
73 
74  lin_src++;
75  lin_dst++;
76  }
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);
81  }
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);
86  }
87  }
88 };
89 
90 
95 template<typename grid, typename ginfo>
96 struct copy_grid_fast<true,2,grid,ginfo>
97 {
98  static void copy(ginfo & gs_src,
99  ginfo & gs_dst,
100  Box<2,size_t> & bx_src,
101  Box<2,size_t> & bx_dst,
102  const grid & gd_src,
103  grid & gd_dst,
104  grid_key_dx<2> (& cnt)[1] )
105  {
106  size_t lin_src = 0;
107  size_t lin_dst = 0;
108 
109 
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++)
113  {
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++)
117  {
118  gd_dst.set(lin_dst,gd_src,lin_src);
119 
120  lin_src++;
121  lin_dst++;
122  }
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);
127  }
128 
129  }
130 };
131 
132 
133 
138 template<typename grid, typename ginfo>
139 struct copy_grid_fast<true,1,grid,ginfo>
140 {
141  static void copy(ginfo & gs_src,
142  ginfo & gs_dst,
143  Box<1,size_t> & bx_src,
144  Box<1,size_t> & bx_dst,
145  const grid & gd_src,
146  grid & gd_dst,
147  grid_key_dx<1> (& cnt)[1] )
148  {
149  size_t lin_src = 0;
150  size_t lin_dst = 0;
151 
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++)
155  {
156  gd_dst.set(lin_dst,gd_src,lin_src);
157 
158  lin_src++;
159  lin_dst++;
160  }
161 
162 
163  }
164 };
165 
167 
168 template<typename grid>
169 void copy_grid_fast_longx_3(Box<3,size_t> & bx_src,
170  unsigned char * ptr_dst,
171  unsigned char * ptr_src,
172  size_t stride_src_x,
173  size_t stride_dst_x,
174  size_t stride_src_y,
175  size_t stride_dst_y,
176  size_t tot_y,
177  size_t n_cpy)
178 {
179  for (size_t i = bx_src.getLow(2) ; i <= bx_src.getHigh(2) ; i++)
180  {
181  for (size_t j = bx_src.getLow(1) ; j <= bx_src.getHigh(1) ; j++)
182  {
183  memcpy(ptr_dst,ptr_src,n_cpy*sizeof(typename grid::value_type));
184 
185  ptr_dst += stride_dst_x;
186  ptr_src += stride_src_x;
187  }
188  ptr_dst += stride_dst_y - tot_y*stride_dst_x;
189  ptr_src += stride_src_y - tot_y*stride_src_x;
190  }
191 }
192 
193 template<typename grid, unsigned int n_cpy>
194 void copy_grid_fast_shortx_3(Box<3,size_t> & bx_src,
195  unsigned char * ptr_dst,
196  unsigned char * ptr_src,
197  size_t stride_src_x,
198  size_t stride_dst_x,
199  size_t stride_src_y,
200  size_t stride_dst_y,
201  size_t tot_y)
202 {
203  for (size_t i = bx_src.getLow(2) ; i <= bx_src.getHigh(2) ; i++)
204  {
205  for (size_t j = bx_src.getLow(1) ; j <= bx_src.getHigh(1) ; j++)
206  {
207  __builtin_memcpy(ptr_dst,ptr_src,n_cpy*sizeof(typename grid::value_type));
208 
209  ptr_dst += stride_dst_x;
210  ptr_src += stride_src_x;
211  }
212  ptr_dst += stride_dst_y - tot_y*stride_dst_x;
213  ptr_src += stride_src_y - tot_y*stride_src_x;
214  }
215 }
216 
217 
219 
220 template<typename grid>
221 void copy_grid_fast_longx_2(Box<2,size_t> & bx_src,
222  unsigned char * ptr_dst,
223  unsigned char * ptr_src,
224  size_t stride_src_x,
225  size_t stride_dst_x,
226  size_t n_cpy)
227 {
228  for (size_t j = bx_src.getLow(1) ; j <= bx_src.getHigh(1) ; j++)
229  {
230  memcpy(ptr_dst,ptr_src,n_cpy*sizeof(typename grid::value_type));
231 
232  ptr_dst += stride_dst_x;
233  ptr_src += stride_src_x;
234  }
235 }
236 
237 template<typename grid, unsigned int n_cpy>
238 void copy_grid_fast_shortx_2(Box<2,size_t> & bx_src,
239  unsigned char * ptr_dst,
240  unsigned char * ptr_src,
241  size_t stride_src_x,
242  size_t stride_dst_x)
243 {
244  for (size_t j = bx_src.getLow(1) ; j <= bx_src.getHigh(1) ; j++)
245  {
246  __builtin_memcpy(ptr_dst,ptr_src,n_cpy*sizeof(typename grid::value_type));
247 
248  ptr_dst += stride_dst_x;
249  ptr_src += stride_src_x;
250  }
251 }
252 
257 template<typename grid, typename ginfo>
258 struct copy_grid_fast<false,3,grid,ginfo>
259 {
260  static void copy(ginfo & gs_src,
261  ginfo & gs_dst,
262  Box<3,size_t> & bx_src,
263  Box<3,size_t> & bx_dst,
264  const grid & gd_src,
265  grid & gd_dst,
266  grid_key_dx<3> (& cnt)[1] )
267  {
268 
269  grid_key_dx<3> zero;
270  zero.zero();
271  grid_key_dx<3> one = zero;
272  one.set_d(1,1);
273 
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));
276 
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));
279 
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()));
282 
283  size_t n_cpy = bx_src.getHigh(0) - bx_src.getLow(0) + 1;
284 
285  size_t tot_y = bx_src.getHigh(1) - bx_src.getLow(1) + 1;
286 
287  size_t stride_src_x = ptr_final_src - ptr_start_src;
288  size_t stride_dst_x = ptr_final_dst - ptr_start_dst;
289 
290  grid_key_dx<3> one2 = zero;
291  one2.set_d(2,1);
292 
293  ptr_final_src = (unsigned char *)&(gd_src.template get<0>(one2));
294  ptr_start_src = (unsigned char *)&(gd_src.template get<0>(zero));
295 
296  ptr_final_dst = (unsigned char *)&(gd_dst.template get<0>(one2));
297  ptr_start_dst = (unsigned char *)&(gd_dst.template get<0>(zero));
298 
299  size_t stride_src_y = ptr_final_src - ptr_start_src;
300  size_t stride_dst_y = ptr_final_dst - ptr_start_dst;
301 
302  switch (n_cpy)
303  {
304  case 1:
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,
308  tot_y);
309  break;
310  case 2:
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,
314  tot_y);
315  break;
316 
317  case 3:
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,
321  tot_y);
322  break;
323 
324  case 4:
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,
328  tot_y);
329  break;
330  case 5:
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,
334  tot_y);
335  break;
336  case 6:
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,
340  tot_y);
341  break;
342 
343  case 7:
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,
347  tot_y);
348  break;
349 
350  case 8:
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,
354  tot_y);
355  break;
356 
357  default:
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,
361  tot_y,n_cpy);
362  }
363  }
364 };
365 
370 template<typename grid, typename ginfo>
371 struct copy_grid_fast<false,2,grid,ginfo>
372 {
373  static void copy(ginfo & gs_src,
374  ginfo & gs_dst,
375  Box<2,size_t> & bx_src,
376  Box<2,size_t> & bx_dst,
377  const grid & gd_src,
378  grid & gd_dst,
379  grid_key_dx<2> (& cnt)[1] )
380  {
381 
382  grid_key_dx<2> zero;
383  zero.zero();
384  grid_key_dx<2> one = zero;
385  one.set_d(1,1);
386 
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));
389 
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));
392 
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()));
395 
396  size_t n_cpy = bx_src.getHigh(0) - bx_src.getLow(0) + 1;
397 
398  size_t stride_src_x = ptr_final_src - ptr_start_src;
399  size_t stride_dst_x = ptr_final_dst - ptr_start_dst;
400 
401  switch (n_cpy)
402  {
403  case 1:
404  copy_grid_fast_shortx_2<grid,1>(bx_src,ptr_dst,ptr_src,
405  stride_src_x,stride_dst_x);
406  break;
407  case 2:
408  copy_grid_fast_shortx_2<grid,2>(bx_src,ptr_dst,ptr_src,
409  stride_src_x,stride_dst_x);
410  break;
411 
412  case 3:
413  copy_grid_fast_shortx_2<grid,3>(bx_src,ptr_dst,ptr_src,
414  stride_src_x,stride_dst_x);
415  break;
416 
417  case 4:
418  copy_grid_fast_shortx_2<grid,4>(bx_src,ptr_dst,ptr_src,
419  stride_src_x,stride_dst_x);
420  break;
421  case 5:
422  copy_grid_fast_shortx_2<grid,5>(bx_src,ptr_dst,ptr_src,
423  stride_src_x,stride_dst_x);
424  break;
425  case 6:
426  copy_grid_fast_shortx_2<grid,6>(bx_src,ptr_dst,ptr_src,
427  stride_src_x,stride_dst_x);
428  break;
429 
430  case 7:
431  copy_grid_fast_shortx_2<grid,7>(bx_src,ptr_dst,ptr_src,
432  stride_src_x,stride_dst_x);
433  break;
434 
435  case 8:
436  copy_grid_fast_shortx_2<grid,8>(bx_src,ptr_dst,ptr_src,
437  stride_src_x,stride_dst_x);
438  break;
439 
440  default:
441  copy_grid_fast_longx_2<grid>(bx_src,ptr_dst,ptr_src,
442  stride_src_x,stride_dst_x,
443  n_cpy);
444  }
445  }
446 };
447 
449 
450 
459 template <bool is_complex,
460  unsigned int dim,
461  typename grid,
462  typename encap_src,
463  typename encap_dst,
464  typename boost_vct,
465  typename it,
466  typename dtype,
467  int ... prp>
469 {
477  static void pack(grid & gr, it & sub_it, dtype & dest)
478  {
479  // Sending property object
480  typedef object<typename object_creator<
481  boost_vct,
482  prp...>::type
483  > prp_object;
484 
485  size_t id = 0;
486 
487  // Packing the information
488  while (sub_it.isNext())
489  {
490  // Copy only the selected properties
491  object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(gr.get_o(sub_it.get()),dest.get(id));
492 
493  ++id;
494  ++sub_it;
495  }
496  }
497 };
498 
499 
500 
501 
510 template <typename grid,
511  typename encap_src,
512  typename encap_dst,
513  typename boost_vct,
514  typename it,
515  typename dtype,
516  int ... prp>
517 struct pack_with_iterator<true,3,grid,encap_src,encap_dst,boost_vct,it,dtype,prp...>
518 {
526  static void pack(grid & gr, it & sub_it, dtype & dest)
527  {
528  // Sending property object
529  typedef object<typename object_creator<
530  boost_vct,
531  prp...>::type
532  > prp_object;
533 
534  size_t id = 0;
535 
536  size_t lin_src = 0;
537 
538  auto & gs_src = gr.getGrid();
539  grid_key_dx<3> start = sub_it.getStart();
540  grid_key_dx<3> stop = sub_it.getStop();
541 
542  lin_src += start.get(2) * gs_src.size_s(1);
543  for (long int i = start.get(2) ; i <= stop.get(2) ; i++)
544  {
545  lin_src += start.get(1) * gs_src.size_s(0);
546  for (long int j = start.get(1) ; j <= stop.get(1) ; j++)
547  {
548  lin_src += start.get(0);
549  for (long int k = start.get(0) ; k <= stop.get(0) ; k++)
550  {
551  // Copy only the selected properties
552  object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(gr.get_o(lin_src),dest.get(id));
553 
554  ++id;
555  ++lin_src;
556  }
557  lin_src -= stop.get(0) + 1;
558  lin_src += gs_src.size_s(0);
559  }
560  lin_src -= (stop.get(1) + 1)*gs_src.size_s(0);
561  lin_src += gs_src.size_s(1);
562  }
563  }
564 };
565 
574 template <typename grid,
575  typename encap_src,
576  typename encap_dst,
577  typename boost_vct,
578  typename it,
579  typename dtype,
580  int ... prp>
581 struct pack_with_iterator<true,2,grid,encap_src,encap_dst,boost_vct,it,dtype,prp...>
582 {
590  static void pack(grid & gr, it & sub_it, dtype & dest)
591  {
592  // Sending property object
593  typedef object<typename object_creator<
594  boost_vct,
595  prp...>::type
596  > prp_object;
597 
598  size_t id = 0;
599 
600  size_t lin_src = 0;
601 
602  auto & gs_src = gr.getGrid();
603  grid_key_dx<2> start = sub_it.getStart();
604  grid_key_dx<2> stop = sub_it.getStop();
605 
606  lin_src += start.get(1) * gs_src.size_s(0);
607  for (long int j = start.get(1) ; j <= stop.get(1) ; j++)
608  {
609  lin_src += start.get(0);
610  for (long int k = start.get(0) ; k <= stop.get(0) ; k++)
611  {
612  // Copy only the selected properties
613  object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(gr.get_o(lin_src),dest.get(id));
614 
615  ++id;
616  ++lin_src;
617  }
618  lin_src -= stop.get(0) + 1;
619  lin_src += gs_src.size_s(0);
620  }
621 
622  }
623 };
624 
626 
627 template<unsigned int dim, int obj_byte, typename git, typename grid>
629 {
630  static void pack(grid & gr,
631  git & sub_it,
632  unsigned char * ptr_dest,
633  unsigned char * ptr,
634  size_t stride_x,
635  size_t n_cpy)
636  {
637  std::cout << __FILE__ << ":" << __LINE__ << " critical error, we shoukd never be here" << std::endl;
638  }
639 };
640 
641 template<int obj_byte, typename git, typename grid>
642 struct pack_with_iterator_longx<2,obj_byte,git,grid>
643 {
644  static void pack(grid & gr,
645  git & sub_it,
646  unsigned char * ptr_dest,
647  unsigned char * ptr,
648  size_t stride_x,
649  size_t n_cpy)
650  {
651  size_t tot_y = sub_it.getStop().get(1) - sub_it.getStart().get(1) + 1;
652 
653  for (size_t i = 0 ; i < tot_y ; i++)
654  {
655  memcpy(ptr_dest,ptr,n_cpy * obj_byte);
656 
657  ptr += stride_x;
658  ptr_dest += n_cpy * obj_byte;
659  }
660  }
661 };
662 
663 template<int obj_byte, typename git, typename grid>
664 struct pack_with_iterator_longx<3,obj_byte,git,grid>
665 {
666  static void pack(grid & gr,
667  git & sub_it,
668  unsigned char * ptr_dest,
669  unsigned char * ptr,
670  size_t stride_x,
671  size_t n_cpy)
672  {
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;
675 
676  grid_key_dx<3> zero;
677  zero.zero();
678  grid_key_dx<3> one = zero;
679  one.set_d(2,1);
680 
681  unsigned char * ptr_final = (unsigned char *)&(gr.template get<0>(one));
682  unsigned char * ptr_start = (unsigned char *)&(gr.template get<0>(zero));
683 
684  size_t stride_y = ptr_final - ptr_start;
685 
686  for (size_t i = 0 ; i < tot_z ; i++)
687  {
688  for (size_t i = 0 ; i < tot_y ; i++)
689  {
690  memcpy(ptr_dest,ptr,n_cpy * obj_byte);
691 
692  ptr += stride_x;
693  ptr_dest += n_cpy * obj_byte;
694  }
695  ptr += stride_y - tot_y*stride_x;
696  }
697  }
698 };
699 
701 
703 
704 template<unsigned int dim, unsigned int n_cpy ,int obj_byte, typename git, typename grid>
706 {
707  static void pack(grid & gr,
708  git & sub_it,
709  unsigned char * ptr_dest,
710  unsigned char * ptr,
711  size_t stride_x)
712  {
713  std::cout << __FILE__ << ":" << __LINE__ << " critical error, we shoukd never be here" << std::endl;
714  }
715 };
716 
717 template<unsigned int n_cpy, int obj_byte, typename git, typename grid>
718 struct pack_with_iterator_shortx<2,n_cpy,obj_byte,git,grid>
719 {
720  static void pack(grid & gr,
721  git & sub_it,
722  unsigned char * ptr_dest,
723  unsigned char * ptr,
724  size_t stride_x)
725  {
726  size_t tot_y = sub_it.getStop().get(1) - sub_it.getStart().get(1) + 1;
727 
728  for (size_t i = 0 ; i < tot_y ; i++)
729  {
730  __builtin_memcpy(ptr_dest,ptr,n_cpy * obj_byte);
731 
732  ptr += stride_x;
733  ptr_dest += n_cpy * obj_byte;
734  }
735  }
736 };
737 
738 template<unsigned int n_cpy, int obj_byte, typename git, typename grid>
739 struct pack_with_iterator_shortx<3,n_cpy,obj_byte,git,grid>
740 {
741  static void pack(grid & gr,
742  git & sub_it,
743  unsigned char * ptr_dest,
744  unsigned char * ptr,
745  size_t stride_x)
746  {
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;
749 
750  grid_key_dx<3> zero;
751  zero.zero();
752  grid_key_dx<3> one = zero;
753  one.set_d(2,1);
754 
755  unsigned char * ptr_final = (unsigned char *)&(gr.template get<0>(one));
756  unsigned char * ptr_start = (unsigned char *)&(gr.template get<0>(zero));
757 
758  size_t stride_y = ptr_final - ptr_start;
759 
760  for (size_t i = 0 ; i < tot_z ; i++)
761  {
762  for (size_t i = 0 ; i < tot_y ; i++)
763  {
764  __builtin_memcpy(ptr_dest,ptr,n_cpy * obj_byte);
765 
766  ptr += stride_x;
767  ptr_dest += n_cpy * obj_byte;
768  }
769  ptr += stride_y - tot_y*stride_x;
770  }
771  }
772 };
773 
775 
784 template <unsigned int dim,
785  typename grid,
786  typename encap_src,
787  typename encap_dst,
788  typename boost_vct,
789  typename it,
790  typename dtype,
791  int ... prp>
792 struct pack_with_iterator<false,dim,grid,encap_src,encap_dst,boost_vct,it,dtype,prp...>
793 {
801  static void pack(grid & gr, it & sub_it, dtype & dest)
802  {
803  // We do not have an optimized version for dimension different from 3 and 2
804  if (dim == 1 || dim > 3)
805  {
807  return;
808  }
809 
810  // Sending property object
811  typedef object<typename object_creator<
812  boost_vct,
813  prp...>::type
814  > prp_object;
815 
816 
817  // fast strided copy
818 
819  grid_key_dx<dim> zero;
820  zero.zero();
821  grid_key_dx<dim> one = zero;
822  one.set_d(1,1);
823 
824  unsigned char * ptr_final = (unsigned char *)&(gr.template get<0>(one));
825  unsigned char * ptr_start = (unsigned char *)&(gr.template get<0>(zero));
826 
827  size_t stride = ptr_final - ptr_start;
828 
829  size_t n_tot = 0;
830  for (size_t i = 1 ; i < dim ; i++)
831  {n_tot += sub_it.getStop().get(i) - sub_it.getStart().get(i) + 1;}
832 
833  size_t n_cpy = sub_it.getStop().get(0) - sub_it.getStart().get(0) + 1;
834  unsigned char * ptr = (unsigned char *)&(gr.template get<first_variadic<prp...>::type::value>(sub_it.getStart()));
835  unsigned char * ptr_dest = (unsigned char *)dest.getPointer();
836 
837  switch (n_cpy)
838  {
839  case 1:
841  sub_it,
842  ptr_dest,
843  ptr,
844  stride);
845  break;
846  case 2:
848  sub_it,
849  ptr_dest,
850  ptr,
851  stride);
852  break;
853  case 3:
855  sub_it,
856  ptr_dest,
857  ptr,
858  stride);
859  break;
860  case 4:
862  sub_it,
863  ptr_dest,
864  ptr,
865  stride);
866  break;
867  case 5:
869  sub_it,
870  ptr_dest,
871  ptr,
872  stride);
873  break;
874  case 6:
876  sub_it,
877  ptr_dest,
878  ptr,
879  stride);
880  break;
881  case 7:
883  sub_it,
884  ptr_dest,
885  ptr,
886  stride);
887  break;
888  case 8:
890  sub_it,
891  ptr_dest,
892  ptr,
893  stride);
894  break;
895  default:
897  sub_it,
898  ptr_dest,
899  ptr,
900  stride,
901  n_cpy);
902 
903  }
904 
905  }
906 };
907 
916 template <typename grid,
917  typename encap_src,
918  typename encap_dst,
919  typename boost_vct,
920  typename it,
921  typename dtype,
922  int ... prp>
923 struct pack_with_iterator<true,1,grid,encap_src,encap_dst,boost_vct,it,dtype,prp...>
924 {
932  static void pack(grid & gr, it & sub_it, dtype & dest)
933  {
934  // Sending property object
935  typedef object<typename object_creator<
936  boost_vct,
937  prp...>::type
938  > prp_object;
939 
940  size_t id = 0;
941 
942  size_t lin_src = 0;
943 
944  auto & gs_src = gr.getGrid();
945  grid_key_dx<1> start = sub_it.getStart();
946  grid_key_dx<1> stop = sub_it.getStop();
947 
948 
949  lin_src += start.get(0);
950  for (long int k = start.get(0) ; k <= stop.get(0) ; k++)
951  {
952  // Copy only the selected properties
953  object_si_d<encap_src,encap_dst,OBJ_ENCAP,prp...>(gr.get_o(lin_src),dest.get(id));
954 
955  ++id;
956  ++lin_src;
957  }
958  lin_src -= stop.get(0) + 1;
959  lin_src += gs_src.size_s(0);
960 
961  }
962 };
963 
965 
974 template <unsigned int dim,
975  typename grid,
976  typename encap_src,
977  typename encap_dst,
978  typename boost_vct,
979  typename it,
980  typename stype,
981  int ... prp>
983 {
991  static void unpack(grid & gr, it & sub_it, stype & src)
992  {
993  size_t id = 0;
994 
995  // Sending property object
996  typedef object<typename object_creator<boost_vct,prp...>::type> prp_object;
997 
998  // unpacking the information
999  while (sub_it.isNext())
1000  {
1001 
1002  // Copy only the selected properties
1003  object_s_di<encap_src,encap_dst,OBJ_ENCAP,prp...>(src.get(id),gr.get_o(sub_it.get()));
1004 
1005  ++id;
1006  ++sub_it;
1007  }
1008  }
1009 };
1010 
1011 
1020 template <typename grid,
1021  typename encap_src,
1022  typename encap_dst,
1023  typename boost_vct,
1024  typename it,
1025  typename stype,
1026  int ... prp>
1027 struct unpack_with_iterator<3,grid,
1028  encap_src,
1029  encap_dst,
1030  boost_vct,
1031  it,
1032  stype,
1033  prp ...>
1034 {
1042  static void unpack(grid & gr, it & sub_it, stype & src)
1043  {
1044  size_t id = 0;
1045 
1046  // Sending property object
1047  typedef object<typename object_creator<boost_vct,prp...>::type> prp_object;
1048 
1049  size_t lin_dst = 0;
1050 
1051  auto & gs_dst = gr.getGrid();
1052  grid_key_dx<3> start = sub_it.getStart();
1053  grid_key_dx<3> stop = sub_it.getStop();
1054 
1055  // unpacking the information
1056 
1057  lin_dst += start.get(2) * gs_dst.size_s(1);
1058  for (long int i = start.get(2) ; i <= stop.get(2) ; i++)
1059  {
1060  lin_dst += start.get(1) * gs_dst.size_s(0);
1061  for (long int j = start.get(1) ; j <= stop.get(1) ; j++)
1062  {
1063  lin_dst += start.get(0);
1064  for (long int k = start.get(0) ; k <= stop.get(0) ; k++)
1065  {
1066  // Copy only the selected properties
1067  object_s_di<encap_src,encap_dst,OBJ_ENCAP,prp...>(src.get(id),gr.get_o(lin_dst));
1068 
1069  ++id;
1070  ++lin_dst;
1071  }
1072  lin_dst -= stop.get(0) + 1;
1073  lin_dst += gs_dst.size_s(0);
1074  }
1075  lin_dst -= (stop.get(1) + 1)*gs_dst.size_s(0);
1076  lin_dst += gs_dst.size_s(1);
1077  }
1078  }
1079 };
1080 
1081 #endif /* OPENFPM_DATA_SRC_GRID_COPY_GRID_FAST_HPP_ */
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
Definition: Box.hpp:479
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
grid_key_dx< dim > getKP2() const
Get the point p12 as grid_key_dx.
Definition: Box.hpp:592
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
Definition: Box.hpp:490
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.
Definition: Box.hpp:579
mem_id get(size_t i) const
Get the i index.
Definition: grid_key.hpp:394
void zero()
Set to zero the key.
Definition: grid_key.hpp:116
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.
Definition: grid_sm.hpp:77
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.
Definition: grid_key.hpp:407
It copy the properties from one object to another.