5 #include <unordered_map>
6 #include "Grid/map_grid.hpp"
7 #include "VCluster/VCluster.hpp"
8 #include "Space/Ghost.hpp"
9 #include "Space/Shape/Box.hpp"
10 #include "util/mathutil.hpp"
11 #include "VTKWriter/VTKWriter.hpp"
13 #include "SparseGridGpu/SparseGridGpu.hpp"
15 #include "Iterators/grid_dist_id_iterator_dec.hpp"
16 #include "Iterators/grid_dist_id_iterator.hpp"
17 #include "Iterators/grid_dist_id_iterator_sub.hpp"
18 #include "grid_dist_key.hpp"
19 #include "NN/CellList/CellDecomposer.hpp"
20 #include "util/object_util.hpp"
21 #include "memory/ExtPreAlloc.hpp"
22 #include "Packer_Unpacker/Packer.hpp"
23 #include "Packer_Unpacker/Unpacker.hpp"
24 #include "Decomposition/CartDecomposition.hpp"
25 #include "data_type/aggregate.hpp"
27 #include "grid_dist_id_comm.hpp"
28 #include "HDF5_wr/HDF5_wr.hpp"
29 #include "SparseGrid/SparseGrid.hpp"
30 #include "lib/pdata.hpp"
32 #include "cuda/grid_dist_id_kernels.cuh"
33 #include "Grid/cuda/grid_dist_id_iterator_gpu.cuh"
39 template<
unsigned int dim>
50 template<
unsigned int dim>
63 #define NO_GDB_EXT_SWITCH 0x1000
65 template<
bool is_sparse>
68 template<
typename key_type1,
typename key_type2,
typename spg_type,
typename lg_type>
69 static void assign(key_type1 & key, key_type2 & key_dst, spg_type & dg, lg_type & lg)
71 dg.insert_o(key_dst) = lg.get_o(key);
74 template<
typename gdb_ext_type,
typename loc_gr
id_type>
75 static void pre_load(gdb_ext_type & gdb_ext_old, loc_grid_type & loc_grid_old, gdb_ext_type & gdb_ext, loc_grid_type & loc_grid)
80 template<
typename e_src,
typename e_dst,
typename indexT>
85 e_dst & block_data_dst;
101 __device__ __host__
inline void operator()(T& t)
const
103 block_data_dst.template get<T::value>()[local_id] =
block_data_src.template get<T::value>();
111 template<
int ... prp>
114 template<
typename this_type,
typename dec_type,
typename cd_sm_type,
typename loc_gr
id_type,
typename gdb_ext_type>
115 static void call(this_type * this_,
118 loc_grid_type & loc_grid,
119 loc_grid_type & loc_grid_old,
120 gdb_ext_type & gdb_ext,
121 gdb_ext_type & gdb_ext_old,
122 gdb_ext_type & gdb_ext_global,
125 this_->template map_<prp ...>(dec,cd_sm,loc_grid,loc_grid_old,gdb_ext,gdb_ext_old,gdb_ext_global,opt);
133 bool operator<(
const ids_pl & i)
const
138 bool operator==(
const ids_pl & i)
const
147 template<
typename key_type1,
typename key_type2,
typename spg_type,
typename lg_type>
148 static void assign(key_type1 & key, key_type2 & key_dst, spg_type & dg, lg_type & lg)
150 typename spg_type::indexT_ local_id;
151 auto block_data_dst = dg.insertBlockFlush(key_dst, local_id);
152 auto block_data_src = lg.get_o(key);
154 copy_all_prop_sparse<decltype(block_data_src),decltype(block_data_dst),decltype(local_id)> cp(block_data_src, block_data_dst, local_id);
156 boost::mpl::for_each_ref< boost::mpl::range_c<
int,0,decltype(block_data_dst)::max_prop> >(cp);
161 template<
typename gdb_ext_type,
typename loc_gr
id_type>
162 static void pre_load(gdb_ext_type & gdb_ext_old, loc_grid_type & loc_grid_old, gdb_ext_type & gdb_ext, loc_grid_type & loc_grid)
164 auto & dg = loc_grid.get(0);
165 auto dlin = dg.getGrid();
166 typedef typename std::remove_reference<decltype(dg)>::type sparse_grid_type;
171 size_t sz[sparse_grid_type::dims];
173 for (
int i = 0 ; i < sparse_grid_type::dims ; i++)
184 for (
int i = 0 ; i < sparse_grid_type::dims ; i++)
186 k.set_d(i,key.get(i)*dlin.getBlockEgdeSize());
194 for (
int i = 0 ; i < gdb_ext_old.size() ; i++)
197 auto & lg = loc_grid_old.
get(i);
198 auto & indexBuffer = lg.private_get_index_array();
199 auto & dg = loc_grid.
get(0);
201 auto slin = loc_grid_old.get(i).getGrid();
206 for (
int j = 0 ; j < sparse_grid_type::dims ; j++)
208 orig.
set_d(j,gdb_ext_old.get(i).origin.get(j));
211 for (
int i = 0; i < indexBuffer.size() ; i++)
213 for (
int ex = 0; ex < gg.
size() ; ex++) {
214 auto key = slin.InvLinId(indexBuffer.template get<0>(i),0);
217 for (
int j = 0 ; j < sparse_grid_type::dims ; j++)
218 {key_dst.
set_d(j,key.get(j) + orig.
get(j) + kp1.
get(j) + gg.get(ex).get(j));}
220 typename sparse_grid_type::indexT_ bid;
223 dlin.LinId(key_dst,bid,
lid);
234 auto & indexBuffer = dg.private_get_index_array();
235 auto & dataBuffer = dg.private_get_data_array();
236 indexBuffer.reserve(ids.
size()+8);
237 dataBuffer.reserve(ids.
size()+8);
238 for (
int i = 0 ; i < ids.
size() ; i++)
240 auto & dg = loc_grid.get(0);
241 dg.insertBlockFlush(ids.get(i).id);
272 template<
unsigned int dim,
324 CellDecomposer_sm<dim,St,shift<dim,St>>
cd_sm;
474 grid_dist_id<dim,St,T,Decomposition,Memory,device_grid> * g =
static_cast<grid_dist_id<dim,St,T,Decomposition,Memory,device_grid> *
>(ptr);
480 size_t lc_id = g->
dec.ProctoID(i);
514 sub_domain =
gdb_ext.get(sub_id).Dbox;
515 sub_domain +=
gdb_ext.get(sub_id).origin;
522 for (
size_t i = 0 ; i < dim ; i++)
529 else if (cmb.
c[i] == -1)
536 sub_domain_other_exp.
enlarge(g);
537 if (sub_domain_other_exp.
Intersect(sub_domain,ib) ==
false)
539 for (
size_t i = 0 ; i < dim ; i++)
557 auto g =
cd_sm.getGrid();
562 for (
size_t i = 0 ; i <
dec.getNNProcessors() ; i++)
565 auto&& pib =
ig_box.last();
567 pib.prc =
dec.IDtoProc(i);
568 for (
size_t j = 0 ; j <
dec.getProcessorNIGhost(i) ; j++)
574 size_t sub_id =
dec.getProcessorIGhostSub(i,j);
575 size_t r_sub =
dec.getProcessorIGhostSSub(i,j);
577 auto & n_box =
dec.getNearSubdomains(
dec.IDtoProc(i));
580 n_box.get(r_sub),
dec.getProcessorIGhostPos(i,j),
589 for (
size_t k = 0 ; k < ibv.
size() ; k++)
592 if (ibv.get(k).bx.isValid() ==
false)
600 bid_t.
g_id =
dec.getProcessorIGhostId(i,j) | (k) << 52;
602 bid_t.
sub = convert_to_gdb_ext(
dec.getProcessorIGhostSub(i,j),
607 bid_t.
cmb =
dec.getProcessorIGhostPos(i,j);
608 bid_t.
r_sub =
dec.getProcessorIGhostSSub(i,j);
626 auto g =
cd_sm.getGrid();
638 for(
size_t i = 0 ; i <
dec.getNNProcessors() ; i++)
640 for (
size_t j = 0 ; j <
ig_box.get(i).bid.
size() ; j++)
642 box_int_send.get(i).add();
643 box_int_send.get(i).last().bx =
ig_box.get(i).bid.get(j).box;
644 box_int_send.get(i).last().g_id =
ig_box.get(i).bid.get(j).g_id;
645 box_int_send.get(i).last().r_sub =
ig_box.get(i).bid.get(j).r_sub;
646 box_int_send.get(i).last().cmb =
ig_box.get(i).bid.get(j).cmb;
648 prc.add(
dec.IDtoProc(i));
651 v_cl.
SSendRecv(box_int_send,box_int_recv,prc,prc_recv,sz_recv);
658 for (
size_t i = 0 ; i < box_int_recv.
size() ; i++)
661 size_t p_id =
dec.ProctoID(prc_recv.get(i));
662 auto&& pib =
eg_box.get(p_id);
663 pib.prc = prc_recv.get(i);
665 eg_box.get(p_id).recv_pnt = 0;
666 eg_box.get(p_id).n_r_box = box_int_recv.get(i).
size();
669 for (
size_t j = 0 ; j < box_int_recv.get(i).
size() ; j++)
671 size_t vol_recv = box_int_recv.get(i).get(j).bx.getVolumeKey();
673 eg_box.get(p_id).recv_pnt += vol_recv;
674 size_t send_list_id = box_int_recv.get(i).get(j).r_sub;
700 size_t g_id = box_int_recv.get(i).get(j).g_id;
701 add_eg_box<dim>(k,box_int_recv.get(i).get(j).cmb,output,
704 box_int_recv.get(i).get(j).bx.getP1(),
707 eb_gid_list.last().eb_list.add(pib.bid.size() - 1);
716 bool no_match =
true;
721 if (pib.bid.get(eb_id).g_e_box == box_int_recv.get(i).get(j).bx)
735 if (no_match ==
true)
740 for (
size_t s = 0 ; s < dim ; s++)
741 {sz[s] = box_int_recv.get(i).get(j).bx.getHigh(s) - box_int_recv.get(i).get(j).bx.getLow(s) + 1;}
749 tmp.
GDbox = box_int_recv.get(i).get(j).bx;
752 for (
size_t s = 0 ; s < dim ; s++)
768 size_t g_id = box_int_recv.get(i).get(j).g_id;
769 add_eg_box<dim>(
gdb_ext.
size()-1,box_int_recv.get(i).get(j).cmb,output,
772 box_int_recv.get(i).get(j).bx.getP1(),
778 eb_gid_list.last().eb_list.add(pib.bid.size() - 1);
785 size_t sub_id = pib.bid.get(fm).sub;
787 for ( ; pib_cnt < pib.bid.size() ; pib_cnt++)
789 pib.bid.get(pib_cnt).lr_e_box -=
gdb_ext.get(sub_id).origin;
800 size_t sub_id = s_sub.get(send_list_id);
804 bid_t.
cmb = box_int_recv.get(i).get(j).cmb;
805 bid_t.
cmb.sign_flip();
808 bid_t.
g_id = box_int_recv.get(i).get(j).g_id;
811 tb -=
gdb_ext.get(sub_id).origin;
836 auto g =
cd_sm.getGrid();
841 for (
size_t i = 0 ; i <
dec.getNSubDomain() ; i++)
846 for (
size_t j = 0 ; j <
dec.getLocalNIGhost(i) ; j++)
860 for (
size_t k = 0 ; k < ibv.
size() ; k++)
863 if (ibv.get(k).bx.isValid() ==
false)
867 pib.bid.last().box = ibv.get(k).bx;
869 pib.bid.last().sub_gdb_ext = convert_to_gdb_ext(i,
874 pib.bid.last().sub =
dec.getLocalIGhostSub(i,j);
877 pib.bid.last().cmb =
dec.getLocalIGhostPos(i,j);
891 size_t r_sub =
dec.getLocalIGhostSub(i,j);
901 pib.bid.last().box = ib;
902 pib.bid.last().sub =
dec.getLocalIGhostSub(i,j);
903 pib.bid.last().k.add(
dec.getLocalIGhostE(i,j));
904 pib.bid.last().cmb =
dec.getLocalIGhostPos(i,j);
905 pib.bid.last().sub_gdb_ext = i;
920 if (j == k) {
continue;}
933 pib.bid.last().box = output;
935 pib.bid.last().sub_gdb_ext = j;
936 pib.bid.last().sub = i;
939 pib.bid.last().cmb.
zero();
958 auto g =
cd_sm.getGrid();
965 for (
size_t i = 0 ; i <
dec.getNSubDomain() ; i++)
969 long int volume_linked = 0;
971 size_t le_sub =
loc_ig_box.get(i).bid.get(j).sub;
990 bool intersect_domain = bx.
Intersect(flp_i,output);
991 bool intersect_gdomain = gbx.
Intersect(flp_i,output);
994 if (intersect_domain ==
false && intersect_gdomain ==
true)
997 loc_ig_box.get(i).bid.get(j).k.add(pib.bid.size());
998 size_t s =
loc_ig_box.get(i).bid.get(j).k.last();
1003 add_loc_eg_box(le_sub,
1012 volume_linked += pib.bid.last().ebox.getVolumeKey();
1021 size_t s =
loc_ig_box.get(i).bid.get(j).k.get(0);
1022 pib.bid.resize(
dec.getLocalNEGhost(k));
1025 pib.bid.get(s).sub =
dec.getLocalEGhostSub(k,s);
1026 pib.bid.get(s).cmb =
loc_ig_box.get(i).bid.get(j).cmb;
1027 pib.bid.get(s).cmb.sign_flip();
1028 pib.bid.get(s).k = j;
1029 pib.bid.get(s).initialized =
true;
1030 pib.bid.get(s).sub_gdb_ext = k;
1046 for (
size_t i = 0 ; i < dim ; i++)
1049 {std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" distributed grids with size smaller than 2 are not supported\n";}
1060 for (
size_t i = 0 ; i < dim ; i++)
1063 {std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" error the simulation domain is invalid\n";}
1089 for (
size_t i = 0 ; i < n_grid ; i++)
1098 for (
size_t j = 0 ; j < dim ; j++)
1116 cd_sm.setDimensions(cd_old,ext);
1132 getCellDecomposerPar<dim>(c_g,
g_sz,bc);
1147 for (
size_t i = 0 ; i < dim ; i++) {this->g_sz[i] =
g_sz[i];}
1157 for (
size_t i = 0 ; i < dim ; i++)
1158 {div[i] = openfpm::math::round_big_2(pow(n_sub,1.0/dim));}
1160 if (g_dist.size(0) != 0)
1162 for (
size_t i = 0 ; i < dim ; i++)
1163 {div[i] = g_dist.size(i);}
1168 dec.decompose(dec_options::DEC_SKIP_ICELL);
1200 for (
size_t i = 0 ; i < dim ; i++) {this->g_sz[i] =
g_sz[i];}
1242 for (
size_t i = 0 ; i < dim ; i++)
1258 this->v_sub_unit_factor = n_sub;
1261 void reset_ghost_structures()
1299 static const unsigned int dims = dim;
1343 return cd_sm.getCellBox().getHigh(i);
1365 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,T::max_prop>>(func);
1374 template<
unsigned int p>
1378 {
loc_grid.get(i).template setBackgroundValue<p>(bv);}
1394 {lins +=
loc_grid.get(i).size_inserted();}
1439 check_new(
this,8,GRID_DIST_EVENT,4);
1442 for (
size_t i = 0 ; i < dim ; i++)
1456 template<
typename H>
1463 check_new(
this,8,GRID_DIST_EVENT,4);
1466 size_t ext_dim[dim];
1467 for (
size_t i = 0 ; i < dim ; i++) {ext_dim[i] = g.getGridInfoVoid().size(i) + ext.
getKP1().
get(i) + ext.
getKP2().
get(i);}
1479 for (
size_t i = 0 ; i < dim ; i++)
1483 if (g.getDecomposition().periodicity(i) == NON_PERIODIC)
1485 this->domain.
setLow(i,g.getDomain().getLow(i) - ext.
getLow(i) * g.spacing(i) - g.spacing(i) / 2.0);
1486 this->domain.
setHigh(i,g.getDomain().getHigh(i) + ext.
getHigh(i) * g.spacing(i) + g.spacing(i) / 2.0);
1490 this->domain.
setLow(i,g.getDomain().getLow(i) - ext.
getLow(i) * g.spacing(i));
1491 this->domain.
setHigh(i,g.getDomain().getHigh(i) + ext.
getHigh(i) * g.spacing(i));
1495 dec.setParameters(g.getDecomposition(),
ghost,this->domain);
1510 template<
typename Decomposition2>
1512 const size_t (&
g_sz)[dim],
1518 check_new(
this,8,GRID_DIST_EVENT,4);
1541 check_new(
this,8,GRID_DIST_EVENT,4);
1586 template<
typename Decomposition2>
1619 check_new(
this,8,GRID_DIST_EVENT,4);
1675 check_new(
this,8,GRID_DIST_EVENT,4);
1702 check_new(
this,8,GRID_DIST_EVENT,4);
1745 check_new(
this,8,GRID_DIST_EVENT,4);
1756 this->use_bx_def =
true;
1767 check_valid(
this,8);
1780 check_valid(
this,8);
1793 check_valid(
this,8);
1806 check_valid(
this,8);
1819 check_valid(
this,8);
1834 check_valid(
this,8);
1836 for (
size_t i = 0 ; i < dim ; i++)
1838 if (gk.
get(i) < 0 || gk.
get(i) >= (
long int)
g_sz[i])
1853 check_valid(
this,8);
1859 total +=
gdb_ext.get(i).Dbox.getVolumeKey();
1873 check_valid(
this,8);
1879 total +=
gdb_ext.get(i).GDbox.getVolumeKey();
1894 check_valid(
this,8);
1907 check_valid(
this,8);
1925 v_cl.
recv(0,0,&size_r,
sizeof(
size_t));
1950 decltype(device_grid::type_of_subiterator()),
1955 check_valid(
this,8);
1964 decltype(device_grid::type_of_subiterator()),
1992 template<
typename lambda_t2>
1993 void setPoints(lambda_t2 f2)
1995 auto it = getGridIteratorGPU();
2006 template<
typename lambda_t2>
2009 auto it = getGridIteratorGPU(k1,k2);
2019 template<
typename lambda_t1,
typename lambda_t2>
2020 void addPoints(lambda_t1 f1, lambda_t2 f2)
2022 auto it = getGridIteratorGPU();
2023 it.setGPUInsertBuffer(1);
2035 template<
typename lambda_t1,
typename lambda_t2>
2038 auto it = getGridIteratorGPU(k1,k2);
2039 it.setGPUInsertBuffer(1);
2075 getGridIteratorGPU()
2113 for (
size_t i = 0; i < dim; i++)
2129 decltype(device_grid::type_of_subiterator()),FREE>
2133 check_valid(
this,8);
2142 decltype(device_grid::type_of_subiterator()),
2155 template<
unsigned int Np>
2163 check_valid(
this,8);
2185 decltype(device_grid::type_of_iterator()),
2190 check_valid(
this,8);
2193 for (
size_t i = 0 ; i < dim ; i++)
2197 decltype(device_grid::type_of_iterator()),
2220 check_valid(
this,8);
2263 check_valid(
this,8);
2276 loc_grid.get(i).removeUnusedBuffers();
2303 check_valid(
this,8);
2321 check_valid(
this,8);
2327 template<
typename ... v_reduce>
2328 void flush(flush_type
opt = flush_type::FLUSH_ON_HOST)
2349 check_valid(
this,8);
2369 -> decltype(
loc_grid.get(v1.getSub()).template insert<p>(v1.getKey()))
2372 check_valid(
this,8);
2375 return loc_grid.get(v1.getSub()).template insert<p>(v1.getKey());
2396 -> decltype(
loc_grid.get(v1.getSub()).template insertFlush<p>(v1.getKey()))
2399 check_valid(
this,8);
2402 return loc_grid.get(v1.getSub()).template insertFlush<p>(v1.getKey());
2422 -> decltype(
loc_grid.get(v1.getSub()).insertFlush(v1.getKey()))
2425 check_valid(
this,8);
2428 return loc_grid.get(v1.getSub()).insertFlush(v1.getKey());
2439 template <
unsigned int p,
typename bg_key>
2441 ->
typename std::add_lvalue_reference<decltype(
loc_grid.get(v1.getSub()).template get<p>(v1.getKey()))>::type
2444 check_valid(
this,8);
2446 return loc_grid.get(v1.getSub()).template get<p>(v1.getKey());
2458 template <
unsigned int p,
typename bg_key>
2460 -> decltype(
loc_grid.get(v1.getSub()).template get<p>(v1.getKey()))
2463 check_valid(
this,8);
2465 return loc_grid.get(v1.getSub()).template get<p>(v1.getKey());
2476 template <
unsigned int p = 0>
2478 -> decltype(v1.getSub()->template get<p>(v1.getKey()))
2481 check_valid(
this,8);
2483 return v1.getSub()->template get<p>(v1.getKey());
2494 template <
unsigned int p = 0>
2498 check_valid(
this,8);
2500 return v1.getSub()->template get<p>(v1.getKey());
2511 template <
unsigned int p = 0>
2515 check_valid(
this,8);
2517 return loc_grid.get(v1.getSub()).template get<p>(v1.getKey());
2528 template <
unsigned int p = 0>
2532 check_valid(
this,8);
2534 return loc_grid.get(v1.getSub()).template get<p>(v1.getKey());
2545 template <
typename bg_key>
2549 check_valid(
this,8);
2553 for (
int i = 0 ; i < dim ; i++)
2568 template<
typename bg_key>
2582 template <
unsigned int p = 0,
typename bgkey>
2585 return this->
template get<p>(v1);
2596 template <
unsigned int p = 0,
typename bgkey>
2599 return this->
template get<p>(v1);
2610 check_valid(
this,8);
2643 template<
template<
typename,
typename>
class op,
int... prp>
void ghost_put()
2646 check_valid(
this,8);
2684 grid_dist_id<dim,St,T,Decomposition,Memory,device_grid> &
copy(
grid_dist_id<dim,St,T,Decomposition,Memory,device_grid> & g,
bool use_memcpy =
true)
2686 if (T::noPointers() ==
true && use_memcpy)
2692 long int start = gs_src.LinId(
gdb_ext.get(i).Dbox.getKP1());
2693 long int stop = gs_src.LinId(
gdb_ext.get(i).Dbox.getKP2());
2695 if (stop < start) {
continue;}
2697 void * dst =
static_cast<void *
>(
static_cast<char *
>(this->
get_loc_grid(i).getPointer()) + start*
sizeof(T));
2698 void * src =
static_cast<void *
>(
static_cast<char *
>(g.
get_loc_grid(i).getPointer()) + start*
sizeof(T));
2700 memcpy(dst,src,
sizeof(T) * (stop + 1 - start));
2718 auto Cp = it.template getStencil<0>();
2720 dst.insert_o(Cp) = src.get_o(Cp);
2742 grid_dist_id<dim,St,T,Decomposition,Memory,device_grid> &
copy_sparse(
grid_dist_id<dim,St,T,Decomposition,Memory,device_grid> & g,
bool use_memcpy =
true)
2764 return cd_sm.getCellBox().getP2();
2780 check_valid(
this,8);
2783 size_t sub_id = k.getSub();
2788 k_glob = k_glob +
gdb_ext.get(sub_id).origin;
2803 CellDecomposer_sm<dim, St, shift<dim,St>> cdsm;
2808 cdsm.setDimensions(
dec.getDomain(),
dec.getDistGrid().getSize(), 0);
2813 for (
size_t i = 0; i < dist.getNOwnerSubSubDomains() ; i++)
2815 dist.getSubSubDomainPos(i,p);
2816 dec.setSubSubDomainComputationCost(dist.getOwnerSubSubDomain(i) , 1 + md.resolution(p));
2819 dec.computeCommunicationAndMigrationCosts(ts);
2821 dist.setDistTol(md.distributionTol());
2828 template<
unsigned int prop_src,
unsigned int prop_dst,
unsigned int stencil_size,
unsigned int N,
typename lambda_f,
typename ... ArgsT >
2836 for (
int j = 0 ; j < dim ; j++)
2838 base.
setLow(j,(
long int)start.
get(j) - (
long int)
gdb_ext.get(i).origin.get(j));
2844 bool overlap = dom.
Intersect(base,inte);
2846 if (overlap ==
true)
2848 loc_grid.get(i).template conv<prop_src,prop_dst,stencil_size>(stencil,inte.
getKP1(),inte.
getKP2(),func,args...);
2857 template<
unsigned int prop_src,
unsigned int prop_dst,
unsigned int stencil_size,
typename lambda_f,
typename ... ArgsT >
2865 for (
int j = 0 ; j < dim ; j++)
2867 base.
setLow(j,(
long int)start.
get(j) - (
long int)
gdb_ext.get(i).origin.get(j));
2873 bool overlap = dom.
Intersect(base,inte);
2875 if (overlap ==
true)
2877 loc_grid.get(i).template conv_cross<prop_src,prop_dst,stencil_size>(inte.
getKP1(),inte.
getKP2(),func,args...);
2886 template<
unsigned int prop_src,
unsigned int prop_dst,
unsigned int stencil_size,
typename lambda_f,
typename ... ArgsT >
2894 for (
int j = 0 ; j < dim ; j++)
2896 base.
setLow(j,(
long int)start.
get(j) - (
long int)
gdb_ext.get(i).origin.get(j));
2902 bool overlap = dom.
Intersect(base,inte);
2904 if (overlap ==
true)
2906 loc_grid.get(i).template conv_cross_b<prop_src,prop_dst,stencil_size>(inte.
getKP1(),inte.
getKP2(),func,args...);
2915 template<
unsigned int stencil_size,
typename v_type,
typename lambda_f,
typename ... ArgsT >
2923 for (
int j = 0 ; j < dim ; j++)
2925 base.
setLow(j,(
long int)start.
get(j) - (
long int)
gdb_ext.get(i).origin.get(j));
2931 bool overlap = dom.
Intersect(base,inte);
2933 if (overlap ==
true)
2935 loc_grid.get(i).template conv_cross_ids<stencil_size,v_type>(inte.
getKP1(),inte.
getKP2(),func,args...);
2944 template<
unsigned int prop_src1,
unsigned int prop_src2,
unsigned int prop_dst1,
unsigned int prop_dst2,
unsigned int stencil_size,
unsigned int N,
typename lambda_f,
typename ... ArgsT >
2952 for (
int j = 0 ; j < dim ; j++)
2954 base.
setLow(j,(
long int)start.
get(j) - (
long int)
gdb_ext.get(i).origin.get(j));
2960 bool overlap = dom.
Intersect(base,inte);
2962 if (overlap ==
true)
2964 loc_grid.get(i).template conv2<prop_src1,prop_src2,prop_dst1,prop_dst2,stencil_size>(stencil,inte.
getKP1(),inte.
getKP2(),func,create_vcluster().rank(),args...);
2973 template<
unsigned int prop_src1,
unsigned int prop_src2,
unsigned int prop_dst1,
unsigned int prop_dst2,
unsigned int stencil_size,
typename lambda_f,
typename ... ArgsT >
2981 for (
int j = 0 ; j < dim ; j++)
2983 base.
setLow(j,(
long int)start.
get(j) - (
long int)
gdb_ext.get(i).origin.get(j));
2989 bool overlap = dom.
Intersect(base,inte);
2991 if (overlap ==
true)
2993 loc_grid.get(i).template conv2<prop_src1,prop_src2,prop_dst1,prop_dst2,stencil_size>(inte.
getKP1(),inte.
getKP2(),func,args...);
3002 template<
unsigned int prop_src1,
unsigned int prop_dst1,
unsigned int stencil_size,
typename lambda_f,
typename ... ArgsT >
3010 for (
int j = 0 ; j < dim ; j++)
3012 base.
setLow(j,(
long int)start.
get(j) - (
long int)
gdb_ext.get(i).origin.get(j));
3018 bool overlap = dom.
Intersect(base,inte);
3020 if (overlap ==
true)
3022 loc_grid.get(i).template conv<prop_src1,prop_dst1,stencil_size>(inte.
getKP1(),inte.
getKP2(),func,args...);
3031 template<
unsigned int prop_src1,
unsigned int prop_src2,
unsigned int prop_dst1,
unsigned int prop_dst2,
unsigned int stencil_size,
typename lambda_f,
typename ... ArgsT >
3039 for (
int j = 0 ; j < dim ; j++)
3041 base.
setLow(j,(
long int)start.
get(j) - (
long int)
gdb_ext.get(i).origin.get(j));
3047 bool overlap = dom.
Intersect(base,inte);
3049 if (overlap ==
true)
3051 loc_grid.get(i).template conv2_b<prop_src1,prop_src2,prop_dst1,prop_dst2,stencil_size>(inte.
getKP1(),inte.
getKP2(),func,args...);
3060 template<
unsigned int prop_src1,
unsigned int prop_src2,
unsigned int prop_src3,
3061 unsigned int prop_dst1,
unsigned int prop_dst2,
unsigned int prop_dst3,
3062 unsigned int stencil_size,
typename lambda_f,
typename ... ArgsT >
3070 for (
int j = 0 ; j < dim ; j++)
3072 base.
setLow(j,(
long int)start.
get(j) - (
long int)
gdb_ext.get(i).origin.get(j));
3078 bool overlap = dom.
Intersect(base,inte);
3080 if (overlap ==
true)
3082 loc_grid.get(i).template conv3_b<prop_src1,prop_src2,prop_src3,prop_dst1,prop_dst2,prop_dst3,stencil_size>(inte.
getKP1(),inte.
getKP2(),func,args...);
3087 template<
typename NNtype>
3088 void findNeighbours()
3100 template<
unsigned int prop_src1,
unsigned int prop_src2,
unsigned int prop_dst1,
unsigned int prop_dst2,
unsigned int stencil_size,
typename lambda_f,
typename ... ArgsT >
3108 for (
int j = 0 ; j < dim ; j++)
3110 base.
setLow(j,(
long int)start.
get(j) - (
long int)
gdb_ext.get(i).origin.get(j));
3116 bool overlap = dom.
Intersect(base,inte);
3118 if (overlap ==
true)
3120 loc_grid.get(i).template conv_cross2<prop_src1,prop_src2,prop_dst1,prop_dst2,stencil_size>(inte.
getKP1(),inte.
getKP2(),func,args...);
3136 bool write(std::string output,
size_t opt = VTK_WRITER | FORMAT_BINARY )
3139 check_valid(
this,8);
3142 file_type ft = file_type::ASCII;
3144 if (
opt & FORMAT_BINARY)
3145 {ft = file_type::BINARY;}
3153 if (
opt & PRINT_GHOST)
3175 for (
int j = 0 ; j < dim ; j++)
3178 offset =
gdb_ext.get(i).origin;
3198 bool write_frame(std::string output,
size_t i,
size_t opt = VTK_WRITER | FORMAT_ASCII)
3201 check_valid(
this,8);
3203 file_type ft = file_type::ASCII;
3205 if (
opt & FORMAT_BINARY)
3206 ft = file_type::BINARY;
3257 gdb_ext.get(i).Dbox.getKP2());
3267 template<
unsigned int Np>
3293 size_t tot_volume = 0;
3295 std::cout <<
"-------- External Ghost boxes ---------- " << std::endl;
3299 std::cout <<
"Processor: " <<
eg_box.get(i).prc <<
" Boxes:" << std::endl;
3301 for (
size_t j = 0; j <
eg_box.get(i).bid.
size() ; j++)
3303 std::cout <<
" Box: " <<
eg_box.get(i).bid.get(j).g_e_box.toString() <<
" Id: " <<
eg_box.get(i).bid.get(j).g_id << std::endl;
3304 tot_volume +=
eg_box.get(i).bid.get(j).g_e_box.getVolumeKey();
3308 std::cout <<
"TOT volume external ghost " << tot_volume << std::endl;
3310 std::cout <<
"-------- Internal Ghost boxes ---------- " << std::endl;
3315 std::cout <<
"Processor: " <<
ig_box.get(i).prc <<
" Boxes:" << std::endl;
3317 for (
size_t j = 0 ; j <
ig_box.get(i).bid.
size() ; j++)
3319 std::cout <<
" Box: " <<
ig_box.get(i).bid.get(j).box.toString() <<
" Id: " <<
ig_box.get(i).bid.get(j).g_id << std::endl;
3320 tot_volume +=
ig_box.get(i).bid.get(j).box.getVolumeKey();
3324 std::cout <<
"TOT volume internal ghost " << tot_volume << std::endl;
3388 for(
int j = 0 ; j < dim ; j++)
3389 {p_dw.
get(j) = mvof.get(i).dw.get(j);}
3406 for(
int j = 0 ; j < dim ; j++)
3407 {p_up.
get(j) = mvof.get(i).up.get(j);}
3419 template<
typename stencil_type>
3442 T> ca(
loc_grid.get(0).getBackgroundValue(),bv);
3444 boost::mpl::for_each_ref<boost::mpl::range_c<int,0,T::max_prop>>(ca);
3446 if (!(
opt & NO_GDB_EXT_SWITCH))
3466 reset_ghost_structures();
3477 inline void save(
const std::string & filename)
const
3489 inline void load(
const std::string & filename)
3501 size_t opt_ = NO_GDB_EXT_SWITCH;
3502 if (std::is_same<Memory,CudaMemory>::value ==
true)
3503 {opt_ |= RUN_ON_DEVICE;}
3517 for (
int j = 0 ; j < dim ; j++)
3522 while (it_src.isNext())
3524 auto key = it_src.get();
3527 for (
int j = 0 ; j < dim ; j++)
3528 {key_dst.
set_d(j,key.get(j) + orig.
get(j) + kp1.
get(j));}
3535 dg.template hostToDevice<0>();
3545 template <
typename stencil = no_stencil>
3573 std::cout <<
"-- REPORT --" << std::endl;
3574 #ifdef ENABLE_GRID_DIST_ID_PERF_STATS
3575 std::cout <<
"Processor: " <<
v_cl.
rank() <<
" Time spent in packing data: " << tot_pack << std::endl;
3576 std::cout <<
"Processor: " <<
v_cl.
rank() <<
" Time spent in sending and receving data: " << tot_sendrecv << std::endl;
3577 std::cout <<
"Processor: " <<
v_cl.
rank() <<
" Time spent in merging: " << tot_merge << std::endl;
3578 std::cout <<
"Processor: " <<
v_cl.
rank() <<
" Time spent in local merging: " << tot_loc_merge << std::endl;
3581 std::cout <<
"Enable ENABLE_GRID_DIST_ID_PERF_STATS if you want to activate this feature" << std::endl;
3588 #ifdef ENABLE_GRID_DIST_ID_PERF_STATS
3594 std::cout <<
"Enable ENABLE_GRID_DIST_ID_PERF_STATS if you want to activate this feature" << std::endl;
3606 void setNumberOfInsertPerThread(
size_t n_ins)
3611 template<
typename func_t,
typename it_t,
typename ... args_t>
3612 void iterateGridGPU(it_t & it, args_t ... args)
3617 {
loc_grid.get(i).setGPUInsertBuffer(0ul,1ul);}
3619 while(it.isNextGrid())
3623 size_t i = it.getGridId();
3625 auto ite =
loc_grid.get(i).getGridGPUIterator(b.getKP1int(),b.getKP2int());
3627 loc_grid.get(i).setGPUInsertBuffer(ite.nblocks(),ite.nthrs());
3628 loc_grid.get(i).initializeGPUInsertBuffer();
3630 ite_gpu_dist<dim> itd = ite;
3632 for (
int j = 0 ; j < dim ; j++)
3634 itd.origin.set_d(j,
gdb_ext.get(i).origin.get(j));
3635 itd.start_base.set_d(j,0);
3638 CUDA_LAUNCH((grid_apply_functor),ite,
loc_grid.get(i).toKernel(),itd,func_t(),args...);
3659 bout -=
gdb_ext.get(i).origin;
3673 template<
unsigned int ... prp>
void deviceToHost()
3677 loc_grid.get(i).template deviceToHost<prp ...>();
3684 template<
unsigned int ... prp>
void hostToDevice()
3688 loc_grid.get(i).template hostToDevice<prp ...>();
3702 template<
unsigned int dim,
typename St,
typename T,
typename Memory = HeapMemory,
typename Decomposition = CartDecomposition<dim,St> >
3705 template<
unsigned int dim,
typename St,
typename T,
typename Memory = HeapMemory,
typename Decomposition = CartDecomposition<dim,St>>
3708 template<
unsigned int dim,
typename St,
typename T,
typename devg,
typename Memory = HeapMemory,
typename Decomposition = CartDecomposition<dim,St>>
3712 template<
unsigned int dim,
typename St,
typename T,
typename Memory = CudaMemory,
typename Decomposition = CartDecomposition<dim,St,CudaMemory,memory_traits_
inte> >
3715 template<
unsigned int dim,
typename St,
typename T,
typename Memory = CudaMemory,
typename Decomposition = CartDecomposition<dim,St,CudaMemory,memory_traits_
inte> >
3718 template<
unsigned int dim,
typename St,
typename T,
typename Memory = CudaMemory,
typename Decomposition = CartDecomposition<dim,St,CudaMemory,memory_traits_
inte> >
Point< dim, T > getP1() const
Get the point p1.
__device__ __host__ T getLow(int i) const
get the i-coordinate of the low bound interval of the box
__device__ __host__ bool Intersect(const Box< dim, T > &b, Box< dim, T > &b_out) const
Intersect.
void zero()
Set p1 and p2 to 0.
__device__ __host__ T getHigh(int i) const
get the high interval of the box
grid_key_dx< dim > getKP1() const
Get the point p1 as grid_key_dx.
void magnify_fix_P1(T mg)
Magnify the box by a factor keeping fix the point P1.
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
grid_key_dx< dim > getKP2() const
Get the point p12 as grid_key_dx.
bool isValid() const
Check if the Box is a valid box P2 >= P1.
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
This class define the domain decomposition interface.
bool isInvalidGhost()
check if the Ghost is valid
This class allocate, and destroy CPU memory.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
void execute()
Execute all the requests.
size_t rank()
Get the process unit id.
size_t size()
Get the total number of processors.
size_t getProcessUnitID()
Get the process unit id.
gpu::ofp_context_t & getGpuContext(bool iw=true)
If nvidia cuda is activated return a gpu context.
size_t getProcessingUnits()
Get the total number of processors.
bool recv(size_t proc, size_t tag, void *v, size_t sz)
Recv data from a processor.
bool send(size_t proc, size_t tag, const void *mem, size_t sz)
Send data to a processor.
Implementation of VCluster class.
bool SGather(T &send, S &recv, size_t root)
Semantic Gather, gather the data from all processors into one node.
bool SSendRecv(openfpm::vector< T > &send, S &recv, openfpm::vector< size_t > &prc_send, openfpm::vector< size_t > &prc_recv, openfpm::vector< size_t > &sz_recv, size_t opt=NONE)
Semantic Send and receive, send the data to processors and receive from the other processors.
Distributed linearized key.
This class is an helper for the communication of grid_dist_id.
void ghost_get_(const openfpm::vector< ip_box_grid< dim >> &ig_box, const openfpm::vector< ep_box_grid< dim >> &eg_box, const openfpm::vector< i_lbox_grid< dim >> &loc_ig_box, const openfpm::vector< e_lbox_grid< dim >> &loc_eg_box, const openfpm::vector< GBoxes< device_grid::dims >> &gdb_ext, const openfpm::vector< e_box_multi< dim >> &eb_gid_list, bool use_bx_def, openfpm::vector< grid_cpu< dim, T > > &loc_grid, const grid_sm< dim, void > &ginfo, std::unordered_map< size_t, size_t > &g_id_to_external_ghost_box, size_t opt)
It fill the ghost part of the grids.
size_t opt
Receiving option.
void ghost_put_(CartDecomposition< dim, St > &dec, const openfpm::vector< ip_box_grid< dim >> &ig_box, const openfpm::vector< ep_box_grid< dim >> &eg_box, const openfpm::vector< i_lbox_grid< dim >> &loc_ig_box, const openfpm::vector< e_lbox_grid< dim >> &loc_eg_box, const openfpm::vector< GBoxes< device_grid::dims >> &gdb_ext, openfpm::vector< grid_cpu< dim, T > > &loc_grid, openfpm::vector< std::unordered_map< size_t, size_t >> &g_id_to_internal_ghost_box)
It merge the information in the ghost with the real information.
Given the decomposition it create an iterator.
Given the decomposition it create an iterator.
This is a distributed grid.
grid_dist_id(const size_t(&g_sz)[dim], const Box< dim, St > &domain, const Ghost< dim, long int > &g, const periodicity< dim > &p, openfpm::vector< Box< dim, long int >> &bx_def)
It construct a grid on the full domain restricted to the set of boxes specified.
grid_dist_id(const grid_dist_id< dim, St, H, typename Decomposition::base_type, Memory, grid_cpu< dim, H >> &g, const Ghost< dim, long int > &gh, Box< dim, size_t > ext)
This constructor is special, it construct an expanded grid that perfectly overlap with the previous.
grid_dist_iterator< dim, device_grid, decltype(device_grid::type_of_subiterator()), FREE > getOldDomainIterator() const
It return an iterator that span the full grid domain (each processor span its local domain)
void conv_cross2(grid_key_dx< 3 > start, grid_key_dx< 3 > stop, lambda_f func, ArgsT ... args)
apply a convolution using the stencil N
Point< dim, St > getPos(const grid_dist_key_dx< dim, bg_key > &v1)
Get the reference of the selected element.
openfpm::vector< std::string > prp_names
properties names
void setBackgroundValue(T &bv)
set the background value
grid_sm< dim, void > ginfo_v
Grid informations object without type.
void set_for_adjustment(size_t sub_id, const Box< dim, St > &sub_domain_other, const comb< dim > &cmb, Box< dim, long int > &ib, Ghost< dim, long int > &g)
this function is for optimization of the ghost size
Decomposition & getDecomposition()
Get the object that store the information about the decomposition.
void InitializeDecomposition(const size_t(&g_sz)[dim], const size_t(&bc)[dim], const grid_sm< dim, void > &g_dist=grid_sm< dim, void >())
Initialize the grid.
const device_grid & get_loc_grid(size_t i) const
Get the i sub-domain grid.
bool init_e_g_box
Flag that indicate if the external ghost box has been initialized.
auto get(const grid_dist_lin_dx &v1) -> decltype(loc_grid.get(v1.getSub()).template get< p >(v1.getKey()))
Get the reference of the selected element.
grid_sm< dim, T > ginfo
Grid informations object.
void conv2_b(grid_key_dx< dim > start, grid_key_dx< dim > stop, lambda_f func, ArgsT ... args)
apply a convolution on 2 property on GPU
grid_dist_iterator_sub< dim, device_grid > getSubDomainIterator(const long int(&start)[dim], const long int(&stop)[dim]) const
It return an iterator that span the grid domain only in the specified part.
void conv2(grid_key_dx< dim > start, grid_key_dx< dim > stop, lambda_f func, ArgsT ... args)
apply a convolution on 2 property on GPU
void removeUnusedBuffers()
Eliminate many internal temporary buffer you can use this between flushes if you get some out of memo...
openfpm::vector< ip_box_grid< dim > > ig_box
Internal ghost boxes in grid units.
const grid_sm< dim, T > & getGridInfo() const
Get an object containing the grid informations.
void InitializeCellDecomposer(const CellDecomposer_sm< dim, St, shift< dim, St >> &cd_old, const Box< dim, size_t > &ext)
Initialize the Cell decomposer of the grid enforcing perfect overlap of the cells.
grid_dist_id(const size_t(&g_sz)[dim], const Box< dim, St > &domain, const Ghost< dim, St > &g, size_t opt=0)
size_t size_local_inserted() const
Return the local total number of points inserted in the grid.
size_t v_sub_unit_factor
Number of sub-sub-domain for each processor.
void map(size_t opt=0)
It move all the grid parts that do not belong to the local processor to the respective processor.
const CellDecomposer_sm< dim, St, shift< dim, St > > & getCellDecomposer() const
Return the cell decomposer.
grid_dist_id(Decomposition &&dec, const size_t(&g_sz)[dim], const Ghost< dim, long int > &g)
grid_dist_id(const Decomposition &dec, const size_t(&g_sz)[dim], const Ghost< dim, long int > &g)
Memory memory_type
Type of Memory.
device_grid d_grid
Which kind of grid the structure store.
openfpm::vector< size_t > gdb_ext_markers
Box< dim, St > domain
Domain.
size_t getLocalDomainSize() const
Get the total number of grid points for the calling processor.
openfpm::vector< e_lbox_grid< dim > > loc_eg_box
Local external ghost boxes in grid units.
const openfpm::vector< std::string > & getPropNames()
Set the properties names.
void flush_remove()
remove an element in the grid
void Create(openfpm::vector< Box< dim, long int >> &bx_def, const Ghost< dim, long int > &g, bool use_bx_def)
Create the grids on memory.
bool init_i_g_box
Flag that indicate if the internal ghost box has been initialized.
void conv_cross_b(grid_key_dx< 3 > start, grid_key_dx< 3 > stop, lambda_f func, ArgsT ... args)
apply a convolution using the stencil N
void conv_cross(grid_key_dx< 3 > start, grid_key_dx< 3 > stop, lambda_f func, ArgsT ... args)
apply a convolution using the stencil N
void ghost_get(size_t opt=0)
It synchronize the ghost parts.
void setBackgroundValue(const typename boost::mpl::at< typename T::type, boost::mpl::int_< p >>::type &bv)
set the background value
grid_dist_id(const size_t(&g_sz)[dim], const Box< dim, St > &domain, const Ghost< dim, long int > &g, const periodicity< dim > &p, size_t opt=0, const grid_sm< dim, void > &g_dec=grid_sm< dim, void >())
void conv_cross_ids(grid_key_dx< 3 > start, grid_key_dx< 3 > stop, lambda_f func, ArgsT ... args)
apply a convolution using the stencil N
static void * msg_alloc_external_box(size_t msg_i, size_t total_msg, size_t total_p, size_t i, size_t ri, void *ptr)
Call-back to allocate buffer to receive incoming objects (external ghost boxes)
Decomposition dec
Space Decomposition.
openfpm::vector< e_box_multi< dim > > eb_gid_list
device_grid device_grid_type
Type of device grid.
grid_dist_iterator< dim, device_grid, decltype(device_grid::type_of_iterator()), FIXED > getDomainGhostIterator() const
It return an iterator that span the grid domain + ghost part.
auto get(const grid_dist_lin_dx &v1) const -> decltype(loc_grid.get(v1.getSub()).template get< p >(v1.getKey()))
Get the reference of the selected element.
void create_ig_box()
Create per-processor internal ghost boxes list in grid units and g_id_to_external_ghost_box.
openfpm::vector< GBoxes< device_grid::dims > > gdb_ext
Extension of each grid: Domain and ghost + domain.
static Ghost< dim, St > convert_ghost(const Ghost< dim, long int > &gd, const CellDecomposer_sm< dim, St, shift< dim, St >> &cd_sm)
Convert a ghost from grid point units into continus space.
Ghost< dim, long int > ghost_int
Ghost expansion.
openfpm::vector< device_grid > & getLocalGrid()
Get the local grid.
auto get(const grid_dist_g_dx< device_grid > &v1) -> decltype(v1.getSub() ->template get< p >(v1.getKey()))
Get the reference of the selected element.
size_t size(size_t i) const
Return the total number of points in the grid.
auto getProp(const grid_dist_key_dx< dim, bgkey > &v1) const -> decltype(this->template get< p >(v1))
Get the reference of the selected element.
size_t g_sz[dim]
Size of the grid on each dimension.
grid_key_dx_iterator_sub< dim, no_stencil > get_loc_grid_iterator(size_t i)
Get the i sub-domain grid.
const Box< dim, St > getDomain() const
Get the domain where the grid is defined.
void setDecompositionGranularity(size_t n_sub)
Set the minimum number of sub-domain per processor.
void clear()
It delete all the points.
grid_dist_iterator< dim, device_grid, decltype(device_grid::template type_of_subiterator< stencil_offset_compute< dim, Np >>()), FREE, stencil_offset_compute< dim, Np > > getDomainIteratorStencil(const grid_key_dx< dim >(&stencil_pnt)[Np]) const
It return an iterator that span the full grid domain (each processor span its local domain)
void conv(grid_key_dx< dim > start, grid_key_dx< dim > stop, lambda_f func, ArgsT ... args)
apply a convolution on GPU
grid_dist_id(const grid_dist_id< dim, St, T, Decomposition, Memory, device_grid > &g)
Copy constructor.
grid_dist_id_iterator_dec< Decomposition, true > getGridGhostIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop)
void tagBoundaries()
construct link between current and the level up
Point< dim, St > getSpacing()
Get the spacing on each dimension.
bool existPoint(const grid_dist_key_dx< dim, bg_key > &v1) const
Check if the point exist.
const openfpm::vector< GBoxes< device_grid::dims > > & getLocalGridsInfo() const
It return the informations about the local grids.
size_t size() const
Return the total number of points in the grid.
static grid_dist_iterator_sub< dim, device_grid > type_of_subiterator()
This is a meta-function return which type of sub iterator a grid produce.
grid_dist_id_iterator_dec< Decomposition > getGridIterator()
~grid_dist_id()
Destructor.
void addComputationCosts(Model md=Model(), size_t ts=1)
Add the computation cost on the decomposition using a resolution function.
auto getProp(const grid_dist_key_dx< dim, bgkey > &v1) -> decltype(this->template get< p >(v1))
Get the reference of the selected element.
auto get(const grid_dist_g_dx< device_grid > &v1) const -> decltype(v1.getSub() ->template get< p >(v1.getKey()))
Get the reference of the selected element.
St spacing(size_t i) const
Get the spacing of the grid in direction i.
bool write(std::string output, size_t opt=VTK_WRITER|FORMAT_BINARY)
Write the distributed grid information.
grid_dist_iterator_sub< dim, device_grid > getSubDomainIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop) const
It return an iterator that span the grid domain only in the specified part.
bool use_bx_def
Indicate if we have to use bx_def to define the grid.
Vcluster & v_cl
Communicator class.
openfpm::vector< i_lbox_grid< dim > > loc_ig_box
Local internal ghost boxes in grid units.
void construct_link_up(self &grid_up, openfpm::vector< offset_mv< dim >> &mvof)
construct link between current and the level up
void ghost_put()
It synchronize the ghost parts.
const openfpm::vector< i_lbox_grid< dim > > & get_loc_ig_box()
Get the internal local ghost box.
size_t getLocalDomainWithGhostSize() const
Get the total number of grid points with ghost for the calling processor.
grid_dist_id(Decomposition &&dec, const size_t(&g_sz)[dim], const Ghost< dim, St > &ghost)
void create_local_eg_box()
Create per-processor external ghost boxes list in grid units.
Ghost< dim, St > ghost
Ghost expansion.
auto get(const grid_dist_key_dx< dim, bg_key > &v1) -> decltype(loc_grid.get(v1.getSub()).template get< p >(v1.getKey()))
Get the reference of the selected element.
grid_dist_id< dim, St, T, Decomposition, Memory, device_grid > & copy_sparse(grid_dist_id< dim, St, T, Decomposition, Memory, device_grid > &g, bool use_memcpy=true)
Copy the give grid into this grid.
bool init_local_i_g_box
Indicate if the local internal ghost box has been initialized.
void conv(int(&stencil)[N][dim], grid_key_dx< 3 > start, grid_key_dx< 3 > stop, lambda_f func, ArgsT ... args)
apply a convolution using the stencil N
openfpm::vector< device_grid > loc_grid_old
Old local grids.
void save(const std::string &filename) const
Save the grid state on HDF5.
Point< dim, St > getOffset(size_t i)
Get the point where it start the origin of the grid of the sub-domain i.
openfpm::vector< std::unordered_map< size_t, size_t > > g_id_to_internal_ghost_box
auto insertFlush(const grid_dist_key_dx< dim, bg_key > &v1) -> decltype(loc_grid.get(v1.getSub()).template insertFlush< p >(v1.getKey()))
insert an element in the grid
grid_dist_id(const Decomposition2 &dec, const size_t(&g_sz)[dim], const Ghost< dim, St > &ghost)
grid_key_dx_iterator_sub< dim, stencil_offset_compute< dim, Np >, typename device_grid::linearizer_type > get_loc_grid_iterator_stencil(size_t i, const grid_key_dx< dim >(&stencil_pnt)[Np])
Get the i sub-domain grid.
Vcluster & getVC()
Get the Virtual Cluster machine.
openfpm::vector< device_grid > loc_grid
Local grids.
openfpm::vector< GBoxes< device_grid::dims > > gdb_ext_global
Global gdb_ext.
auto insertFlush(const grid_dist_key_dx< dim, bg_key > &v1) -> decltype(loc_grid.get(v1.getSub()).insertFlush(v1.getKey()))
insert an element in the grid
openfpm::vector< size_t > recv_sz
Receiving size.
const Decomposition & getDecomposition() const
Get the object that store the information about the decomposition.
void check_domain(const Box< dim, St > &dom)
Check the domain is valid.
grid_dist_iterator< dim, device_grid, decltype(device_grid::type_of_subiterator()), FREE > getDomainIterator() const
It return an iterator that span the full grid domain (each processor span its local domain)
void remove_no_flush(const grid_dist_key_dx< dim, bg_key > &v1)
remove an element in the grid
bool isInside(const grid_key_dx< dim > &gk) const
Check that the global grid key is inside the grid domain.
grid_dist_id(const size_t(&g_sz)[dim], const Box< dim, St > &domain, const Ghost< dim, St > &g, const periodicity< dim > &p, size_t opt=0)
void remove(const grid_dist_key_dx< dim, bg_key > &v1)
remove an element in the grid
void load(const std::string &filename)
Reload the grid from HDF5 file.
size_t getN_loc_grid() const
Return the number of local grid.
void create_eg_box()
Create per-processor internal ghost box list in grid units.
auto get(const grid_dist_key_dx< dim, bg_key > &v1) const -> typename std::add_lvalue_reference< decltype(loc_grid.get(v1.getSub()).template get< p >(v1.getKey()))>::type
Get the reference of the selected element.
static const unsigned int dims
Number of dimensions.
bool init_fix_ie_g_box
Flag that indicate if the internal and external ghost box has been fixed.
Box< dim, size_t > getDomain(size_t i)
Given a local sub-domain i with a local grid Domain + ghost return the part of the local grid that is...
void construct_link(self &grid_up, self &grid_dw)
construct link between levels
void construct_link_dw(self &grid_dw, openfpm::vector< offset_mv< dim >> &mvof)
construct link between current and the level down
openfpm::vector< ep_box_grid< dim > > eg_box
External ghost boxes in grid units.
void debugPrint()
It print the internal ghost boxes and external ghost boxes in global unit.
void create_local_ig_box()
Create local internal ghost box in grid units.
const openfpm::vector< i_lbox_grid< dim > > & get_ig_box()
Get the internal ghost box.
grid_dist_id(const size_t(&g_sz)[dim], const Box< dim, St > &domain, const Ghost< dim, long int > &g, size_t opt=0)
void InitializeStructures(const size_t(&g_sz)[dim], openfpm::vector< Box< dim, long int >> &bx, const Ghost< dim, long int > &g, bool use_bx_def)
Initialize the grid.
const grid_sm< dim, void > & getGridInfoVoid() const
Get an object containing the grid informations without type.
grid_dist_id(const Decomposition2 &dec, const size_t(&g_sz)[dim], const Ghost< dim, long int > &g)
Decomposition decomposition
Decomposition used.
void InitializeStructures(const size_t(&g_sz)[dim])
Initialize the grid.
std::unordered_map< size_t, size_t > g_id_to_external_ghost_box
CellDecomposer_sm< dim, St, shift< dim, St > > cd_sm
Structure that divide the space into cells.
void check_size(const size_t(&g_sz)[dim])
Check the grid has a valid size.
void conv3_b(grid_key_dx< dim > start, grid_key_dx< dim > stop, lambda_f func, ArgsT ... args)
apply a convolution on 2 property on GPU
bool is_staggered() const
Indicate that this grid is not staggered.
device_grid & get_loc_grid(size_t i)
Get the i sub-domain grid.
openfpm::vector< Box< dim, long int > > bx_def
Set of boxes that define where the grid is defined.
grid_dist_id_iterator_dec< Decomposition > getGridIterator(const grid_key_dx< dim > &start, const grid_key_dx< dim > &stop)
bool write_debug(std::string output)
Write all grids indigually.
openfpm::vector< HeapMemory > recv_mem_gg
Receiving buffer for particles ghost get.
openfpm::vector< GBoxes< device_grid::dims > > gdb_ext_old
Extension of each old grid (old): Domain and ghost + domain.
void InitializeCellDecomposer(const size_t(&g_sz)[dim], const size_t(&bc)[dim])
Initialize the Cell decomposer of the grid.
void conv2(int(&stencil)[N][dim], grid_key_dx< dim > start, grid_key_dx< dim > stop, lambda_f func, ArgsT ... args)
apply a convolution using the stencil N
size_t gpu_n_insert_thread
number of insert each GPU thread does
auto insert(const grid_dist_key_dx< dim, bg_key > &v1) -> decltype(loc_grid.get(v1.getSub()).template insert< p >(v1.getKey()))
insert an element in the grid
void setPropNames(const openfpm::vector< std::string > &names)
Set the properties names.
grid_key_dx< dim > getGKey(const grid_dist_key_dx< dim > &k) const
Convert a g_dist_key_dx into a global key.
grid_dist_id< dim, St, T, Decomposition, Memory, device_grid > & copy(grid_dist_id< dim, St, T, Decomposition, Memory, device_grid > &g, bool use_memcpy=true)
Copy the give grid into this grid.
bool init_local_e_g_box
Indicate if the local external ghost box has been initialized.
void getGlobalGridsInfo(openfpm::vector< GBoxes< device_grid::dims >> &gdb_ext_global) const
It gathers the information about local grids for all of the processors.
bool write_frame(std::string output, size_t i, size_t opt=VTK_WRITER|FORMAT_ASCII)
Write the distributed grid information.
Distributed grid iterator.
Distributed grid iterator.
Grid key for a distributed grid.
base_key & getKeyRef()
Get the reference key.
size_t getSub() const
Get the local grid.
base_key getKey() const
Get the key.
Distributed linearized key.
Declaration grid_key_dx_iterator_sub.
const grid_key_dx< dim > & get() const
Get the actual key.
bool isNext()
Check if there is the next element.
grid_key_dx is the key to access any element in the grid
void one()
Set to one the key.
__device__ __host__ void set_d(index_type i, index_type id)
Set the i index.
__device__ __host__ index_type get(index_type i) const
Get the i index.
void setDimensions(const size_t(&dims)[N])
Reset the dimension of the grid.
__device__ __host__ const size_t(& getSize() const)[N]
Return the size of the grid as an array.
__device__ __host__ size_t size() const
Return the size of the grid.
Implementation of 1-D std::vector like structure.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
Internal ghost box sent to construct external ghost box into the other processors.
size_t g_id
Global id of the internal ghost box.
comb< dim > cmb
In which sector live the box.
size_t r_sub
from which sub-domain this internal ghost box is generated (or with which sub-domain is overlapping)
Box< dim, size_t > bx
Box in global unit.
This structure store the Box that define the domain inside the Ghost + domain box.
Box< dim, long int > GDbox
Ghost + Domain ghost.
Point< dim, long int > origin
origin of GDbox in global grid coordinates
Box< dim, long int > Dbox
Domain box.
Position of the element of dimension d in the hyper-cube of dimension dim.
void sign_flip()
Flip the sign of the combination.
signed char c[dim]
Array that store the combination.
Structure to copy aggregates.
const e_src & block_data_src
encapsulated source object
__device__ __host__ copy_all_prop_sparse(const e_src &block_data_src, e_dst &block_data_dst, indexT local_id)
constructor
It store the information about the external ghost box.
size_t sub
sub_id in which sub-domain this box live
::Box< dim, long int > g_e_box
Box defining the external ghost box in global coordinates.
::Box< dim, long int > l_e_box
Box defining the external ghost box in local coordinates for gdb_ext.
comb< dim > cmb
Sector position of the external ghost.
it store a box, its unique id and the sub-domain from where it come from
comb< dim > cmb
Sector where it live the linked external ghost box.
::Box< dim, long int > box
Box.
size_t r_sub
r_sub id of the sub-domain in the sent list
It contain the offset necessary to move to coarser and finer level grids.
Point< dim, long int > up
offset to move up on an upper grid (coarse)
Point< dim, long int > dw
offset to move on the lower grid (finer)
this class is a functor for "for_each" algorithm
Structure for stencil iterator.